Graphics Reference
In-Depth Information
where
is a unit vector that's the axis of rotation of the matrix and
θ
is the angle
v
of rotation. And we discussed how to recover the axis
from an
arbitrary rotation matrix (except that when the matrix was I , the axis could be any
unit vector and the angle was 0). The associated element q of S 3 has cos(
and the angle
θ
v
θ/
2 )
as its first coordinate and sin(
θ/
2 )
v
as its last three coordinates. The case where
θ
2 )= 0, so the
last three entries are all zeroes. There is an ambiguity, however: When we found
the axis
= 0 and
is indeterminate presents no problem, because sin(
θ/
v
and the angle
θ
we could instead have found
v
and
−θ
; those two
v
would have produced
q instead of q . So our “inverse” to K really can produce
one of two opposite values, depending on choices made in the axis-and-angle
computation. To make all this concrete, we'll give pseudocode for a function L
whose domain is SO ( 3 ) and whose codomain is pairs of antipodal points in S 3 ;
L will act as an inverse to K , in the sense that if M
SO ( 3 ) is a rotation matrix
are two elements of S 3 , then K ( q 1 )= K (
and L ( M )=
q 1 )= M .In
the pseudocode in Listing 11.3, neither q1 nor q2 is guaranteed to be a continuous
function of the entries of the matrix m .
{
q 1 ,
q 1 }
Listing 11.3: Code to convert a rotation matrix to the two corresponding
quaternions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void RotationToQuaternion(Mat33 m, out Quaternion q1, out Quaternion q2)
{
// convert a 3x3 rotation matrix m to the two quaternions
// q1 and q2 that project to m under the map K.
if ( m is the identity )
{
q1 = Quaternion(1,0,0,0);
q2 = -q1;
return;
}
Vector3D omega;
double theta;
RotationToAxisAngle(m, omega, theta);
q1 = Quaternion(Math.cos(theta/2), Math.sin(theta/2) * omega);
q2 = -q1;
}
We now have a method for going from S 3 to SO ( 3 ) and for going from SO ( 3 )
back to pairs of elements of S 3 . To interpolate between rotations in SO ( 3 ) ,we'll
interpolate between points of S 3 .
11.2.6.1 Spherical Linear Interpolation
Suppose we have two points q 1 and q 2 of the unit sphere, and that q 1
q 2 , that
is, they're not antipodal. Then there's a unique shortest path between them, just
as on the Earth there's a unique shortest path from the North Pole to any point
except the South Pole. (There is a shortest path from the North to the South Pole;
the problem is that it's no longer unique—any line of longitude is a shortest path.)
We'll now construct a path
=
γ
that starts at q 1
(i.e.,
γ
( 0 )= q 1 ), ends at q 2
(i.e.,
( 1 )= q 2 ), and goes at constant speed along the shorter great arc between
them. This is called spherical linear interpolation and was first described for use
in computer graphics by Shoemake [Sho85], who called it slerp. There are three
steps.
γ
 
 
Search WWH ::




Custom Search