Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Today’s Topics Questions/comments? 3d –Inverses –homogeneous coordinates reminder –3d primitive transform matrices translation scaling rotation about each coordinate axis –rotation about an arbitrary axis –fixed point scaling

3 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Inverse Transforms and Identity The inverse of a Matrix is the matrix that when multiplied by the original results in the Identity matrix. The identity matrix is an nxn matrix with 1's along the main diagonal (from upperleft to lowerright) and 0's elsewhere. MM -1 = I = M -1 M

4 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Reminder about Homogeneous Coordinates When we transform some homogeneous point (x,y,z,1) we may end up with something other than 1 in the homogeneous parameter slot i.e. (x 1,y 1,z 1,w), w != 1. To figure out which point to plot in 3d, we need to divide each coordinate by w x' = x 1 / w y' = y 1 / w z' = z 1 / w 1 = w / w so we plot (x',y',z')‏

5 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 3d transformations Translation Scale Rotation Shear

6 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 3d Translation 3d Translation in homogeneous coordinates is a direct extension of translation in 2d. [ 1 0 0 t x ] [x] [x+t x ] [ 0 1 0 t y ] [y] = [y+t y ] [ 0 0 1 t z ] [z] [z+t z ] [ 0 0 0 1 ] [1] [ 1 ]

7 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 3d Scale [ s x 0 0 0 ] [x] [s x x] [ 0 s y 0 0 ] [y] = [s y y] [ 0 0 s z 0 ] [z] [s z z] [ 0 0 0 1 ] [1] [ 1 ] 3d Scale has the same problem/feature that 2d scaling has, namely it also translates.

8 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 3d Rotation Positive rotations are defined to be Rotation about the x-axis is positive going from y to z Rotation about the y-axis is positive going from z to x Rotation about the z-axis is positive going from x to y (see figures 5-36 and 5-38 in text.)‏

9 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Right-handed 3d coordinate system

10 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 3d Rotation About z-axis [ cos θ -sin θ 0 0 ] [ sin θ cos θ 0 0 ] [ 0 0 1 0 ] [ 0 0 0 1 ] About x-axis [ 1 0 0 0 ] [ 0 cos θ -sin θ 0 ] [ 0 sin θ cos θ 0 ] [ 0 0 0 1 ] About y-axis [ cos θ 0 sin θ 0 ] [ 0 1 0 0 ] [ -sin θ 0 cos θ 0 ] [ 0 0 0 1 ] Let's, as an example rotate the point (4,6,0) (in homogeneous it is (4,6,0,1)) about x-axis, positive 60 degrees.

11 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 xy Shear [ 1 0 sh x 0 ] [x] [x+sh x z] [ 0 1 sh y 0 ] [y] = [y+sh y z] [ 0 0 1 0 ] [z] [ z ] [ 0 0 0 1 ] [1] [ 1 ] Let's transform a unit cube with this shear and set sh x = 1 and sh y = 2 points are: (0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1)

12 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 xy Shear [ 1 0 sh x 0 ] [x] [x+sh x z] [ 0 1 sh y 0 ] [y] = [y+sh y z] [ 0 0 1 0 ] [z] [ z ] [ 0 0 0 1 ] [1] [ 1 ] Let's transform a unit cube with this shear and set sh x = 1 and sh y = 2 points are: (0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1) transformed they are: (0,0,0), (1,2,1), (0,1,0), (1,0,0), (1,3,1), (2,2,1), (1,1,0), (2,3,1)

13 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Rotation of θ about an arbitrary axis To rotate about an arbitrary axis: The axis can be specified by two points on it, P 1 and P 2 The vector P 2 - P 1 is on this axis. Before anything else, we should translate P 1 to the origin. If P 1 = (x 1,y 1,z 1 ) then T = [ 1 0 0 -x 1 ] [ 0 1 0 -y 1 ] [ 0 0 1 -z 1 ] [ 0 0 0 1 ]

14 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 We know how to rotate about the x-axis, y-axis and z-axis. We also know how to translate. Therefore we will use a composition of these primitive transforms to get the rotation about an arbitrary axis. Rotation of θ about an arbitrary axis

15 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 What we want to do next is to rotate the axis so that it is on the z-axis. Then rotate by an angle of  about the z axis. Then we need to do the inverses of the transforms in reverse order. That is, rotate back from z-axis to original angle. Then translate back from origin to P 1. Does that make sense? Rotation of θ about an arbitrary axis

16 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 What we want to do now is to rotate the axis so that it is on the z-axis. To rotate the axis from where it is now to the z- axis we can do this in two steps (rotate about 2 different coordinate axes). One way to do this is: –a) rotate the axis so that it is on the y-z plane What axis will we rotate about, to get it on y-z plane? –b) rotate the axis so that it is on the z-axis Once we have it on the y-z plane, what axis will we rotate about to get it on z-axis? Rotation of θ about an arbitrary axis

17 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 What we want to do now is to rotate the axis so that it is on the z-axis. To rotate the axis from where it is now to the z- axis we can do this in two steps –a) rotate the axis so that it is on the y-z plane Rotate about y-axis to get it on y-z plane. –b) rotate the axis so that it is on the z-axis Rotate about x-axis to get it on z-axis. Rotation of θ about an arbitrary axis

18 a) rotate the axis so that it is on the y-z plane Rotate about y-axis to get it on y-z plane. See handout diagram. U = (u 1,u 2,u 3 )‏ We need to find angle β, the triangle with side lengths u 3 u 1 and a is a right triangle: cos β = u 3 / a sin β = u 1 / a a = sqrt(u 1 2 + u 3 2 )‏ Rotating U towards y-z is a negative angle, so the matrix is R y (- β )‏ Rotation of θ about an arbitrary axis

19 b) rotate the axis so that it is on the z-axis Rotate about x-axis to get it on z-axis. See second handout diagram. This is the y-z plane It may not be immediately obvious, but the length a, on this diagram is the same as from the previous. U = (u 1,u 2,u 3 )‏ We need to find angle μ, the triangle with side lengths u 2 a and |U| is a right triangle: cos μ = a / |U| sin μ = u 2 / |U| a = sqrt(u 1 2 + u 3 2 )‏ This rotation is in a positive direction, so the matrix is R x ( μ )‏ Rotation of θ about an arbitrary axis

20 The remaining steps are: Rotate by an angle of θ about the z axis, which is simply R z ( θ )‏ Then we need to do the inverses of the transforms in reverse order. That is, rotate back from z-axis to original angle. Then translate back from origin to P 1. R x (- μ )‏ R y ( β )‏ T -1 Rotation of θ about an arbitrary axis

21 To rotate an angle of θ about an arbitrary axis the composite transform is: T -1 R y ( β ) R x (- μ ) R z ( θ ) R x ( μ ) R y (- β ) T Notice that we are multiplying this matrix by a point and the point goes on the right. Therefore, it acts like the first transform applied to the point is T, then R y (- β ), then the rest from right to left. Rotation of θ about an arbitrary axis

22 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 3d Scale w/ fixed point First transform the fixed point to the origin with a translation matrix. Then do the 3d Scale [ s x 0 0 0 ] [ 0 s y 0 0 ] [ 0 0 s z 0 ] [ 0 0 0 1 ] Then transform the origin back to the fixed point via the inverse of the first translation matrix.

23 Michael Eckmann - Skidmore College - CS 325 - Spring 2010 Rigid body vs. Affine Transformations that preserve line lengths and angles do not deform shapes. Therefore they are called rigid body transformations. –Translation and Rotation (and any combination of these) are examples of rigid body transformations. Transformations that preserve parallel lines, that is, lines that were parallel before the transform remain parallel after the transform are called affine transformations. –Line lengths and angles need not be preserved for a transformation to be considered affine –Rotation, Translation, Scale and Shear (and any combination of these) are examples of affine transformations.


Download ppt "CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann."

Similar presentations


Ads by Google