# A simple way to rotate a Vector3 with a Quaternion?

**URL:** <https://forum.babylonjs.com/t/a-simple-way-to-rotate-a-vector3-with-a-quaternion/50288>\
**Category:** Questions\
**Created:** [May 4, 2024, 8:24pm UTC](https://forum.babylonjs.com/t/a-simple-way-to-rotate-a-vector3-with-a-quaternion/50288 "2024-05-04T20:24:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fresidue](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@fresidue](https://forum.babylonjs.com/u/fresidue)\
**Post date:** [May 4, 2024, 8:24pm UTC](https://forum.babylonjs.com/t/a-simple-way-to-rotate-a-vector3-with-a-quaternion/50288/1 "2024-05-04T20:24:25Z")

</div>

Explicitly converting to an Euler Matrix to then perform a rotation defined by a Quaternion seems kind of clunky. Am I missing something?

It would be nice, given a Quaternion `quat` and Vector3 `vec` to just be able to say

```auto
const rotatedVec = quat.rotate(vec);

```

---

<div class="post-metadata">

**Author:** ![fresidue](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@fresidue](https://forum.babylonjs.com/u/fresidue)\
**Post date:** [May 4, 2024, 9:03pm UTC](https://forum.babylonjs.com/t/a-simple-way-to-rotate-a-vector3-with-a-quaternion/50288/2 "2024-05-04T21:03:04Z")

</div>

ok, I missed that this works:

```auto
const rotatedVec = vec.applyRotationQuaternion(quat);

```

Conceptually and syntactically, the `rotate` function would be nice to have on the Quaternion, though I suppose that might lead to circular imports

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [May 5, 2024, 1:04pm UTC](https://forum.babylonjs.com/t/a-simple-way-to-rotate-a-vector3-with-a-quaternion/50288/3 "2024-05-05T13:04:22Z")

</div>

> [@fresidue](#):
>
> the `rotate` function would be nice to have on the Quaternion

I you want to still have it on your side, you can still do :

```javascript
BABYLON.Quaternion.prototype.rotate = function(vec) {
    const rotatedVec = vec.applyRotationQuaternion(this);
    return rotatedVec;
};

```

or

```javascript
BABYLON.Quaternion.prototype.rotate = function(vec) {
    vec.applyRotationQuaternionInPlace(this);
};

```

The first one is like on your example : `const rotatedVec = quat.rotate(vec);`  
The second one would be for a direct usage : `quat.rotate(vec);` and vec end up rotated.

++  
Tricotou

---

<div class="post-metadata">

**Author:** ![fresidue](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@fresidue](https://forum.babylonjs.com/u/fresidue)\
**Post date:** [May 9, 2024, 9:04pm UTC](https://forum.babylonjs.com/t/a-simple-way-to-rotate-a-vector3-with-a-quaternion/50288/5 "2024-05-09T21:04:57Z")

</div>

Thanks for the response Tricotou,

I generally try not to mess around with the `prototype` prop of anything out of my control unless desperation mandates it 🙂 and in this case it doesn’t really feel necessary. But a very good point and handy trick indeed.
