chapter 6 3 d transformational geometry
play

Chapter 6 3-D Transformational Geometry In the previous chapter, - PDF document

Chapter 6 3-D Transformational Geometry In the previous chapter, we showed how 2-D points could be represented by homogeneous three-element vectors, and any affine transformation can be applied by the multiplication of a 3 3 matrix. Similarly


  1. Chapter 6 3-D Transformational Geometry In the previous chapter, we showed how 2-D points could be represented by homogeneous three-element vectors, and any affine transformation can be applied by the multiplication of a 3 × 3 matrix. Similarly we will represent a 3-D point using homogeneous coordinates as a four-element vector, and use a 4 × 4 transformation matrix to transform them. In general       a b c d x ax + by + cz + d e f g h y ex + fy + gz + h        =  . (6.1)       i j k l z ix + jy + kz + l     0 0 0 1 1 1 By properly selecting the matrix values a, b, c, . . . , these matrices can be configured to apply any affine transformation, to change the size, propor- tions, position or orientation of a 3-D shape. 6.1 Scale and Translation The 4 × 4 transformation matrices for scaling and translating 3-D points as homogeneous four-element vectors are are simple extensions of the 3 × 3 transformations used for 2-D points. We can scale an object in 3-D, by a uniform scale factor s, by multi- plying a scale matrix times the homogeneous coordinates of its vertices,       s x sx s y sy        =  . (6.2)       s z sz     1 1 1 We use the shorthand S ( s ) to denote a uniform scale matrix with scale factor s. 37

  2. 38 � 2012 John C. Hart c S ( 1 2 , 1 2 , 1 S ( 1 2 , 1 S (1 , 1 , 1 S (1 , 1 , 1) 2 ) 2 , 2) 4 ) S (1 , 1 , 0) Figure 6.1: A sphere scaled by various factors. A 3-D stretch and squash transformation is similarly defined using a separate horizontal, vertical and depth scaling factors h, v and d to scale x, y and z,       h x hx v y vy        =  . (6.3)       d z dz     1 1 1 We use the shorthand S ( h, v, d ) to indicate such a matrix. These scaling factors stretch when greater than one, and squash when less than one. Also similar to the 2-D case, we translate a 3-D space position ( x, y, z ) by the offset vector ( a, b, c ) using a matrix-vector product enables by ho- mogeneous coordinates       1 a x x + a 1 b y y + b        =  . (6.4)       1 c z z + c     1 1 1 Hence, as in the 2-D case, homogeneous coordinates enable us to represent any number of scales and translations (and any other affine transforma- tions) in any order with a single transformation matrix that is the product of these transformation matrices. 6.2 Left-Handed v. Right-Handed Coordinate Systems In 2-D, we use the convention that rotations by positive angles occur counter-clockwise, and that the positive y axis is rotated 90 ◦ from the positive x axis. We tend to draw the positive x axis extending horizontally to the right, so the y axis extends vertically upward. This is a convention. One could also define positive rotations to occur clockwise and extend the positive y axis downward from a positive x axis extending right, but such a configuration is non-standard and would seem unintuitive to anyone al- ready familiarized to the counter-clockwise convention.

  3. � 2012 John C. Hart c 39 y +z (lhc) x +z (rhc) Figure 6.2: Left-handed v. right-handed coordinate systems. If the + x direction extends right, and the + y direction extends up, then the + z direction either extends into the screen in a left-handed coordinate system, or extends toward the viewer in a right-handed coordinate system. In 3-D, there is also an arbitrary orientation choice. Using the con- vention that positive x extends right and positive y extends up, then the positive z axis can extend either toward, or away from, the viewer. If the + z axis extends toward the viewer, then we say the coordinate system is right-handed . If we can place our right hand at the origin and fold our fingers from the + x axis to the + y axis, then our right-hand’s thumb ex- tends in the + z direction. Conversely, if the + z axis extents away from the viewer, then we say the coordinate system is left-handed , and we must use our left-hand’s fingers to fold from the + x direction to the + y direction, and our left-hand’s thumb extends in the + z direction. Different applications use different coordinate systems, so, unlike the 2-D clockwise convention, there is not a strong convention between left- and right-handed 3-D coordinate systems. For this book (as is mostly the case for modern computer graphics), we will always use right-handed 3-D coordinate systems. The matrix   1 1   S (1 , 1 , − 1) = (6.5)   − 1   1 converts between a left-handed and right-handed coordinate system, by in- verting only the z coordinate. Similarly, the inversions S ( − 1 , 1 , 1) , S (1 , − 1 , 1) and S ( − 1 , − 1 , − 1) would also convert between left-handed and right-handed coordinate systems, though in non-intuitive ways since the primary differ- ence between left-handed and right-handed coordinate systems in most real-world applications is the sign of the z coordinate. 6.3 Vector Arithmetic As did the previous chapter’s discussion of homogeneous coordinates for 2- D graphics, we will use the homogeneous coordinate to differentiate points and vectors in 3-D as well. We will represent points and vectors in 3-

  4. 40 � 2012 John C. Hart c x   y   p = y   z     1 x   y   v =   z     0 x o = [0 0 0 1] T Figure 6.3: Homogenous representations of points and vectors. D both with 4-element column vectors [ x y z w ] T . The difference is that the fourth (homogeneous) element w of a vector will be zero whereas the fourth (homogeneous) element w of a point will be non-zero. For now, w will always equal one for points. Hence p = [1 2 3 1] T represents the point at 3-D position (1 , 2 , 3) whereas v = [1 2 3 0] represents the vector (1 , 2 , 3) . The origin o is the point [0 0 0 1] , so v = p − o . For 3-D computer graphics, we will rely on a lot of vector arithmetic, mostly using the dot product and cross product. These operations are designed to work on ordinary three element vectors. Even though they can be extended to work on homogeneous vectors, the extensions are a bit ugly and cumbersome. Because of that, we tend to work with ordinary vectors when performing the vector arithmetic needed to derive and analyze properties, and then switch to the homogeneous representation for vectors when working on their implementation in the pipeline, or when we need the projective properties of the homogeneous representation. To be able to do this without confusion, we should find a notation to differentiate between ordinary and homogeneous representations. We’ll denote an ordinary 3-D vectors with a lowercase bold variable, v = ( x, y, z ) (6.6) whereas its homogeneous representation is denoted with an uppercase ro- man variable   x y   V =  . (6.7)   z  0 We use uppercase roman letters for both homogeneous transformation ma- trices and homogeneous column vectors (which are 4 × 1 matrices). When we do, definitions and context should make it clear which is which.

  5. LET R V ( θ ) BE A ROTATION BY θ HOW TO ROTATE ABOUT ANY UNIT VECTOR V ABOUT AN v = ( x, y, z ) v = ( x, y, z ) R v ( θ ) ARBITRARY AXIS y “THE ALGEBRAIC WAY” x z STEP 1: CREATE A NEW <T,U,V> COORDINATE SYSTEM (SEE “HOW TO MAKE AN ORTHOGONAL COORDINATE SYSTEM”) STEP 2: MAKE A MATRIX OUT OF <T,U,V>, T X T Y T Z 0 U X U Y U Z 0 R = V X V Y V Z 0 0 0 0 1 R ROTATES T,U,V INTO X,Y,Z R IS A ROTATION MATRIX T.T T.U T.V U.T U.U U.V R T = = X, R U = = Y, R V = = Z V.T V.U V.V SINCE T,U,V ARE UNIT LENGTH... 0 0 0 T.T = U.U = V.V = 1 SINCE <T,U,V> IS ORTHOGONAL... STEP 3: COMPOSE ROTATIONS: R V ( θ ) = R T R Z ( θ ) R T.U = T.V = U.V = 0 ROTATE BACK ROTATE BY θ ABOUT Z ROTATE V TO Z y T.T T.U T.V 0 T X T Y T Z 0 T X U X V X 0 U.T U.U U.V 0 R R T = = I U X U Y U Z 0 T Y U Y V Y 0 V.T V.U V.V 0 R z ( θ ) x V X V Y V Z 0 T Z U Z V Z 0 0 0 0 1 0 0 0 1 0 0 0 1 z

Recommend


More recommend