Transformation of 3D Shapes
An Introduction
Prof. David Bernstein
James Madison University
Computer Science Department
bernstdh@jmu.edu
Motivation
What We Have:
Methods for representing lines, triangles, and convex polygons in 2D and 3D
The ability to transform 2D shapes
What We Need:
The ability to transform 3D shapes in various ways
Coordinate Systems
In 2D:
We considered scaling, reflection, shear, rotation and translation in both Cartesian and homogeneous coordinates
In 3D:
We could consider both Cartesian and homogeneous coordinates but we will only consider homogeneous coordinates
Remember
This discussion assumes that we are using column vectors
If you implement using row vectors then you will need to reverse the order of the operations
Visualization
As we have seen, it can be useful to visualize these kinds of operations
Unfortunately, we can't draw figures in three dimensions (we have to project onto two)
This can cause misconceptions so it is better to use physical models and not drawings
Translation
Translation Matrix:
\( \bs{T} = \left[ \begin{array}{c c c c} 1 & 0 & 0 & \tau_{1} \\ 0 & 1 & 0 & \tau_{2} \\ 0 & 0 & 1 & \tau_{3} \\ 0 & 0 & 0 & 1 \end{array} \right] \)
Inverse Translation Matrix:
\( \bs{T}^{-1} = \left[ \begin{array}{c c c c} 1 & 0 & 0 & -\tau_{1} \\ 0 & 1 & 0 & -\tau_{2} \\ 0 & 0 & 1 & -\tau_{3} \\ 0 & 0 & 0 & 1 \end{array} \right] \)
Scaling
Scaling Matrix:
\( \bs{S} = \left[ \begin{array}{c c c c} \sigma_{1} & 0 & 0 & 0 \\ 0 & \sigma_{2} & 0 & 0 \\ 0 & 0 & \sigma_{3} & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] \)
Inverse Scaling Matrix:
\( \bs{S}^{-1} = \left[ \begin{array}{c c c c} 1/\sigma_{1} & 0 & 0 & 0 \\ 0 & 1/\sigma_{2} & 0 & 0 \\ 0 & 0 & 1/\sigma_{3} & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] \)
Rotation Around Axes
Rotation Around the \(x\)-Axis:
\( \bs{R_{x}} = \left[ \begin{array}{c c c c} 1 & 0 & 0 & 0 \\ 0 & \cos \phi & - \sin \phi & 0 \\ 0 & \sin \phi & \cos \phi & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] \)
Rotation Around the \(y\)-Axis:
\( \bs{R_{y}} = \left[ \begin{array}{c c c c} \cos \theta & 0 & \sin \theta & 0 \\ 0 & 1 & 0 & 0 \\ - \sin \theta & 0 & \cos \theta & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] \)
Rotation Around the \(z\)-Axis:
\( \bs{R_{z}} = \left[ \begin{array}{c c c c} \cos \psi & - \sin \psi & 0 & 0 \\ \sin \psi & \cos \psi & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1\end{array} \right] \)
Rotation Around Axes (cont.)
Inverse Rotation Matrices:
Just rotate an equal amount in the opposite direction (e.g.,. replace \(\theta\) with \(- \theta\))
An Additional Result:
All of the \(\cos\) terms are on the diagonal and all of the \(\sin\) terms are off the diagonal
\(\cos(-\theta) = \cos \theta\)
\(\sin(-\theta) = - \sin \theta\)
So, \(\bs{R}^{-1} = \bs{R}^{T}\)
Shear
Defined:
A shear transforms the point \(\left[ \begin{array}{c c c c}x \\ y \\ z \\ 1\end{array} \right]\)
to the point \(\left[ \begin{array}{c c c c}x+ay+bz \\ cx+y+dz \\ ex+fy+z \\ 1\end{array} \right]\)
Shear Matrix:
\( \left[ \begin{array}{c c c c} 1 & a & b & 0 \\ c & 1 & d & 0 \\ e & f & 1 & 0 \\ 0 & 0 & 0 & 1\end{array} \right] \)
Concatenating Transforms
Sequential Transformations:
Being Careful About Dimensionality:
\(\bs{q} = \bs{A} \bs{p}\)
\(\bs{r} = \bs{B} \bs{q} = \bs{B} (\bs{A} \bs{p})\)
\(\bs{s} = \bs{C} \bs{r} = \bs{C} (\bs{B} \bs{q}) = \bs{C} (\bs{B} (\bs{A} \bs{p}))\)
Concatenating Transforms (cont.)
Associativity of Matrix Multiplication:
\(\bs{C} (\bs{B} (\bs{A} \bs{p})) = ((\bs{C} \bs{B}) \bs{A}) \bs{p}\)
The Concatenated Transform:
Complicated Rotations
Around the point \(\bs{p}\):
Translate by \(-\bs{p}\)
Rotate
Translate by \(\bs{p}\)
Rotation Around Multiple Axes:
\(\bs{R} = \bs{R_{x}} \bs{R_{y}} \bs{R_{z}}\)
Rotation Around a Line:
Combine the two above ideas
There's Always More to Learn