Geometric Transformations
Transformations are very fundamental in computer graphics. They are used for Object Modelling, Viewing, and Projection.
Objects in a scene are a collection on points which have some location, orientation and size. These properties can be changed by Translations(\(\mathbf{T}\)), Rotations(\(\mathbf{R}\)), and Scaling (\(\mathbf{S}\)).
Homogeneous Coordinates
We can represent Rotation and Scaling as 2x2 matrices, but we cannot do so for Translation. There is non-linearity in Translation. To make Translation linear, we use Homogeneous Coordinates. This allows us to represent all 3 2D transformations as 3x3 matrices.
Proof that translation is non-linear
Let \(\mathbf{T}(p) = p + t\) be the translation of point \(p\) by vector \(t\). Then,
Hence, Translation is non-linear.
To convert a point \((x, y)\) to Homogeneous Coordinates, we do the following:
where \(w\) is a scaling factor. We can convert back to Cartesian Coordinates by dividing by \(w\). For linear transformations, embed the 2x2 matrix in a 3x3 matrix by adding a row and a column of 0s and a 1 in the bottom right corner.
2D Transformations in Homogeneous Coordinates
Transformation | Matrix |
---|---|
Translation | \(\begin{bmatrix}1 & 0 & t_x\\0 & 1 & t_y\\0 & 0 & 1\end{bmatrix}\) |
Rotation | \(\begin{bmatrix}\cos\theta & -\sin\theta & 0\\\sin\theta & \cos\theta & 0\\0 & 0 & 1\end{bmatrix}\) |
Scaling | \(\begin{bmatrix}s_x & 0 & 0\\0 & s_y & 0\\0 & 0 & 1\end{bmatrix}\) |
\(\text{Shear}_x\) (\(\phi\) is angle along axis) | \(\begin{bmatrix}1 & \tan{\phi} & 0\\0 & 1 & 0\\0 & 0 & 1\end{bmatrix}\) |
\(\text{Shear}_y\) | \(\begin{bmatrix}1 & 0 & 0\\ \tan{\phi} & 1 & 0\\0 & 0 & 1\end{bmatrix}\) |
Properties of Rotation Matrix
- Rows are orthogonal to each other
- Columns are orthogonal to each other
- \(\mathbf{R}^\top = \mathbf{R}^{-1}\)
- \(\det(\mathbf{R}) = 1\)
Make sure these are always satisfied.
Composition of Transformations
To apply multiple transformations to a point, we multiply the matrices of the transformations. The order of multiplication is important. For example, to rotate and then translate a point, we would do \(\mathbf{T}\mathbf{R}p\). Operations are evaluated from right to left.
Order of Multiplication
In general, Matrix Multiplication is not commutative. \(\mathbf{AB} \neq \mathbf{BA}\).
Transformation about Arbitrary Point
To rotate a point about an arbitrary point \((p_x, p_y)\), we first translate the point to the origin, rotate it, and then translate it back.
Similarly for scaling, we can perform the following:
Decomposition of Transformations
Any 2D matrix can be decomposed into a product of rotation, scale, rotation.
- Eigenvalue Decomposition: \(\mathbf{A} = \mathbf{R} \hspace{10px} \mathbf{S} \hspace{10px} \mathbf{R}^{\top}\)
Note
Eigenvalue Decomposition only works for symmetric matrices.
Info
- \(\mathbf{R}^{\top}\): Rotate the object to X and Y axes.
- \(\mathbf{S}\): Scale the object.
- \(\mathbf{R}\): Rotate the object back to its original orientation.
In a way it's directional scaling.
-
SVD Decomposition: \(\mathbf{A} = \mathbf{U} \hspace{10px} \mathbf{S} \hspace{10px} \mathbf{V}^{\top}\)
-
Paeth Decomposition: Applies only to rotations. Uses shear to represent non-zero rotations. Very useful in raster image rotations.
3D Transformations
Properties which were applicable in 2D transformations are also applicable in 3D transformations. The only difference is that we have an additional axis.
Transformation | Matrix |
---|---|
Translation | \(\begin{bmatrix}1 & 0 & 0 & t_x\\0 & 1 & 0 & t_y\\0 & 0 & 1 & t_z\\0 & 0 & 0 & 1\end{bmatrix}\) |
Rotation about X-axis | \(\begin{bmatrix}1 & 0 & 0 & 0\\0 & \cos\theta & -\sin\theta & 0\\0 & \sin\theta & \cos\theta & 0\\0 & 0 & 0 & 1\end{bmatrix}\) |
Rotation about Y-axis | \(\begin{bmatrix}\cos\theta & 0 & \sin\theta & 0\\0 & 1 & 0 & 0\\-\sin\theta & 0 & \cos\theta & 0\\0 & 0 & 0 & 1\end{bmatrix}\) |
Rotation about Z-axis | \(\begin{bmatrix}\cos\theta & -\sin\theta & 0 & 0\\\sin\theta & \cos\theta & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{bmatrix}\) |
Scaling | \(\begin{bmatrix}s_x & 0 & 0 & 0\\0 & s_y & 0 & 0\\0 & 0 & s_z & 0\\0 & 0 & 0 & 1\end{bmatrix}\) |
Arbitrary Axis Rotation
Given 3 mutually orthogonal unit vectors \(\mathbf{u} = (x_u, y_u, z_u)\), \(\mathbf{v} = (x_v, y_v, z_v)\), \(\mathbf{w} = (x_w, y_w, z_w)\), \(R_{uvw}\) transforms the coordinate system from \(xyz\) to \(uvw\).
To rotate around arbitrary vector \(\mathbf{a} = (x_a, y_a, z_a)\)
- Form an orthonormal \(uvw\) coordinate system with \(w = \mathbf{a}\)
- Rotate \(uvw\) basis to canonical basis \(xyz\)
- Rotate about \(z\) axis by \(\phi\)
- Rotate back to \(uvw\) basis
Constructing a basis from a vector
- make \(w\) a unit vector \(w = \frac{a}{||a||}\)
- Choose any vector \(t\) not parallel to \(w\), and build \(u = \frac{t \times w}{||t \times w||}\)
- Complete the basis by \(v = w \times u\)
Transforming Normals
- Normals are very common in computer graphics, so we need a way to also transform surface normals.
- They do not transform the way surfaces do
- Let the surface points be transformed by the matrix \(\mathbf{M}\). Then the normal vectors are transformed by the the following
Proof of Transforming Normals
Say you have a point \(p\) and a normal \(n\) on a surface. The normal is perpendicular to the surface at that point, i.e.
If we transform the point to \(p' = \mathbf{M}p\), then the new normal \(n'\) should be perpendicular to the new surface at \(p'\), i.e.
Let the new normal be \(n' = \mathbf{N}n\). Then,
Since we already know that \(n^\top p = 0\), we can say that \(\mathbf{N}^\top \mathbf{M} = I\). Hence, \(\mathbf{N} = \mathbf{M}^{-\top}\).