I have an existing quaternion (Java Quat4f). I would like to rotate this quaternion around an axis (i.e. 90 degrees around the x axis, 25 degrees around the y axis, 10 degrees around the z axis, 180 degrees around the y axis, etc.)

How can I rotate the existing quaternion around an axis?

Thank you!


To combine rotations, I believe you canjust multiply that quaternion with a quaternion for each of the other axis rotations you require.

For example, in this simple (extension) method I wrote, I get the final quaternion by combining 3 quaternions for X, Y and Z rotations.

    //Takes in angles in degrees
    //Useful wiki page: http://www.ogre3d.org/tikiwiki/Euler+Angle+Class and http://www.ogre3d.org/tikiwiki/Euler+Angle+Class+Mogre
    public static Quaternion ToOrientation(this Vector3 vec)
        Quaternion xRot = new Quaternion(Math.DegreesToRadians(vec.x), Vector3.UNIT_X);
        Quaternion yRot = new Quaternion(Math.DegreesToRadians(vec.y), Vector3.UNIT_Y);
        Quaternion zRot = new Quaternion(Math.DegreesToRadians(vec.z), Vector3.UNIT_Z);
        return xRot * yRot * zRot;

I must admit my knowledge of quaternions is not amazing, so any expansions on this answer would be appreciated.

Good luck! :)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.