Further Transformations

Graphics 1 CMP-5010B

Dr. David Greenwood

February, 2022

Content

  • Inverse Rotations
  • Scaling, Shearing, and Reflection
  • Homogeneous Coordinates

Inverse Rotations

\[R^{-1}\]

Inverse Rotations

We commonly need to compute the inverse of a rotation, for example, in the hierarchical transformations in character animation skeletons.

Inverse Rotations

\[ \begin{aligned} v' &= R v \\ v &= R^{-1} v' \end{aligned} \]

Where \(R\) is the rotation matrix and \(v\) is a vertex.

Properties of Rotation Matrices

Rotation matrices are square.

Properties of Rotation Matrices

The determinant of a rotation matrix is 1.

  • because: \(\cos^2 \alpha + \sin^2 \alpha = 1\)
  • hint: think about the radius in the unit circle

Properties of Rotation Matrices

Rotation matrices are orthonormal.

  • column vectors are orthogonal
  • column vectors are unit
  • hint: think about the radius in the unit circle
  • exercise: plot the column vectors

Properties of Rotation Matrices

\[ R^TR = I,~ ~RR^T = I \]

Where \(I\) is the identity matrix.

Properties of Rotation Matrices

We can use all these properties to test if a matrix is a rotation matrix.

Inverse Rotation Matrices

Therefore the inverse of a rotation matrix is the transpose of the rotation matrix.

\[ R^{-1} = R^T \]

Inverse Rotation Matrices

Therefore the inverse of a rotation matrix is the transpose of the rotation matrix.

\[ \begin{bmatrix} \cos \alpha &-\sin \alpha \\ \sin \alpha &~\cos \alpha \end{bmatrix}^{-1} = \begin{bmatrix} \cos \alpha &-\sin \alpha \\ \sin \alpha &~\cos \alpha \end{bmatrix}^T = \begin{bmatrix} ~\cos \alpha &\sin \alpha \\ -\sin \alpha &\cos \alpha \end{bmatrix} \]

Scaling, Shearing and Reflection

for Affine transformations

Scaling

We can separate scaling to uniform scaling and non-uniform scaling.

Uniform Scaling

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix}s~ ~0 \\ 0~ ~s \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

model to scale
uniform scaling, s=2

Uniform Scaling

In the example, notice that all vertices are scaled equally by 2.

Non-Uniform Scaling

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix}s_x~ ~0 \\ 0~ ~s_y \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

model to scale
non-uniform scaling, s_x=1, s_y=2

Non-Uniform Scaling

In the non-uniform example, notice that all vertices are scaled in the \(y\) direction by 2 and in the \(x\) direction by 1, so there is no change in \(x\).

Non-Uniform Scaling

Uniform scaling is a special case of non-uniform scaling where: \[s_x = s_y\]

Shearing

Shearing is an operation that moves vertices parallel to an axis, scaled by the distance from that axis.

Shearing

To shear parallel to the \(x\) axis:

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1~ ~\lambda \\ 0~ ~1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

model to shear
shearing parallel x, \lambda=2

To shear parallel to the \(y\) axis:

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1~ ~0 \\ \lambda~ ~1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

shearing parallel y, \lambda=1

Reflection

Reflection is an operation that imposes symmetry across an axis.

Reflection

To reflect across the \(y\) axis:

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} -1& 0 \\ ~ ~0& 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

model to reflect
reflection across y axis

Reflection

To reflect across the \(x\) axis:

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1& \hfill 0 \\ 0& \hfill -1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

reflection across x axis

Reflection

To reflect across the \(x=y\) axis:

\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 0& ~1 \\ 1& ~0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]

reflection across x=y axis

Homogeneous Coordinates

adjective: “of the same kind; alike.”

2D transformation problem

  • We have so far, explored a number of elementary transformations in 2D.
  • For ease of implementation, it would be better if translation could also be done using matrix multiplication.
  • Solution: Homogeneous Coordinates.

Homogeneous Coordinates

  • Define a new set of coordinates one dimension higher.
  • For 2D, \(\mathbb{R}^{2} \rightarrow \mathbb{R}^{3}\)
  • We add a third coordinate \(w\).

Homogeneous Coordinates

The homogeneous coordinates relate to our 2D coordinates as follows:

\[ x_h = \frac{x}{w}~, ~y_h = \frac{y}{w}~, ~w \]

Homogeneous Coordinates

Thus: \(x = w x_h\), \(y = w y_h\).

  • \(w\) functions as a scaling factor.
  • we can set \(w\) to 1, so \(x = x_h\), \(y = y_h\)
  • How do we use 3D homogeneous coordinates to represent 2D transformations?

Homogeneous Coordinates

For a general transformation operation, we extend the matrix multiplication we have seen so far, to include the \(w\) coordinate:

\[ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} a~ ~b~ ~c~ \\ d~ ~e~ ~f~ \\ 0~ ~0~ ~1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \]

Homogeneous Rotation

For our homogeneous 3 x 3 transformation matrix, rotation is now:

\[ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos \alpha& -\sin \alpha& ~0 \\ \sin \alpha& \hfill \cos \alpha& ~0 \\ 0& 0& ~1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \]

Homogeneous Rotation

Remains a true rotation matrix.

  • All the properties of a rotation matrix are preserved.

\[ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} \cos \alpha& -\sin \alpha& ~0 \\ \sin \alpha& \hfill \cos \alpha& ~0 \\ 0& 0& ~1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \]

Homogeneous Scaling

For our homogeneous 3 x 3 transformation matrix, scaling is now:

\[ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} s_x& ~0& ~0 \\ 0 & ~s_y& ~0 \\ 0 & ~0 & ~1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \]

Homogeneous Coordinates

For our homogeneous 3 x 3 transformation matrix, generally, the 2 x 2 matrix of the 2D elementary operations occupies the top left corner:

\[ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} a & ~b& ~0 \\ c & ~d& ~0 \\ 0 & ~0 & ~1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \]

Homogeneous Translation

How do we fit a translation into our 3 x 3 matrix?

\[ \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & ~0& ~t_x \\ 0 & ~1& ~t_y \\ 0 & ~0& ~1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} \]

Summary

  • Inverse Rotations
  • Scaling, Shearing, and Reflection
  • Homogeneous Coordinates

Reading:

  • Hearn, D. et al. (2004). Computer Graphics with OpenGL.
  • Strang, Gilbert, et al. (1993) Introduction to linear algebra.
// reveal.js plugins