- Home /

# Python Code for Converting Quaternion to Euler Angles

I am having trouble converting the Quaternion to Euler Angle in python. The results often disagree with Unity. I tried using the PSpincalc library (https://pypi.python.org/pypi/PSpincalc).

I then use the code:

```
import PSpincalc as sp
quaternion = np.array([0, 0.7, 0, 0.7])
ea = sp.Q2EA(quaternion, EulerOrder="zyx", ignoreAllChk=True)[0]
```

The above result should be (0, 90, 0) according to Unity but I get (0, -90, 0). It is not just a matter of negating the second component, results are often off by 180 degree or other angles, that I have been unable to fix. Thanks.

**Answer** by brian-kf
·
Mar 16, 2018 at 03:35 PM

Probably because Unity uses a left-handed coordinate system instead of a right one; you have to convert the quaternion from one system to the other.

Right, also (0, 0.7, 0, 0.7) is not a unit quaternion. Unity only shows one decimal place when printing vectors or quaternions. An actual unit quaternion would be more like (0, 0.70710678, 0, 0.70710678). Also Unity uses the eulerangles order of ZXY around the world axis (or YXZ around local axis). Without knowing the exact axes layout it's difficult to convert between two systems. Not every system has Y as up vector.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Find Opposite Quaternion 2 Answers

Rotate with raw gyro data. 0 Answers