1 / 43

2D and 3D Transformation

2D and 3D Transformation. Pradondet Nilagupta Dept. of Computer Engineering Kasetsart University. Transformations and Matrices. Transformations are functions Matrices are functions representations Matrices represent linear transformation {2x2 Matrices}  {2D Linear Transformation}.

giza
Download Presentation

2D and 3D Transformation

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. 2D and 3D Transformation Pradondet Nilagupta Dept. of Computer Engineering Kasetsart University 204481 Foundation of Computer Graphics

  2. Transformations and Matrices • Transformations are functions • Matrices are functions representations • Matrices represent linear transformation • {2x2 Matrices}  {2D Linear Transformation} 204481 Foundation of Computer Graphics

  3. Transformations (1/3) • What are they? • changing something to something else via rules • mathematics: mapping between values in a range set and domain set (function/relation) • geometric: translate, rotate, scale, shear,… • Why are they important to graphics? • moving objects on screen / in space • mapping from model space to screen space • specifying parent/child relationships • … 204481 Foundation of Computer Graphics

  4. ty tx hnew hold wold wnew Transformation (2/3) • Translation • Moving an object • Scale • Changing the size of an object xnew = xold + tx; ynew = yold + ty sx=wnew/wold sy=hnew/hold xnew = sxxold ynew = syyold 204481 Foundation of Computer Graphics

  5. (x,y) Transformation (3/3) • To rotate a line or polygon, we must rotate each of its vertices • Shear Original Data y Shear x Shear 204481 Foundation of Computer Graphics

  6. What is a 2D Linear Transform? Example 204481 Foundation of Computer Graphics

  7. Example Scale in x by 2 204481 Foundation of Computer Graphics

  8. Transformations: Translation (1/2) • A translation is a straight line movement of an object from one position to another. • A point (x,y) is transformed to the point (x’,y’) by adding the translation distances Tx and Ty: x’ = x + Tx y’ = y + Ty 204481 Foundation of Computer Graphics

  9. Transformations: Translation(2/2) • moving a point by a given tx and ty amount • e.g. point P is translated to point P’ • moving a line by a given tx and ty amount • translate each of the 2 endpoints 204481 Foundation of Computer Graphics

  10. Transformations: Rotation (1/4) • Objects rotated according to angle of rotation theta () • Suppose a point P(x,y) is transformed to the point P'(x',y') by an anti-clockwise rotation about the origin by an angle of  degrees, then: Given x = r cos  , y = r sin  x’ = x cos  – y sin  y’ = y sin  + y cos  204481 Foundation of Computer Graphics

  11. Transformations: Rotation (2/4) • Rotation P by  anticlockwise relative to origin (0,0) 204481 Foundation of Computer Graphics

  12. Transformations: Rotation (3/4) • Rotation about an arbitary pivot point (xR,yR) Step 1: translation of the object by (-xR,-yR) x1 = x - xR y1 = y - yR Step 2: rotation about the origin x2 = x1 cos(q) - y1sin (q) y2 = y1cos(q) - x1sin (q) Step 3: translation of the rotated object by (xR,yR) x’ = xr + x2 y’ = yr + y2 204481 Foundation of Computer Graphics

  13. Transformations: Rotation (4/4) • object can be rotated around an arbitrary point (xr,yr) known as rotation or pivot point by: x' = xr + (x - xr) cos(q) - (y - yr) sin (q) y' = yr + (x - xr) sin (q)+(y - yr) cos(q) 204481 Foundation of Computer Graphics

  14. Transformations: Scaling (1/5) • Scaling changes the size of an object • Achieved by applying scaling factors sx and sy • Scaling factors are applied to the X and Y co-ordinates of points defining an object’s 204481 Foundation of Computer Graphics

  15. Transformations: Scaling (2/5) • uniform scaling is produced when sx and sy have same value i.e. sx = sy • non-uniform scaling is produced when sx and sx are not equal - e.g. an ellipse from a circle. • i.e. sx sy x2 = sxx1 y2 = syy1 204481 Foundation of Computer Graphics

  16. Transformations: Scaling (3/5) Simple scaling - relative to (0,0) • General form: Ex: sx = 2 and sy=1 204481 Foundation of Computer Graphics

  17. Transformations: Scaling (4/5) • If the point (xf,yf) is to be the fixed point, the transformation is: x' = xf + (x - xf) Sx y' = yf + (y - yf) SyThis can be rearranged to give: x' = x Sx + (1 - Sx) xf y' = y Sy + (1 - Sy) yfwhich is a combination of a scaling about the origin and a translation. 204481 Foundation of Computer Graphics

  18. Transformations: Scaling (5/5) 204481 Foundation of Computer Graphics

  19. Transformation as Matrices Scale: x’ = sxx y’ = syy Rotation: x’ = xcos - ysin  y’ = xsin  + ycos  Translation: x’ = x + tx y’ = y + ty 204481 Foundation of Computer Graphics

  20. Transformations: Shear (1/2) Shear in x: 204481 Foundation of Computer Graphics

  21. Transformations: Shear (2/2) Shear in y: 204481 Foundation of Computer Graphics

  22. Shear in x then in y 204481 Foundation of Computer Graphics

  23. Shear in y then in x 204481 Foundation of Computer Graphics

  24. Homogeneous coordinate • As translations do not have a 2 x 2 matrix representation, we introduce homogeneous coordinates to allow a 3 x 3 matrix representation. • The Homogeneous coordinate corresponding to the point (x,y) is the triple (xh, yh, w) where: xh = wx yh = wyFor the two dimensional transformations we can set w = 1. 204481 Foundation of Computer Graphics

  25. Matrix representation 204481 Foundation of Computer Graphics

  26. Basic Transformation (1/3) • Translation 204481 Foundation of Computer Graphics

  27. Basic Transformation (2/3) • Rotation 204481 Foundation of Computer Graphics

  28. Basic Transformation (3/3) • Scaling 204481 Foundation of Computer Graphics

  29. Composite Transformation Suppose we wished to perform multiple transformations on a point: 204481 Foundation of Computer Graphics

  30. Example of Composite Transformation(1/3) • A scaling transformation at an arbitrary angle is a combination of two rotations and a scaling:R(-t) S(Sx,Sy) R(t) • A rotation about an arbitrary point (xf,yf) by and angle t anti-clockwise has matrix:T(-xf,-yf) R(t) T(xf,yf) 204481 Foundation of Computer Graphics

  31. Example of Composite Transformation(2/3) Reflection about the y-axis Reflection about the x-axis 204481 Foundation of Computer Graphics

  32. Example of Composite Transformation(3/3) Reflection about the origin Reflection about the line y=x 204481 Foundation of Computer Graphics

  33. Y Y Z X X Z 3D Transformation 204481 Foundation of Computer Graphics

  34. Basic 3D Transformations • Translation • Scale • Rotation • Shear • As in 2D, we use homogeneous coordinates (x,y,z,w), so that transformations may be composited together via matrix multiplication. 204481 Foundation of Computer Graphics

  35. 3D Translation and Scaling TP = (x + tx, y + ty, z + tz) SP = (sxx, syy, szz) 204481 Foundation of Computer Graphics

  36. 3D Rotation (1/4) Positive Rotations are defined as follows: Axis of rotation isDirection of positive rotation is x y to z y z to x z x to y 204481 Foundation of Computer Graphics

  37. 3D Rotation (2/4) • Rotation about x-axis Rx(ß)P 204481 Foundation of Computer Graphics

  38. 3D Rotation (3/4) • Rotation about y-axis Ry(ß)P 204481 Foundation of Computer Graphics

  39. 3D Rotation (4/4) • Rotation about z-axis Rz(ß)P 204481 Foundation of Computer Graphics

  40. 3D Shear • xy Shear: SHxyP 204481 Foundation of Computer Graphics

  41. P2 Z U P1 c u3 Y a ß u2 b u1 X Rotation About An Arbitary Axis (1/3) • Translate one end of the axis to the origin • Rotate about the y-axis and angle  • Rotate about the x-axis through an angle  204481 Foundation of Computer Graphics

  42. P2 Z Z U Z a c U u3 P1 c u3 µ Y Y a Y ß a ß u2 u2 u2 b b X u1 u1 X X Rotation About An Arbitary Axis (2/3) 4. When U is aligned with the z-axis, apply the original rotation, R, about the z-axis. 5. Apply the inverses of the transformations in reverse order. 204481 Foundation of Computer Graphics

  43. Rotation About An Arbitary Axis (3/3) T-1 Ry(ß) Rx(-µ) R Rx(µ) Ry(-ß) T P 204481 Foundation of Computer Graphics

More Related