CSE328 Fundamentals of Computer Graphics: Theor, Algorithms, and Applications Hong in State Universit of New York at Ston Brook (Ston Brook Universit) Ston Brook, New York 794-44 Tel: (63)632-845; Fa: (63)632-8334 qin@cs.sunsb.edu http://www.cs.sunsb.edu/~qin
2D-3D Transformations From local, model coordinates to global, world coordinates
Modeling Transformations 2D-3D transformations Specif transformations for objects Allows definitions of objects in their own coordinate sstems Allows use of object definition multiple times in a scene Please pa attention to how OpenGL provides a transformation stack because the are so frequentl reused
Overview 2D Transformations Basic 2D transformations Matri representation Matri composition 3D Transformations Basic 3D transformations Same as 2D
From Model Coordinates to World Coordinates (Local to Global) Model coordinates (local) World coordinates (global) CSE528 Lectures
Basic 2D Transformations Translation: = + t = + t Scale: = * s = * s Shear: = + h * = + h * Rotation: = *cos - *sin = *sin + *cos
Scaling Scaling a coordinate means multipling each of its components b a scalar Uniform scaling means this scalar is the same for all components: Non-uniform scaling: different scalars per component: How can we represent scaling in matri form?
Scaling Operation in Matri Form b a b a
Scaling Scaling operation: Or, in matri form: b a b a scaling matri
Rotation
2-D Rotation = cos() - sin() = sin() + cos()
2D Rotation Derivation = r cos (f) = r sin (f) = r cos (f + ) = r sin (f + ) = r cos(f) cos() r sin(f) sin() = r sin(f) sin() + r cos(f) cos() = cos() - sin() = sin() + cos()
2-D Rotation It is straightforward to see this procedure in matri form: cos sin sin cos Even though sin() and cos() are nonlinear functions of, is a linear combination of and is a linear combination of and
2D Rotation cos sin sin cos
Basic 2D Transformations Translation: = + t = + t Scale: = * s = * s Shear: = + h * = + h * Rotation: = *cos - *sin = *sin + *cos
Basic 2D Transformations Translation: = + t = + t Scale: = * s = * s Shear: = + h * = + h * Rotation: = *cos - *sin = *sin + *cos Transformations can be combined (with simple algebra)
Combining Transformations Transformations can be combined (with simple algebra)
Composite Transformations Transformations can be combined (with simple algebra)
Matri Representation Represent 2D transformation b a matri Multipl matri b column vector appl transformation to point
Overview 2D Transformations Basic 2D transformations Matri representation Matri composition 3D Transformations Basic 3D transformations Same as 2D
Matri Representation a c b d a c b d a c b d
Matri Representation Represent 2D transformation b a matri a c b d Multipl matri b column vector appl transformation to point a c b d a c b d
Matri Representation a c b d e g f h i k j l
Matri Representation Transformations can be combined b multiplication Matrices are a convenient and efficient wa to represent a sequence of transformations!
Matri Representation Transformations combined b multiplication a c b d e g f h i k j l Matrices are a convenient and efficient wa to represent a sequence of transformations!
22 Matrices What tpes of transformations can be represented with a 22 matri? 2D Identit? 2D Scale around (,)? s s * * s s
22 Matrices What tpes of transformations can be represented with a 22 matri? 2D Rotate around (,)? * cos * sin * sin * cos cos sin sin cos 2D Shear? sh sh * * sh sh
22 Matrices What tpes of transformations can be represented with a 22 matri? 2D Mirror about Y ais? 2D Mirror over (,)?
22 Matrices What tpes of transformations can be represented with a 22 matri? 2D Translation? t t NO! Onl linear 2D transformations can be represented with a 22 matri
Linear Transformations Linear transformations are combinations of Scale, Rotation, Shear, and Mirror Properties of linear transformations: Satisfies: Origin maps to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition a d T( sp s2p2) st ( p) s2t ( p2) c b
Homogeneous Coordinates : How can we represent translation as a 33 matri? t t
Homogeneous Coordinates Homogeneous coordinates represent coordinates in 2 dimensions with a 3- vector homogeneou s coords Homogeneous coordinates appear to be far less intuitive, but the indeed make graphics operations much easier
Homogeneous Coordinates : How can we represent translation as a 33 matri? A: Using the rightmost column: t t Translation t t
Translation Eample of translation t t t t
Homogeneous Coordinates Add a 3rd coordinate to ever 2D point (,, w) represents a point at location (/w, /w) (,, ) represents a point at infinit (,, ) is not allowed Note that, (6,3,); (2,6,2); and (8,9,3) represent the SAME POINT in 2D Convenient coordinate sstem to represent man useful transformations
Basic 2D Transformations Basic 2D transformations as 33 matrices cos sin sin cos t t sh sh Translate Rotate Shear s s Scale
Affine Transformations Affine transformations are combinations of Linear transformations, and Translations Properties of affine transformations: Origin does not necessaril map to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition a d w b e c f w
Projective Transformations Projective transformations Affine transformations, and Projective warps w Properties of projective transformations: Origin does not necessaril map to origin Lines map to lines Parallel lines do not necessaril remain parallel Ratios are not preserved Closed under composition a d g b e h c f i w
Overview 2D Transformations Basic 2D transformations Matri representation Matri composition 3D Transformations Basic 3D transformations Same as 2D
Matri Composition Transformations can be combined b matri multiplication w s s t t w cos sin sin cos p = T(t,t ) * R() * S(s,s ) * p
Matri Composition Matrices are a convenient and efficient wa to represent a sequence of transformations General purpose representation Hardware matri multipl p = (T * (R * (S*p) ) ) p = (T*R*S) * p
Matri Composition From local coordinates to global coordinates Be aware: order of transformations matters Matri multiplication is not commutative p = T * R * S * p
Matri Composition A more complicated eample: rotating 9 degrees around the mid-point of a line segment (whose coordinates are (3,2)) Can we change the order between rotation and translation?
Will this sequence of operations work? Matri Composition 2 3 cos(9) sin(9) sin(9) cos(9) 2 3 a a a a
Matri Composition After correctl ordering the matrices Multipl matrices together What results is one matri store it (on stack)! Multipl this matri b the vector of each verte All vertices easil transformed with one matri multipl
Overview 2D Transformations Basic 2D transformations Matri representation Matri composition 3D Transformations Basic 3D transformations Same as 2D
3D Transformations Same idea as 2D transformations Homogeneous coordinates: (,,z,w) 44 transformation matrices w z p o n m l k j i h g f e d c b a w z
Basic 3D Transformations w z w z w z t t t w z z w z s s s w z z w z w z Identit Scale Translation Mirror about Y/Z plane
Basic 3D Transformations w z w z cos sin sin cos Rotate around Z ais: w z w z cos sin sin cos Rotate around Y ais: w z w z cos sin sin cos Rotate around X ais:
Reverse Rotations : How do ou undo a rotation of, R()? A: Appl the inverse of the rotation R - () = R(-) How to construct R-() = R(-) Inside the rotation matri: cos() = cos(-) The cosine elements of the inverse rotation matri are unchanged The sign of the sine elements will flip This is because the rotation matri is orthogonal matri Therefore R - () = R(-) = R T ()
Summar Coordinate sstems are the basis for computer graphics World vs. model coordinates (Global vs. Local) 2-D and 3-D transformations Trigonometr and geometr Matri representations Linear, affine, and projective transformations Matri operations Matri composition