290 likes | 431 Views
Lecture 4c Geometry and transformations. Rotations around an arbitrary axis Rotations Using rotation matrices Using a Householder reflection matrix Using a quaternion. Rotation. 3 degrees of freedom (DOF) 2 angles that specify the orientation of the rotation vector
E N D
Lecture 4cGeometry and transformations • Rotations around an arbitrary axis • Rotations • Using rotation matrices • Using a Householder reflection matrix • Using a quaternion
Rotation • 3 degrees of freedom (DOF) • 2 angles that specify the orientation of the rotation vector • 1 angles that specifies the amount of rotation
Rotation • We know the following: • We can concatenate rotations about our standard axes x, y, and z to create a general rotation • We can always rotate about the origin if we translate everything first • We can easily undo rotations and translations by negating the angle of rotation or distances.
Rotation around an arb. axis • We will use this information to find a rotation around an arbitrary axis, R(),where • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T Note: , x,and y,are three different angles. Note: Apply transformations from left to right so that translation to origin is done first, then a rotation around the x axis, then around the y and z, and then the inverses are applied.
p2 v p1 x p0 z Rotation around an arb. axis • The problem: • Rotate an object centered at p0° around an axis defined by v = p2 - p1 • Graphically: y
y u = (x, y,z) x z p0 Translation • First: • Normalize v vUNIT = u = (p2 - p1) / |p2 - p1| • Translate all points to the origin • Giving:
Translation • This takes care of the translation. • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • T = 1 0 0 -p1x • 0 1 0 -p1y • 0 0 1 -p1z • 0 0 0 1
How shall we perform rotation? • Our goal: • To rotate our object around a standard axis (because we know how to do this). Let’s choose the z axis. • If we were to align our rotation axis, v, with the z axis, we could easily rotate our ° • Then: • The problem becomes how to align v with z. • We will do this with a series of rotations.
Direction angles • Let’s look at some tools we can use: • The angles, x,y,z, that u makes with the x, x,y,z axes respectively, are called the direction angles • The cosines of these angles are called the direction cosines cosx= x cosy= y cosz = z x2+y2+z2= 1 (u unit vec) => cosx2+cosy2+cosz2= 1 y (x, y,z) y x x z z
Rotations about x,y,z axes • Here is our strategy: 1.Rotate u about x axis into the xz plane - call the rotated vector u. 2.Rotate u about the y axis into the yz plane, which will align it with the z axis - call the rotated vector u. 3.Rotate our object about u (which is now the z axis). 4.Undo rotations 1. and 2., which brings u back to u.
y u=(x, y,z) x x u z Rotation of u to xz plane • First: • Rotate u about x axis into the xz plane - call the rotated vector u. But, how do we find x?
y u=(x, y,z) up=(0, y,z) x x x u z Rotation of u to xz plane • If we project u onto the yz plane, then the angle that up makes with the z axis is also x. • Again, how do we find x?
Rotation of u to xz plane • It happens that we don’t really need x, what we really need is the sin and cos of x which can be found geometrically • cosx = z /d and sinx = y /d y d = sqrt(y2+z2) - the length of up, d, is different than the length of u z up=(0, y,z) u=(x, y,z) d x x x y u z If we project u onto the yz plane, then the angle up makes with z is equal to x
Rotation: Rx(x) • This takes care of the rotation of u around the x axis. • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • Rx(x) = 1 0 0 0 0 cosx-sinx 0 0 sinx cosx 0 0 0 0 1 = 1 0 0 0 0 z/d -y/d 0 0 y/d z/d 0 0 0 0 1
y u=(x, y,z) x u y z Rotation of u to yz plane • Second: • Rotate u about y axis into the yz plane - call the rotated vector u (or z!) But, how do we find y? If u is a unit vector then u is a unit vector (because we rotated u instead of projecting it)
Rotation of u to yz plane • To find y we can use the same machinery we employed to find x, i.e. y 1. If we rotate u to z (y) we get u. What is the sin and cos of y? u=(x,y,z) up =(0,y,z) d x x cos y up u x 2. If we project u to z then the length of up will be equal to the length of up = d (rotat- ing u about x axis does not change the length of its projection onto yz) u y z 3. cosy = z coord of u = length of up = length of up (rotating up about x does not change its length) = d, so cosy = sqrt(y2+z2) Therefore, sin y = x(rotating u about x does not change its x coord.) but we want a pos. rot. instead of the neg we see in illustration, so sin y = -x
Rotation of u to yz plane • Or, we can use the direction angles and direction cosines of u to find y, i.e. y 2. We know that x, the direction angle of u, does not change as u rotates around x. 1. We know that the y axis makes a 90° angle with the xz plane. u=(x, y,z) 90° x y x x u x u z cos2x+cos2(90)+cos2y = 1 => cosy2= 1- cos2x - cos2(90)= 1- x2= y2+z2 => cosy = sqrt(y2 +z2 ) => siny = +-sqrt(1- cos2y) = + -sqrt(1-1+x2) = -x (x2 +y2 +z2 =1)
Rotation: Ry(y) • This takes care of the rotation of u around the y axis. • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • Ry(y) = d 0 -x 0 0 1 0 0 x 0 d 0 0 0 0 1 cosy 0 -siny 0 0 1 0 0 siny 0 cosy 0 0 0 0 1 =
Rotation: Rz() • The rotation around z is the user- specified angle, • This takes care of the rotation of the object around the z axis. • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • Rz() = cos -sin 0 0 • sin cos 0 0 • 0 0 1 0 • 0 0 0 1
Rotation: Inverses • Now find the inverses • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • That’s it! • Or is it?
Householder matrices • Using rotation matrices to align the rotation axis with the z axis we found: • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • A more efficient way to do this is to use a reflection matrix to align the rotation axis with z: • R() = T-1 H Rz(-) H T • where H is a Householder matrix
Reflection plane, Rp b a b b n=(b-a)/|b-a| a n Householder matrices • Given an arbitrary axis of rotation, u, translate it to the origin as usual • Find a plane that we can reflect u (b) through to give us the z axis (a) (assume a,b unit vectors) 1. Find n; the reflection plane is defined by its normal 2. Find vector, v, from b to Rp v = -(b*n) n, where (b*n) is length and -n is direction Subtract a from b (and normalize) to find normal, n, of Rp len=(b*n) is b projected to n
b a Householder matrices • To find vector a we add 2*v to vector b a = b + 2*(-(b*n)n) = b - 2n(b*b) = b - 2nnTb = (I - 2nnT)b rearrange terms rewrite in matrix form, n*b = [nxnynz][bx] = nTb [by] [bz] Householder matrix H = (I-2nnT)/|n||n| = (I-2nnT)/nTn |n| = sqrt(nx2+ny2+nz2) |n|2 = nx2+ny2+nz2 = [nxnynz][nx] [ny] = nTn [nz] the general form makes no assumptions about normalization
Householder matrices • The Householder matrix: • H(n) = (I - 2nnT)/nTn • = I + cnnT, where c = -2/nTn (a scalar) nx2 nxny nxnz nxny ny2 nynz nxnz nynz nz2 1 0 0 0 1 0 0 0 1 = + c nnT = [nx][nx ny nz] [nx] [nx] Bonus: a Householder matrix is its own inverse (H=H-1)!
Quaternions • Using rotation matrices to align the rotation axis with the z axis we found: • R() = T-1 Rx-1(x) Ry-1(y) Rz() Ry(y) Rx(x) T • Using a Householder reflection matrix to align the rotation axis with z we found: • R() = T-1 H Rz(-) H T • Using a quaternion is even more efficient: • Rq() = T-1 MR() T
Quaternions • The most efficient way to perform a rotation about an arb. axis is with a quaternion • A quaternion is a: • 4D generalization of a 2D complex number • q = s + ia + jb + kc • s,a,b,c R • i,j,k imaginary terms with property i2=j2=k2=-1 • Super-concise representation of a matrix • the most efficient way to do rotations • very easy to interpolate orientations
Quaternions • Representation • q = (s,v), s a scalar and v a vector • Given and u, arguments of a rotation matrix, s = cos(/2), v = u*sin(/2), u a unit vector • Multiplication • Concatenating 2 rotations is equivalent to multiplying 2 quaternions q1q2= (s1s2 - v1*v2, s1v2 + s2v1 + v1xv2) • Treat a point as p=(0,v), a pure imaginary p=Rq(p)=qp-q= s2 p + v(p*v) 2s(vxp) + vx(vxp)
Quaternions • Rotate (ax,ay,az,deg) { • Quat quat = new Quat(ax,ay,az,deg); • Mat3D mat = quat.toMatrix(); • } • Class Quat { • double s, a, b, c; • Quat(ax,ay,az,deg) { • rad = deg * PI/180; s = cos; • cos = cos(rad/2); a = sin * ax; • sin = sin(rad/2); b = sin * ay; • c = sin * az; • }
Quaternions • Mat3D toMatrix () { • M[0][0] = 1-2b2-2c2; • : • : • M[3][3] = 1-2a2-2b2; • } • } 1-2b2-2c2 2ab-2sc 2ac-2sb 2ab+2sc 1-2a2-2c2 2bc-2sa 2ac-2sb 2bc+2sa 1-2a2-2b2 Rq = M =