A simple way to rotate a Vector3 with a Quaternion?

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

const rotatedVec = quat.rotate(vec);

ok, I missed that this works:

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


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

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


BABYLON.Quaternion.prototype.rotate = function(vec) {

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.


1 Like

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 :slight_smile: and in this case it doesn’t really feel necessary. But a very good point and handy trick indeed.

1 Like