390 likes | 408 Views
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
E N D
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 • Look at OpenGL in some detail
struct { UNIT_SQUARE; 30; 2, 3;} GeomObj; CS approach to geometric objects struct { enum shape; float angle; float xpos, ypos;} GeomObj;
Vertex approach Column vectors Collapses shape, orientation, and position into a single (ordered and typed) representation Shape and orientation become implicit
Can operations to change the shape, orientation, and position of vertex-defined geometry also be collapsed into a single representation? Yes!
Translation Move a vertex tx units right and ty units up: T(v, 2, 1)
Rotation (about the origin) Rotate a vertex θ degrees ccw about the origin: R(v, 45)
Scale (about the origin) Scale a vertex sx in x and sy in y: S(v, 1.5, 2)
Shear (about the origin) Shear a vertex hxin thexdirection andhyin theydirection: H(v, 1, 0)
Composition of T, R, S, and H Does not require a 3x3 matrix!
Rotation about (xr ,yr)T Translate (xr ,yr)T to the origin, rotate, then translate back:
Always these values Homogeneous translation Move a vertex tx units right and ty units up: T(v, 2, 1)
Homogeneous rotation (about the origin) Rotate a vertex θ degrees ccw about the origin: R(v, 45)
Homogeneous scale (about the origin) Scale a vertex sx in x and sy in y: S(v, 1.5, 2)
Homogeneous shear (about the origin) Shear a vertex hx in the x direction andhyin theydirection: H(v, 1, 0)
Homogeneous rotation about (xr ,yr)T Translate (xr ,yr)T to the origin, rotate, then translate back:
U321 t321 Homogeneous rotation about (xr ,yr)T
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!
The line equation Note: this is how fragment selection is done during rasterization.
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.
Inverse transforms Can get inverse of a composed matrix two ways: • Direct computation • Gauss-Jordan, pivots, … • Composition of elemental inverses: Order is reversed!
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.
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.
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
Relationship of R, S, and H A rotation can be composed of a shear and a scale:
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
Assignments No reading assignment for Thursday’s class Project 2: • Assigned today • Due Wednesday 24 October