3-D Transformational Geometry CS418 Computer Graphics John C. Hart
Graphics Pipeline Model Model World Viewing Viewing Perspective Coords Xform Coords Xform Coords Distortion Still Homogeneous Clip Clip Clipping Divide Coords. Coords. Window Window Viewport to Coordinates Coordinates Viewport
3-D Affine Transformations • General • Translation
3-D Coordinates Right Handed Coord. Sys. z • Points represented x by 4-vectors y • Need to decide z y orientation of x 1 coordinate axes Left Handed Coord. Sys. z y +z (lhc) x +z (rhc) y x
a x ax y Scale b y by x c z cz z 1 1 1 Uniform Scale a = b = c = ¼ Squash Project Invert Stretch a = b = 1, c = ¼ a = b = 1, c = 0 a = b = 1, c = -1 a = b = 1, c = 4
3-D Rotations 1 • About x -axis cos sin sin cos – rotates y z 1 cos sin • About y -axis 1 – rotates z x sin cos 1 • About z -axis cos sin sin cos – rotates x y 1 1 • Rotations do not commute!
Arbitrary Axis Rotation y p ’ p • Rotations about x, y and z axes a • Rotation x rotation = rotation b o v • Can rotate about any axis direction x • Can do simply with vector algebra – Ensure || v || = 1 – Let o = ( p v ) v z b – Let a = p – o p ’ – Let b = v a , (note that ||b||=||a||) – Then p’ = o + a cos + b sin || a ||sin • Simple solution to rotate a single point • Difficult to generate a rotation matrix p || a ||cos to rotate all vertices in a meshed model a
Arbitrary Rotation • Find a rotation matrix that rotates by an angle about an arbitrary unit direction vector v 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y v v v x x z z z z [ ]=[ ][ ][ ] Rotate Rotate Rotate Rotate by by v to z z to v about z about v
Rotate v to z 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y 1. Project v onto the yz plane and 2 + z v 2 ) let d = sqrt( y v z v v yz v d x y v z
Rotate v to z 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y 1. Project v onto the yz plane and 2 + z v 2 ) let d = sqrt( y v z v 2. Then cos f x = z v / d and sin f x = y v / d v yz v d f x x y v z
Rotate v to z 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y 1. Project v onto the yz plane and 2 + z v 2 ) let d = sqrt( y v z v 2. Then cos f x = z v / d and sin f x = y v / d v yz 3. Rotate v by f x about x into the xz plane v d f x x y v z 1 z y v v d d y z v v d d 1
Rotate v to z 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y 1. Project v onto the yz plane and 2 + z v 2 ) let d = sqrt( y v 2. Then cos f x = z v / d and sin f x = y v / d 3. Rotate v by f x about x into the xz plane v f x x z v xz 1 z y v v d d y z v v d d 1
Rotate v to z 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y 1. Project v onto the yz plane and 2 + z v 2 ) let d = sqrt( y v 2. Then cos f x = z v / d and sin f x = y v / d 3. Rotate v by f x about x into the xz plane v 4. Then cos f y = d and sin f y = x v x d f y 1 x v z v xz 1 z y v v d d y z v v d d 1
Rotate v to z 2 + y v 2 + z v 2 =1 v = ( x v , y v , z v ), x v y 1. Project v onto the yz plane and 2 + z v 2 ) let d = sqrt( y v 2. Then cos f x = z v / d and sin f x = y v / d 3. Rotate v by f x about x into the xz plane v 4. Then cos f y = d and sin f y = x v f x x 5. Rotate v xz by f y about y into the z axis f y z v xz 1 d x v z y v v 1 d d y z x d v v v d d 1 1
Rotate about v • Let R v () be the rotation matrix for rotation by about arbitrary axis direction v • Recall (R x R y ) is the matrix (product) that rotates direction v to z axis • Then R v () = (R y R x ) -1 R z ( ) (R y R x ) -1 R z ( ) R y R x -1 R y = R x T R z ( ) R y R x T R y = R x (since the inverse of a rotation matrix is the transpose of the rotation matrix)
Easier Way y • Find an orthonormal vector system u v x z
Easier Way y • Find an orthonormal vector system u – Let r = u v /|| u v || v r x z
Easier Way y u’ • Find an orthonormal vector system u – Let r = u v /|| u v || – Let u ’ = v r v r x z
Easier Way y u’ • Find an orthonormal vector system u – Let r = u v /|| u v || – Let u ’ = v r v r • Find a rotation x from < r , u’ , v > < x , y , z > z r r r r ' 1 r u v r 1 x y z x x x x x ' ' ' u u u r ' 0 r u v r 0 x y z y y y y y 0 0 ' v v v r r u v r x y z z z z z z 1 1 1 1 1 1
Graphics Pipeline Model Model World Viewing Viewing Perspective Coords Xform Coords Xform Coords Distortion Still Homogeneous Clip Clip Clipping Divide Coords. Coords. Screen Model Window Window Viewport to W2V Persp View Model Coordinates Coordinates Vertices Vertices Viewport
Graphics Pipeline Model Model World Viewing Viewing Perspective Coords Xform Coords Xform Coords Distortion Still Homogeneous Clip Clip Clipping Divide Coords. Coords. Window Window Viewport to Coordinates Coordinates Viewport x x s m y y s m W2V Persp View Model 0 z m 1 1
Graphics Pipeline Model Model World Viewing Viewing Perspective Coords Xform Coords Xform Coords Distortion Still Homogeneous Clip Clip Clipping Divide Coords. Coords. Window Window Viewport to Coordinates Coordinates Viewport x x s m M y y s m 0 z m 1 1
Transformation Order glutSolidTeapot(1); glRotate3f(-90, 0,0,1); glTranslate3f(0,1,0); glTranslate3f(0,1,0); glRotate3f(-90, 0,0,1); glutSolidTeapot(1); glutSolidTeapot(1); y x z x x x x x x s m s m s m M M R T M T R y y y y y y s m s m s m 0 0 0 z z z m m m 1 1 1 1 1 1
Recommend
More recommend