Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course Website: Computer Graphics 3: 2D Transformations.

Similar presentations


Presentation on theme: "Course Website: Computer Graphics 3: 2D Transformations."— Presentation transcript:

1 Course Website: http://www.comp.dit.ie/bmacnameehttp://www.comp.dit.ie/bmacnamee Computer Graphics 3: 2D Transformations

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

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

4 4 of 25 Translation Simply moves an object from one position to another x new = x old + dxy new = y old + dy Note: House shifts position relative to origin y x 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6

5 5 of 25 Translation Example y x 0 1 1 2 2 345678910 3 4 5 6 (1, 1) (3, 1) (2, 3)

6 6 of 25 Scaling Scalar multiplies all coordinates WATCH OUT: Objects grow and move! x new = Sx × x old y new = Sy × y old Note: House shifts position relative to origin y x 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6

7 7 of 25 Scaling Example y 0 1 1 2 2 345678910 3 4 5 6 (1, 1) (3, 1) (2, 3)

8 8 of 25 Rotation Rotates all coordinates by a specified angle x new = x old × cosθ – y old × sinθ y new = x old × sinθ + y old × cosθ Points are always rotated about the origin y x 0 1 1 2 2 3 4 5 6 7 8 9 10 3 4 5 6

9 9 of 25 Rotation Example y 0 1 1 2 2 345678910 3 4 5 6 (3, 1) (5, 1) (4, 3)

10 10 of 25 Homogeneous Coordinates A point (x, y) can be re-written in homogeneous coordinates as (x h, y h, h) The homogeneous parameter h 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 11 of 25 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 12 of 25 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 13 of 25 Remember Matrix Multiplication Recall how matrix multiplication takes place:

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

15 15 of 25 Homogenous Coordinates (cont…) Rotation:

16 16 of 25 Inverse Transformations Transformations can easily be reversed using inverse transformations

17 17 of 25 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 18 of 25 Combining Transformations (cont…) 1 2 3 4

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

20 20 of 25 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 21 of 25 Exercises 1 x y 0 1 1 2 2 345678910 3 4 5 6 (2, 3) (3, 2) (1, 2) (2, 1) Translate the shape below by (7, 2)

22 22 of 25 Exercises 2 x y 0 1 1 2 2 345678910 3 4 5 6 (2, 3) (3, 2) (1, 2) (2, 1) Scale the shape below by 3 in x and 2 in y

23 23 of 25 Exercises 3 Rotate the shape below by 30° about the origin x y 0 1 1 2 2 345678910 3 4 5 6 (7, 3) (8, 2) (6, 2) (7, 1)

24 24 of 25 Exercise 4 Write out the homogeneous matrices for the previous three transformations TranslationScalingRotation

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

26 26 of 25 Scratch x y 0 1 1 2 2 345678910 3 4 5 6

27 27 of 25 Equations Translation: x new = x old + dxy new = y old + dy Scaling: x new = Sx × x old y new = Sy × y old Rotation x new = x old × cosθ – y old × sinθ y new = x old × sinθ + y old × cosθ


Download ppt "Course Website: Computer Graphics 3: 2D Transformations."

Similar presentations


Ads by Google