Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003
David Luebke 2 12/23/2015 Admin ● Call roll ● Assn 1 ■ Remember, due Monday 10 AM (ie, don’t skip class) ■ Several people have turned in already – nice job
David Luebke 3 12/23/2015 Recap: Translations ● For convenience we usually describe objects in relation to their own coordinate system ● We can translate or move points to a new position by adding offsets to their coordinates: ■ Note that this translates all points uniformly
David Luebke 4 12/23/2015 Recap: Scaling ● Scaling operation: ● Or, in matrix form: scaling matrix
David Luebke 5 12/23/2015 Recap: 3-D Rotation ● 3x3 matrix for rotation about the z-axis:
David Luebke 6 12/23/2015 Recap: 3-D Rotation ● 3x3 matrix for rotation about the y-axis:
David Luebke 7 12/23/2015 Recap: 3-D Rotation ● 3x3 matrix for rotation about the x-axis:
David Luebke 8 12/23/2015 Recap: Composing Canonical Rotations ● Goal: rotate about arbitrary vector A by ■ Idea: we know how to rotate about X,Y,Z So, rotate about Y by until A lies in the YZ plane Then rotate about X by until A coincides with +Z Then rotate about Z by Then reverse the rotation about X (by - ) Then reverse the rotation about Y (by - )
David Luebke 9 12/23/2015 Composing Canonical Rotations ● First: rotating about Y by until A lies in YZ ■ Draw it… ● How exactly do we calculate ? ■ Project A onto XZ plane ■ Find angle to X: = -(90° - ) = - 90 ° ● Second: rotating about X by until A lies on Z ● How do we calculate ?
David Luebke 10 12/23/2015 Composing Canonical Rotations ● Why are we slogging through all this tedium? ● A: Because you’ll have to do it on the test
David Luebke 11 12/23/ D Rotation Matrices ● So an arbitrary rotation about A composites several canonical rotations together ● We can express each rotation as a matrix ● Compositing transforms == multiplying matrices ● Thus we can express the final rotation as the product of canonical rotation matrices ● Thus we can express the final rotation with a single matrix!
David Luebke 12 12/23/2015 Compositing Matrices ● So we have the following matrices: p: The point to be rotated about A by R y : Rotate about Y by R x : Rotate about X by R z : Rotate about Z by R x -1 : Undo rotation about X by R y -1 : Undo rotation about Y by ● In what order should we multiply them?
David Luebke 13 12/23/2015 Compositing Matrices ● Remember: the transformations, in order, are written from right to left ■ In other words, the first matrix to affect the vector goes next to the vector, the second next to the first, etc. ■ This is the rule with column vectors (OpenGL); row vectors would be the opposite ● So in our case: p’ = R y -1 R x -1 R z R x R y p
David Luebke 14 12/23/2015 Rotation Matrices ● Notice these two matrices: R x : Rotate about X by R x -1 : Undo rotation about X by ● How can we calculate R x -1 ? ■ Obvious answer: calculate R x (- ) ■ Clever answer: exploit fact that rotation matrices are orthogonal ● What is an orthogonal matrix? ● What property are we talking about?
David Luebke 15 12/23/2015 Rotation Matrices ● Rotation matrix is orthogonal ■ Columns/rows linearly independent ■ Columns/rows sum to 1 ● The inverse of an orthogonal matrix is just its transpose:
David Luebke 16 12/23/2015 Translation Matrices? ● We can composite scale matrices just as we did rotation matrices ● But how to represent translation as a matrix? ● Answer: with homogeneous coordinates
David Luebke 17 12/23/2015 Homogeneous Coordinates ● Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector (Note that typically w = 1 in object coordinates)
David Luebke 18 12/23/2015 Homogeneous Coordinates ● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier ● Our transformation matrices are now 4x4:
David Luebke 19 12/23/2015 Homogeneous Coordinates ● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier ● Our transformation matrices are now 4x4:
David Luebke 20 12/23/2015 Homogeneous Coordinates ● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier ● Our transformation matrices are now 4x4:
David Luebke 21 12/23/2015 Homogeneous Coordinates ● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier ● Our transformation matrices are now 4x4:
David Luebke 22 12/23/2015 Homogeneous Coordinates ● How can we represent translation as a 4x4 matrix? ● A: Using the rightmost column:
David Luebke 23 12/23/2015 Translation Matrices ● Now that we can represent translation as a matrix, we can composite it with other transformations ● Ex: rotate 90° about X, then 10 units down Z:
David Luebke 24 12/23/2015 Translation Matrices ● Now that we can represent translation as a matrix, we can composite it with other transformations ● Ex: rotate 90° about X, then 10 units down Z:
David Luebke 25 12/23/2015 Translation Matrices ● Now that we can represent translation as a matrix, we can composite it with other transformations ● Ex: rotate 90° about X, then 10 units down Z:
David Luebke 26 12/23/2015 Translation Matrices ● Now that we can represent translation as a matrix, we can composite it with other transformations ● Ex: rotate 90° about X, then 10 units down Z:
David Luebke 27 12/23/2015 Transformation Commutativity ● Is matrix multiplication, in general, commutative? Does AB = BA? ● What about rotation, scaling, and translation matrices? ■ Does R x R y = R y R x ? ■ Does R A S = SR A ? ■ Does R A T = TR A ?