Re: spherical linear interpolation

New Message Reply Date view Thread view Subject view Author view

Don Hatch (hatch++at++hell.asd.sgi.com)
Tue, 11 Mar 1997 17:04:47 -0800


On Mar 11, 8:57am, David Plew <kishore++at++aimnet.com> wrote:
> Subject: spherical linear interpolation
>
> Hi :
>
> Pardon me for my ignorance, but I need to know how does pfSlerpQuat
> perform spherical linear interpolation. Where can I find info on this kind
> of interpolation? For some reasons I am cornered with the problem of
> generating arbitrary axis for rotation of an objenct, manually. And I
> think that knowing how to do this spherical interpolation, will enable
> me to generate the axis. As a simple example, here is what I would like
> to to:
>
> model a cube at the origin with default position and orientation.
> Rotate it about X
> Rotate it about Y
> Rotate it about Z - all rotations are by 90 deg.
>
> Each of the above actions are represented as key frames consisting of
> list of keyframe positions and orientations. The animation is computed
> using pfSlerpQuat for orientation and Catmull-Rom method for position
> interpolation. I do not have any tool to generate these key frames, hence
> have to do it by hand. Interpolation of both position and orientation
> takes place from one key frame to next. The rotations in the key frames
> are expressed as quaternions. My task is to be able to generate these
> quats by hand. How can I compute the axis for each of the key frames so that
> pfSlerpQuat interpolates properly between two frames?
>
> Specifying the orientation as the list:
>
> [ 1 0 0 90,
> 0 1 0 90,
> 0 0 1 90 ]
>
> doesn't work (First three floats are axis, last one is angle in deg.).
>
> any ideas?
>
> thanks
> -anita
>
> kishore++at++aimnet.com

If I am understanding correctly, you want to compose (i.e. multiply)
the above quaternions together to accumulate the keyframes.
The following code seems to give a believable answer--
note that the final orientation (i.e. the composite
of the three 90-degree rotations) is equivalent to a single
90-degree rotation about the Y axis.
I assume you mean the rotations to be expressed in terms of the world
space axes (as opposed to the object space axes)--
if not, just multiply by the incremental rotation quaternion
on the left instead of the right.

(My impression is that you are willing to use the Performer math libs as
a calculator, but if you *really* want to do the quaternion multiplication
by hand, see the references at the end of the pfQuat man page.)

#include <Performer/pr/pfLinMath.h>

main(int argc, char **argv)
{
    pfQuat qident, qx, qy, qz;
    qident.makeRot(0, 1,0,0);
    qx.makeRot(90, 1,0,0);
    qy.makeRot(90, 0,1,0);
    qz.makeRot(90, 0,0,1);

    pfQuat keyframes[4];
    keyframes[0] = qident;
    keyframes[1] = keyframes[0] * qx;
    keyframes[2] = keyframes[1] * qy;
    keyframes[3] = keyframes[2] * qz;

    pfQuat q;
    for (k = 0; k < 3; ++k)
    {
        int i, n = 4; // number of steps from one keyframe to the next
        for (i = 0; i <= n; ++i)
        {
            float t = (float)i/(float)n;
            q.slerp(t, keyframes[k], keyframes[k+1]);
            float angle, x, y, z;
            q.getRot(&angle, &x, &y, &z);
            printf("%f %f %f %f\n", angle, x, y, z);
        }
        printf("\n");
    }
}

The output is:

0.000000 0.000000 0.000000 1.000000
22.500017 1.000000 0.000000 0.000000
44.999989 1.000000 0.000000 0.000000
67.500008 1.000000 0.000000 0.000000
89.999992 1.000000 0.000000 0.000000

89.999992 1.000000 0.000000 0.000000
92.181213 0.962637 0.191480 -0.191480
98.421036 0.862856 0.357407 -0.357407
107.978378 0.726831 0.485653 -0.485653
120.000000 0.577350 0.577350 -0.577350

120.000000 0.577350 0.577350 -0.577350
107.978378 0.485653 0.726831 -0.485653
98.421051 0.357407 0.862856 -0.357407
92.181213 0.191480 0.962637 -0.191480
89.999992 0.000000 1.000000 0.000000

Don

-- 
Don Hatch  hatch++at++sgi.com  (415) 933-5150  Silicon Graphics, Inc.
=======================================================================
List Archives, FAQ, FTP:  http://www.sgi.com/Technology/Performer/
            Submissions:  info-performer++at++sgi.com
        Admin. requests:  info-performer-request++at++sgi.com

New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:54:53 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.