Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#
Tip/Trick

How to Convert Right-Handed to Left-Handed Coordinates and Quaternions In Unity

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
19 Apr 2018CPOL 33.5K   1   3
Formulas to Convert Right-Handed Vectors and Quaternions to Left-Handed Equivalents

Converting Coordinates and Vectors

To convert a right-handed vector (assuming that z is up) to left-handed vector (Unity coordinate system), simply swap y and z coordinates.

The following is a method that performs this conversion:

C#
private Vector3 ConvertRightHandedToLeftHandedVector (Vector3 rightHandedVector)
{      
    return new Vector3(rightHandedVector.x, rightHandedVector.z, rightHandedVector.y);
}

Converting Quaternions

To convert a right-handed quaternion to left-handed quaternion:

  1. Negate x
  2. Swap y and z and negate both

The following is a method that performs this conversion:

C#
private Quaternion ConvertRightHandedToLeftHandedQuaternion (Quaternion rightHandedQuaternion)
{
    return new Quaternion (- rightHandedQuaternion.x,
                           - rightHandedQuaternion.z,
                           - rightHandedQuaternion.y,
                             rightHandedQuaternion.w);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Canada Canada
I develop virtual reality applications.

Comments and Discussions

 
QuestionDon't think so Pin
Member 1349605529-May-20 1:22
Member 1349605529-May-20 1:22 
QuestionAnd what about Left-Handed coordinates to Right handed oposites Pin
ronconsoda28-Sep-19 9:21
ronconsoda28-Sep-19 9:21 
QuestionLeft-handed (Unity) to Right-handed (Universal Robots) Pin
nielsson933-Jun-18 8:02
nielsson933-Jun-18 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.