Upcoming SlideShare
×

# Lect9 transformation3d

804 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
804
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
42
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Lect9 transformation3d

1. 1. Graphics 3D Geometric Transformation Sudipta Mondal sudipta.hit@gmail.com
2. 2. Contents BCET n Translation n Scaling n Rotation n Rotations about an arbitrary axis in space n Other Transformations n Coordinate Transformations sudipta.hit@gmail.com
3. 3. Transformation in 3D BCET n Transformation Matrix éA D G Jù é ù êB E H Kú ê 3´ 3 3 ´ 1ú ê ú Þ ê ú êC F I Lú ê ú ê ú ê ú ë0 0 0 Sû ë 1´ 3 1 ´ 1û 3´3 : Scaling, Reflection, Shearing, Rotation 3´1 : Translation 1´1 : Uniform global Scaling 1´3 : Homogeneous representation sudipta.hit@gmail.com
4. 4. 3D Translation BCET n Translation of a Point x' = x + t x , y' = y + t y , z' = z + t z y é x 'ù é1 0 0 tx ùé xù ê y 'ú ê 0 1 0 ty úê yú ê ú=ê úê ú ê z ' ú ê0 0 1 tz úê z ú ê ú ê úê ú x ë 1 û ë0 0 0 1 ûë1 û z sudipta.hit@gmail.com
5. 5. 3D Scaling BCET n Uniform Scaling x' = x × s x , y' = y × s y , z' = z × sz y é x 'ù é s x 0 0 0ù é x ù ê y 'ú ê 0 sy 0 0ú ê y ú ê ú=ê úê ú ê z 'ú ê 0 0 sz 0ú ê z ú ê ú ê úê ú x ë1û ë 0 0 0 1û ë1 û z sudipta.hit@gmail.com
6. 6. Relative Scaling BCET n Scaling with a Selected Fixed Position y y y y z x z x z x z x Original position Translate Scaling Inverse Translate éx'ù é1 0 0 x f ùésx 0 0 0ùé1 0 0 - x f ùéxù ê y'ú ê0 1 0 y f úê 0 sy 0 0úê0 1 0 - y f úê yú T (x f , y f , z f ) × S(sx , sy , sz ) ×T(-x f ,-y f ,-z f ) = ê ú = ê úê úê úê ú ê z'ú ê0 0 1 z f úê 0 0 sz 0úê0 0 1 - z f úê z ú ê ú ê úê úê úê ú ë 1 û ë0 0 0 1 ûë 0 0 0 1ûë0 0 0 1 ûë1û sudipta.hit@gmail.com
7. 7. 3D Rotation BCET n Coordinate-Axes Rotations n X-axis rotation n Y-axis rotation n Z-axis rotation n General 3D Rotations n Rotation about an axis that is parallel to one of the coordinate axes n Rotation about an arbitrary axis sudipta.hit@gmail.com
8. 8. Coordinate-Axes Rotations BCET n Z-Axis Rotation n X-Axis Rotation n Y-Axis Rotation é x'ù écos q - sin q 0 0ù é x ù é x'ù é1 0 0 0ù é x ù é x'ù é cos q 0 sin q 0ù é x ù ê y'ú ê sin q cos q 0 0ú ê y ú ê y'ú ê0 cos q - sin q 0ú ê y ú ê y'ú ê 0 1 0 0ú ê y ú ê ú=ê úê ú ê ú=ê úê ú ê ú=ê úê ú ê z 'ú ê 0 0 1 0ú ê z ú ê z 'ú ê0 sin q cos q 0ú ê z ú ê z 'ú ê- sin q 0 cos q 0ú ê z ú ê ú ê úê ú ê ú ê úê ú ê ú ê úê ú ë1û ë 0 0 0 1û ë 1 û ë 1 û ë0 0 0 1û ë 1 û ë1û ë 0 0 0 1û ë 1 û y y y x x x z z z sudipta.hit@gmail.com
9. 9. Order of Rotations BCET n Order of Rotation Affects Final Position n X-axis è Z-axis n Z-axis è X-axis sudipta.hit@gmail.com
10. 10. General 3D Rotations BCET n Rotation about an Axis that is Parallel to One of the Coordinate Axes n Translate the object so that the rotation axis coincides with the parallel coordinate axis n Perform the specified rotation about that axis n Translate the object so that the rotation axis is moved back to its original position sudipta.hit@gmail.com
11. 11. General 3D Rotations BCET n Rotation about an Arbitrary Axis y Basic Idea T 1. Translate (x1, y1, z1) to the origin (x2,y2,z2) 2. Rotate (x’2, y’2, z’2) on to the z R axis (x1,y1,z1) 3. Rotate the object around the z-axis 4. Rotate the axis to the original x R-1 orientation z 5. Translate the rotation axis to the T-1 original position R (q ) = T -1R -1 (a )R -1 (b )R z (q )R y (b )R x (a )T x y sudipta.hit@gmail.com
12. 12. General 3D Rotations BCET n Step 1. Translation y (x2,y2,z2) é1 0 0 - x1 ù ê0 1 0 - y1 ú T=ê ú (x1,y1,z1) ê0 0 1 - z1 ú ê ú x ë0 0 0 1 û z sudipta.hit@gmail.com
13. 13. General 3D Rotations BCET n Step 2. Establish [ TR ]ax x axis y b b sin a = = b +c 2 2 d (0,b,c) c c (a,b,c) cos a = = b +c 2 2 d Projected Point a a é1 0 0 0ù é1 0 0 0ù ê0 cos a - sin a 0 ú ê0 c / d -b/d 0ú x R x (a ) = ê ú=ê ú ê0 sin a cos a 0 ú ê0 b / d c/d 0ú z ê ú ê ú ë0 0 0 1 û ë0 0 0 1û Rotated Point sudipta.hit@gmail.com
14. 14. Arbitrary Axis Rotation BCET n Step 3. Rotate about y axis by b y a d sin b = , cos b = l l l 2 = a 2 + b2 + c2 = a2 + d 2 (a,b,c) d = b2 + c2 Projected l Point écos b 0 - sin b 0ù éd / l 0 - a / l 0ù d ê 0 1 0 0ú ê 0 1 0 0ú b x R y (b ) = ê ú=ê ú ê sin b 0 cos b 0ú ê a / l 0 d / l 0ú (a,0,d) ê ú ê ú ë 0 0 0 1û ë 0 0 0 1û Rotated z Point sudipta.hit@gmail.com
15. 15. Arbitrary Axis Rotation BCET n Step 4. Rotate about z axis by the desired angle q y écosq - sin q 0 0ù ê sin q cosq 0 0ú R z (q ) = ê ú ê 0 0 1 0ú l x ê ú q ë 0 0 0 1û z sudipta.hit@gmail.com
16. 16. Arbitrary Axis Rotation BCET n Step 5. Apply the reverse transformation to place the axis back in its initial position y é1 0 0 - x1 ù é1 0 0 0ù ê0 1 0 - y1 ú ê0 cos a sin a 0ú T -1R -1 (a )R -1 ( )= ê y b úê ú l x ê0 0 1 - z1 ú ê0 - sin a cos a 0ú ê úê ú ë0 0 0 1 û ë0 0 0 1û é cos b 0 sin b 0ù l ê 0 1 0 0ú x ê ú ê- sin b 0 cos b 0ú ê ú ë 0 0 0 1û z R (q ) = T -1R -1 (a )R -1 (b )R z (q )R y (b )R x (a )T x y sudipta.hit@gmail.com
17. 17. Example BCET Find the new coordinates of a unit cube 90º-rotated about an axis defined by its endpoints A(2,1,0) and B(3,3,1). A Unit Cube sudipta.hit@gmail.com
18. 18. Example BCET n Step1. Translate point A to the origin y é1 0 0 - 2ù B’(1,2,1) ê0 1 0 - 1ú T=ê ú ê0 0 1 0ú A’(0,0,0) x ê ú ë0 0 0 1û z sudipta.hit@gmail.com
19. 19. Example BCET n Step 2. Rotate axis A’B’ about the x axis by and angle a, until it lies on the xz plane. 2 2 2 5 sin a = = = 2 2 + 12 5 5 1 5 cos a = = y 5 5 Projected point (0,2,1) B’(1,2,1) l = 12 + 2 2 + 12 = 6 a l é1 0 0 0ù x ê 5 2 5 ú z ê0 - 0ú B”(1,0,Ö5) R x (a ) = ê 5 5 ú ê0 2 5 5 0ú ê 5 5 ú ê0 ë 0 0 1ú û sudipta.hit@gmail.com
20. 20. Example BCET n Step 3. Rotate axis A’B’’ about the y axis by and angle b , until it coincides with the z axis. 1 6 sin b = = y 6 6 5 30 cos b = = 6 6 l é 30 6 ù b x ê 0 - 0ú (0,0,Ö6) ê 6 6 ú B”(1,0, Ö 5) R y (b ) = ê 0 1 0 0ú ê 6 30 z 0 0ú ê 6 6 ú ê ë 0 0 0 1ú û sudipta.hit@gmail.com
21. 21. Example BCET n Step 4. Rotate the cube 90° about the z axis é0 - 1 0 0 ù ê1 0 0 0ú R z (90°) = ê ú ê0 0 1 0 ú ê ú ë0 0 0 1 û n Finally, the concatenated rotation matrix about the arbitrary axis AB becomes, R (q ) = T -1R -1 (a )R -1 (b )R z (90°)R y (b )R x (a )T x y sudipta.hit@gmail.com
22. 22. Example BCET é1 0 0 0ù é 30 6 ù é1 0 0 2ù ê 5 2 5 úê 0 0ú é 0 - 1 0 0ù ê0 ú ê0 0ú ê 6 6 úê 1 0 1ú 5 5 0ú ê 1 0 0 0ú R (q ) = ê ê úê 0 1 0 ú ê0 0 1 0ú ê 2 5 5 6 30 ê0 0 1 0ú ê ú 0 - 0ú ê - 0 0ú ê ú ë0 0 0 1û ê 5 5 úê 6 6 ú 0 0 ë 0 1û ê0 ë 0 0 1ú ê 0 ûë 0 0 1ú û é 30 6 ù é1 0 0 0ù ê 0 - 0ú ê 5 2 5 ú é1 0 0 - 2ù 6 6 - 0 ú ê0 ê 0 1 0 ú ê0 0ú ê 5 5 1 0 - 1ú ê úê ú ê 6 30 2 5 5 ê0 0 1 0ú 0 0 ú ê0 0ú ê ú ê 6 6 úê 5 5 ú 0 0 0 1û ê ë ë 0 0 0 1 ú ê0 ûë 0 0 1úû é 0.166 - 0.075 0.983 1.742 ù ê 0.742 0.667 0.075 - 1.151ú =ê ú ê - 0.650 0.741 0.167 0.560 ú ê ú ë 0 0 0 1 û sudipta.hit@gmail.com
23. 23. Example BCET n Multiplying R(θ) by the point matrix of the original cube [P¢] =R(q)×[P] é 0.166 - 0.075 0.983 1.742 ù é0 0 1 1 0 0 1 1ù ê 0.742 0.667 0.075 - 1.151ú ê1 1 1 1 0 0 0 0ú [P¢] = ê úê ú ê- 0.650 0.741 0.167 0.560 ú ê1 0 0 1 1 0 0 1ú ê úê ú ë 0 0 0 1 û ë1 1 1 1 1 1 1 1û é 2.650 1.667 1.834 2.816 2.725 1.742 1.909 2.891 ù ê- 0.558 - 0.484 0.258 0.184 - 1.225 - 1.151 - 0.409 - 0.483ú =ê ú ê 1.467 1.301 0.650 0.817 0.726 0.560 - 0.091 0.076 ú ê ú ë 1 1 1 1 1 1 1 1 û sudipta.hit@gmail.com
24. 24. Other Transformations BCET n Reflection Relative to the xy Plane é x' ù é1 0 0 0ù é x ù y y ê y 'ú ê 0 1 0 0ú ê y ú ê ú=ê úê ú z ê z' ú ê0 0 - 1 0ú ê z ú ê ú ê úê ú z x x ë 1 û ë0 0 0 1û ë1 û n Z-axis Shear é x 'ù é1 0 a 0ù é x ù ê y 'ú ê 0 1 b 0ú ê y ú ê ú=ê úê ú ê z ' ú ê0 0 1 0ú ê z ú ê ú ê úê ú ë 1 û ë0 0 0 1ûë1 û sudipta.hit@gmail.com
25. 25. Other Transformations BCET n Z-axis Shear The effect of this transformation matrix is to alter x and y-coordinate values by an amount that is proportional to the z value, while leaving the z coordinate unchanged. q Boundaries of planes that are perpendicular to the z axis are thus shifted by an amount proportional to z. q An example of the effect of this shearing matrix on a unit cube is shown in Fig., for shearing values a = b = 1. Shearing matrices for the x axis and y axis are defined similarly. é x 'ù é1 0 a 0ù é x ù ê y 'ú ê 0 1 b 0ú ê y ú ê ú=ê úê ú ê z ' ú ê0 0 1 0ú ê z ú ê ú ê úê ú ë 1 û ë0 0 0 1ûë1 û sudipta.hit@gmail.com
26. 26. Coordinate Transformations BCET n Multiple Coordinate System n Local (modeling) coordinate system n World coordinate scene Local Coordinate System sudipta.hit@gmail.com
27. 27. Coordinate Transformations BCET n Multiple Coordinate System n Local (modeling) coordinate system n World coordinate scene Word Coordinate System sudipta.hit@gmail.com
28. 28. Coordinate Transformations BCET n Example – Simulation of Tractor movement n As tractor moves, tractor coordinate system and front-wheel coordinate system move in world coordinate system n Front wheels rotate in wheel coordinate system sudipta.hit@gmail.com
29. 29. Coordinate Transformations BCET n Transformation of an Object Description from One Coordinate System to Another n Transformation Matrix n Bring the two coordinates systems into alignment 1. Translation y’ y u'y x’ y u'x u'y (x0,y0,z0) u'x x z’ u'z z (0,0,0) u'z (0,0,0) x z T(- x0 , - y0 , - z0 ) sudipta.hit@gmail.com
30. 30. Coordinate Transformations BCET 2. Rotation & Scaling y’ y y y u'y x’ u'x x x (0,0,0) x z (0,0,0) z (0,0,0) z z’ u'z é u ¢1 x u¢2x u¢3x 0ù êu ¢ u ¢y 2 u ¢y 3 0ú R = ê y1 ú ê u ¢1 z u ¢2 z u ¢3 z 0ú ê ú ë 0 0 0 1û sudipta.hit@gmail.com