Composite Transformations

This notebook introduces 3D geometrical composite transformations which are used in computer graphics.

Farhad Kamangar 2017

Preliminaries

One of the common tasks in computer graphics is to transform the coordinates from one coordinate system to another, for example from the world coordinates to the camera coordinates. These transformations can be efficiently handled using composite transformations. A composite transformation is two or more transformations performed one after the other.

Using the homogeneous coordinates we can combine multiple geometrical transformations into a single matrix representation. For example if we want to scale an object around some arbitrary point , $p$ then we can:

  • Calculate the translation matrix, $\left[ {\matrix{ T } } \right]$ which will translate point $p$ to the origin
  • Calculate the scale matrix $\left[ {\matrix{ S} } \right]$ to scale the object around the origin by the desired scale factors.
  • Calculate the inverse of the translation matrix Translate $\left[ {\matrix{ T } } \right]^{-1}$ to move the point $p$ back to its original position.
  • Multiply the sequence of the above three matrices to form a single composite matrix : $\left[ {\matrix{ C } } \right]=\left[ {\matrix{ T } } \right]^{-1}\left[ {\matrix{ S} } \right]\left[ {\matrix{ T } } \right]$

Below, are some preliminary operations which are useful in transforming a coordinate system to another coordinate system.

Rotate a vector around $x$ axis until it lies in the $xz$ plane

Given vector $\overrightarrow V = \left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right]$ ; Rotate $\overrightarrow V$ around $x$ axis such that after rotation it lies in the $xz$ plane

The matrix to perform this operation is:

$$\large {R_x} = \left[ {\matrix{ 1 & 0 & 0 & 0 \cr 0 & {{c \over {\sqrt {{b^2} + {c^2}} }}} & {{{ - b} \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & {{b \over {\sqrt {{b^2} + {c^2}} }}} & {{c \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]$$

It is clear that if we multiply the vector $\overrightarrow V$ by the matrix $R_x$ the vector will be rotated around the $x$ axis and it will lie in the $xz$ plane:

$$\large \overrightarrow V ' = {R_x}\overrightarrow V = \left[ {\matrix{ 1 & 0 & 0 & 0 \cr 0 & {{c \over {\sqrt {{b^2} + {c^2}} }}} & {{{ - b} \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & {{b \over {\sqrt {{b^2} + {c^2}} }}} & {{c \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]\left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right] = \left[ {\matrix{ a \cr 0 \cr {\sqrt {{b^2} + {c^2}} } \cr 1 \cr } } \right]$$

Notice that after the rotation the $x$ component of the vector does not change and the $y$ component of the vector will be 0.

Rotate a vector around $y$ axis until it lies in the $yz$ plane

Given vector $\overrightarrow V = \left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right]$ ; Rotate $\overrightarrow V$ around $y$ axis such that after rotation it lies in the $yz$ plane

The matrix to perform this operation is:

$$\large{R_y} = \left[ {\matrix{ {{c \over {\sqrt {{a^2} + {c^2}} }}} & 0 & {{{ - a} \over {\sqrt {{a^2} + {c^2}} }}} & 0 \cr 0 & 1 & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {c^2}} }}} & 0 & {{c \over {\sqrt {{a^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]$$

If we multiply the vector $\overrightarrow V$ by the matrix $R_y$ the vector will be rotated around the $y$ axis and it will lie in the $yz$ plane:

$$\large \overrightarrow V ' = {R_y}\overrightarrow V = \left[ {\matrix{ {{c \over {\sqrt {{a^2} + {c^2}} }}} & 0 & {{{ - a} \over {\sqrt {{a^2} + {c^2}} }}} & 0 \cr 0 & 1 & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {c^2}} }}} & 0 & {{c \over {\sqrt {{a^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]\left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right] = \left[ {\matrix{ 0 \cr b \cr {\sqrt {{a^2} + {c^2}} } \cr 1 \cr } } \right]$$

Notice that after the rotation the $y$ component of the vector does not change and the $x$ component of the vector will be 0 which means that the vector lies in the $yz$ plane.

Rotate a vector around $z$ axis until it lies in the $yz$ plane

Given vector $\overrightarrow V = \left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right]$ ; Rotate $\overrightarrow V$ around $z$ axis such that after rotation it lies in the $yz$ plane

The matrix to perform this operation is:

$$\large {R_z} = \left[ {\matrix{ {{b \over {\sqrt {{a^2} + {b^2}} }}} & {{{ - a} \over {\sqrt {{a^2} + {b^2}} }}} & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {b^2}} }}} & {{b \over {\sqrt {{a^2} + {b^2}} }}} & 0 & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]$$

If we multiply the vector $\overrightarrow V$ by the matrix $R_z$ the vector will be rotated around the $z$ axis and it will lie in the $yz$ plane:

$$\large \overrightarrow V ' = {R_z}\overrightarrow V = \left[ {\matrix{ {{b \over {\sqrt {{a^2} + {b^2}} }}} & {{{ - a} \over {\sqrt {{a^2} + {b^2}} }}} & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {b^2}} }}} & {{b \over {\sqrt {{a^2} + {b^2}} }}} & 0 & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]\left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right] = \left[ {\matrix{ 0 \cr {\sqrt {{a^2} + {b^2}} } \cr c \cr 1 \cr } } \right]$$

Notice that after the rotation the $z$ component of the vector does not change and the $x$ component of the vector will be 0 which means that the vector lies in the $yz$ plane.

Rotate a vector until it is aligned with the $z$ axis

Using the above transformations we can form a composite transformation that aligns a given vector $\overrightarrow V = \left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right]$ to align with the $z$ axis.

To do this we first rotate the the vector $\overrightarrow V$ around the $x$ axis until it lies in the $xz$ plane then we rotate the resulting vector around the $y$ axis until it is aligned with the $z$ axis.

From previous sections we know that the matrix to rotate vector $\overrightarrow V$ around the $x$ axis is: $$\large {R_x} = \left[ {\matrix{ 1 & 0 & 0 & 0 \cr 0 & {{c \over {\sqrt {{b^2} + {c^2}} }}} & {{{ - b} \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & {{b \over {\sqrt {{b^2} + {c^2}} }}} & {{c \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]$$

After the rotation around the $x$ axis the vector $\overrightarrow V'$ (which is the rotated version of the vector $\overrightarrow V$) will be $$\large \overrightarrow V ' = {R_x}\overrightarrow V = \left[ {\matrix{ 1 & 0 & 0 & 0 \cr 0 & {{c \over {\sqrt {{b^2} + {c^2}} }}} & {{{ - b} \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & {{b \over {\sqrt {{b^2} + {c^2}} }}} & {{c \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]\left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right] = \left[ {\matrix{ a \cr 0 \cr {\sqrt {{b^2} + {c^2}} } \cr 1 \cr } } \right]$$

Next, we need to rotate the vector $\overrightarrow V'$ around the $y$ axis until it is aligned with the $z$ axis. From previous sections we know the general form of a matrix to rotate a given vector around the $y$ axis until it lies in the $yz$ plane. In this case the vector that we need to rotate around y is the vector $\overrightarrow V' = \left[ {\matrix{ a \cr 0 \cr {\sqrt {{b^2} + {c^2}} } \cr 1 \cr } } \right]$

Thus, the matrix to rotate this vector around the $y$ axis is: $$\large {R_y} = \left[ {\matrix{ {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 & {{{ - a} \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 1 & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 & {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]$$

After this rotation the resulting vector $\overrightarrow V''$ will be: $$\large \overrightarrow V '' = {R_y}\overrightarrow V ' = \left[ {\matrix{ {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 & {{{ - a} \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 1 & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 & {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]\left[ {\matrix{ a \cr 0 \cr {\sqrt {{b^2} + {c^2}} } \cr 1 \cr } } \right] = \left[ {\matrix{ 0 \cr 0 \cr {\sqrt {{a^2} + {b^2} + {c^2}} } \cr 1 \cr } } \right]$$

Notice that the vector $\overrightarrow V''$ is aligned with the $z$ axis (both $x$ and $y$ components are zeros).

The final composite matrix to rotate a general vector $\overrightarrow V = \left[ {\matrix{ a \cr b \cr c \cr 1 \cr } } \right]$ such that it is aligned with the $z$ axis will be: $$\left[ {\matrix{ {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 & {{{ - a} \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 1 & 0 & 0 \cr {{a \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 & {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]\left[ {\matrix{ 1 & 0 & 0 & 0 \cr 0 & {{c \over {\sqrt {{b^2} + {c^2}} }}} & {{{ - b} \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & {{b \over {\sqrt {{b^2} + {c^2}} }}} & {{c \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right] = \left[ {\matrix{ {{{\sqrt {{b^2} + {c^2}} } \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & {{{ - ab} \over {\sqrt {{b^2} + {c^2}} \sqrt {{a^2} + {b^2} + {c^2}} }}} & {{{ - ac} \over {\sqrt {{b^2} + {c^2}} \sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & {{c \over {\sqrt {{b^2} + {c^2}} }}} & {{{ - b} \over {\sqrt {{b^2} + {c^2}} }}} & 0 \cr {{a \over {\sqrt {{a^2} + {b^2} + {c^2}} }}} & {{{b\sqrt {{b^2} + {c^2}} } \over {\sqrt {{b^2} + {c^2}} \sqrt {{a^2} + {b^2} + {c^2}} }}} & {{{c\sqrt {{b^2} + {c^2}} } \over {\sqrt {{b^2} + {c^2}} \sqrt {{a^2} + {b^2} + {c^2}} }}} & 0 \cr 0 & 0 & 0 & 1 \cr } } \right]$$