views:

41

answers:

3

(perhaps this is better for a math Stack Exchange?)

I have a chain composed of bones. Each bone has a with a tip and tail. The following code computes where its tip will be, given a rotation, and sets the next link in the chain's position appropriately:

    // Quaternion is a hand-rolled class that works correctly (as far as I can tell.)
    Quaternion quat = new Quaternion(getRotationAngleDegrees(), getRotation());

    // figure out where the tip will be after applying the rotation
    Vector3f rotatedTip = quat.applyRotationTo(tip);

    // set the next bone's tail to be at this one's tip
    updateNextPosFrom(rotatedTip);

This works if the rotation is supposed to occur around the origin of the object's coordinate system. But what if I want the rotation to occur around some other arbitrary point in the object? I'm not sure how to translate the quaternion. What is the best way to do it?

(I'm using JOGL / OpenGL.)

+3  A: 

A quaternion is used specifically to handle a rotation factor, but does not include a translation at all.

Typically, in this situation, you'll want to apply a rotation to a point based on the "bone's" length, but centered at the origin. You can then translate post-rotation to the proper location in space.

Reed Copsey
A: 

The Wikipedia page on forward kinematics points to this paper: Introduction to Homogeneous Transformations & Robot Kinematics.

jholl
+1  A: 

Quaternions are generally used to represent rotations only; they cannot represent translations as well.

You need to convert your quaternion into a rotation matrix, insert it into the appropriate part of your standard OpenGL 4x4 matrix, and combine it with a translation in order to rotate about an arbitrary point.

4x4 rotation matrix:
  [ r r r 0 ]
  [ r r r 0 ]  <- the r's are the 3x3 rotation matrix from the wiki article
  [ r r r 0 ]
  [ 0 0 0 1 ]
comingstorm