Computer Graphics Transformations. Types of Transformations 2D

Computer Graphics Transformations. Types of Transformations 2D

9/22 /2011 Transformations. What is a transformation? • P′=T(P) What does it do? Computer Graphics Transform the coordinates / normal vectors of objects Why use them? • Modelling Lecture 2 -Moving the objects to the desired location in the environment -Multiple instances of a prototype shape Transformations -Kinematics of linkages/skeletons – character animation • Viewing – Virtual camera: parallel and perspective projections Lecture 2 1 2 Types of Transformations Geometric Transformation – Once the models are prepared, we need to place them in the environment – Geometric Transformations – Objects are defined in their own local coordinate • Translation system • Rotation • scaling – We need to translate, rotate and scale them to put them •• Linear (preserves parallel lines) into the world coordinate system • Non-uniform scales, shears or skews – Projection (preserves lines) • Perspective projection • Parallel projection – Non-linear (lines become curves) • Twists, bends, warps, morphs, 3 22/09/2011 Lecture 1 4 2D Translations. 2D Scaling from the origin. Point P defined as P( x , y ), Point P defined as P(x, y), ′′′ ′′′ Perform a scale (stretch) to Point P( x , y ) by a factor sx along the x axis, translate to Point P( x , y ) a distance dx parallel to x axis, dy parallel to y axis. and s along the y axis. ′ = + ′ = + y x x dx y y d y x′ = s. x , y′ = s. y Define the column vec tors x y Define the matrix P’ ′ P x x d x P = , P′ = ,T = s 0 ′ = x y y dy S P’ 0 sy Now P Now P′ = P +T x′ s 0 x ′ = ⋅ = x PSP or ′ . y 0 sy y 5 6 1 9/22/2011 2D Rotation about the origin. 2D Rotation about the origin. y y θ P’(x’,y’) P’(x’,y’) P(x,y) P(x,y) r r x= r.cosφ y= r.sinφ θ y r φ r x x x 7 8 2D Rotation about the origin. 2D Rotation about the origin. x′ = r.cos(θ +φ)= r .cosφ.cosθ − r.sinφ.sinθ x′ = r.cos(θ +φ)= r .cosφ.cosθ − r.sinφ.sinθ ′ = θ +φ = φ θ + φ θ ′ = θ +φ = φ θ + φ θ y y r.sin( )r .cos .sin r.sin .cos y r.sin( )r .cos .sin r.sin .cos Substituting for r : P’(x’,y’) x= r.cosφ P(x,y) y= r.sinφ r x= r.cosφ y= r.sinφ Gives us : θ y x′ = x.cosθ − y.sinθ φ r x y′ = x.sinθ + y.cosθ x 9 10 2D Rotation about the origin. Transformations. • Translation. x′ = x.cosθ − y.sinθ – P′=T + P y′ = x.sinθ + y.cosθ • Scale P′=S ⋅ P Rewriting in matrix form gives us : – • Rotation x′ cosθ −sinθx ′ θ − θ = . x cos sin x P′=R ⋅ P ′ θ θ = . – y sin cos y y′ sinθ cosθ y • We would like all transformations to be multiplications so we can concatenate them cosθ − sinθ • ⇒ express points in homogenous coordinates. Define the matrix R = , P′ =RP ⋅ sinθ cosθ 11 12 2 9/22/2011 Homogeneous coordinates Translations in homogenised coordinates • Add an extra coordinate, W, to a point. – P(x,y,W). • Transformation matrices for 2D translation • Two sets of homogeneous coordinates represent the are now 3x3. same point if they are a multiple of each other. – (2,5,3) and (4,10,6) represent the same point. • If W≠ 0 , divide by it to get Cartesian coordinates of point ′ ′ x 1 0 d x x x = x+ d (x/W,y/W,1). x y′ = 0 1 d . y y′ = y+ d • If W=0, point is said to be at infinity. y y 1 0 0 1 1 1 =1 13 14 Concatenation. Concatenation. ⋅ • When we perform 2 translations on the same point The matrix product T( d x1,d y1) T( d x2 ,d y2 ) is : P′ = T(,) d d ⋅ P x1 y 1 1 0 d x1 1 0 d x2 ′′ = ⋅ ′ P T(,) d x2d y 2 P = 0 1 d y1 .0 1 d y2 ? P′′ = T(,)(,) d d ⋅T d d ⋅P = T( d + d ,d + d )⋅ P x1 y 1 x2 y 2 x1 x2 y 1 y2 0 0 1 0 0 1 So we expect : Matrix product is variously referred to as compounding, ⋅ = + + concatenation, or composition T(,)(,) dx1 d y 1 T d x2d y 2 T( d x1 d x2,d y 1 d y2 ) 15 16 Concatenation. Properties of translations. ⋅ = The matrix product T( d x1,d y1) T( d x2 ,d y2 ) is : 1. T (0,0) I ⋅ = + + + 2. T( sx , s y )T ( tx , t y ) T( sx tx, s y t y ) 1 0 d x1 1 0 dx2 1 0 d x1 d x2 ⋅ = ⋅ = + 3. T( sx , s y )T ( tx , t y ) T(,)(,) tx t y T sx s y 0 1 d y1 .0 1 d y2 0 1 d y1 d y2 4. T-1 (s , s ) = T (−s ,−s ) 0 0 1 0 0 1 0 0 1 x y x y Matrix product is variously referred to as compounding, concatenation, or composition. Note : 3. translation matrices are commutative. 17 18 3 9/22 /2011 Homogeneous form of scale. Concatenation of scales. Recall the (x,y) form of Scale : sx 0 ⋅ S(,) s s = The matrix product S(, sx1 s y1) S( sx2 , sy2 ) is : x y 0 s y ⋅ sx1 0 0 sx2 0 0 sx1 sx2 0 0 = ⋅ In homogeneous coordinates : 0 sy1 0 . 0 sy2 0 0 sy1 sy2 0 sx 0 0 0 0 1 0 0 1 0 0 1 = S(,) sx s y 0 sy 0 Only diagonal elements in the matrix - easy to multiply! 0 0 1 19 20 Homogeneous form of rotation. Orthogonality of rotation matrices. x′ cos θ − sin θ 0 x y′ = sin θ cos θ 0 . y cos θ − sin θ 0 cos θ sin θ 0 1 0 0 1 1 θ = θ θ T θ = − θ θ R() sin cos 0 , R () sin cos 0 For rotation matrices, 0 0 1 0 0 1 −1 θ = −θ R () R( ). cos −θ − sin −θ 0 cos θ sin θ 0 −θ = −θ −θ = − θ θ Rotation matrices are orthogonal , i.e : R() sin cos 0 sin cos 0 R−1()θ = RT ()θ 0 0 1 0 0 1 21 22 How are transforms combined? Other properties of rotation. Scale then Translate R )0( = I (5,3) Scale(2,2) (2,2) Translate(3,1) R()()θ ⋅ R φ = R(θ +φ) (1,1) (3,1) (0,0) (0,0) and Use matrix multiplication: p' = T ( S p ) = TS p θ ⋅ φ = φ ⋅ θ R()()R R()()R 1 0 3 2 0 0 2 0 3 But this is only because the axis of rotation TS = 0 1 1 0 2 0 = 0 2 1 is the same 0 0 1 0 0 1 0 0 1 For 3D rotations , need to be more careful Caution: matrix multiplication is NOT commutative! 23 02/10/09 Lecture 4 24 4 9/22 /2011 Non-commutative Composition Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p Scale then Translate: p' = T ( S p ) = TS p (5,3) 1 0 3 2 0 0 2 0 3 Scale(2,2) (2,2) Translate(3,1) (1,1) (3,1) TS = 0 1 1 0 2 0 = 0 2 1 (0,0) (0,0) 0 0 1 0 0 1 0 0 1 Translate then Scale: p' = S ( T p ) = ST p Translate then Scale: p' = S ( T p ) = ST p (8,4) 2 0 0 1 0 3 2 0 6 (4,2) Translate(3,1) Scale(2,2) (6,2) (1,1) (3,1) ST = 0 2 0 0 1 1 = 0 2 2 (0,0) 0 0 1 0 0 1 0 0 1 02/10/09 Lecture 4 25 02/10/09 Lecture 4 26 How are transforms combined? Non-commutative Composition Rotate then Translate Rotate then Translate: p' = T ( R p ) = TR p (3,sqrt(2)) 1 0 3 0 -1 3 (0,sqrt(2)) 0 -1 0 (1,1) Rotate 45 deg Translate(3,0) TR = 0 1 1 1 0 0 0 0 1 (0,0) (0,0) (3,0) 0 0 1 0 0 1 0 0 1 Translate then Rotate = Translate then Rotate: p' = R ( T p ) = RT p (1,1) Translate(3,0) (3/sqrt(2),3/sqrt(2)) Rotate 45 deg 0 -1 0 1 0 3 0 -1 -1 (0,0) (0,0) (3,0) RT = 1 0 0 0 1 1 = 1 0 3 0 0 1 0 0 1 0 0 1 Caution: matrix multiplication is NOT commutative! 02/10/09 Lecture 4 27 02/10/09 Lecture 4 28 Types of transformations. Transformations of coordinate systems. • Rotation and translation • Have been discussing transformations as – Angles and distances are preserved transforming points. – Unit cube is always unit cube • Always need to think the transformation in the – Rigid-Body transformations. world coordinate system • Rotation, translation and scale. • Sometimes this might not be so convenient – Angles & distances not preserved. – i.e. rotating objects at its location – But parallel lines are. 29 30 5 9/22 /2011 Transformations of coordinate Transformations of coordinate systems - Example systems - example • Concatenate local transformation matrices from left to right • Can obtain the local – world transformation matrix • p’,p’’,p’’’ are the world coordinates of p after • is the world coordinate of point p after n each transformation transformations 31 32 Quiz Solution • I sat in the car, and find the side mirror is 0.4m on • The side mirror position is locally my right and 0.3m in my front (0,4,0.3) • I started my car and drove 5m forward, turned 30 • The matrix of first driving degrees to right, moved 5m forward again, and forward 5m is turned 45 degrees to the right, and stopped 1 0 0 • What is the position of the side mirror now, T = 0 1 5 relative to where I was sitting in the beginning? 1 0 0 1 33 34 Solution Solution • The matrix to turn to the right The local-to-global transformation matrix at the last configuration of the car is 30 and 45 degrees (rotating -30 3 1 1 1 0 0 and -45 degrees around the 1 0 0 2 2 1 0 0 2 2 1 3 1 1 TR TR = − 0 − 0 1 2 0 1 5 2 2 0 1 5 2 2 origin) are 0 0 1 0 0 10 0 1 0 0 1 3 1 1 1 0 0 2 2 2 2 1 3 1 1 The final position of the side mirror can be R = − 0 , R = − 0 , respective ly 1 2 2 2 2 2 computed by TR 1TR 2 p which is around (2.89331, 9.0214) 0 0 1 0 0 1 35 36 6 9/22 /2011 This is convenient for character animation / robotics Transformations of coordinate • In robotics / animation, we systems.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us