1 / 43

Computer Graphics

Computer Graphics. Chapter 5 Geometric Transformations. Andreas Savva. y. T. x. 2D Translation. Repositioning an object along a straight line path from one co-ordinate location to another ( x,y ) ( x’,y’ )

sharla
Download Presentation

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. Computer Graphics Chapter 5 Geometric Transformations Andreas Savva

  2. y T x 2D Translation • Repositioning an object along a straight line path from one co-ordinate location to another (x,y) (x’,y’) To translate a 2D position, we add translation distances tx and ty to the original coordinates (x,y) to obtain the new coordinate position (x’,y’) x’= x + tx, y’= y + ty Matrix form

  3. 20 20 15 15 10 10 y y 5 5 5 5 10 10 15 15 20 20 x x 2D Translation • Moving a polygon from position (a) to position (b) with the translation vector (-5, 10), i.e. (a) (b)

  4. Translating a Polygon class Point2D { public: GLfloat x, y; }; void translatePoly(Point2D P[], GLint n, GLfloat tx, GLfloat ty) { GLint i; for (i=0; i<n; i++) { P[i].x = P[i].x + tx; P[i].y = P[i].y + ty; } glBegin (GL_POLYGON); for (i=0; i<n; i++) glVertex2f(P[i].x, P[i].y); glEnd(); }

  5. r r θ φ y (x’,y’) (x,y) x 2D Rotation • Repositioning an object along a circular path in the xy-plane The original coordinates are:

  6. r r θ φ y (x’,y’) (x,y) x 2D Rotation • Substituting Matrix form

  7. (x’,y’) r θ r (x,y) φ yr xr y x 2D Rotation about a Pivot position • Rotating about pivot position (xr, yr)

  8. Translating a Polygon class Point2D { public: GLfloat x, y; }; void rotatePoly(Point2D P[], GLint n, Point2D pivot, GLdouble theta) { Point2D *V; V = new Point2D[n]; GLint i; for (i=0; i<n; i++) { V[i].x = pivot.x + (P[i].x – pivot.x) * cos(theta) - (P[i].y – pivot.y) * sin(theta); V[i].y = pivot.y + (P[i].x – pivot.x) * sin(theta) - (P[i].y – pivot.y) * cos(theta); } glBegin (GL_POLYGON); for (i=0; i<n; i++ glVertex2f(V[i].x, V[i].y); glEnd(); delete[] V; }

  9. Sx = Sy = ½ y x’ x Reduced in size and moved closer to the origin Sx = Sy = ½ x 2D Scaling • Altering the size of an object. Sx and Sy are the scaling factors. If Sx = Sy then uniform scaling. Matrix form

  10. P1 P1’ (xf , yf) P2’ P2 P3’ P3 Sx = ¼ , Sy = ½ y x 2D Scaling relative to Fixed point • Scaling relative to fixed point(xf, yf) OR where the additive terms xf(1-Sx) and yf(1-Sy) are constants for all points in the object.

  11. Translating a Polygon class Point2D { public: GLfloat x, y; }; void scalePoly(Point2D P[], GLint n, Point2D fixedPt, GLfloat Sx, GLfloat Sy) { Point2D *V; V = new Point2D[n]; GLfloat addx = fixedPt.x * (1 – Sx); GLfloat addy = fixedPt.y * (1 – Sy); GLint i; for (i=0; i<n; i++) { V[i].x = P[i].x * Sx + addx; V[i].y = P[i].y * Sy + addy; } glBegin (GL_POLYGON); for (i=0; i<n; i++ glVertex2f(V[i].x, V[i].y); glEnd(); delete[] V; }

  12. Matrix Representation • Use 3×3 matrices to combine transformations • Translation • Rotation • Scaling

  13. Inverse Transformations • Translation • Rotation • Scaling

  14. (30, 25) (10, 10) y x Example • Consider the line with endpoints (10, 10) and (30, 25). Translate it by tx = -20, ty = -10 and then rotate it by θ = 90º. Right-to-left

  15. (30, 25) (10, 10) y x Solution

  16. y (30, 25) (-15, 10) (10, 10) x (0, -10) Solution (continue) Point (10, 10) Point (30, 25)

  17. y (30, 25) (-15, 10) (10, 10) x (0, -10) y y (10, 15) (-15, 10) (-10, 0) x x (0, -10) Result Step-by-step T(-20, -10) R(90º)

  18. y 25 10 x 10 45 Exercises • Consider the following object: • Apply a rotation by 145º then scale it by Sx=2 and Sy=1.5 and then translate it by tx=20 and ty=-30. • Scale it by Sx=½ and Sy=2 and then rotate it by 30º. • Apply a rotation by 90º and then another rotation by 45º. • Apply a rotation by 135º.

  19. Exercises • Composite 2D Transformations • Translation: Show that: • Rotation: Show that: • Scaling: Show that:

  20. (xr , yr) y y y y x x x x (xr , yr) General 2D Pivot-Point Rotation Original position and Pivot Point Translate Object so that Pivot Point is at origin Rotation about origin Translate object so that Pivot Point is return to position (xr , yr)

  21. General Pivot-point Rotation Using Matrices

  22. y 25 10 x 10 45 Exercises • Consider the following object: • Apply a rotation by 60° on the Pivot Point (-10, 10) and display it. • Apply a rotation by 30° on the Pivot Point (45, 10) and display it. • Apply a rotation by 270° on the Pivot Point (10, 0) and then translate it by tx = -20 and ty = 5. Display the final result.

  23. (xf , yf) y y y y x x x x (xf , yf) General 2D Fixed-Point Scaling Original position and Fixed Point Translate Object so that Fixed Point is at origin Scale Object with respect to origin Translate Object so that Fixed Point is return to position (xf , yf)

  24. General 2D Fixed-Point Scaling Using Matrices

  25. y 125 50 x 60 220 Exercises • Consider the following object: • Scale it by sx = 2 and sy = ½ relative to the fixed point (140, 125) and display it. • Apply a rotation by 90° on the Pivot Point (50, 60) and then scale it by sx = sy = 2 relative to the Fixed Point (0, 200). Display the result. • Scale it sx = sy = ½ relative to the Fixed Point (50, 60) and then rotate it by 180° on the Pivot Point (50, 60). Display the final result.

  26. y y x x Object is first translated in the x direction and then rotated by 90º Object is first rotated by 90º and then translated in the x direction Order of Transformations

  27. y y x x Reflection of an object about the x axis Reflection of an object about the y axis Reflection About the x axis About the y axis

  28. y x Same as a rotation with 180º y = x y x Reflection Relative to the coordinate origin With respect to the line y = x

  29. 1 1 Initial object y y 1 1 3 2 shx = 2 x x 2D Shear • x-direction shear Matrix form

  30. y 1 1 x yref = -1 yref = -1 1 1 3 x 2 shx = ½, yref = -1 2D Shear • x-direction relative to other reference line Matrix form y

  31. 1 1 Initial object 3 y y 2 1 1 shy = 2 x x 2D Shear • y-direction shear Matrix form

  32. y 1 x 1 xref = -1 xref = -1 y 2 1 x 1 2D Shear • y-direction relative to other reference line Matrix form shy = ½, xref = -1

  33. y y’  y0 x x’ x0 Transformations between 2D Coordinate Systems • To translate object descriptions from xy coordinates to x’y’ coordinates, we set up a transformation that superimposes the x’y’ axes onto the xy axes. This is done in two steps: • Translate so that the origin (x0, y0) of the x’y’ system is moved to the origin (0, 0) of the xy system. • Rotate the x’ axis onto the x axis.

  34. Transformations between 2DCoordinate Systems • i.e. 1) 2) Concatenating:

  35. y y’ 30º 10 (35, 20) x x’ 30 (10, 20) Example • Find the x’y’-coordinates of the xy points (10, 20) and (35, 20), as shown in the figure below:

  36. y’ y’ (-12.38, 18.66) x’ y (9.31, 6.16) 30º 10 x’ 30 (35, 20) x (10, 20)

  37. y y’ 20 10 60º x x’ 10 Exercise • Find the x’y’-coordinates of the rectangle shown in the figure below:

  38. y T(tx, ty, tz) x z 3D Translation • Repositioning an object along a straight line path from one co-ordinate location to another (x,y,z) (x’,y’,z’) To translate a 3D position, we add translation distances txty and tz to the original coordinates (x,y,z) to obtain the new coordinate position (x’,y’) x’= x + tx, y’= y + ty , z’= z + tz Matrix form (4 × 4)

  39. y y x x z z 3D Rotation • z-axis • The 2D z-axis rotation equations are extended to 3D. Matrix form

  40. y x z 3D Rotation • x-axis Matrix form

  41. y x z 3D Rotation • y-axis Matrix form

  42. y x z 3D Scaling Matrix form

  43. y x z Other 3D Transformations • Reflection z-axis • Shears z-axis

More Related