1 / 39

2-D Transformations

2-D Transformations. Kurt Akeley CS248 Lecture 7 16 October 2007 http://graphics.stanford.edu/courses/cs248-07/. Overview. Today 2-D transformation Composition of 2-D transformations Line equations, 2-D normals, and inverses Thursday Apply 2-D concepts to 3-D

kjudkins
Download Presentation

2-D 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. 2-D Transformations Kurt Akeley CS248 Lecture 7 16 October 2007 http://graphics.stanford.edu/courses/cs248-07/

  2. Overview Today • 2-D transformation • Composition of 2-D transformations • Line equations, 2-D normals, and inverses Thursday • Apply 2-D concepts to 3-D • Look at OpenGL in some detail

  3. struct { UNIT_SQUARE; 30; 2, 3;} GeomObj; CS approach to geometric objects struct { enum shape; float angle; float xpos, ypos;} GeomObj;

  4. Vertex approach Column vectors Collapses shape, orientation, and position into a single (ordered and typed) representation Shape and orientation become implicit

  5. Can operations to change the shape, orientation, and position of vertex-defined geometry also be collapsed into a single representation? Yes!

  6. Translation Move a vertex tx units right and ty units up: T(v, 2, 1)

  7. Rotation (about the origin) Rotate a vertex θ degrees ccw about the origin: R(v, 45)

  8. Scale (about the origin) Scale a vertex sx in x and sy in y: S(v, 1.5, 2)

  9. Shear (about the origin) Shear a vertex hxin thexdirection andhyin theydirection: H(v, 1, 0)

  10. Composition of R, S, and H

  11. Composition of T

  12. Composition of T, R, S, and H Does not require a 3x3 matrix!

  13. Composition of T, R, S, and H

  14. Rotation about (xr ,yr)T Translate (xr ,yr)T to the origin, rotate, then translate back:

  15. Rotation about (xr ,yr)T

  16. Rotation about (xr ,yr)T

  17. Homogeneous Coordinates

  18. Homogeneous coordinates

  19. Always these values Homogeneous translation Move a vertex tx units right and ty units up: T(v, 2, 1)

  20. Homogeneous rotation (about the origin) Rotate a vertex θ degrees ccw about the origin: R(v, 45)

  21. Homogeneous scale (about the origin) Scale a vertex sx in x and sy in y: S(v, 1.5, 2)

  22. Homogeneous shear (about the origin) Shear a vertex hx in the x direction andhyin theydirection: H(v, 1, 0)

  23. Homogeneous composition of R, S, H, and T

  24. Homogeneous rotation about (xr ,yr)T Translate (xr ,yr)T to the origin, rotate, then translate back:

  25. U321 t321 Homogeneous rotation about (xr ,yr)T

  26. Non-homogeneous rotation about (xr ,yr)T

  27. Homogeneous representation trade-offs Advantages: • Simple, familiar, and regular composition rules • Standard 3x3 matrix composition • Division by w will facilitate perspective projection • Graphics is full of 4-component things • Homogeneous 3-D vertexes • R,G,B,A color representations • Homogeneous 3-D texture coordinates Problem areas: • Full homogeneous semantics are complex • E.g., clipping a line may result in two separate segments • Graphics systems generally don’t implement the full semantics • But the subsets vary!

  28. The line equation Note: this is how fragment selection is done during rasterization.

  29. The normal to the line n

  30. Derivation

  31. Transformation of normals Normals are transformed by the inverse of the matrix that transforms vertexes: Note: line equations are transformed by the full homogeneous matrix. Normals are typically transformed by the upper-left 2x2 (actually (n-1)x(n-1)) matrix of the vertex matrix, which is denoted as M in this derivation.

  32. Inverse transforms Can get inverse of a composed matrix two ways: • Direct computation • Gauss-Jordan, pivots, … • Composition of elemental inverses: Order is reversed!

  33. Elemental inverse transforms are simple

  34. Transforming normals correctly matters Transforming a normal with the vertex matrix M, rather than M-1, can give the wrong result: This example treats M as non-homogeneous, or, equivalently, as the upper-left 2x2 matrix of the homogeneous matrix.

  35. Correct Transforming normals correctly matters Transforming a normal with the vertex matrix M, rather than M-1, can give the wrong result: This example treats M as non-homogeneous, or, equivalently, as the upper-left 2x2 matrix of the homogeneous matrix.

  36. Rigid-body transformations Change orientation and position, but not shape Preserve geometric lengths and (relative) angles Rigid-body transformations are: • Translation and Rotation • Not Scale and Shear (with occasional exceptions) A homogeneous matrix is a rigid-body matrix if its upper-left 2x2 ((n-1)x(n-1)) matrix is orthogonal A matrix is orthogonal if and only if • All columns are orthogonal and unit-length, and • All rows are orthogonal and unit-length

  37. Relationship of R, S, and H A rotation can be composed of a shear and a scale:

  38. Summary Vertex specification of geometry collapses shape, orientation, and position into a single representation Transformations can be collapsed (through composition) into a single representation too • With an efficient 6-value U,t representation • That uses customized composition rules • With 3x3 matrix representation, and a homogeneous 3-component vertex • That uses standard matrix-composition rules Homogeneous representation is a clever approach • We’ll see more application in future lectures • But beware, graphics typically neither needs nor gets the full power of homogeneous coordinates Normals are transformed by the inverse of the composite matrix • They derive directly from line equations

  39. Assignments No reading assignment for Thursday’s class Project 2: • Assigned today • Due Wednesday 24 October

More Related