# Quaternion to euler returns wrongs angles

**URL:** <https://forum.babylonjs.com/t/quaternion-to-euler-returns-wrongs-angles/20768>\
**Category:** Questions\
**Created:** [May 12, 2021, 3:21pm UTC](https://forum.babylonjs.com/t/quaternion-to-euler-returns-wrongs-angles/20768 "2021-05-12T15:21:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qualcuno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qualcuno/32/16153_2.png) [@Qualcuno](https://forum.babylonjs.com/u/Qualcuno)\
**Post date:** [May 12, 2021, 3:21pm UTC](https://forum.babylonjs.com/t/quaternion-to-euler-returns-wrongs-angles/20768/1 "2021-05-12T15:21:29Z")

</div>

Hi all, i hope this is the right place to ask for my problem.  
I want to convert a quaternion into euler angles but values looks wrong.  
This is the piece of code

```
// values are in x, y, z, w order
var rot = new BABYLON.Quaternion(-0.1245631, 0.7443593, -0.6470615, -0.108281);
var euler = rot.toEulerAngles();

```

if i print euler, the content is  
X: 1.4311703869613368 Y: 3.141592409759389 Z: -0.33161295970567284  
and if i converted in degrees with BABYLON.Angle(angle\_rad).degrees(), they are around  
X: 82 Y: 179 Z:340

but the values are wrong. The values i expect are X: 98 Y: 0 Z: 161  
I tested the quaternion value also in Unity3D and online tools and all returns 98, 0, 161.

But another stranger thing is if i set the values (-0.1245631, 0.7443593, -0.6470615, -0.108281)  
to a quaternion of an object in Unity3D, the object rotate correctly,  
while if i set the values in a quaternion of Babylon, the rotation object is different.  
Maybe the euler problem is just an effect and the real problem is the quaternion itself.

What’s wrong? I spent a whole day figuring out what’s wrong.  
Thanks at all

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 14, 2021, 9:17am UTC](https://forum.babylonjs.com/t/quaternion-to-euler-returns-wrongs-angles/20768/2 "2021-05-14T09:17:55Z")

</div>

Welcome aboard!

If I use [MathLab](https://www.mathworks.com/help/nav/ref/quat2eul.html#:~:text=eul%20%3D%20quat2eul(%20quat%20)%20converts,the%20axis%20rotation%20sequence%2C%20sequence%20.) to do the conversion, it yields the same results than in Babylon, save for Y/Z inversion and the values being negated (I think we don’t use the same coordinate system):  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/a/3/a385c4723bcc3062860225d07e51eb53af227d80.png)

Values are not exactly the same, maybe it’s a precision problem in the computation, but the values are still close to `X: 1.4311703869613368 Z: -0.33161295970567284 Y: 3.141592409759389`.

> [@Qualcuno](#):
>
> but the values are wrong. The values i expect are X: 98 Y: 0 Z: 161  
> I tested the quaternion value also in Unity3D and online tools and all returns 98, 0, 161.

I guess it depends on the coordinate system: the values returned by Babylon are offseted by 180° from the values you expect.

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [May 14, 2021, 1:21pm UTC](https://forum.babylonjs.com/t/quaternion-to-euler-returns-wrongs-angles/20768/3 "2021-05-14T13:21:44Z")

</div>

Hi @Qualcuno and welcome from me.

This docs page [Rotation Quaternions | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_quaternions) has a playground [Babylon.js Playground](https://playground.babylonjs.com/#DN4IPH) showing that the conversion matches in Babylon.js.

---

<div class="post-metadata">

**Author:** ![Qualcuno](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qualcuno/32/16153_2.png) [@Qualcuno](https://forum.babylonjs.com/u/Qualcuno)\
**Post date:** [May 14, 2021, 3:13pm UTC](https://forum.babylonjs.com/t/quaternion-to-euler-returns-wrongs-angles/20768/4 "2021-05-14T15:13:51Z")

</div>

I will take a look at the start of next week.  
Thanks at all for the support and have a good weekend 😉
