Quaternion

ryan G 21 Reputation points
2020-12-18T16:20:14.467+00:00

Hi, what's the difference between concatenate and multiply quaternion in C#?? Thanks

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,006 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2020-12-21T09:11:50.307+00:00

    It seems that multiplication is *Q1*Q2*, concatenation is *Q2*Q1*.

    See the source of Concatenate and Multiply:


1 additional answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,591 Reputation points
    2020-12-21T09:21:13.15+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.