Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

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

5.00/5 (2 votes)
19 Apr 2018CPOL 35.4K  
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)