# Source code incorrect comment on rotation order, or my misunderstanding?

**URL:** <https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204>\
**Category:** Questions\
**Tags:** documentation\
**Created:** [August 22, 2025, 9:13pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204 "2025-08-22T21:13:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lima](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lima/32/47720_2.png) [@lima](https://forum.babylonjs.com/u/lima)\
**Post date:** [August 22, 2025, 9:13pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/1 "2025-08-22T21:13:50Z")

</div>

```typescript
packages/dev/core/src/Maths/math.vector.ts

    public static RotationYawPitchRollToRef<T extends Quaternion>(yaw: number, pitch: number, roll: number, result: T): T {
        // Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)
        const halfRoll = roll * 0.5;
        const halfPitch = pitch * 0.5;
        const halfYaw = yaw * 0.5;

        const sinRoll = Math.sin(halfRoll);
        const cosRoll = Math.cos(halfRoll);
        const sinPitch = Math.sin(halfPitch);
        const cosPitch = Math.cos(halfPitch);
        const sinYaw = Math.sin(halfYaw);
        const cosYaw = Math.cos(halfYaw);

        result._x = cosYaw * sinPitch * cosRoll + sinYaw * cosPitch * sinRoll;
        result._y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
        result._z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;
        result._w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;
        result._isDirty = true;
        return result;
    }

```

Hi, in the source code I see this comment that claims z-y-x orientation but I think the math here indicates YXZ (which is what the docs say as well). Is the comment wrong or am I missing something?

`q = (x,y,z,w) = ( cy*sx*cz + sy*cx*sz, sy*cx*cz - cy*sx*sz, cy*cx*sz - sy*sx*cz, cy*cx*cz + sy*sx*sz )` where `sy=sin(yaw/2)`, `cy=cos(yaw/2)`, `sx=sin(pitch/2)`, `cx=cos(pitch/2)`, `sz=sin(roll/2)`, `cz=cos(roll/2)`. extrinsic YXZ, intrinsic ZXY, not zyx

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 22, 2025, 11:32pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/2 "2025-08-22T23:32:39Z")

</div>

I think you are correct, lets double check either @Deltakosh ?

---

<div class="post-metadata">

**Author:** ![alexchuber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alexchuber/32/52000_2.png) [@alexchuber](https://forum.babylonjs.com/u/alexchuber)\
**Post date:** [August 23, 2025, 2:29am UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/3 "2025-08-23T02:29:12Z")

</div>

> [@lima](#):
>
> extrinsic YXZ, intrinsic ZXY,

Yes, I also think you’re right….

> **[Babylon.js Playground](https://playground.babylonjs.com/#S9R9K0%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL and WebGPU 3D scenes

If this is the case, though, then I wonder if our docs have got some things swapped as well?

If the intrinsic sequence of rotations is `z - x' - y''` for the following two code snippets,

```auto
mesh.rotate(BABYLON.Axis.Y, yaw, BABYLON.Space.LOCAL);
mesh.rotate(BABYLON.Axis.X, pitch, BABYLON.Space.LOCAL);
mesh.rotate(BABYLON.Axis.Z, roll, BABYLON.Space.LOCAL);

```

```auto
const yprQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(yaw, pitch, roll);

```

whereby roll is actually applied first, followed by pitch, and finally yaw,

then we should switch `YXZ Local Space` =\> `ZXY Local Space` and `ZXY World Axes` =\> `YXZ World Axes`, etc. throughout the docs. Right?

Someone please correct me if I made a wrong step somewhere 😃

---

<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:** [August 25, 2025, 3:04pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/4 "2025-08-25T15:04:28Z")

</div>

This is totally correct. We historically work with YXZ 😃

---

<div class="post-metadata">

**Author:** ![lima](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/lima/32/47720_2.png) [@lima](https://forum.babylonjs.com/u/lima)\
**Post date:** [August 25, 2025, 10:22pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/5 "2025-08-25T22:22:17Z")

</div>

I agree with YXZ, but the source code comment claims z-y-x

---

<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:** [August 26, 2025, 3:17pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/6 "2025-08-26T15:17:55Z")

</div>

i’ll fix that comment 😉

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 26, 2025, 4:24pm UTC](https://forum.babylonjs.com/t/source-code-incorrect-comment-on-rotation-order-or-my-misunderstanding/60204/7 "2025-08-26T16:24:23Z")

</div>

done and merged 🙂
