3

I'm using the following code to produce a quaternion from XYZ Euler-Angles in radians:

c1 = Math.cos( x / 2 )
c2 = Math.cos( y / 2 )
c3 = Math.cos( z / 2 )

s1 = Math.sin( x / 2 )
s2 = Math.sin( y / 2 )
s3 = Math.sin( z / 2 )

quaternion = [
              c1 * c2 * c3 - s1 * s2 * s3,
              s1 * c2 * c3 + c1 * s2 * s3,
              c1 * s2 * c3 - s1 * c2 * s3,
              c1 * c2 * s3 + s1 * s2 * c3,
             ]

from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm

This produces a quaternion that first rotates around the z, then y, then finally the x-axis - Z-Y-X. Is it possible to alter this formula so that it rotates around the axes in a different order? What I'm looking for is the opposite, so X-Y-Z.

2
  • 1
    You can create 3 quaternions for rotations around single axis, and compose them by multiplication any way you need. Commented Apr 25, 2018 at 6:42
  • Yeah that's definitely the most versatile way and is how i'm working atm. Just looking for a more preferment method. Commented Apr 25, 2018 at 11:39

1 Answer 1

4

If anyone's interested...

Yes you can, turns out on this occasion I just needed to swap the plus and minus signs around to get an X-Y-Z order (traditionally written ZYX). Like so...

       [
        c1 * c2 * c3 + s1 * s2 * s3,
        s1 * c2 * c3 - c1 * s2 * s3,
        c1 * s2 * c3 + s1 * c2 * s3,
        c1 * c2 * s3 - s1 * s2 * c3
        ]

Three.js has a full list of the different formulas for various xyz orders - in the function THREE.Quaternion.setFromEuler

https://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/steps/index.htm

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.