Title: Transformations
1Transformations
- Aaron Bloomfield
- CS 445 Introduction to Graphics
- Fall 2006
- (Slide set originally by David Luebke)
2Graphics coordinate systems
- X is red
- Y is green
- Z is blue
3Graphics coordinate systems
- If you are on the z axis, and y is up, then x
is to the right - Math fields have x going to the left
4Outline
- Scaling
- Rotations
- Composing Rotations
- Homogeneous Coordinates
- Translations
- Projections
5Scaling
- Scaling a coordinate means multiplying each of
its components by a scalar - Uniform scaling means this scalar is the same for
all components
6Scaling
- Non-uniform scaling different scalars per
component - How can we represent this in matrix form?
7Scaling
- Scaling operation
- Or, in matrix form
scaling matrix
8Outline
- Scaling
- Rotations
- Composing Rotations
- Homogeneous Coordinates
- Translations
- Projections
92-D Rotation
x x cos(?) - y sin(?) y x sin(?) y cos(?)
102-D Rotation
- This is easy to capture in matrix form
- 3-D is more complicated
- Need to specify an axis of rotation
- Simple cases rotation about X, Y, Z axes
11Rotation example airplane
123-D Rotation
- What does the 3-D rotation matrix look like for a
rotation about the Z-axis? - Build it coordinate-by-coordinate
- 2-D rotation from last slide
133-D Rotation
- What does the 3-D rotation matrix look like for a
rotation about the Y-axis? - Build it coordinate-by-coordinate
143-D Rotation
- What does the 3-D rotation matrix look like for a
rotation about the X-axis? - Build it coordinate-by-coordinate
15Rotations about the axes
163-D Rotation
- General rotations in 3-D require rotating about
an arbitrary axis of rotation - Deriving the rotation matrix for such a rotation
directly is a good exercise in linear algebra - Another approach express general rotation as
composition of canonical rotations - Rotations about X, Y, Z
17Outline
- Scaling
- Rotations
- Composing Rotations
- Homogeneous Coordinates
- Translations
- Projections
18Composing 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 -?)
- Show video
19Composing 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 ??
203-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!
21Compositing Matrices
- So we have the following matrices
- p The point to be rotated about A by ?
- Ry? Rotate about Y by ?
- Rx ? Rotate about X by ?
- Rz? Rotate about Z by ?
- Rx ? -1 Undo rotation about X by ?
- Ry?-1 Undo rotation about Y by ?
- In what order should we multiply them?
22Compositing 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 Ry?-1 Rx ? -1 Rz? Rx ? Ry? p
23Rotation Matrices
- Notice these two matrices
- Rx ? Rotate about X by ?
- Rx ? -1 Undo rotation about X by ?
- How can we calculate Rx ? -1?
- Obvious answer calculate Rx (-?)
- Clever answer exploit fact that rotation
matrices are orthonormal - What is an orthonormal matrix?
- What property are we talking about?
24Rotation Matrices
- Rotation matrix is orthogonal
- Columns/rows linearly independent
- Columns/rows sum to 1
- The inverse of an orthogonal matrix is just its
transpose
25Rotation Matrix for Any Axis
- Given glRotated (angle, x, y, z)
- Let c cos(angle)
- Let s sin(angle)
- And normalize the vector so that (x,y,z 1
- The produced matrix to rotate something by angle
degrees around the axis (x,y,z) is
26Outline
- Scaling
- Rotations
- Composing Rotations
- Homogeneous Coordinates
- Translations
- Projections
27Translations
- 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
28Translation Matrices?
- We can composite scale matrices just as we did
rotation matrices - But how to represent translation as a matrix?
- Answer with homogeneous coordinates
29Homogeneous Coordinates
- Homogeneous coordinates represent coordinates in
3 dimensions with a 4-vector - x, y, z, 0T represents a point at infinity (use
for vectors) - 0, 0, 0T is not allowed
- Note that typically w 1 in object coordinates
30Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
31Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
32Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
33Homogeneous Coordinates
- Homogeneous coordinates seem unintuitive, but
they make graphics operations much easier - Our transformation matrices are now 4x4
- Performing a scale
34More On Homogeneous Coords
- What effect does the following matrix have?
- Conceptually, the fourth coordinate w is a bit
like a scale factor
35More On Homogeneous Coords
- Intuitively
- The w coordinate of a homogeneous point is
typically 1 - Decreasing w makes the point bigger, meaning
further from the origin - Homogeneous points with w 0 are thus points at
infinity, meaning infinitely far away in some
direction. (What direction?) - To help illustrate this, imagine subtracting two
homogeneous points
36Outline
- Scaling
- Rotations
- Composing Rotations
- Homogeneous Coordinates
- Translations
- Projections
37Homogeneous Coordinates
- How can we represent translation as a 4x4 matrix?
- A Using the rightmost column
- Performing a translation
38Translation 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
39Translation 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
40Translation 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
41Translation 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
42Transformation Commutativity
- Is matrix multiplication, in general,
commutative? Does AB BA? - What about rotation, scaling, and translation
matrices? - Does RxRy RyRx?
- Does RAS SRA ?
- Does RAT TRA ?
43Outline
- Scaling
- Rotations
- Composing Rotations
- Homogeneous Coordinates
- Translations
- Projections
44Perspective Projection
- In the real world, objects exhibit perspective
foreshortening distant objects appear smaller - The basic situation
45Perspective Projection
- When we do 3-D graphics, we think of the screen
as a 2-D window onto the 3-D world - The view plane
46Perspective Projection
- The geometry of the situation is that of similar
triangles. View from above - What is x?
47Perspective Projection
- Desired result for a point x, y, z, 1T
projected onto the view plane - What could a matrix look like to do this?
48A Perspective Projection Matrix
49A Perspective Projection Matrix
- Example
- Or, in 3-D coordinates
50A Perspective Projection Matrix
- OpenGLs gluPerspective() command generates a
slightly more complicated matrix - Can you figure out what this matrix does?
51Projection Matrices
- Now that we can express perspective
foreshortening as a matrix, we can composite it
onto our other matrices with the usual matrix
multiplication - End result can create a single matrix
encapsulating modeling, viewing, and projection
transforms - Though you will recall that in practice OpenGL
separates the modelview from projection matrix
(why?)