Docstoc

09transformation3d

Document Sample
09transformation3d Powered By Docstoc
					                                 Graphics



                      3D Geometric
                     Transformation

                   고려대학교 컴퓨터 그래픽스 연구실




cgvr.korea.ac.kr                      Graphics Lab @ Korea University
Contents
                                                CGVR


   Translation
   Scaling
   Rotation
   Rotations with Quaternions
   Other Transformations
   Coordinate Transformations




cgvr.korea.ac.kr                 Graphics Lab @ Korea University
Transformation in 3D
                                                                             CGVR

   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

cgvr.korea.ac.kr                                              Graphics Lab @ Korea University
3D Translation
                                                                           CGVR

   Translation of a Point

        x'  x  t x ,   y'  y  t y ,   z'  z  tz

                         y

                                           x ' 1     0       0      tx  x
                                           y ' 0     1       0          y
                                                                       ty  
                                           
                                           z '  0    0       1      tz  z 
                                                                        
                                   x       1  0      0       0      1  1 
             z


cgvr.korea.ac.kr                                            Graphics Lab @ Korea University
3D Scaling
                                                                        CGVR

   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


cgvr.korea.ac.kr                                         Graphics Lab @ Korea University
Relative Scaling
                                                                                                                               CGVR

    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 ( s x , s y , s z )  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 


cgvr.korea.ac.kr                                                                                              Graphics Lab @ Korea University
3D Rotation
                                                                  CGVR

   Coordinate-Axes Rotations
         X-axis rotation
         Y-axis rotation
         Z-axis rotation


   General 3D Rotations
         Rotation about an axis that is parallel to one of the
          coordinate axes
         Rotation about an arbitrary axis



cgvr.korea.ac.kr                                   Graphics Lab @ Korea University
Coordinate-Axes Rotations
                                                                                                                        CGVR


    Z-Axis Rotation                           X-Axis Rotation                              Y-Axis Rotation

 x' cos           sin    0 0  x     x' 1     0           0        0  x         x'  cos       0 sin      0  x 
 y '  sin        cos      0 0  y     y ' 0 cos          sin     0  y         y '  0         1       0   0  y 
                                                                                                            
 z'  0              0       1 0  z     z '  0 sin        cos       0  z         z '   sin    0 cos      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




cgvr.korea.ac.kr                                                                                  Graphics Lab @ Korea University
Order of Rotations
                                                        CGVR

   Order of Rotation Affects Final Position
         X-axis  Z-axis




         Z-axis  X-axis




cgvr.korea.ac.kr                         Graphics Lab @ Korea University
General 3D Rotations
                                                                  CGVR

   Rotation about an Axis that is Parallel to One of
    the Coordinate Axes
         Translate the object so that the rotation axis
          coincides with the parallel coordinate axis
         Perform the specified rotation about that axis
         Translate the object so that the rotation axis is
          moved back to its original position




cgvr.korea.ac.kr                                   Graphics Lab @ Korea University
General 3D Rotations
                                                                            CGVR

   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   T1R1  R1  R z  R y  R x  T
                       x       y

cgvr.korea.ac.kr                                             Graphics Lab @ Korea University
General 3D Rotations
                                                                  CGVR

   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




cgvr.korea.ac.kr                                   Graphics Lab @ Korea University
     General 3D Rotations
                                                                                            CGVR

           Step 2. Establish [ TR ]x x axis
                        y                                            b             b
                                                      sin                   
                                                                   b2  c2         d
     (0,b,c)                                                          c            c
                            (a,b,c)                   cos                    
                                                                   b2  c2         d
Projected
  Point                                               1   0       0        0  1   0            0      0
                                                        0 cos     sin     0  0 c / d       b/d      0
                                         x   R x                                                    
                                                        0 sin    cos       0  0 b / d        c/d      0
             z                                                                                           
                                                        0   0       0        1  0   0            0      1
                               Rotated
                                Point




     cgvr.korea.ac.kr                                                        Graphics Lab @ Korea University
    Arbitrary Axis Rotation
                                                                                             CGVR

           Step 3. Rotate about y axis by 
                        y                                         a               d
                                                        sin        , cos  
                                                                   l              l
                                                        l 2  a 2  b2  c2  a2  d 2
                            (a,b,c)
                                                         d  b2  c2
Projected               l
  Point                                                 cos     0  sin     0  d / l    0  a / l 0
              d                                          0       1     0      0  0        1   0     0
                                        x   R y                                                
                                                         sin    0   cos     0  a / l    0 d / l 0
                             (a,0,d)                                                                 
                                                         0       0     0      1  0        0   0     1
                               Rotated
     z                          Point




     cgvr.korea.ac.kr                                                         Graphics Lab @ Korea University
Arbitrary Axis Rotation
                                                                CGVR

   Step 4. Rotate about z axis by the desired
    angle 
                   y



                                       cos       sin        0 0
                                        sin      cos         0 0
                            R z                               
                                        0            0         1 0
          l
                       x                                          
                                       0            0         0 1


z



cgvr.korea.ac.kr                                 Graphics Lab @ Korea University
Arbitrary Axis Rotation
                                                                                      CGVR

   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         sin      0
                              T 1R 1  R 1                                              
                                                       0 0     1  z1  0  sin       cos      0
                                    x        y
                       l
                                                                                                 
                                                       0 0     0 1  0       0           0       1
                                                      cos     0 sin      0
          l                                           0        1   0       0
                                 x                                          
                                                      sin    0 cos      0
                                                                            
                                                      0        0   0       1
z

              R   T1R1  R1  R z  R y  R x  T
                          x       y

cgvr.korea.ac.kr                                                       Graphics Lab @ Korea University
Example
                                                             CGVR



     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

cgvr.korea.ac.kr                              Graphics Lab @ Korea University
Example
                                                                     CGVR

   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



cgvr.korea.ac.kr                                      Graphics Lab @ Korea University
Example
                                                                                          CGVR

   Step 2. Rotate axis A’B’ about the x axis by and
    angle , until it lies on the xz plane.
                                                             2            2    2 5
                                                 sin                      
                                                           2 2  12        5    5
                                                           1     5
                                                 cos        
                          y                                 5   5
        Projected point
            (0,2,1)                  B’(1,2,1)
                                                 l  12  2 2  12  6

                             l
                                                               1          0       0         0
                                         x                                 5      2 5        
                   z                                           0                           0
                                  B”(1,0,5)        R x               5        5         
                                                               0         2 5       5
                                                                                             0
                                                                          5       5          
                                                               0
                                                                          0       0         1
                                                                                              
cgvr.korea.ac.kr                                                           Graphics Lab @ Korea University
Example
                                                                                     CGVR

   Step 3. Rotate axis A’B’’ about the y axis by and
    angle , until it coincides with the z axis.
                                                            1     6
                                                  sin        
                           y                                 6   6
                                                            5   30
                                                  cos       
                                                            6   6


                               l                                30             6      
                                          x                          0             0
           (0,0,6)
                                                                6             6       
                                   B”(1,0,  5)
                                                  R y       0     1      0       0
                   z                                             6
                                                                       0
                                                                              30
                                                                                      0
                                                                6            6        
                                                             
                                                                0     0      0       1
                                                                                       

cgvr.korea.ac.kr                                                      Graphics Lab @ Korea University
Example
                                                                     CGVR


   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
         Finally, the concatenated rotation matrix about the
          arbitrary axis AB becomes,


          R   T1R1  R1  R z 90R y  R x  T
                      x       y




cgvr.korea.ac.kr                                      Graphics Lab @ Korea University
Example
                                                                                                CGVR

                               1     0        0    0  30              6       
              1   0    0   2        5      2 5               0            0  0  1   0   0
              0   1    0     0
                            1
                                                    0  6              6                     0
     R                          5        5      0         1     0      0  1 0     0    
              0            0                                                    0 0         0
                                                    0                       0 
                   0    1            2 5        5          6            30                  1
                               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
                                                              0 
                                                                             0  1
                  6             6      0                         0   1
                  0    1       0    0       5       5                        
                                                                 0         1 0
                                     0  0                    0 
                    6           30            2 5      5                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 


cgvr.korea.ac.kr                                                                 Graphics Lab @ Korea University
Example
                                                                             CGVR

   Multiplying R(θ) by the point matrix of the original cube

                                    P  R  P
        0.166       0.075 0.9831.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     2.891 
                                                              1.909
          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 


cgvr.korea.ac.kr                                              Graphics Lab @ Korea University
Rotations with Quaternions
                                                                     CGVR

   Quaternion
         Scalar part s + vector part v = (a, b, c)
         Real part + complex part (imaginary numbers i, j, k)
                     q  s, v   s  ai  bj  ck
   Rotation about any axis
         Set up a unit quaternion (u: unit vector)
                                            
                         s  cos , v  u sin
                                2            2
         Represent any point position P in quaternion notation
          (p = (x, y, z))
                            P  0, p 

cgvr.korea.ac.kr                                      Graphics Lab @ Korea University
Rotations with Quaternions
                                                                    CGVR

         Carry out with the quaternion operation (q-1=(s, –v))
                                  P  qPq 1
         Produce the new quaternion
                                  P  0, p
                 p  s 2p  vp  v   2sv  p   v  v  p 
         Obtain the rotation matrix by quaternion multiplication
           M R    R 1  R 1  R z  R y  R x  
                        x        y

                 1  2b 2  2c 2 2ab  2sc      2ac  2sb 
                                                           
                 2ab  2sc 1  2a  2c
                                      2     2
                                                 2bc  2sa 
                  2ac  2sb      2bc  2sa 1  2a 2  2b 2 
                                                           
       Include the translations:
                                    R    T 1M  T
                                                     R
cgvr.korea.ac.kr                                     Graphics Lab @ Korea University
Example
                                                                         CGVR

   Rotation about z axis
                                                             
         Set the unit quaternion: s  cos , v  0, 0, 1sin
                                          2                   2
         Substitute a=b=0, c=sin(θ/2) into the matrix:
                          2                   
                        1  2 sin 2  2 cos 2 sin 2 0
                                                  
            M R    2 cos sin     1  2 sin 2    0
                              2    2             2   
                              0            0        1                 
                                                                         cos 
                                                                 1  2 sin 2
                                                                      2
                                                                     
                       cos  sin  0                        2 cos sin  sin 
                       sin  cos 0
                                                                    2   2
                                       
                        0
                                  0  1
cgvr.korea.ac.kr                                          Graphics Lab @ Korea University
Other Transformations
                                                                              CGVR

   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 

   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 



cgvr.korea.ac.kr                                               Graphics Lab @ Korea University
Coordinate Transformations
                                                               CGVR

   Multiple Coordinate System
         Local (modeling) coordinate system
         World coordinate scene




                      Local Coordinate System
cgvr.korea.ac.kr                                Graphics Lab @ Korea University
Coordinate Transformations
                                                              CGVR

   Multiple Coordinate System
         Local (modeling) coordinate system
         World coordinate scene




                      Word Coordinate System
cgvr.korea.ac.kr                               Graphics Lab @ Korea University
Coordinate Transformations
                                                             CGVR

   Example – Simulation of Tractor movement
         As tractor moves, tractor coordinate system and
          front-wheel coordinate system move in world
          coordinate system
         Front wheels rotate in wheel coordinate system




cgvr.korea.ac.kr                              Graphics Lab @ Korea University
Coordinate Transformations
                                                               CGVR

 Transformation of an Object Description from
  One Coordinate System to Another
 Transformation Matrix
       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 
cgvr.korea.ac.kr                                Graphics Lab @ Korea University
Coordinate Transformations
                                                                         CGVR

      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 2
                                 x        u3
                                           x     0
                        u     u 2      u 3   0
                    R   y1     y         y      
                        u 1
                           z    u2
                                 z        u 3
                                            z    0
                                                 
                        0          0      0     1

cgvr.korea.ac.kr                                          Graphics Lab @ Korea University

				
About if any file u wil find copyright contact me it will be remove in 3 to 4 buisnees days. add me on sanjaydudeja007@gmail.com or visit http://www.ohotech.com/