# How to get euler angles from a rotation matrix?

**URL:** <https://forum.babylonjs.com/t/how-to-get-euler-angles-from-a-rotation-matrix/16919>\
**Category:** Questions\
**Created:** [December 25, 2020, 1:59am UTC](https://forum.babylonjs.com/t/how-to-get-euler-angles-from-a-rotation-matrix/16919 "2020-12-25T01:59:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blindinghues](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blindinghues/32/15289_2.png) [@blindinghues](https://forum.babylonjs.com/u/blindinghues)\
**Post date:** [December 25, 2020, 1:59am UTC](https://forum.babylonjs.com/t/how-to-get-euler-angles-from-a-rotation-matrix/16919/1 "2020-12-25T01:59:52Z")

</div>

Hi there!

My use case is a little difficult to explain, but is there an opposite of BABYLON.Matrix.RotationYawPitchRoll such that given a matrix, I can derive its yaw pitch and roll?

I tried to follow an [answer from SO](https://stackoverflow.com/questions/15022630/how-to-calculate-the-angle-from-rotation-matrix) but with no success.

```
            const newRotation = BABYLON.Matrix.RotationYawPitchRoll(mesh.rotation.y, mesh.rotation.x, mesh.rotation.z);
            const rotationEuler = new BABYLON.Vector3(
                Math.atan2(newRotation.getRow(2).y, newRotation.getRow(2).z),
                Math.atan2(-newRotation.getRow(2).x, Math.sqrt(Math.pow(newRotation.getRow(2).y, 2) + Math.pow(newRotation.getRow(2).z, 2))),
                Math.atan2(newRotation.getRow(1).x, newRotation.getRow(0).x)
            );

```

Unfortunately, rotationEuler is never equal to mesh.rotation…

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [December 25, 2020, 4:37am UTC](https://forum.babylonjs.com/t/how-to-get-euler-angles-from-a-rotation-matrix/16919/2 "2020-12-25T04:37:14Z")

</div>

Hi @blindinghues, maybe this could help?

```auto
const scale = new BABYLON.Vector3();
const rotation = new BABYLON.Quaternion();
const position = new BABYLON.Vector3();

// variable matrix is matrix you're trying to derive yaw, pitch, and roll from
matrix.decompose(scale, rotation, position);

// matrix's rotation should now be stored in the variable rotation

// convert quaternion to Euler angles
rotation.toEulerAngles();

```

---

<div class="post-metadata">

**Author:** ![blindinghues](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blindinghues/32/15289_2.png) [@blindinghues](https://forum.babylonjs.com/u/blindinghues)\
**Post date:** [December 25, 2020, 7:10am UTC](https://forum.babylonjs.com/t/how-to-get-euler-angles-from-a-rotation-matrix/16919/3 "2020-12-25T07:10:46Z")

</div>

This totally worked, saved me further hours of struggling, much appreciated!
