# Quaternions and multiple rotations

This topic is 609 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi

If I want to combine quaternions in one transform, what's the proper way?

In the code below, I have a  point at a location, and I want to concatenate another rotation given an axis angle.

The if (1) etc. shows some possible ways.

I'm not getting the result I want, and perhaps I'm doing this incorrectly.

Thanks for any help!

Rick

void TransformPoint(Quaternion<double> & currentPose, double angleInDegreesForSegment,double axis, double P1[3]) { Quaternion<double> transformQ;  transformQ.SetRotationAngleAndAxis(RadiansFromDegrees(angleInDegreesForSegment), axis);  Quaternion<double> transformConjugate = transformQ.Conjugated(); Quaternion<double> P1q(0, P1[0], P1[1], P1[2]);
if (1)
â€‹{
// Is it just this?
Quaternion<double> P1R =  currentPose * transformQ * P1q * transformConjugate;     P1[0] = P1R.getX();     P1[1] = P1R.getY();     P1[2] = P1R.getZ();
}
â€‹else
{
// Or ?
Quaternion<double> currentConjugate = currentPose.Conjugated();

Quaternion<double> P1R =  currentPose * transformQ * P1q * transformConjugate * currentConjugate;
P1[0] = P1R.getX();
P1[1] = P1R.getY();
P1[2] = P1R.getZ();

}
â€‹ }

##### Share on other sites
Write your axis+angle rotation as another quaternion. Composition of rotations corresponds to quaternion multiplication. That's all there is to it. You have to be careful to multiply the quaternions in the right order, because quaternion multiplication is not commutative.

##### Share on other sites

I hope the following example helps.

Define ref_joint_rotation as a constant reference joint rotation. ref_joint_rotation transforms vectors defined in joint frame to vectors in parent joint frame at pose configuration. Now you want to define the current reference joint rotation cur_joint_rotation as the reference joint rotation plus a rotation about 90 degrees about the z axis relative to the parent frame. That's how you would do this:

Vector3 axis
axis.Set(0.0f, 0.0f, 1.0f);
float angle = 0.5f * PI;

Quaternion joint_rotation;
joint_rotation.SetAxisAngle(axis, angle);

cur_joint_rotation = joint_rotation * ref_joint_rotation;


cur_joint_rotation rotates vectors in child frame to vectors in parent frame at the current configuration. Here the quaternion multiplication is defined in the original form. That is, a rotation by ref_joint_rotation followed by a rotation by joint_rotation.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013549
×