1 / 35

CS430 Computer Graphics

CS430 Computer Graphics. Transformations of Objects – 2D Part I. Topics. Matrix Prelim Introduction Fundamental Transformations Affine Transformations More Affine Transformations Inverse of Affine Transformations Composition of Affine Transformations. Matrix Prelim.

galena-hull
Download Presentation

CS430 Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS430 Computer Graphics Transformations of Objects – 2D Part I Chi-Cheng Lin, Winona State University

  2. Topics • Matrix Prelim • Introduction • Fundamental Transformations • Affine Transformations • More Affine Transformations • Inverse of Affine Transformations • Composition of Affine Transformations

  3. Matrix Prelim • Matrix: rectangle array of numbers • A: nm matrix  n rows, m columns • A vector in nD-space  an n1 matrix

  4. Matrix Multiplication • A: nm matrix B: mp matrix C = A B : np matrix, where • Ai =i th row vector of A Bj =j th column vector of B cij = Ai • Bj • A B = B A ?? • A (B + C )= A B + A C ??

  5. Identity Matrix • Identity matrix I

  6. Determinant of Matrix • Determinant of a 22 matrix A: • Determinant of an nnmatrix A: where A1i = determinant of an (n-1)(n-1) matrix obtained by deleting the first row and i th column from A • Find the determinant of a 33 matrix! (p.824)

  7. Transpose and Inverse of Matrix • Transpose of an nmmatrix A is an mnmatrix B • B = AT, i.e., bij = aji • Transpose of an n1 column vector is a 1n row vector • Inverse of an nnmatrix A is an nnmatrix B • B = A-1 • A B = B A = I

  8. Introduction • Transformation: cornerstone of CG • Change the position, size, orientation of objects • We will focus on linear transformation • Like other graphics systems, transformation is also central to OpenGL

  9. OpenGL Graphics Pipeline • OpenGL pipeline • Example • glBegin(GL_LINES); glVertex3f(…) // send P1 through the pipeline glVertex3f(…) // send P2 through the pipeline glVertex3f(…) // send P3 through the pipeline glEnd(); P1, P2, … Q1, Q2, … Process & display CT Q2 P2 Q1 P1

  10. Transforming Points and Objects • Transformation alters each point P in space into a new point Q by means of formula or algorithm • P is mapped to Q • Q is the image of P under the mapping T • Fundamental transformations • Translate • Scale • Rotate

  11. Fundamental Transformations - Translation • Translation • Change the position of an object • (Qx, Qy) = (Px + dx, Py + dy) or Q = P + T, where T = (dx, dy) y Q2 P2 Q1 dy x P1 dx

  12. Translation Example • Example dx= 3 dy=-4

  13. Sy=2 Sy=2 Sx=3 Sx=3 x x Fundamental Transformations - Scaling • Scaling • Change the size of an object • (Qx, Qy) = (Sx Px, SyPy) or or • Actually it is scaling about the origin X y

  14. Scaling Example • Example Sx=1/2 Sy=1/4

  15. Fundamental Transformations - Rotation • Rotation • Change the orientation of an object • (Qx, Qy) = (Pxcos -Pysin, Pxsin+ Pycos) or or • Derivation of rotation mapping? y Q r r P   x

  16. Fundamental Transformation -Rotation • Rotation (cont’d) • Rotation is performed about the origin y  x

  17. Rotation Example • Example   = 45o

  18. Affine Transformations • Questions • How do we scale/rotate about any point? • How do we combine transformations? • Problem of composing transformations • Translation: Q = T + P  addition • Scaling: Q = SP multiplication • Rotation: Q = RP  multiplication • Solution: homogeneous coordinates • Represent a 2D point (x, y) as (x, y, 1) • A vector (a, b) = (a, b, 0)

  19. Affine Transformations • Coordinates of point Q are linear combinations of those of point P: • Translation, scaling, and rotation are affine transformations (so are their combinations)

  20. Affine Transformations • Translation, scaling, and rotation are affine transformations • Succession of affine transformation is an affine transformation • Affine transformation from vector V to vector W : • The third row of the transformation matrix is always (0, 0, 1)

  21. Fundamental Transformations Revisit • Translation • (Qx, Qy) = (Px + dx, Py + dy)

  22. Fundamental Transformations Revisit • Scaling • (Qx, Qy) = (Sx Px, SyPy)

  23. Fundamental Transformations Revisit • Rotation • (Qx, Qy) = (Pxcos -Pysin, Pxsin+ Pycos)

  24. More Affine Transformations - Reflection • Reflection – special case of scaling • Sx< 0  reflection about the y-axis • Sy< 0  reflection about the x-axis y Sy=2 Sy=1 Sx=3 Sx=-0.5 x Sx=3 Sy=-2

  25. More Affine Transformations - Reflection • Pure reflection • Each of the scale factors is either +1 or –1 • Examples • T(Px, Py) = (-Px, Py) flip horizontally about y-axis • T(Px, Py) = (Px, -Py) flip vertically about x-axis • T(Px, Py) = (-Px, -Py) ? • Uniform scaling • Sx= Sy = S, where |S| is magnification factor • Differential scaling • SxSy

  26. More Affine Transformations - Shearing • ShearX • x-coordinate is translated by an amount that increases linearly with y • y-coordinate is unaffected • Can be used to make italic letters out of regular ones • (Qx, Qy) = (Px + hPy, Py)

  27. More Affine Transformations - Shearing • ShearY • y-coordinate is translated by an amount that increases linearly with x • x-coordinate is unaffected • (Qx, Qy) = (Px, gPx + Py)

  28. Inverse of Affine Transformations • If Q =MP, then P =M–1Q, where M–1 is the inverse of M (i.e., M M–1 = I ) where det M = m11m22 - m12m21 • Inverse of an affine transformation is an affine transformation!

  29. Inverse of Affine Transformations • Translation: T -1(dx, dy) = T(-dx, -dy) • Scaling: S -1(Sx, Sy) = S(1/Sx, 1/Sy) • Rotation: R -1() = R(-) • ShearX: ShX-1(h) = ShX(-h) • ShearY: Shy-1(g) = Shy(-g) • Verify that those matrices are correct • If M = I, what transformation is it?

  30. Composition of Affine Transformations • Composing (concatenating) transformations • Process of applying several transformations in succession to form one overall transformation • Composition of affine transformations is affine • If a sequence of transformations are represented by matrices M1, M2, …, Mn, then a point P is transformed to a point Q = (Mn((M2(M1P))) = (Mn M2M1)P

  31. Composition of Affine Transformations • Example: Build a transformation matrix that • Rotates 45 degrees • Scales in x by 1.5 and in y by –2 • Translates by (3, 5) Find the transformed point of P = (1, 2) • Solution: Q = MP = (1.94, 0.758, 1)

  32. Applications of Composition • Rotate about an arbitrary point (x, y) • Translate by (-x, -y) • Rotate about the origin through angle  • Translate by (x, y) • Transformation matrix M = T(x, y)R()T(-x, -y) 3 2 1

  33. Applications of Composition • Scale about an arbitrary point (x, y) • Translate by (-x, -y) • Scale in x by Sx and in y by Sy • Translate by (x, y)  Transformation matrix M = T(x, y)S(Sx, Sy)T(-x, -y) = ?? • Window-to-viewport transformation is also a good example of composition of affine transformations (why?)

  34. Applications of Composition • Reflection about an axis of reflection that makes an angel of  with the x axis • Rotate by - • Reflect about x-axis (i.e., scale in x by 1 and in y by –1) • Rotate by 

  35. Applications of Composition • Reflection about an axis of reflection that makes an angel of  with the x axis • Translation matrix M = R()S(1, -1)R(-) Let c = cos(-) and s = sin(-), Check it out!

More Related