2D Geometrical Transformations Fole & Van Dam, Chapter 5
2D Geometrical Transformations Translation Scaling Rotation Shear Matri notation Compositions Homogeneous coordinates
2D Geometrical Transformations Assumption: Objects consist of points and lines. A point is represented b its Cartesian coordinates: P (, ) Geometrical Transformation: Let (A, B) be a straight line segment between the points A and B. Let T be a general 2D transformation. T transforms (A, B) into another straight line segment (A, B ), where: A TA and B TB
Translation Translate(a, b): (, ) (+a, +b) Translate(2, 4)
Scale Scale (a, b): (, ) (a, b) Scale (2, 3) Scale (2, 3)
Scale How can we scale an object without moving its origin (lower left corner)? Translate(-,-) Translate(,) Scale(2,3)
Reflection Special case of scale Scale(-,) Scale(,-)
Rotation Rotate(): (, ) ( cos()+ sin(), - sin()+ cos()) Rotate(9) Rotate(9)
Rotation How can we rotate an object without moving its origin (lower left corner)? Translate(-,-) Translate(,) Rotate(9)
Shear Shear (a, b): (, ) (+a, +b) Shear(,) Shear(,2)
Classes of Transformations Rigid transformation (distance preserving): Translation + Rotation Similarit transformation (angle preserving): Translation + Rotation + Uniform Scale Affine transformation (parallelism preserving): Translation + Rotation + Scale + Shear All above transformations are groups where Rigid Similarit Affine Affine Similarit Rigid
Matri Notation Let s treat a point (, ) as a 2 matri (column vector): What happens when this vector is multiplied b a 22 matri? a c b d a c + + b d
2D Transformations 2D object is represented b points and lines that join them Transformations can be applied onl to the the points defining the lines A point (, ) is represented b a 2 column vector, so we can represent 2D transformations b using 22 matrices: ' ' a c b d
Scale Scale (a, b): (, ) (a, b) a b a b If a or b are negative, we get reflection Inverse: S - (a,b) S(/a, /b)
Reflection Reflection through the ais: Reflection through the ais: Reflection through : Reflection through -:
Shear Shear (a, b): (, ) (+a, +b) b a + + a b
Rotation Rotate(): (, ) ( cos()+ sin(), - sin()+ cos()) cos sin sin cos cos + sin + sin cos Inverse: R - (q) R T (q) R(-q)
Composition of Transformations A sequence of transformations can be collapsed into a single matri: A B C D [ ][ ][ ] [ ] Note: Order of transformations is important! translate rotate rotate translate
Translation (a, b): Translation Problem: Cannot represent translation using 22 matrices Solution: Homogeneous Coordinates + a + b
Homogeneous Coordinates Is a mapping from R n to R n+ : (, ) ( X, Y, W ) ( t, t, t ) Note: All triples (t, t, t) correspond to the same non-homogeneous point (, ) Eample (2, 3, ) (6, 9, 3). Inverse mapping: X ( X, Y, W ), W Y W
Translation Translate(a, b): Inverse: T - (a, b) T(-a, -b) Affine transformations now have the following form: + + b a b a f d c e b a
Geometric Interpretation A 2D point is mapped to a line (ra) in 3D The non-homogeneous points are obtained b projecting the ras onto the plane Z W (X,Y,) Y (X,Y,W) X
Eample Rotation about an arbitrar point. Translate the coordinates so that the origin is at (, ) 2. Rotate b 3. Translate back (, ) + sin ) cos ( cos sin sin ) cos ( sin cos cos sin sin cos
Eample Reflection about an arbitrar line p 2 L p + t (p 2 -p ) t p 2 + (-t) p p. Translate the coordinates so that P is at the origin 2. Rotate so that L aligns with the -ais 3. Reflect about the -ais 4. Rotate back 5. Translate back
Change of Coordinates It is often required to transform the description of an object from one coordinate sstem to another Rule: Transform one coordinate frame towards the other in the opposite direction of the representation change Representation Transformation
Eample Change of coordinates: Represent P ( p, p, ) in the (, ) coordinate sstem P ' MP Where: M cos sin sin cos ( p, p ) (, )
Eample Change of coordinates: Alternative method: assume (u, u) and (v, v) in the (, ) coordinate sstem where MP P ' v v u u M (, ) (u, u ) (v, v )
Eample Reflection about an arbitrar line Define a coordinate sstems (u, v) parallel to P P 2 : p p 2 L p + t (p 2 -p ) t p 2 + (-t) p u u p p p p 2 2 u v v u u v p p v v u u v u v u p p M
3D Viewing Transformation Pipeline Viewing coordinates World Coordinates Object in World 3D:2D mapping 2D:2D mapping Viewport Device Coordinates
World to Viewing Coordinates In order to define the viewing window we have to specif: Windowing-coordinate origin P (, ) View vector up v (v,v ) Using v, we can find u: u v (,,) Transformation from world to viewing coordinates : M world wc vc view (, ) u v view u v (v,v ). world (u,u ).
Window to Viewport Coordinates ( ma, ma ) ( min, min ) Window is Viewing Coordinates Window translated to origin (u man,v man ) (u min,v min ) Window scaled and translated to Viewport location in device coordinates Window scaled to Normalized Viewport size M vc dc u v min min u ma u min v ma v min ma min ma min min min Normalized Device Coordinates
Efficienc Considerations A 2D point transformation requires 9 multiplies and 6 adds a b c a + b + cz d e f d e fz + + g h i z g + h + iz But since affine transformations have alwas the form: a b c a + b + c d e f d e f + + The number of operations can be reduced to 4 multiplies and 4 adds
Efficienc Considerations The rotation matri is: cos sin sin cos cos + sin + sin cos When rotating of small angles, we can use the fact that cos() and simplif sin + sin sin sin +
Determinant of a Matri a b ad c d bc a b c d e f aei + bfg + cdh ceg afh bdi g h i e f d f d e a b + c h i g i g h If P is a polgon of area A P, transformed b a matri M, the area of the transformed polgon is A P M