Transformations
Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation matrices Learn to build arbitrary transformation matrices from simple transformations
Transformations Transformations make possible the project of 3D objects onto 2D screen The graphics transformation process is analogous to taking a photograph with a camera Every transformation can be thought of as changing the representation of a vertex from one coordinate system to another
Affine Transformations Affine transformation is a special class of transformation that is very important for graphical applications. Affine transformation will not alter the type of object. A transformed line (polygon) is still a line (polygon). Any composition of affine transformations is still affine. Translation, rotation, scaling, reflection, and shear are examples of two-dimensional affine transformations. Any general two-dimensional affine transformation can always be expressed as a composition of these five transformations.
Translation Move (translate, displace) a point to a new location Displacement determined by a vector d Three degrees of freedom P’=P+d P P’ d
Translation P’ = P + Twhere Matrix representation:
Rotation (2D) Consider rotation about the origin by degrees ◦ radius stays the same, angle increases by x’=x cos –y sin y’ = x sin + y cos x = r cos y = r sin x = r cos ( y = r sin (
Rotation About the Origin Matrix representation: P’ = R·P where
UniformNon-Uniform (x,y) (x’,y’) (x,y) (x’,y’) Scaling About the Origin The parameters s x, s y are called scale factors.
Scaling About the Origin Matrix representation: P’ = S·P or
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.
Translation P’=TP Rotation [O] P’=RP Scaling [O] P’=SP Basic Transformations Homogeneous Coordinates
In composite transformations, the order of transformations is very important. Order of Transformations Rotation followed by Translation: Translation followed by Rotation:
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
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Reflection corresponds to negative scale factors original s x = -1 s y = 1 s x = -1 s y = -1s x = 1 s y = -1
Reflections Matrix representation : Reflection about x-axis: M x = Reflection about y-axis: M y = Reflection about origin: M O =
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rotation About a Fixed Point other than the Origin Move fixed point to origin Rotate Move fixed point back M = T(p f ) R( ) T(-p f )
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shear Helpful to add one more basic transformation Equivalent to pulling faces in opposite directions
Matrix representation: Shear Shear along x-axis: H x (h) = Shear along x-axis: H y (h) =