1 Computer Graphics Chapter 6 2D Transformations
[6]-2RM Transform every point on an object according to certain rule. Initial Object Transformed Object P (x,y) Q (x’, y’) xx’ yy’ Transformation T The point Q is the image of P under the transformation T.
[6]-3RM (10,5)(30,5) (20,35) (55,60) (65,30) (45,30) Translation The vector (t x, t y ) is called the offset vector.
[6]-4RM Translation (OpenGL)
[6]-5RM (x,y) (x’,y’) o (x,y) (x’,y’) x y Rotation About the Origin The above 2D rotation is actually a rotation about the z-axis (0,0,1) by an angle .
[6]-6RM Rotation About the Origin
[6]-7RM (x p, y p ) (x,y) (x’,y’) Pivot Point Pivot point is the point of rotation Pivot point need not necessarily be on the object Rotation About a Pivot Point
[6]-8RM (x p, y p ) (x,y) (x1, y1) STEP-1: Translate the pivot point to the origin Rotation About a Pivot Point
[6]-9RM (x1, y1) STEP-2: Rotate about the origin (x2, y2) Rotation About a Pivot Point
[6]-10RM STEP-3: Translate the pivot point to original position (x2, y2) (x p, y p ) (x’, y’) Rotation About a Pivot Point
[6]-11RM Rotation About a Pivot Point
[6]-12RM UniformNon-Uniform (x,y) (x’,y’) (x,y) (x’,y’) Scaling About the Origin The parameters s x, s y are called scale factors.
[6]-13RM Scaling About the Origin
[6]-14RM (x f, y f ) (x,y) (x’,y’) Translate the fixed point to origin Scale with respect to the origin Translate the fixed point to its original position. Scaling About a Fixed Point
[6]-15RM Reflections Initial Object Reflection about x y = y x y Reflection about origin x = x y = y Reflection about y x = x
[6]-16RM Reflections
[6]-17RM Shear A shear transformation in the x-direction (along x) shifts the points in the x-direction proportional to the y-coordinate. The y-coordinate of each point is unaffected.
[6]-18RM Translation Rotation [Origin] Scaling [Origin] Matrix Representations
[6]-19RM Reflection about x Matrix Representations Reflection about y Reflection about the Origin
[6]-20RM Shear along x Matrix Representations Shear along y
[6]-21RM Homogeneous Coordinates To obtain square matrices an additional row was added to the matrix and an additional coordinate, the w-coordinate, was added to the vector for a point. In this way a point in 2D space is expressed in three-dimensional homogeneous coordinates. This technique of representing a point in a space whose dimension is one greater than that of the point is called homogeneous representation. It provides a consistent, uniform way of handling affine transformations.
[6]-22RM Cartesian Homogeneous Examples: (5, 8) (15, 24, 3) (x, y) (x, y, 1) Homogeneous Coordinates If we use homogeneous coordinates, the geometric transformations given above can be represented using only a matrix pre-multiplication. A composite transformation can then be represented by a product of the corresponding matrices.
[6]-23RM Translation P’=TP Rotation [O] P’=RP Scaling [O] P’=SP Basic Transformations Homogeneous Coordinates
[6]-24RM If, then, Examples: Inverse of Transformations
[6]-25RM Additional Properties: Transformation Matrices
[6]-26RM Transformation T followed by Transformation Q followed by Transformation R: Example: (Scaling with respect to a fixed point) Composite Transformations Order of Transformations
[6]-27RM In composite transformations, the order of transformations is very important. Order of Transformations Rotation followed by Translation: Translation followed by Rotation:
[6]-28RM OpenGL postmultiplies the current matrix with the new transformation matrix Order of Transformations (OpenGL) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(tx, ty, 0); glRotatef(theta, 0, 0, 1.0); glVertex2f(x,y); Rotation followed by Translation !! Current Matrix [ I ] [ T ] [ T ] [ R ] [ T ] [ R ] P
[6]-29RM Preserved Attributes General Properties
[6]-30RM A general invertible, linear, transformation. Affine Transformation Transformation Matrix:
[6]-31RM Product of affine transformations is affine. Affine transformations preserve linearity of segments. Affine transformations preserve parallelism between lines. Affine transformations are invertible. Affine Transformation: Properties