Rotating around an arbitrary point

I’ve just started learning both Java3D, and 3d graphics in general. Consider an object displaced by a fair amount from the origin. Is there a good way to rotate it about its cetner of mass, or an arbitrary point, rather than the origin? Preferably without having to overwrite any methods in the standard Java3D classes.

Now, I realise it’s possible to do this using Transform3D objects, by rotating first, then translating back to the position. But I’d like to make these two operations independent of each other. Does anyone have any ideas?

Rotating an object about a point is done in the way you describe. There are rotational interpolators in Java3D to help with the animation of the rotation.

Rotating an object about it’s center of mass can be accomplished independent of the object translation by using Quaternions. This support is documented rather lightly but you set an quaternion on the Transform3D of the TransformGroup.

A quaternion is a normalized 4 element vector-like object that represents the rotational axis vector (3 of the elements) and the amount of rotation about the axis (the forth element). There are well documented conversion routines to convert Euler angles (such as yaw, pitch and roll) into a quaternion (for example, have a look at http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/).

Animating the rotation requires the use of an angular velocity that you must keep around in addition to the quaternion. The quaternion can be incrementally updated similar to:

position = prior position + rate * deltaTime

(Euler’s method of numeric integration).

Mike

Oh, so that’s what quaternions are for! Thanks mnjacobs. Just looking at the documentation, I got the impression they were just a complicated way to rotate something about the origin. :slight_smile: