2D Geometric Transformations (Chapter 5 in FVD) 2D Geometric Transformations Question: How do we represent a geometric object in the plane? Answer: For now, assume that objects consist of points and lines. A point is represented b its Cartesian coordinates: (x,). Question: How do we transform a geometric object in the plane? Answer: Let (A,B) be a straight line segment and T a general 2D transformation: T transforms (A,B) into another straight line segment (A,B ), where A =TA and B =TB. 2
Translation Translate (a,b): (x,) (x+a,+b) Translate(2,4) 3 Scale Scale (a,b): (x,) (ax,b) Scale (2,3) Scale (2,3) 4
How can we scale an object without moving its origin (lower left corner)? Translate(-,-) Translate(,) Scale(2,3) 5 Reflection Scale(-,) Scale(,-) 6
Rotate(θ): Rotation (x,) (x cos(θ)+ sin(θ), -x sin(θ)+ cos(θ)) Rotate(9) Rotate(9) 7 How can we rotate an object without moving its origin (lower left corner)? Translate(-,-) Translate(,) Rotate(9) 8
Shear Shear (a,b): (x,) (x+a,+bx) Shear(,) Shear(,2) 9 Composition of Transformations Rigid transformation: Translation + Rotation (distance preserving). Similarit transformation: Translation + Rotation + uniform Scale (angle preserving). Affine transformation: Translation + Rotation + Scale + Shear (parallelism preserving). All above transformations are groups where Rigid Similarit Affine.
Matrix Notation Let s treat a point (x,) as a 2x matrix (a column vector): x What happens when this vector is multiplied b a 2x2 matrix? a c bx ax + b = d cx + 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 (x,) is represented b a 2x column vector, and we can represent 2D transformations using 2x2 matrices: x' a = ' bx d 2
3 Scale Scale(a,b): (x,) (ax,b) If a or b are negative, we get reflection. = b ax x b a 4 Reflection Reflection through the axis: Reflection through the x axis: Reflection through =x: Reflection through =-x:
Shear, Rotation Shear(a,b): (x,) (x+a,+bx) b ax x + a = + bx Rotate(θ): (x,) (xcosθ+sinθ, -xsinθ + cosθ) cosθ sinθ sinθ x x cosθ + sinθ = cosθ xsinθ + cosθ 5 Composition of Transformations A sequence of transformations can be collapsed into a single matrix: x x [ A][ B][ C] = [ D] Note: order of transformations is important! (otherwise - commutative groups) translate rotate rotate translate 6
Translation x x + a Translation(a,b): + b Problem: Cannot represent translation using 2x2 matrices. Solution: Homogeneous Coordinates 7 Homogeneous Coordinates Homogeneous Coordinates is a mapping from R n to R n+ : ( x, ) ( X, Y, W) = ( tx, t, t) Note: (tx,t,t) all correspond to the same non-homogeneous point (x,). E.g. (2,3,) (6,9,3). Inverse mapping: X ( X, Y, W ), W Y W 8
9 Translation Translate(a,b): Affine transformation now have the following form: + + = b a x x b a f d c e b a 2 (X,Y,W) x X Y W (X,Y,) 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=.
Example: Rotation about an arbitrar point: Actions: θ (x, ) Translate the coordinates so that the origin is at (x, ). Rotate b θ. Translate back. x cosθ sinθ sinθ cosθ x x = cosθ = sinθ sinθ cosθ x ( cosθ ) + 2 ( cosθ ) x sinθ x sin θ Another example: Reflection about an Arbitrar Line: p 2 p L=p +t (p 2 -p )=t p 2 +(-t) p Actions: Translate the coordinates so that P is at the origin. Rotate so that L aligns with the x- axis. Reflect about the x-axis. Rotate back. Translate back. 22
Viewing in 2D (Chapter 6 in FVD) Device Coordinate Viewport World Coordinate Window Object in World 2D:2D mapping 3D:2D mapping Device Coordinates World Coordinates Objects are given in world coordinates. The world is viewed through a worldcoordinate window. The WC window is mapped onto a device coordinate viewport. 23 Viewing in 2D (cont.) Window Viewport Maximum range of screen coordinates World Coordinates Screen Coordinates (Device Coordinates) Window to Viewport Transformation 24
Window to Viewport Transformation (x max, max ) (u max,v max ) (x min, min ) (u min,v min ) Window in World Coordinates Window translated to origin Window scaled to viewport size. Translated to viewport position in screen coordinates. u M wv = T(u min,v min ) S( max -u min v, max -v min x ) T(-x min,- min ) max -x min max - min = u min v min u max -u min x max -x min vmax -v min max - min -x min - min = u max -u min u max -u min x max -x min x max -x (-x min ) + u min min vmax -v min v max -v min max - min max - (- min ) + v min min 25