{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture05-3

lecture05-3 - Introduction to Computer Graphics CS 445 645...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computer Graphics CS 445 / 645 Lecture 5 Transformations M.C. Escher – Smaller and Smaller (1956) Modeling Transformations Specify transformations for objects Specify • Allows definitions of objects in own coordinate systems • Allows use of object definition multiple times in a scene – Remember how OpenGL provides a transformation Remember stack because they are so frequently reused stack Chapter 5 from Hearn and Baker H&B Figure 109 Overview 2D Transformations • Basic 2D transformations • Matrix representation • Matrix composition 3D Transformations • Basic 3D transformations • Same as 2D 2D Modeling Transformations Modeling Coordinates Scale Translate y x Scale Rotate Translate World Coordinates 2D Modeling Transformations Modeling Coordinates y x Let’s look at this in detail… World Coordinates 2D Modeling Transformations Modeling Coordinates y x Initial location at (0, 0) with x- and y-axes aligned 2D Modeling Transformations Modeling Coordinates y x Scale .3, .3 Rotate -90 Translate 5, 3 2D Modeling Transformations Modeling Coordinates y x Scale .3, .3 Rotate -90 Translate 5, 3 2D Modeling Transformations Modeling Coordinates y x Scale .3, .3 Rotate -90 Translate 5, 3 World Coordinates Scaling Scaling a coordinate means multiplying each of its components by a scalar components Uniform scaling means this scalar is the same for all components: components: ×2 Scaling Non-uniform scaling: different scalars per component: Non-uniform X × 2, Y × 0.5 How can we represent this in matrix form? Scaling Scaling operation: Or, in matrix form: x' ax y ' = by x ' a y ' = 0 0 x y b scaling matrix 2-D Rotation (x’, y’) (x, y) θ x’ = x cos(θ) - y sin(θ) y’ = x sin(θ) + y cos(θ) 2-D Rotation (x’, y’) (x, y) θ φ x = r cos (φ) y = r sin (φ) x’ = r cos (φ + θ) y’ = r sin (φ + θ) Trig Identity… x’ = r cos(φ) cos(θ) – r sin(φ) sin(θ) y’ = r sin(φ) sin(θ) + r cos(φ) cos(θ) Substitute… x’ = x cos(θ) - y sin(θ) y’ = x sin(θ) + y cos(θ) 2-D Rotation This is easy to capture in matrix form: x ' cos(θ ) y ' = sin (θ ) − sin (θ ) x cos(θ ) y Even though sin(θ) and cos(θ) are nonlinear functions are of θ, • x’ is a linear combination of x and y • y’ is a linear combination of x and y Basic 2D Transformations Translation: • x’ = x + tx • y’ = y + ty Scale: • x’ = x * sx • y’ = y * sy Shear: • x’ = x + hx*y • y’ = y + hy*x Rotation: • x’ = x*cosΘ - y*sinΘ • y’ = x*sinΘ + y*cosΘ Transformations can be combined (with simple algebra) Basic 2D Transformations Translation: • x’ = x + tx • y’ = y + ty Scale: • x’ = x * sx • y’ = y * sy Shear: • x’ = x + hx*y • y’ = y + hy*x Rotation: • x’ = x*cosΘ - y*sinΘ • y’ = x*sinΘ + y*cosΘ Basic 2D Transformations Translation: • x’ = x + tx • y’ = y + ty (x,y) Scale: • x ’ = x * sx x’ (x’,y’) • y ’ = y * sy y’ Shear: • x’ = x + hx*y • y’ = y + hy*x Rotation: • x’ = x*cosΘ - y*sinΘ • y’ = x*sinΘ + y*cosΘ x’ = x*sx y’ = y*sy Basic 2D Transformations Translation: • x’ = x + tx • y’ = y + ty Scale: • x’ = x * sx • y’ = y * sy Shear: • x’ = x + hx*y • y’ = y + hy*x Rotation: • x’ = x*cosΘ - y*sinΘ • y’ = x*sinΘ + y*cosΘ (x’,y’) x’ = (x*sx)*cosΘ - (y*sy)*sinΘ y’ = (x*sx)*sinΘ + (y*sy)*cosΘ Basic 2D Transformations Translation: • x’ = x + t x x’ • y’ = y + t y y’ Scale: (x’,y’) • x’ = x * sx • y’ = y * sy Shear: • x’ = x + hx*y • y’ = y + hy*x Rotation: • x’ = x*cosΘ - y*sinΘ • y’ = x*sinΘ + y*cosΘ x’ = ((x*sx)*cosΘ - (y*sy)*sinΘ) + tx y’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + ty Basic 2D Transformations Translation: • x’ = x + tx • y = y + ty Scale: • x’ = x * sx • y’ = y * sy Shear: • x’ = x + hx*y • y’ = y + hy*x Rotation: • x’ = x*cosΘ - y*sinΘ • y’ = x*sinΘ + y*cosΘ x’ = ((x*sx)*cosΘ - (y*sy)*sinΘ) + tx y’ = ((x*sx)*sinΘ + (y*sy)*cosΘ) + ty Overview 2D Transformations • Basic 2D transformations • Matrix representation • Matrix composition 3D Transformations • Basic 3D transformations • Same as 2D Matrix Representation Represent 2D transformation by a matrix a c b d Multiply matrix by column vector ⇔ apply transformation to point x' = a y ' c b x d y x' = ax + by y ' = cx + dy Matrix Representation Transformations combined by multiplication x' = a y ' c b e d g f i h k j x l y Matrices are a convenient and efficient way to represent a sequence of transformations! 2x2 Matrices What types of transformations can be What represented with a 2x2 matrix? represented 2D Identity? x' = x y' = y x' = 1 y ' 0 0 x 1 y 2D Scale around (0,0)? x' = s x * x y' = s y * y x ' s x y ' = 0 0 x s y y 2x2 Matrices What types of transformations can be What represented with a 2x2 matrix? represented 2D Rotate around (0,0)? x ' = cos Θ* x − sin Θ* y y ' = sin Θ* x + cos Θ* y x ' cos Θ − sin Θ x y ' = sin Θ cos Θ y 2D Shear? x ' = x + shx * y y ' = shy * x + y x ' 1 y ' = sh y shx x 1 y 2x2 Matrices What types of transformations can be What represented with a 2x2 matrix? represented 2D Mirror about Y axis? x ' = −x y' = y x' = −1 0 x y ' 0 1 y 2D Mirror over (0,0)? x ' = −x y' = −y x' = −1 0 x y ' 0 −1 y 2x2 Matrices What types of transformations can be What represented with a 2x2 matrix? represented 2D Translation? x' = x + t x y' = y + t y NO! Only linear 2D transformations can be represented with a 2x2 matrix Linear Transformations Linear transformations are combinations of … • Scale, • Rotation, • Shear, and x' a y ' = c b x d y • Mirror Properties of linear transformations: • Satisfies: T ( s1p1 + s2p 2 ) = s1T (p1 ) + s2T (p 2 ) • Origin maps to origin • Lines map to lines • Parallel lines remain parallel • Ratios are preserved • Closed under composition Homogeneous Coordinates Q: How can we represent translation as a 3x3 matrix? x' = x + t x y' = y + t y Homogeneous Coordinates Homogeneous coordinates • represent coordinates in 2 represent dimensions with a 3-vector dimensions x x homogeneous coords y → y 1 Homogeneous coordinates seem unintuitive, but they Homogeneous make graphics operations much easier much Homogeneous Coordinates Q: How can we represent translation as a 3x3 matrix? x' = x + t x y' = y + t y A: Using the rightmost column: 1 Translation = 0 0 0 1 0 tx ty 1 Translation Example of translation Homogeneous Coordinates x ' 1 0 t x x x + t x y ' = 0 1 t y = y + t y y 1 0 0 1 1 1 α tx = 2 ty = 1 Homogeneous Coordinates Add a 3rd coordinate to every 2D point • (x, y, w) represents a point at location (x/w, y/w) • (x, y, 0) represents a point at infinity • (0, 0, 0) is not allowed y 2 (2,1,1) or (4,2,2) or (6,3,3) 1 Convenient coordinate system to represent many useful transformations 1 2 x Basic 2D Transformations Basic 2D transformations as 3x3 matrices x ' 1 y ' = 0 1 0 0 1 0 x ' s x y ' = 0 1 0 t x x t y y 1 1 Translate x' cos Θ y ' = sin Θ 1 0 − sin Θ cos Θ Rotate 0 0 x 0 y 11 0 sy 0 Scale 0 x 0 y 11 x ' 1 y ' = sh y 1 0 shx 1 0 Shear 0 x 0 y 11 Affine Transformations Affine transformations are combinations of … • Linear transformations, and • Translations x ' a y ' = d w 0 Properties of affine transformations: • Origin does not necessarily map to origin • Lines map to lines • Parallel lines remain parallel • Ratios are preserved • Closed under composition b e 0 c x f y 1 w Projective Transformations Projective transformations … • Affine transformations, and • Projective warps x' a y ' = d w' g Properties of projective transformations: • Origin does not necessarily map to origin • Lines map to lines • Parallel lines do not necessarily remain parallel • Ratios are not preserved • Closed under composition b e h c x f y i w Overview 2D Transformations • Basic 2D transformations • Matrix representation • Matrix composition 3D Transformations • Basic 3D transformations • Same as 2D Matrix Composition Transformations can be combined by Transformations matrix multiplication matrix x ' 1 y ' = 0 w' 0 p’ = 0 1 0 T(tx,ty) tx cos Θ − sin Θ 0sx ty sin Θ cos Θ 0 0 0 1 0 1 0 R(Θ) 0 sy 0 S(sx,sy) 0 x y 0 1 w p Matrix Composition Matrices are a convenient and efficient way to Matrices represent a sequence of transformations represent • General purpose representation • Hardware matrix multiply p’ = (T * (R * (S*p) ) ) p’ = (T*R*S) * p Matrix Composition Be aware: order of transformations matters – Matrix multiplication is not commutative p’ = T * R * S * p “Global” “Local” Matrix Composition What if we want to rotate and translate? What and • Ex: Rotate line segment by 45 degrees about endpoint a Ex: and lengthen a a Multiplication Order – Wrong Way Our line is defined by two endpoints • Applying a rotation of 45 degrees, R(45), affects both points • We could try to translate both endpoints to return endpoint a to its We original position, but by how much? original a a Wrong R(45) a Correct T(-3) R(45) T(3) Multiplication Order - Correct Isolate endpoint a from rotation effects Isolate • First translate line so a is at origin: T (-3) First • Then rotate line 45 degrees: R(45) a a a • Then translate back so a is where it was: T(3) Then a Matrix Composition Will this sequence of operations work? Will 1 0 − 3 cos(45) − sin( 45) 0 1 0 3 a x a ' x 0 1 0 sin( 45) cos(45) 0 0 1 0 a = a' y y 0 0 1 0 0 1 0 0 1 1 1 Matrix Composition After correctly ordering the matrices Multiply matrices together What results is one matrix – store it (on stack)! What store Multiply this matrix by the vector of each vertex All vertices easily transformed with one matrix All multiply multiply Overview 2D Transformations • Basic 2D transformations • Matrix representation • Matrix composition 3D Transformations • Basic 3D transformations • Same as 2D 3D Transformations Same idea as 2D transformations • Homogeneous coordinates: (x,y,z,w) Homogeneous • 4x4 transformation matrices x' a y' e z' = i w' m b f j n c g k o d x h y l z p w Basic 3D Transformations x' 1 y ' 0 z ' = 0 w 0 0 1 0 0 0 0 1 0 0 x 0 y 0 z 1w Identity x ' 1 y ' 0 = z ' 0 w 0 0 1 0 0 0 0 1 0 t x x t y y t z z 1 w Translation x ' s x y ' 0 = z' 0 w 0 x' −1 y ' 0 z' = 0 w 0 0 sy 0 0 0 0 sz 0 0 1 0 0 0 0 1 0 Scale 0 x 0 y 0 z 1w 0 x 0 y 0 z 1 w Mirror about Y/Z plane Basic 3D Transformations Rotate around Z axis: x' cos Θ − sin Θ y ' sin Θ cos Θ z ' = 0 0 w 0 0 x ' cos Θ y ' 0 Rotate around Y axis: = z ' − sin Θ w 0 Rotate around X axis: x' 1 y ' 0 z ' = 0 w 0 0 1 0 0 0 0 1 0 0 x 0 y 0 z 1w sin Θ 0 x 0 0 y cos Θ 0 z 0 1w 0 0 cos Θ − sin Θ sin Θ cos Θ 0 0 0 x 0 y 0 z 1w Reverse Rotations Q: How do you undo a rotation of θ , R(θ )? Q: R( A: Apply the inverse of the rotation… R-1(θ ) = R(-θ ) How to construct R-1(θ ) = R(-θ ) How • Inside the rotation matrix: cos(θ) = cos(-θ) – The cosine elements of the inverse rotation matrix are unchanged • The sign of the sine elements will flip Therefore… R-1(θ ) = R(-θ ) = RT(θ ) Summary Coordinate systems • World vs. modeling coordinates 2-D and 3-D transformations • Trigonometry and geometry • Matrix representations • Linear vs. affine transformations Matrix operations • Matrix composition ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern