Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Today’s Topics Questions? 3d –3 dimensional vectors –dot product –cross product –parametric equation of a line in 3 dimensions –equation of a plane in 3 dimensions and its derivation –3d primitive transform matrices translation scaling rotation about each coordinate axis –Inverses –homogeneous coordinates reminder –rotation about an arbitrary axis –fixed point scaling

3 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 vectors A vector is a directed line segment that has magnitude (length) and direction. We can define a vector as the difference between two points. (Example on board.) In 2 dimensions: V = P 2 -P 1 = (v x, v y ) In 3 dimensions: V = P 2 -P 1 = (v x, v y, v z ) The v x, v y, and v z values are the projections of the line segment onto the x, y and z axes, respectively. Magnitude of a Vector is determined by the Pythagorean theorem: For 2d: |V| = sqrt(v x 2 + v y 2 ) and for 3d: |V| = sqrt(v x 2 + v y 2 + v z 2 )

4 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 vectors Vector addition: V 1 + V 2 = (v 1x +v 2x, v 1y +v 2y, v 1z +v 2z ) Scalar multiplication: sV = (sv x, sv y, sv z ) Dot product (aka scalar product) of 2 vectors results in a scalar: V 1 ● V 2 = |V 1 | |V 2 |cos θ θ is the (smaller) angle between the two vectors alternatively: V 1 ● V 2 = v 1x v 2x +v 1y v 2y +v 1z v 2z

5 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 vectors Cross product (aka vector product) of 2 vectors results in a vector: V 1 x V 2 = u |V 1 | |V 2 |sin θ θ is the angle between the two vectors u is a unit vector (length = 1) perpendicular to both V 1 and V 2 u's direction is determined by the right-hand rule Right-hand rule is: with your right hand, grasp the axis perpendicular to the plane of the two vectors and make sure that the direction of your fingers curve from v1 to v2. u's direction is the direction of your thumb. Alternatively: V 1 x V 2 = (v 1y v 2z – v 1z v 2y, v 1z v 2x – v 1x v 2z, v 1x v 2y – v 1y v 2x ) Cross product is not commutative, nor associative. V 1 x V 2 = - (V 2 x V 1 )

6 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 vectors Cross product of two vectors is a vector that is perpendicular to the two vectors and has magnitude equal to the area of the parallelogram formed by the two vectors. (picture on board)

7 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 vectors Recap –a vector has magnitude and direction (but no position) –addition of 2 vectors results in a vector –a scalar times a vector results in a vector –Cross product of two vectors results in a vector –but –dot product of two vectors results in a scalar

8 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 lines Parametric equation of a line in 3 dimensions –Given points P 1 and P 2 the equation of a line that contains these points is: x = x 1 + t(x 2 – x 1 ) y = y 1 + t(y 2 – y 1 ) z = z 1 + t(z 2 – z 1 ) –Given a point P 1 and vector V the equation of a line that contains the point and is in the direction of V is: x = x 1 + t(x v ) y = y 1 + t(y v ) z = z 1 + t(z v ) Line = P 1 + t (P 2 – P 1 ) Line = P 1 + Vt

9 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Planes (part of sec. 3.15) The general plane equation: Ax + By + Cz + D = 0 A, B, C, D are constants and (x,y,z) are the coordinates of the points on the plane. A useful form of the plane equation is: A'x + B'y + C'z + D' = 0 where A'=A/d, B'=B/d, C'=C/d, D'=D/d, and d = sqrt(A 2 + B 2 + C 2 ) Because then it's easy to find the distance between a point (x 1, y 1, z 1 ) and the plane which is simply: A'x 1 + B'y 1 + C'z 1 + D' A normal vector to a plane is perpendicular to the plane. If the equation of the plane is Ax + By + Cz + D = 0, then a normal to the plane is the vector (A, B, C) Pictures on board.

10 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 The plane equation From the drawing on the board –Equation of the plane: Ax + By + Cz + D = 0 –Given three non collinear points, P 1, P 2, P 3 these points uniquely determine the plane –The cross product of P 1 - P 2 and P 3 - P 2, gives us a normal vector N. –For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –Why?

11 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 The plane equation From the drawing on the board –Equation of the plane: Ax + By + Cz + D = 0 –Given three non collinear points, P 1, P 2, P 3 these points uniquely determine the plane –The cross product of P 1 - P 2 and P 3 - P 2, gives us a normal vector N. –For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –Why? Because if N is normal to the plane, and P-P 2 is a vector on the plane, then the angle between these is 90 degrees and so the dot product will be 0, since cos(90) = 0. –If P is not on the plane, therefore P-P 2 is not on the plane, so what happens?

12 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 The plane equation For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –So, we can derive the plane equation like so: –N = (A, B, C) and is normal to the plane –P = (x, y, z) and represents any point on the plane –P 2 = (x 2, y 2, z 2 ) is some fixed point on the plane N ● [ P - P 2 ] = [A,B,C] ● [x- x 2,y-y 2, z- z 2 ]= A(x- x 2 ) + B(y-y 2 ) + C(z- z 2 ) = Ax + By + C z + A(- x 2 ) + B(-y 2 ) + C(- z 2 ) = 0 Notice that x, y and z are variables and the rest are constant values so this gives Ax + By + C z + D = 0 where D = A(- x 2 ) + B(-y 2 ) + C(- z 2 )

13 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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

14 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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')

15 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 3d transformations Translation Scale Rotation Shear

16 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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 ]

17 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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.

18 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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.)

19 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Right-handed 3d coordinate system

20 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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 1 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.

21 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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)

22 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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)

23 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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 ]

24 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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

25 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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

26 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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

27 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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

28 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

29 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

30 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

31 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

32 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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.

33 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 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 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann."

Similar presentations


Ads by Google