It seems that multiplication is *Q1*Q2*, concatenation is *Q2*Q1*.
See the source of Concatenate and Multiply:
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, what's the difference between concatenate and multiply quaternion in C#?? Thanks
It seems that multiplication is *Q1*Q2*, concatenation is *Q2*Q1*.
See the source of Concatenate and Multiply:
The answer is that the rotation order of the new quaternion obtained by the two methods is reversed.
The multiplication of quaternions means to form two rotations: perform one rotation and then perform another rotation, which means that the multiplication of quaternions cannot be commutative.
When we want to get q1*q2, we will use Quaternion.Multiply(q1,q2);
When we want to get q2*q1, we can use Quaternion.Multiply(q2,q1) or Quaternion.Concatenate(q1,q2);
You can see this in the source code of these two methods:
Multiply method:
public static Quaternion Multiply(Quaternion value1, Quaternion value2)
{
Quaternion ans;
float q1x = value1.X;
float q1y = value1.Y;
float q1z = value1.Z;
float q1w = value1.W;
float q2x = value2.X;
float q2y = value2.Y;
float q2z = value2.Z;
float q2w = value2.W;
// cross(av, bv)
float cx = q1y * q2z - q1z * q2y;
float cy = q1z * q2x - q1x * q2z;
float cz = q1x * q2y - q1y * q2x;
float dot = q1x * q2x + q1y * q2y + q1z * q2z;
ans.X = q1x * q2w + q2x * q1w + cx;
ans.Y = q1y * q2w + q2y * q1w + cy;
ans.Z = q1z * q2w + q2z * q1w + cz;
ans.W = q1w * q2w - dot;
return ans;
}
Concatenate method:
public static Quaternion Concatenate(Quaternion value1, Quaternion value2)
{
Quaternion ans;
// Concatenate rotation is actually q2 * q1 instead of q1 * q2.
// So that's why value2 goes q1 and value1 goes q2.
float q1x = value2.X;
float q1y = value2.Y;
float q1z = value2.Z;
float q1w = value2.W;
float q2x = value1.X;
float q2y = value1.Y;
float q2z = value1.Z;
float q2w = value1.W;
// cross(av, bv)
float cx = q1y * q2z - q1z * q2y;
float cy = q1z * q2x - q1x * q2z;
float cz = q1x * q2y - q1y * q2x;
float dot = q1x * q2x + q1y * q2y + q1z * q2z;
ans.X = q1x * q2w + q2x * q1w + cx;
ans.Y = q1y * q2w + q2y * q1w + cy;
ans.Z = q1z * q2w + q2z * q1w + cz;
ans.W = q1w * q2w - dot;
return ans;
}
You can see the source code here: referencesource.microsoft.com
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.