Computer Graphics Modeling Transformations Explained

ceng 477 n.w
1 / 72
Embed
Share

Learn about modeling transformations in computer graphics, including translation, rotation, scaling, and their applications. Understand how to move objects, rotate them around arbitrary points, and change their sizes effectively. Dive into the world of basic geometric transformations used for modeling, animation, and viewing in computer graphics.

  • Computer Graphics
  • Modeling Transformations
  • Translation
  • Rotation
  • Scaling

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CENG 477 Introduction to Computer Graphics Modeling Transformations

  2. Modeling Transformations Model coordinates to World coordinates: World coordinates: All shapes with their absolute coordinates and sizes. yworld Model coordinates: All shapes with their local coordinates and sizes. xworld zworld CENG 477 Computer Graphics 2

  3. Basic Geometric Transformations Used for modelling, animation as well as viewing What to transform? We typically transform the vertices (points) and vectors describing the shape (such as the surface normal) This works due to the linearity of transformations Some, but not all, transformations may preserve attributes like sizes, angles, ratios of the shape CENG 477 Computer Graphics 3

  4. Translation Simply move the object to a relative position P' x' = x + t y' = y + t x y P t x x' x P T P ' = = = t y y' y P P T ' = + CENG 477 Computer Graphics 4

  5. Rotation A rotation is defined by a rotation axis and a rotation angle For 2D rotation, the parameters are rotation angle ( ) and the rotation point (xr, yr) We reposition the object in a circular path around the rotation point (pivot point) a yr xr CENG 477 Computer Graphics 5

  6. Rotation P' When (xr, yr)=(0,0) we have: sin( r y + = = + = cos( ) cos cos sin sin x r r r P = + ) cos sin sin cos r r = cos x r The original coordinates are: = sin y r = cos sin x x y Substituting them in the first equation we get: = + sin cos y x y = P R cos P In the matrix form we have: cos sin = R sin CENG 477 Computer Graphics 6

  7. Rotation Rotation around an arbitrary point (xr, yr) P' = + ( ) cos ( ) sin x x x x y y r r r P = + + ( ) sin ( ) cos y y x x y y r r r (xr,yr) These equations can be written as matrix operations (we will see when we discuss homogeneous coordinates) CENG 477 Computer Graphics 7

  8. Scaling Changes the size of an object Input: scaling factors (sx, sy) P' P x' = xs y' = ys x y 0 s 0 x S = s y non-uniform vs. uniform scaling ' P S P = CENG 477 Computer Graphics 8

  9. Homogenous Coordinates Translation is additive, rotation and scaling is multiplicative (and additive if you rotate around an arbitrary point or scale around a fixed point) We use homogenous coordinates to represent larger family of transformations, in particular including translation Goal: Make all transformations as matrix operations Solution: Add a third dimension x h x x h x y h h h x = y = P = y = h y = y h h h 1 h CENG 477 Computer Graphics 9

  10. Homogenous Coordinates In HC, each point now becomes a line The entire line represents the same point The original (non-homogeneous) point resides on the w=1 plane w y p2 p1 w = 1 x CENG 477 Computer Graphics 10

  11. Transformations in HC 1 0 t x ( ) ( ) Translation: ' where P 0 1 P = T t t , T t t , = t x y x y y 0 0 1 cos cos sin 0 ( ) ( ) P' where P sin 0 = R R = Rotation: 0 0 1 0 s 0 s x ( ) ( ) where P 0 0 P = S s s , S s s , = Scaling: x y x y y 0 0 1 CENG 477 Computer Graphics 11

  12. Composite Transformations Often, objects are transformed multiple times Such transformations can be combined into a single composite transformation E.g. Application of a sequence of transformations to a point: M P = = M P 2 1 M P Composing one single matrix is advantageous cos you will be applying the same matrix to all model points. Instead of multiplying many matrices for each model point, pre-multiply only once: Made possible thanks to the homogenous coordinates . CENG 477 Computer Graphics 12

  13. Composite Transformations Composition of same representation of transformations is simple Translate to origin, scale, rotate, translate back to desired point. CENG 477 Computer Graphics 13

  14. Composite Transformations Composition of same representation of transformations is simple E.g. translation: = P T T P ( , ) { ( , ) } t t t t 2 t 2 t 1 1 x y x y = T T P { ( , ) ( , )} t t 2 2 1 1 x y x y + 1 0 1 0 1 0 t t t t 2 1 1 2 x x x x ( ) ( T ) ( ) + 0 1 0 1 0 1 T t t , t t , = t t = t t = T t + t t , + t 2 2 1 1 2 1 1 1 1 2 1 2 1 2 x y x y y y y y x x y y 0 0 0 0 0 0 1 CENG 477 Computer Graphics 14

  15. Composite Transformations Rotation and scaling are similar: cos cos cos sin 0 cos sin 0 ( ) ( ) R R sin 0 sin 0 = = 0 0 1 0 0 1 cos( cos cos sin sin cos sin sin cos 0 cos( ) sin( ) 0 + + ) ( ) R sin cos cos sin sin sin cos cos 0 sin( ) 0 + 0 + 0 = + + = + 0 0 1 1 0 0 0 0 0 0 s s s s 2 0 1 0 1 2 x x x x ( ) ( S ) ( ) S S 0 0 0 0 s s , s s , = s s = s s = s s s , s 2 2 1 1 2 0 1 0 1 2 1 2 1 2 x y x y y y y y x x y y 0 1 0 1 0 0 1 CENG 477 Computer Graphics 15

  16. Rotation Around a Pivot Point Step 1: Translate the object so that the pivot point moves to the origin ( ) x T , y r r ( ) = T M x , y 1 r r CENG 477 Computer Graphics 16

  17. Rotation Around a Pivot Point Step 2: Rotate around origin ( ) R ( ) = R M 2 CENG 477 Computer Graphics 17

  18. Rotation Around a Pivot Point Step 3: Translate the object so that the pivot point is back to its original position ( ) T ry , x r ( ) = T M x ry , 3 r CENG 477 Computer Graphics 18

  19. Rotation Around a Pivot Point The composite transformation is equal to their successive application: ( ) ( ) ( R ) = = T T M M M M x y , x , y 3 2 1 r r r r CENG 477 Computer Graphics 19

  20. Scaling w.r.t. a Fixed Point ( ) x T , y The idea is the same: Translate to origin Scale Translate back ( 0 1 0 0 s f f ) ( s ) ( 0 ) , T S T x y , s s , x y = ( ) f x f x y f f S s xs , y 1 0 0 s 1 0 x f x f 0 1 0 0 0 1 y y = f y f 1 0 1 0 0 1 ( ) T x fy , ( ( ) ) f 0 s x s x f x 1 0 1 y s y f y 0 0 CENG 477 Computer Graphics 20

  21. Order of matrix compositions Matrix composition is not commutative. So, be careful when applying a sequence of transformations. Pivot Pivot 2 1 1 2 Rotation and translation Translation and rotation CENG 477 Computer Graphics 21

  22. Other Transformations Reflection: special case of scaling 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 CENG 477 Computer Graphics 22

  23. Other Transformations Shear: Deform the shape like shifted slices (or deck of cards). Can be in x or y direction (2,1) (0,1) (1,1) (3,1) x' x shxy shx y' y 1 0 0 0 0 1 1 0 CENG 477 Computer Graphics 23

  24. 3D Transformations Similar to 2D but with an extra z component We assume a right handed coordinate system With homogeneous coordinates we have 4 dimensions Basic transformations: Translation, rotation, scaling z y x y x z x y z Equivalent ways of thinking about a right-handed CS CENG 477 Computer Graphics 24

  25. Translation Move the object by some offset: y 1 0 0 x t x P x 0 1 0 y t y y = x P 0 0 1 z t z z z 1 0 0 0 1 1 y = P T P x z CENG 477 Computer Graphics 25

  26. Rotation Rotation around the coordinate axes y y y y y y x x x x x x z z z z z z z-axis y-axis x-axis Positive angles represent counter-clockwise (CCW) rotation when looking along the positive half towards origin CENG 477 Computer Graphics 26

  27. Rotation Around Major Axes cos 0 ) ( 1 0 0 0 cos sin 0 Around x: = = ( R P R P ) x x 0 sin 0 0 0 0 1 cos 0 sin 0 0 1 0 0 Around y: = R ( ) = ( P R P ) y y sin 0 cos 0 0 0 0 1 cos cos sin 0 0 sin 0 0 Around z: = R = ( ( ) P R P ) z z 0 0 1 0 0 0 0 1 CENG 477 Computer Graphics 27

  28. Rotation Around a Parallel Axis Rotating the object around a line parallel to one of the axes: Translate to axis, rotate, translate back E.g. rotate around a line parallel to x-axis: R T P = ) , , 0 ( x p p z y T P ( ) , 0 ( , ) y z p p y y y y x x (yp, zp) x x z z z z Translate back Translate Rotate CENG 477 Computer Graphics 28

  29. Rotation Around an Arbitrary Axis Step 1: Translate the object so that the rotation axis passes though the origin Step 2: Rotate the object so that the rotation axis is aligned with one of the major axes Step 3: Make the specified rotation Step 4: Reverse the axis rotation Step 5: Translate back y x z CENG 477 Computer Graphics 29

  30. Rotation Around an Arbitrary Axis CENG 477 Computer Graphics 30

  31. Rotation Around an Arbitrary Axis First determine the axis of rotation: = = v P P ( , , ) x x y y z z 2 1 2 1 2 1 2 1 u is the unit vector along v: v = = u ( , , ) a b c v CENG 477 Computer Graphics 31

  32. Rotation Around an Arbitrary Axis Next translate P1 to origin: 1 0 0 x 1 0 1 0 y 1 = T 0 0 1 z 1 0 0 0 1 CENG 477 Computer Graphics 32

  33. Rotation Around an Arbitrary Axis Then align u with one of the major axis (x, y, or z) This is a two-step process: Rotate around x to bring u onto xz plane Rotate around y to align the result with the z-axis y y u x x u z z We need cosine and sine of angles and CENG 477 Computer Graphics 33

  34. Rotation Around an Arbitrary Axis We need cosine and sine of angles and : y uy u = ux + uy + uz = ux + u u b u' x ux c uz z 1 0 c 0 0 b u c 0 0 =u = = + 2 2 cos where z d b c d d x = R ( ) d b c 0 0 u b d d y sin =u = 0 0 0 1 d CENG 477 Computer Graphics 34

  35. Rotation Around an Arbitrary Axis We need cosine and sine of angles and : y + b 2 2 b c a 0 0 + + + + 2 2 2 2 2 2 a c a b c ux 0 1 0 0 x y = R ( ) u + 2 y 2 z + b 2 2 u a b c 0 0 u + 0 + + + 2 2 2 2 2 2 a b c a c z 0 0 1 + 2 y 2 z u u + 2 2 b + c + = = cos (via Rx( )) u 2 2 2 a b c As u rotates on xz plane, its shadow on yz plane, i.e., u , rotates simultaneously to z axis, hence the z-component (depth) of u is obtained as ux u a = = sin u + 2 y 2 z u + + 2 2 2 a b c CENG 477 Computer Graphics 35

  36. Rotation Around an Arbitrary Axis Putting it all together: = R T R R R R R T ( ) ( , , ) ( ) ( ) ( ) ( ) ( ) ( , , ) x y z x y z 1 1 1 1 1 1 x y z y x This is the actual desired rotation. Other terms are for alignment and undoing the alignment CENG 477 Computer Graphics 36

  37. Alternative Method Assume we wanna rotate around the unit vector u: We create an orthonormal basis (ONB) uvw: To find v, set the smallest (abs) component of u to zero and swap the other two while negating one: y y u u v E.g. if u = (a, b, c) with c being the smallest value then v = (-b, a, 0) x x w = u x v w z z Note that we are just finding one of the infinitely many solutions CENG 477 Computer Graphics 37

  38. Alternative Method Now rotate uvw such that it aligns with xyz: call this transform M Rotate around x (u is now x) Undo the initial rotation: call this M-1 Finding M-1 is trivial: x v u M 0 u v w x x 0 w y y y = 1 0 u v w z z z 0 0 0 1 Verify that this matrix transforms x to u, y to v, and z to w CENG 477 Computer Graphics 38

  39. Alternative Method Finding M is also trivial as M-1 is an orthonormal matrix (all rows and columns are orthogonal unit vectors) For such matrices, inverse is equal to transpose: 0 u u u x y z 0 v v v x y z = M 0 w w w x y z 0 0 0 1 CENG 477 Computer Graphics 39

  40. Alternative Method The final rotation transform is: ? 1??(?)? We assumed that the origin of uvw is the same as the origin of xyz Otherwise, we should account for this difference: ? 1? 1??(?)?? Undo the translation Translate the origin of uvw to xyz CENG 477 Computer Graphics 40

  41. Scaling Change the coordinates of the object by scaling factors y P 0 sy 0 0 0 0 sz 0 0 0 0 1 sx 0 0 0 x' y' z' 1 x y z 1 P x z y P' S P P = S P x z CENG 477 Computer Graphics 41

  42. Scaling w.r.t. a Fixed Point Translate to origin, scale, translate back = P T S T P ( , , ) ( , , ) x y z x y z f f f f f f x y y y y x x x z z z z Translate Scale Translate back CENG 477 Computer Graphics 42

  43. Reflection Reflection over the major planes: y y y How about reflection over an arbitrary plane? x x x z z z 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 CENG 477 Computer Graphics 43

  44. Transforming Normals When we transform an object, what happens to its normals? Do they get transformed by the same matrix or does it require a different one? y y Scale by: 3/ 2 1/ 2 0 3 0 0 1/ 2 1/ 2 0 ? = ? = = 0 1 0 S 0 0 1 1 1 x x 1 3 CENG 477 Computer Graphics 44

  45. Transforming Normals After the transformation the normal is no longer perpendicular to the object Also it is not a unit vector anymore y y Scale by: 3/ 2 1/ 2 0 3 0 0 1/ 2 1/ 2 0 ? = ? = = 0 1 0 S 0 0 1 1 1 x x 1 3 CENG 477 Computer Graphics 45

  46. Transforming Normals Rotation and translation has no problems But, since all transformations are combined into a single matrix M, we should consider the general case. n b v a We must have n.(b-a) = n.v = 0 and this relationship should be preserved after the transformation CENG 477 Computer Graphics 46

  47. Transforming Normals That is n.v = 0 and n'.v' = 0 where v' = Mv and n' = Zn Z is the matrix we are looking for How to compute Z? n b v a CENG 477 Computer Graphics 47

  48. Transforming Normals n.v = nTv =0 n'.v' = n'Tv' = n'TMv = nTZTMv = 0 If ZTM = I (identity) the relationship will be preserved So Z = (M-1)T Note that this is equal to (MT)-1 as (M-1)T= (MT)-1 for a square (n by n) matrix M n b v a CENG 477 Computer Graphics 48

  49. Quaternions Another way to represent rotations 4D numbers: (a, b, c, d) More advantageous over 3x3 rotation matrices Less storage space (4 vs. 3x3=9) Concatenation of quaternions requires fewer operations Easily interpolated for smooth animations

  50. Quaternions Another way to represent rotations 4D numbers: (a, b, c, d) More advantageous over 3x3 rotation matrices Less storage space (4 vs. 3x3=9) Concatenation of quaternions requires fewer operations Easily interpolated for smooth animations Articulated interpolation achieved after segmenting the object into rigid parts and rigging them

Related


More Related Content