Sign in to follow this  
rickfrank@me.com

Quaternions and multiple rotations

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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this