Discussion:
Quaternion Extrapolation
(too old to reply)
Ady
2003-07-02 08:39:07 UTC
Permalink
Animation in my app is based on keyframes. In a rotation key frame I
keep a quaternion value, when interpolating between rotation key
frames I do a slerp. When the last rotation keyframe is passed I would
like to give the user the option to continue the animation, to do this
I need to extrapolate a quaternion delta from the quaternions in the
last frame and the penultimate frame and add this rotation delta to
the objects current rotation ( quaternion multiply ). The way I am
extrapolating a rotation delta currently is:

D3DXQUATERNION to = pRotateToKeyFrame->GetRotation();
D3DXQUATERNION from = pRotateFromKeyFrame->GetRotation();
D3DXQUATERNION delta = ( ( to - from ) / float(
pRotateToKeyFrame->GetFrame() - pRotateFromKeyFrame->GetFrame() ) );
D3DXQuaternionNormalize( &delta, &delta );

But this is not giving the results I was expecting, not knowing too
much about quaternions I dont know if my approach is a little naive.
Any help would be great.

PS: The GetFrame call on the rotation keyframe returns the position of
that keyframe in the animation.
Just d' FAQs
2003-07-03 02:10:15 UTC
Permalink
Post by Ady
Animation in my app is based on keyframes. In a rotation key frame I
keep a quaternion value, when interpolating between rotation key
frames I do a slerp. When the last rotation keyframe is passed I would
like to give the user the option to continue the animation, to do this
I need to extrapolate a quaternion delta from the quaternions in the
last frame and the penultimate frame and add this rotation delta to
the objects current rotation ( quaternion multiply ). The way I am
D3DXQUATERNION to = pRotateToKeyFrame->GetRotation();
D3DXQUATERNION from = pRotateFromKeyFrame->GetRotation();
D3DXQUATERNION delta = ( ( to - from ) / float(
pRotateToKeyFrame->GetFrame() - pRotateFromKeyFrame->GetFrame() ) );
D3DXQuaternionNormalize( &delta, &delta );
But this is not giving the results I was expecting, not knowing too
much about quaternions I dont know if my approach is a little naive.
Any help would be great.
PS: The GetFrame call on the rotation keyframe returns the position of
that keyframe in the animation.
I'm not sure I properly understand your code, but it looks as if it
subtracts two quaternions, divides by the time interval, and then
normalizes. The problem is, Slerp should give an arc, not a line.

Remember also that we accumulate quaternions by multiplication. So you
want for the quaternion interval, not Qto-Qfrom, but Qto Qfrom^-1. And
instead of scaling that by 1/(Tto-Tfrom), you want to Slerp by it.

delta = Slerp(Qid,Qto Qfrom^-1; 1/(Tto-Tfrom))

where Qid = [(0,0,0),1].
Ady
2003-07-03 07:36:42 UTC
Permalink
I have just implemented extrapolation by performing a slerp outside of
the 0 -> 1 range and it all works fine.
Just d' FAQs
2003-07-03 21:55:19 UTC
Permalink
On Thu, 3 Jul 2003 13:35:33 +0100, Stephen Riley
I thought I'd implement this slerp as an applet, since I was fiddling
around getting to grips with quaternions anyway.
http://www.sriley.co.uk/qSlerp
As you say, and the mathematics leaving little doubt, this slerp gives
uniformly spaced points. From what I see there (with quaternions
displayed in axis/angle form) the vector part giving uniformly spaced
points around a unit circle, and the angle around the vector part also
rotating/slerping uniformly.
One good way to understand an abstraction is to make it concrete;
another is to explain it. Looks like you're well on your way with
Slerp. Examination from different points of view also can help, so
here's some relevant background.

In elementary trigonometry we learn to draw a unit circle:

x = cos(t)
y = sin(t)

The xy coordinate system is arbitrary. Given any two perpendicular
unit vectors U and V we could just as well write a unit circle as

C(t) = cos(t)*U + *sin(t)*V

One nice feature of this form is that the same formula works in any
dimension, whether 2D or 3D or 4D or whatever. The circle will be in
the plane spanned by U and V.

More suggestively, let t run from 0 to 1 in

C(t) = cos(t*pi/2)*U + sin(t*pi/2)*V

to draw a quarter-circle arc from U to V. Because cosine is an even
function, cos(x) = cos(-x), and a shifted sine, we can rewrite the
first term.

cos(t*pi/2) = cos(-t*pi/2)
= sin(pi/2 - t*pi/2)
= sin((1-t)*pi/2)

Now suppose U and V are unit vectors but at an angle of A instead of
perpendicular. Then the portion of V perpendicular to U does not have
unit magnitude, but is diminished to sin(A). Likewise for U to V. By
compensating for that we arrive at the general Slerp formula.

sin((1-t)*A)*U + sin(t*A)*V
Slerp(U,V;t) = ---------------------------
sin(A)

This derivation makes absolutely no use of quaternion properties.
Slerp is no more nor less than a flexible way to draw a circular arc!

The fact that drawing an arc is the appropriate way to interpolate
unit quaternions is a different, deeper, discussion.
Stephen Riley
2003-07-04 18:42:27 UTC
Permalink
Post by Just d' FAQs
One good way to understand an abstraction is to make it concrete;
another is to explain it. Looks like you're well on your way with
Slerp. Examination from different points of view also can help, so
here's some relevant background.
x = cos(t)
y = sin(t)
The xy coordinate system is arbitrary. Given any two perpendicular
unit vectors U and V we could just as well write a unit circle as
C(t) = cos(t)*U + *sin(t)*V
One nice feature of this form is that the same formula works in any
dimension, whether 2D or 3D or 4D or whatever. The circle will be in
the plane spanned by U and V.
More suggestively, let t run from 0 to 1 in
C(t) = cos(t*pi/2)*U + sin(t*pi/2)*V
to draw a quarter-circle arc from U to V. Because cosine is an even
function, cos(x) = cos(-x), and a shifted sine, we can rewrite the
first term.
cos(t*pi/2) = cos(-t*pi/2)
= sin(pi/2 - t*pi/2)
= sin((1-t)*pi/2)
Now suppose U and V are unit vectors but at an angle of A instead of
perpendicular. Then the portion of V perpendicular to U does not have
unit magnitude, but is diminished to sin(A). Likewise for U to V. By
compensating for that we arrive at the general Slerp formula.
sin((1-t)*A)*U + sin(t*A)*V
Slerp(U,V;t) = ---------------------------
sin(A)
This derivation makes absolutely no use of quaternion properties.
Slerp is no more nor less than a flexible way to draw a circular arc!
Excellent. Having not seen or derived the general case above before, I
didn't connect the general slerp you give above to the aforementioned
quaternion slerp. Thanks for the background info!
Post by Just d' FAQs
The fact that drawing an arc is the appropriate way to interpolate
unit quaternions is a different, deeper, discussion.
I suppose if unit quaternions represent points on a 4-dimensional unit
hypersphere, it might be hoped (I'd better not say expected!) that a
slerp on a great circle in that space would also be a minimum distance
in 2 and 3-dimensions (or rather follow a minimum energy curve/gradient
or whatever the mathematical term) in lower dimensions, especially since
the vector part only moves in 2D. Is that right? Are geodesics in higher
dimensions just 2 dimensional? In any case, I've no doubt coming to the
correct conclusion rigorously would be a much deeper issue!

Is there a way of visualising a 4-dimensional sphere btw?
--
Stephen Riley
Just d' FAQs
2003-07-05 00:58:57 UTC
Permalink
On Fri, 4 Jul 2003 19:42:27 +0100, Stephen Riley
Post by Stephen Riley
I suppose if unit quaternions represent points on a 4-dimensional unit
hypersphere, it might be hoped (I'd better not say expected!) that a
slerp on a great circle in that space would also be a minimum distance
in 2 and 3-dimensions (or rather follow a minimum energy curve/gradient
or whatever the mathematical term) in lower dimensions, especially since
the vector part only moves in 2D. Is that right? Are geodesics in higher
dimensions just 2 dimensional? In any case, I've no doubt coming to the
correct conclusion rigorously would be a much deeper issue!
On a sphere in of any positive dimension a Slerp gives a uniform speed
great circle arc, which is both planar and a geodesic. Different ways
to characterize the quaternion Slerps are: straightest path, shortest
path, and constant angular velocity. In Lie group terms, that last one
is called "one-parameter-subgroup", multiplying the same infinitesimal
rotation times itself over and over. An ordinary sphere in 3D is not a
group, so we can't use this last idea, but the first two still work.
Now try drawing on a cylinder, which is a rolled up plane; most of the
geodesics look like coiled springs.
Post by Stephen Riley
Is there a way of visualising a 4-dimensional sphere btw?
Yes, but not without distortion. Stereographic projection is a purely
geometric way. Plant a lighthouse at the "south pole", (0,0,-1), and
place a sheet of paper opposite; now trace rays to establish a map
between points on the sphere and points on the paper. This procedure
for the ordinary sphere puts the north pole at the center and circles
of longitude become radiating lines. It works in 2D and 4D as well.

While that has the advantage of mapping circles to circles (counting
those radial lines as really big circles!), it puts the south pole at
infinity. A more compact depiction uses geodesics. Start at the north
pole and walk straight measuring distance. Transfer the measurements
to a flat piece of paper. The ordinary sphere becomes a disk, with all
points on the rim of the disk corresponding to the south pole. When we
apply the same idea in 2D we get a line segment from -pi to pi; in 4D,
we get a solid 3D ball of radius pi.

Since it's boring and unhelpful to draw a picture of a ball, we often
see pictures of the sphere in 4D dissected into circular fibers, the
beautiful Hopf fibration of S3 over S2.

<http://www.theory.org/geotopo/3-sphere/html/>
<http://hopf.math.purdue.edu/new-html/hopflogo.html>
<http://www.math.uni-bonn.de/people/weber/research/tori/>

Continue reading on narkive:
Search results for 'Quaternion Extrapolation' (Questions and Answers)
6
replies
What is the 4th dimension of math?
started 2006-11-30 17:48:41 UTC
mathematics
Loading...