1 / 27

Computer Graphics 3: 2D Transformations

Computer Graphics 3: 2D Transformations. Contents. In today’s lecture we’ll cover the following: Why transformations Transformations Translation Scaling Rotation Homogeneous coordinates Matrix multiplications Combining transformations. Why Transformations?.

johnna
Download Presentation

Computer Graphics 3: 2D Transformations

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. Computer Graphics 3:2D Transformations

  2. Contents • In today’s lecture we’ll cover the following: • Why transformations • Transformations • Translation • Scaling • Rotation • Homogeneous coordinates • Matrix multiplications • Combining transformations

  3. Why Transformations? Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004) • In graphics, once we have an object described, transformations are used to move that object, scale it and rotate it

  4. Translation y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 x Note: House shifts position relative to origin • Simply moves an object from one position to another • xnew = xold + dx ynew = yold + dy

  5. Translation Example y 6 5 4 3 2 1 x 0 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 1) (3, 1)

  6. Scaling y 6 5 4 3 x 2 Note: House shifts position relative to origin 1 0 1 2 3 4 5 6 7 8 9 10 • Scalar multiplies all coordinates • WATCH OUT: Objects grow and move! • xnew = Sx × xold ynew = Sy × yold

  7. Scaling Example y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 1) (3, 1)

  8. Rotation • Rotates all coordinates by a specified angle • xnew = xold×cosθ – yold×sinθ • ynew = xold×sinθ + yold×cosθ • Points are always rotated about the origin y 6 5 4 3 2 1 x 0 1 2 3 4 5 6 7 8 9 10

  9. Rotation Example y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 (4, 3) (3, 1) (5, 1)

  10. Homogeneous Coordinates • A point (x, y) can be re-written in homogeneous coordinates as (xh, yh, h) • The homogeneous parameterh is a non-zero value such that: • We can then write any point (x, y) as (hx, hy, h) • We can conveniently choose h = 1 so that (x, y) becomes (x, y, 1)

  11. Why Homogeneous Coordinates? • Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations • We will see in a moment that all of the transformations we discussed previously can be represented as 3*3 matrices • Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!

  12. Homogeneous Translation • The translation of a point by (dx, dy) can be written in matrix form as: • Representing the point as a homogeneous column vector we perform the calculation as:

  13. Remember Matrix Multiplication • Recall how matrix multiplication takes place:

  14. Homogenous Coordinates • To make operations easier, 2-D points are written as homogenous coordinate column vectors Translation: Scaling:

  15. Homogenous Coordinates (cont…) Rotation:

  16. Inverse Transformations • Transformations can easily be reversed using inverse transformations

  17. Combining Transformations • A number of transformations can be combined into one matrix to make things easy • Allowed by the fact that we use homogenous coordinates • Imagine rotating a polygon around a point other than the origin • Transform to centre point to origin • Rotate around origin • Transform back to centre point

  18. Combining Transformations (cont…) 2 1 3 4

  19. Combining Transformations (cont…) • The three transformation matrices are combined as follows REMEMBER: Matrix multiplication is not commutative so order matters

  20. Summary • In this lecture we have taken a look at: • 2D Transformations • Translation • Scaling • Rotation • Homogeneous coordinates • Matrix multiplications • Combining transformations • Next time we’ll start to look at how we take these abstract shapes etc and get them on-screen

  21. Exercises 1 y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 • Translate the shape below by (7, 2) (2, 3) (1, 2) (3, 2) (2, 1) x

  22. Exercises 2 y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 • Scale the shape below by 3 in x and 2 in y (2, 3) (1, 2) (3, 2) (2, 1) x

  23. Exercises 3 y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 • Rotate the shape below by 30° about the origin (7, 3) (6, 2) (8, 2) (7, 1) x

  24. Exercise 4 • Write out the homogeneous matrices for the previous three transformations Translation Scaling Rotation

  25. Exercises 5 y 5 (5, 4) 4 (4, 3) (6, 3) 3 2 (5, 2) 1 x 0 1 2 3 4 5 6 7 8 9 10 • Using matrix multiplication calculate the rotation of the shape below by 45° about its centre (5, 3)

  26. Scratch y 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 x

  27. Equations • Translation: • xnew = xold + dx ynew = yold + dy • Scaling: • xnew = Sx × xold ynew = Sy × yold • Rotation • xnew = xold×cosθ – yold×sinθ • ynew = xold×sinθ + yold×cosθ

More Related