2D Transformations 7 Februar 27 Week 5-2D Transformations
Matri math Is there a difference between possible representations? a c b e d f ae bf ce df a c b d e f ae cf be df a b c d e f ae bf ce df 7 Februar 27 Week 5-2D Transformations 2
Pick a convention We ll use the column-vector representation for a point. Which implies that we use pre-multiplication of the transformation it appears before the point to be transformed in the equation. A C B D A B C D What if we needed to switch to the other convention (to use some librar, for instance)? How could we do that? 7 Februar 27 Week 5-2D Transformations 3
A translation moves all points in an object along the same straight-line path to new positions. Translation The path is represented b a vector, called the translation or shift vector. We can write the components: p' = p + t p' = p + t or in matri form: P' = P + T 7 Februar 27 Week 5-2D Transformations 4
Rotation A rotation repositions all points in an object along a circular path in the plane centered at the pivot point. First, we ll assume the pivot is at the origin. We can write the components: p' = p cos p sin p' = p sin + p cos or in matri form: P' = R P 7 Februar 27 Week 5-2D Transformations 5
7 Februar 27 Week 5-2D Transformations 6 More rotation Another convention, we ll take to be counterclockwise, as in our eample. R, the rotation matri, looks like: cos sin sin cos R cos sin sin cos cos sin sin cos 9 (5,) ), ( 5 5 5 cos9 sin9 5 sin9 cos9 5
Scaling alters the size of an object. Scales are about the the origin. Scale factors between and shrink objects. Scale factors greater than enlarge objects. We can write the components: p' = s p p' = s p or in matri form: P' = S P The scale factors need not be the same in each direction. Scaling 7 Februar 27 Week 5-2D Transformations 7
We write a scale matri as: More scaling S s s Scaling also translates objects; awa from the origin if the scale factor is greater than, or towards the origin if the scale factor is less than. What does scaling b do? What is that matri called? What does scaling b a negative value do? 7 Februar 27 Week 5-2D Transformations 8
Combining transformations We have a general transformation of a point: P' = M P + A When we scale or rotate, we set M, and A is the additive identit. When we translate, we set A, and M is the multiplicative identit. To combine multiple transformations, we must eplicitl compute each transformed point. It d be nicer if we could use the same matri operation all the time. But we d have to combine multiplication and addition into a single operation. 7 Februar 27 Week 5-2D Transformations 9
A less than obvious solution Let s move our problem into 3D. Let point (, ) in 2D be represented b point (,, ) in the new space. w Scaling our new point b an value a puts us somewhere along a particular line: (a, a, a). We can alwas map back to the original 2D point b dividing b the last coordinate. The fact that all the points along each line can be mapped back to the same point in 2D gives this coordinate sstem its name homogeneous coordinates. (,,) (,,) w =, 7 Februar 27 Week 5-2D Transformations
So what? Well, now we can wedge some addition into our multiplicative matri. Our point now has three coordinates. So our matri is needs to be 33. We want a matri which gives us: t t 7 Februar 27 Week 5-2D Transformations
7 Februar 27 Week 5-2D Transformations 2 Now what? t t t t
7 Februar 27 Week 5-2D Transformations 3 And? Rotations: Scales: cos sin sin cos s s
What of it? We can represent an of our three transformations as a single matri. No special cases when transforming a point matri vector. Composite transformations matri matri. Composite transformations: Rotate about an arbitrar point translate, rotate, translate Scale about an arbitrar point translate, scale, translate Change coordinate sstems translate, rotate, scale Does the order of operations matter? 7 Februar 27 Week 5-2D Transformations 4
7 Februar 27 Week 5-2D Transformations 5 Is matri multiplication associative? dhl cfl dgj cej dhk cfk dgi cei bhl afl bgj aej bhk afk bgi aei l k j i dh cf dg ce bh af bg ae l k j i h g f e d c b a dhl dgj cfl cej dhk dgi cfk cei bhl bgj afl aej bhk bgi afk aei hl gj hk gi fl ej fk ei d c b a l k j i h g f e d c b a
Is matri multiplication commutative? a c b d e g f h ae bg ce dg af cf bh dh e g f h a c b d ea ga fc hc eb gb fd hd 7 Februar 27 Week 5-2D Transformations 6
Order of operations So, it does matter. Let s look at an eample: 7 Februar 27 Week 5-2D Transformations 7
Useful compositions Rotate about a pivot point: T(pivot) R() T( pivot) P Scale about a fied point: T(fied) S(scale) T( fied) P General scaling directions: R( ) S(scale) R() P 7 Februar 27 Week 5-2D Transformations 8
7 Februar 27 Week 5-2D Transformations 9 Other transformations Reflection: -ais -ais
7 Februar 27 Week 5-2D Transformations 2 Other transformations Reflection: origin line =
7 Februar 27 Week 5-2D Transformations 2 Other transformations Shear: -direction -direction sh sh
Coordinate sstem transformations We often need to transform points from one coordinate sstem to another:. We might model an object in non-cartesian space (polar) 2. Objects ma be described in their own local sstem 3. Other reasons: tetures, displa, etc 7 Februar 27 Week 5-2D Transformations 22
Matri multiplication So we can do a lot with one basic operation. We d better make this operation as fast as possible. Let s start with the form of the matri: M a d e f c Wh haven t we used the bottom row of the matri? b 7 Februar 27 Week 5-2D Transformations 23
7 Februar 27 Week 5-2D Transformations 24 Matri multiplication Since we don t use the bottom row of the 2D transformation matri, we could have a special transform composition operation: f e d c b a M 2 l k j i h g M 2 f el di ek dh ej dg c bl ai bk ah bj ag l k j i h g f e d c b a M M