1 / 41

CS 445/645 Fall 2001

CS 445/645 Fall 2001. Parameterized Rotations & Curves. Parameterizing Rotations. Straightforward in 2D A scalar, q , represents rotation in plane More complicated in 3D Three scalars are required to define orientation Note that three scalars are also required to define position

thy
Download Presentation

CS 445/645 Fall 2001

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 445/645Fall 2001 Parameterized Rotations & Curves

  2. Parameterizing Rotations • Straightforward in 2D • A scalar, q, represents rotation in plane • More complicated in 3D • Three scalars are required to define orientation • Note that three scalars are also required to define position • Objects free to translate and tumble in 3D have 6 degrees of freedom (DOF)

  3. Representing 3 Rotational DOFs • 3x3 Matrix (9 DOFs) • Rows of matrix define orthogonal axes • Euler Angles (3 DOFs) • Rot x + Rot y + Rot z • Axis-angle (4 DOFs) • Axis of rotation + Rotation amount • Quaternion (4 DOFs) • 4 dimensional complex numbers

  4. Rotation Matrix • 9 DOFs must reduce to 3 • Rows must be unit length (-3 DOFs) • Rows must be orthogonal (-3 DOFs) • Drifting matrices is very bad • Numerical errors results when trying to gradually rotate matrix by adding derivatives • Resulting matrix may scale / shear • Gram-Schmidt algorithm will re-orthogonalize your matrix • Difficult to interpolate between matrices

  5. Euler Angles • (qx, qy, qz) = RzRyRx • Rotate qx degrees about x-axis • Rotate qy degrees about y-axis • Rotate qz degrees about z-axis • Axis order is not defined • (y, z, x), (x, z, y), (z, y, x)… are all legal • Pick one

  6. Euler Angles • Rotations not uniquely defined • ex: (z, x, y) = (90, 45, 45) = (45, 0, -45)takes positive x-axis to (1, 1, 1) • cartesian coordinates are independent of one another, but Euler angles are not • Gimbal Lock • Term derived from mechanical problem that arises in gimbal mechanism that supports a compass or a gyro

  7. Gimbal Lock

  8. Gimbal Lock • Occurs when two axes are aligned • Second and third rotations have effect of transforming earlier rotations • ex: Rot x, Rot y, Rot z • If Rot y = 90 degrees, Rot z == -Rot x

  9. Interpolation • Interpolation between two Euler angles is not unique • ex: (x, y, z) rotation • (0, 0, 0) to (180, 0, 0) vs. (0, 0, 0) to (0, 180, 180) • Interpolation about different axes are not independent

  10. Interpolation

  11. Axis-angle Notation • Define an axis of rotation (x, y, z) and a rotation about that axis, q: R(q, n) • 4 degrees of freedom specify 3 rotational degrees of freedom because axis of rotation is constrained to be a unit vector

  12. rperp = r – (n.r) n q V = nx (r – (n.r) n) = nxr Rr rpar = (n.r) n r n Axis-angle Notation Rr = Rrpar + Rrperp = Rrpar + (cos q) rperp + (sin q) V =(n.r) n + cos q(r – (n.r)n) + (sin q) n x r = (cos q)r + (1 – cos q) n (n.r) + (sin q) n x r

  13. Axis-angle Rotation Given r – Vector in space to rotate n – Axis in space about which to rotate q – The amount about n to rotate Solve r’ – The rotated vector r’ r n

  14. Axis-angle Rotation • Step 1 • Compute rk an extended version of the rotation axis, n • rk = (n ¢ r) r rk r’ r

  15. Axis-angle Rotation • Compute r? • r? = r– (n¢r) n r? r’ r

  16. v q Axis-angle Rotation • Compute v, a vector perpendicular to rk and r? • v = rk£ r? • Use v and r? and q to compute r’ cos(q) r? + sin(q) v r?

  17. Axis-angle Notation • No easy way to determine how to concatenate many axis-angle rotations that result in final desired axis-angle rotation • No simple way to interpolate rotations

  18. Quaternion • Remember complex numbers: a + ib • Where i2 = -1 • Invented by Sir William Hamilton (1843) • Remember Hamiltonian path from Discrete II? • Quaternion: • Q = a + bi + cj + dk • Where i2 = j2 = k2 = -1 and ij = k and ji = -k • Represented as: q = (s, v) = s + vxi + vyj + vzk

  19. Quaternion • Let q1 = (s1, v1) and q2 = (s2, v2) • q1q2 = (s1s2 – v1.v2, s1v2 + s2v1 + v1 x v2) • Conjugate = q1’ = (s, -v) • q1q1’ = s2 + |v|2 = |q|2 = magnitude • If q has unit magnitude • q’ = q-1 (conjugate = inverse) • Define a pure quaternion: p = (0, r), r = unit vector • Rotating p by q • (0, cos2q r + (1 – cos2q) n (n.r) + sin2qn.r)

  20. Quaternion • Continue to represent quaternion as a 4 DOF vector (as in axis-angle) • But use quaternion algebra: • (cos (q/2), sin(q/2) nx, sin(q/2) ny, sin(q/2) nz) • Quaternion easily converted into rotation matrix • The product of two unit quaternions is a unit quaternion

  21. Quaternion Example • X-roll of p • (cos (p/2), sin (p/2) (1, 0, 0)) = (0, (1, 0, 0)) • Y-roll 0f p • (0, (0, 1, 0)) • Z-roll of p • (0, (0, 0, 1)) • Ry (p) followed by Rz (p) • (0, (0, 1, 0) times (0, (0, 0, 1)) = (0, (0, 1, 0) x (0, 0, 1) = (0, (1, 0, 0))

  22. Quaternion Interpolation • Biggest advantage of quaternions • Interpolation • Cannot linearly interpolate between two quaternions because it would speed up in middle • Instead, Spherical Linear Interpolation, slerp() • Used by modern video games for third-person perspective • Why?

  23. Quaternion Interpolation • Quaternion (white) vs. Euler (black) interpolation • Left images are linear interpolation • Right images are cubic interpolation

  24. Quaternion Code • http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm • Registration required • Camera control code • http://www.xmission.com/~nate/smooth.html • File, gltb.c • gltbMatrix and gltbMotion

  25. Representations of Curves • Problems with series of points used to model a curve • Piecewise linear - Does not accurately model a smooth line • It’s tedious • Expensive to manipulate curve because all points must be repositioned • Instead, model curve as piecewise-polynomial • x = x(t), y = y(t), z = z(t) • where x(), y(), z() are polynomials

  26. Specifying Curves • Control Points • A set of points that influence the curve’s shape • Knots • Control points that lie on the curve • Interpolating Splines • Curves that pass through the control points (knots) • Approximating Splines • Control points merely influence shape

  27. Parametric Curves • Very flexible representation • They are not required to be functions • They can be multivalued with respect to any dimension • Decouples dimension of object from dimension of space

  28. Cubic Polynomials • x(t) = axt3 + bxt2 + cxt + dx • Similarly for y(t) and z(t) • Let t: (0 <= t <= 1) • Let T = [t3 t2 t 1] • Coefficient Matrix C • Curve: Q(t) = T.C

  29. Parametric Curves • Derivative of Q(t) is the tangent vector at t: • d/dt Q(t) = Q’(t) = d/dt T . C = [3t2 2t 1 0] . C

  30. Piecewise Curve Segments • One curve constructed by connecting many smaller segments end-to-end • Continuity describes the joint

  31. Continuity of Curves • Two curves that join together • G0, geometric continuity • If direction (but not necessarily magnitude) of tangent matches • G1 geometric continuity • Matching tangent vectors (direction and magnitude) • C1 continuous, first-degree continuity in t (parametric continuity) • Matching direction and magnitude of dn / dtn • Cn continous

  32. Parametric Cubic Curves • In order to assure C2 continuity, curves must be of at least degree 3 • Here is the parametric definition of a spline in two dimensions

  33. Parametric Cubic Splines • Can represent this as a matrix too

  34. Coefficients • So how do we select the coefficients? • [ax bx cx dx] and [ay by cy dy] must satisfy the constraints defined by the knots and the continuity conditions

  35. Parametric Curves • Difficult to conceptualize curve as • x(t) = axt3 + bxt2 + cxt + dx • Instead, define curve as weighted combination of 4 well-defined cubic polynomials • Each curve type defines different cubic polynomials and weighting schemes

  36. Parametric Curves • Hermite – two endpoints and two endpoint tangent vectors • Bezier - two endpoints and two other points that define the endpoint tangent vectors • Splines – four control points. • C1 and C2 continuity at the join points • Come close to their control points, but not guaranteed to touch them

  37. Hermite Cubic Splines • An example of knot and continuity constraints

  38. Assignment 4, part 2 • Environment Maps • Alpha Blending • Multipass Rendering • Multitexturing

  39. Reflections

  40. Reflections

  41. Using Quaternions in Assignment 4 part 2 • Nate’s ‘Smooth’ program uses axis-angle to represent the rotation • He then uses glRotate to convert this to a rotation matrix and adds it to the modelview matrix stack • Instead, you convert axis-angle to quaternion and then to rotation matrix • You then put this rotation matrix on stack

More Related