# toEulerAngles Conversion Issue

**URL:** <https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491>\
**Category:** Bugs\
**Created:** [February 20, 2019, 12:04pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491 "2019-02-20T12:04:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tejashwini\_Basavaraj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tejashwini_basavaraj/32/843_2.png) [@Tejashwini\_Basavaraj](https://forum.babylonjs.com/u/Tejashwini_Basavaraj)\
**Post date:** [February 20, 2019, 12:04pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/1 "2019-02-20T12:04:51Z")

</div>

Hi,

**rotationQuaternion.toEulerAngles** is not returning the proper value when we have rotated the perticular mesh in the **X-axis** by **180° (1π rad)**.

Example:  
Step 1: Create mesh  
Step 2: Rotate mesh in X-axis by 180°  
mesh.rotateAround(pt, new BABYLON.Vector3(1, 0, 0), Math.PI / 2 \* 2);  
Step 3: Convert Euler angles that can be used in mesh.rotation by doing rotation quaternion  
mesh.rotationQuaternion.toEulerAngles();

In this scenario, expected output for x coordinate is 3.14 but we are getting 4.440892098500626e-16

Can you please help us over here?

Thanks,  
Tejashwini

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 20, 2019, 5:02pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/2 "2019-02-20T17:02:31Z")

</div>

well 0 or 2PI are equivalent and technically represents the same angle

This is unfortunate but there is no simple way to decide between both values

Can you tell me why 0 is not good in your case?

---

<div class="post-metadata">

**Author:** ![Tejashwini\_Basavaraj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tejashwini_basavaraj/32/843_2.png) [@Tejashwini\_Basavaraj](https://forum.babylonjs.com/u/Tejashwini_Basavaraj)\
**Post date:** [February 21, 2019, 4:26am UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/3 "2019-02-21T04:26:52Z")

</div>

@Deltakosh, I am rotating Pi rad/ 180deg. Not 0/2Pi .

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 21, 2019, 4:50pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/4 "2019-02-21T16:50:14Z")

</div>

Oh sorry I misunderstood!

Can you repro that in the playground? I will have a look at the math then

---

<div class="post-metadata">

**Author:** ![Tejashwini\_Basavaraj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tejashwini_basavaraj/32/843_2.png) [@Tejashwini\_Basavaraj](https://forum.babylonjs.com/u/Tejashwini_Basavaraj)\
**Post date:** [February 27, 2019, 4:51pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/5 "2019-02-27T16:51:06Z")

</div>

@Deltakosh, Kindly refer this playground: [https://playground.babylonjs.com/#7QYKIG#1](https://playground.babylonjs.com/#7QYKIG#1)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [February 27, 2019, 6:05pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/6 "2019-02-27T18:05:49Z")

</div>

actually the result is correct (even though it is not the one you expected) as the complete rotation angles is  
(0, PI, PI)

That is the problem when converting from quaternion as multiple euler angles combinations can be used

I recommend keeping everything in euler since the beginning:  
[https://playground.babylonjs.com/#7QYKIG#2](https://playground.babylonjs.com/#7QYKIG#2)

---

<div class="post-metadata">

**Author:** ![Tejashwini\_Basavaraj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tejashwini_basavaraj/32/843_2.png) [@Tejashwini\_Basavaraj](https://forum.babylonjs.com/u/Tejashwini_Basavaraj)\
**Post date:** [March 7, 2019, 10:10am UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/7 "2019-03-07T10:10:53Z")

</div>

@Deltakosh, Please refer this latest code: [https://playground.babylonjs.com/#7QYKIG#4](https://playground.babylonjs.com/#7QYKIG#4)

Basically, toEulerAngles() has issue while converting 180deg rotation. It is working fine with other angles.

---

<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:** [March 7, 2019, 10:47am UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/8 "2019-03-07T10:47:59Z")

</div>

Do not quite understand the problem. The method rotateAbout is cumulative as you can see in this PG [https://www.babylonjs-playground.com/#A1210C#37](https://www.babylonjs-playground.com/#A1210C#37). This is what you are doing two rotations of 90 degs make 180 degs [https://playground.babylonjs.com/#7QYKIG#4](https://playground.babylonjs.com/#7QYKIG#4)

---

<div class="post-metadata">

**Author:** ![Tejashwini\_Basavaraj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tejashwini_basavaraj/32/843_2.png) [@Tejashwini\_Basavaraj](https://forum.babylonjs.com/u/Tejashwini_Basavaraj)\
**Post date:** [March 7, 2019, 11:31am UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/9 "2019-03-07T11:31:18Z")

</div>

@JohnK, yes you are right. But I am not facing any issue while doing rotation.

Once we do _mesh.rotateAround()_, the rotation details will be maintained by _mesh.rotationQuaternion_ property and _mesh.rotation_ will become invalid. As, when a _rotationQuaternion_ is set, the value of _rotation_ is set to (0, 0, 0).

[https://doc.babylonjs.com/features/position,\_rotation,\_scaling#rotationquaternion](https://doc.babylonjs.com/features/position,_rotation,_scaling#rotationquaternion)

Now, rotation details are in _Quaternion_, i.e _mesh.rotationQuaternion_ will have the rotation details.

But, I want the rotation details in _Euler Angles_, so I will use _quaternion.toEulerAngles()_

[https://doc.babylonjs.com/resources/rotation\_conventions#warning](https://doc.babylonjs.com/resources/rotation_conventions#warning)

The Bug I am reporting here is _quaternion.toEulerAngles()_ is not converting _Quaternion_ to _Euler Angles_ properly, when the rotated angle is +/-180deg.

---

<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:** [March 7, 2019, 12:13pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/10 "2019-03-07T12:13:06Z")

</div>

> [@Deltakosh](#):
>
> That is the problem when converting from quaternion as multiple euler angles combinations can be used

> **[Babylon.js Playground](https://playground.babylonjs.com/#7QYKIG%235)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

As you can see when you convert the rotationQuaternion to Euler Angles and then use them on the clone of the subComponent the Euler Angles give the same rotation. As DK said for any quaternion there are more than one set of Euler angles that give the same result. It is just that the algorithm used in producing the Euler angles from the quaternion do not produce the ones you expect.

---

<div class="post-metadata">

**Author:** ![Tejashwini\_Basavaraj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tejashwini_basavaraj/32/843_2.png) [@Tejashwini\_Basavaraj](https://forum.babylonjs.com/u/Tejashwini_Basavaraj)\
**Post date:** [March 7, 2019, 12:57pm UTC](https://forum.babylonjs.com/t/toeulerangles-conversion-issue/1491/11 "2019-03-07T12:57:04Z")

</div>

Ok got it. So we can’t do anything here:(  
Thank you @Deltakosh and @JohnK 🙂
