Reading Optional reading: Affine transformations Brian Curless CSE 557 Autumn 207 Angel and Shreiner: 3., 3.7-3. Marschner and Shirle: 2.3, 2.4.-2.4.4, 6..-6..4, 6.2., 6.3 Further reading: Angel, the rest of Chapter 3 Fole, et al, Chapter 5.-5.5. David F. Rogers and J. Alan Adams, Mathematical Elements for Computer Graphics, 2 nd Ed., McGraw-Hill, New York, 990, Chapter 2. 2 Geometric transformations Vector representation Geometric transformations will map points in one space to points in another: (,, ) = f (,, ). These transformations can be ver simple, such as scaling each coordinate, or comple, such as nonlinear twists and bends. We'll focus on transformations that can be represented easil with matri operations. We can represent a point, p = (, ), in the plane or p = (,, ) in 3D space: as column vectors as row vectors 3 4
Canonical aes Vector length and dot products v u 5 6 Vector cross products Representation, cont. v u We can represent a 2-D transformation M b a matri a b c d If p is a column vector, M goes on the left: p' Mp ' ' a b c d If p is a row vector, M T goes on the right: ' p' pm T ' a b c d We will use column vectors. 7 8
Two-dimensional transformations Identit Here's all ou get with a 2 2 transformation matri M : So: ' ' a b c d ' a b ' c d Suppose we choose a = d =, b = c = 0: Gives the identit matri: 0 0 Doesn't move the points at all We will develop some intimac with the elements a, b, c, d 9 0 Scaling Suppose we set b = c = 0, but let a and d take on an positive value: Gives a scaling matri: a 0 0 d Provides differential (non-uniform) scaling in and : ' a ' d Suppose we keep b = c = 0, but let either a or d go negative. Eamples: 0 0 0 0 2 0 0 2 2 0 0 2 2
Now let's leave a = d = and eperiment with b... Effect on unit square Let's see how a general 2 2 transformation M affects the unit square: The matri gives: b 0 ' b ' a c a c b d b d q r s t 0 0 0 0 q' r' s' t' 0 a a b b 0 c c d d 0 3 4 Effect on unit square, cont. Rotation Observe: Origin invariant under M M can be determined just b knowing how the corners (,0) and (0,) are mapped a and d give - and -scaling b and c give - and -shearing From our observations of the effect on the unit square, it should be eas to write down a matri for rotation about the origin : 0 0 5 Thus, M R() 6
Linear transformations Limitations of the 2 2 matri The unit square observations also tell us the 22 matri transformation implies that we are representing a point in a new coordinate sstem: p' Mp a b c d u v u v A 2 2 linear transformation matri allows Scaling Rotation Reflection Shearing Q: What important operation does that leave out? where u=[a c] T and v=[b d] T are vectors that define a new basis for a linear space. The transformation to this new basis (a.k.a., change of basis) is a linear transformation. 7 8 Affine transformations In order to incorporate the idea that both the basis and the origin can change, we augment the linear space u, v with an origin t. We call u, v, and t (basis and origin) a frame for an affine space. Then, we can represent a change of frame as: p' u v t This change of frame is also known as an affine transformation. How do we write an affine transformation with matrices? Homogeneous coordinates Idea is to loft the problem up into 3-space, adding a third component to ever point: Adding the third w component puts us in homogenous coordinates. And then transform with a 3 3 matri: ' 0 t ' T (t) 0 t w' 0 0 0 0 2 0 0 9... gives translation! 20
Anatom of an affine matri Rotation about arbitrar points The addition of translation to linear transformations gives us affine transformations. In matri form, 2D affine transformations alwas look like this: a b t M c d t A t 0 0 0 0 2D affine transformations alwas have a bottom row of [0 0 ]. Until now, we have onl considered rotation about the origin. With homogeneous coordinates, ou can specif a rotation b, about an point q = [q q ] T with a matri. Let s do this with rotation and translation matrices of the form R( ) and T(t), respectivel. An affine point is a linear point with an added w-coordinate which is alwas : p aff p lin Appling an affine transformation gives another affine point: Ap Mp aff lin t 2. Translate q to origin 2. Rotate 3. Translate back 22 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 matri? Combinations of points Note that we seem to have constructed a point b adding points together, which we said was illegal, but as long as the have coefficients that sum to one, it s ok. More generall, a weighted sum of points A i : 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 One useful combination of affine operations is: P() t P tu o is an affine combination if: n i i It is a vector combination if: n i 0 i And it is a conve combination if: n i and i 0 i A conve combination of points will alwas lie in the conve hull of those points. Q: What does this describe? 23 24
Barcentric coordinates A set of points can be used to create an affine frame. Consider a triangle ABC and a point P : C P B A We can form a frame with an origin C and the vectors from C to the other vertices: u B A v C A t A We can then write P in this affine coordinate frame: Computing barcentric coordinates Writing out the barcentric combination of points leads to a linear sstem: A B C P A BC P A B C P A B C P A B C P A cool result is that we can write the solution as: P u v t (B P) (C P) 2D (B A) 2D (C A) (C P) (A P) 2D (B A) 2D (C A) (A P) (B P) 2D (B A) 2D (C A) which can be interpreted geometricall as: C The coordinates (,, ) are called the barcentric coordinates of P relative to A, B, and C. 25 SArea(PBC) SArea(ABC) SArea(APC) SArea(ABC) SArea(ABP) SArea(ABC) Q: What does it mean for a barcentric coordinate to be negative? A P B 26 Basic 3-D transformations: scaling Translation in 3D Some of the 3-D transformations are just like the 2-D ones. For eample, scaling: ' s 0 0 0 ' 0 s ' 0 0 0 0 s 0 0 0 0 ' 0 0 t ' 0 0 t ' 0 0 t 0 0 0 27 28
Rotation in 3D For an transformation, we can count its degrees of freedom the number of independent (though not necessaril unique) parameters needed to specif the transformation. One wa to count them is to add up all the apparentl free variables and subtract the number of independent equations that constrain them. How man degrees of freedom are there in an arbitrar 3D rotation? Rotation in 3D (cont d) These are the rotations about the canonical aes: R ( ) 0 0 0 0 cos sin 0 0 sin cos 0 0 0 0 R ( ) R cos 0 sin 0 0 0 0 sin 0 cos 0 R 0 0 0 R R ( ) cos sin 0 0 Use right hand rule sin cos 0 0 0 0 0 0 0 0 A general rotation can be specified in terms of a product of these three matrices. How else might ou specif a rotation? 29 30 Shearing in 3D Shearing is also more complicated. Here is one eample: ' ' ' b 0 0 0 0 0 0 0 0 0 0 0 Preservation of affine combinations A transformation F is an affine transformation if it preserves affine combinations: where the A i are points, and: n i Clearl, the matri form of F has this propert. i One special eample is a matri that drops a dimension. For eample: 0 0 0 0 0 0 0 0 0 We call this a shear with respect to the - plane. This transformation, known as an orthographic projection is an affine transformation. We ll use this fact later 3 32
Properties of affine transformations Here are some useful properties of affine transformations: Lines map to lines Parallel lines remain parallel Midpoints map to midpoints (in fact, ratios are alwas preserved) pq s p'q' ratio qr t q'r' 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 2 transformation matri do and how these generalie to 3 3 transformations. What homogeneous coordinates are and how the work for affine transformations. How to concatenate transformations. The mathematical properties of affine transformations. 33 34