Reading Required: Affine transformations Brian Curless CSEP 557 Fall 2016 Angel 3.1, 3.7-3.11 Further reading: Angel, the rest of Chapter 3 Fole, et al, Chapter 5.1-5.5. David F. Rogers and J. Alan Adams, Mathematical Elements for Computer Graphics, 2 nd Ed., McGraw-Hill, New York, 1990, Chapter 2. 1 2 Geometric transformations Vector representation Geometric transformations will map points in one space to points in another: (x',, z ) = f (x,, z ). These transformations can be ver simple, such as scaling each coordinate, or complex, such as nonlinear twists and bends. We'll focus on transformations that can be represented easil with matrix operations. We can represent a point, p = (x, ), in the plane or p = (x,, z ) in 3D space as column vectors as row vectors x x x z x z 3 4
Canonical axes Vector length and dot products 5 6 Vector cross products Representation, cont. We can represent a 2-D transformation M b a matrix a b c d If p is a column vector, M goes on the left: p' Mp x' a bx ' c d If p is a row vector, M T goes on the right: x' ' x We will use column vectors. T p' pm a c b d 7 8
Two-dimensional transformations Identit Here's all ou get with a 2 x 2 transformation matrix M : x' a bx ' c d So: x ' ax b ' cx d Suppose we choose a =d =1, b =c =0: Gives the identit matrix: 1 0 0 1 Doesn't move the points at all We will develop some intimac with the elements a, b, c, d 9 10 Scaling Suppose we set b =c =0, but let a and d take on an positive value: Gives a scaling matrix: a 0 0 d Provides differential (non-uniform) scaling in x and : x' ax ' d Suppose we keep b =c =0, but let either a or d go negative. Examples: 1 0 0 1 1 0 0 1 2 0 0 2 12 0 0 2 11 12
Effect on unit square Now let's leave a =d =1 and experiment with b... The matrix 1 b 0 1 gives: x ' xb ' Let's see how a general 2 x 2 transformation M affects the unit square: a c b d p q r s p' q' r' s' a b0 1 1 0 0 a a b b c d 0 0 1 1 0 c c d d 1 1 0 1 13 14 Effect on unit square, cont. Rotation Observe: Origin invariant under M M can be determined just b knowing how the corners (1,0) and (0,1) are mapped a and d give x -and -scaling b and c give x -and -shearing From our observations of the effect on the unit square, it should be eas to write down a matrix for rotation about the origin : 1 0 0 1 Thus, MR( ) 15 16
Limitations of the 2 x 2 matrix A 2 x 2 linear transformation matrix allows Scaling Rotation Reflection Shearing Q: What important operation does that leave out? Homogeneous coordinates Idea is to loft the problem up into 3-space, adding a third component to ever point: x x 1 Adding the third w component puts us in homogenous coordinates. And then transform with a 3 x 3 matrix: x' x 1 0 tx x ' T() t 0 1 t w ' 1 0 0 11 1 0 1 0 1 12 0 0 1 17... gives translation! 18 Anatom of an affine matrix The addition of translation to linear transformations gives us affine transformations. In matrix form, 2D affine transformations alwas look like this: a b tx A t M c d t 0 0 1 0 0 1 Rotation about arbitrar points Until now, we have onl considered rotation about the origin. With homogeneous coordinates, ou can specif a rotation b, about an point q = [q x q ] T with a matrix. Let s do this with rotation and translation matrices of the form R() and T(t), respectivel. 2D affine transformations alwas have a bottom row of [0 0 1]. An affine point is a linear point with an added w-coordinate which is alwas 1: x plin p aff 1 1 Appling an affine transformation gives another affine point: Aplin t Mpaff 1 19 1. Translate q to origin 2. Rotate 3. Translate back 20
Points and vectors Vectors have an additional coordinate of w = 0. Thus, a change of origin has no effect on vectors. Q: What happens if we multipl a vector b an affine matrix? These representations reflect some of the rules of affine operations on points and vectors: vector + vector scalar vector point - point point + vector point + point scalar vector + scalar vector scalar point + scalar point Basic 3-D transformations: scaling Some of the 3-D transformations are just like the 2-D ones. For example, scaling: x ' sx 0 0 0x ' 0 s 0 0 z ' 0 0 sz 0z 1 0 0 0 11 One useful combination of affine operations is: p() t po tu Q: What does this describe? 21 22 Translation in 3D Rotation in 3D (cont d) x ' 1 0 0 tx x ' 0 1 0 t z ' 0 0 1 tz z 1 0 0 0 11 These are the rotations about the canonical axes: 1 0 0 0 0 cos sin 0 R x ( ) 0 sin cos 0 0 0 0 1 R cos 0 sin 0 0 1 0 0 R ( ) sin 0 cos 0 R x 0 0 0 1 R z cos sin 0 0 sin cos 0 0 Use right hand rule R ( ) z 0 0 1 0 0 0 0 1 A general rotation can be specified in terms of a product of these three matrices. How else might ou specif a rotation? 23 24
Shearing in 3D Properties of affine transformations Shearing is also more complicated. Here is one example: x ' 1 b 0 0x ' 0 1 0 0 z ' 0 0 1 0z 1 0 0 0 11 Here are some useful properties of affine transformations: Lines map to lines Parallel lines remain parallel (when transforming from N dimensions to N dimensions) Midpoints map to midpoints (in fact, ratios are alwas preserved) pq s ratio qr t p'q' q'r' We call this a shear with respect to the x-z plane. 25 26 Affine transformations in OpenGL OpenGL maintains a modelview matrix that holds the current transformation M. The modelview matrix is applied to points (usuall vertices of polgons) before drawing. It is modified b commands including: glloadidentit() set M to identit gltranslatef(t x, t, t z ) translate b (t x, t, t z ) M I M MT glrotatef(θ, x,, z) M MR rotate b angle θ about axis (x,, z) Summar What to take awa from this lecture: All the names in boldface. How points and transformations are represented. How to compute lengths, dot products, and cross products of vectors, and what their geometrical meanings are. What all the elements of a 2 x 2 transformation matrix do and how these generalize to 3 x 3 transformations. What homogeneous coordinates are and how the work for affine transformations. How to concatenate transformations. The mathematical properties of affine transformations. glscalef(s x, s, s z ) scale b (s x, s, s z ) M MS Note that OpenGL adds transformations b postmultiplication of the modelview matrix. 27 28