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.

Kromster
  • 7,181
  • 7
  • 63
  • 111
treeseal7
  • 739
  • 8
  • 22
  • 1
    You can create 3 quaternions for rotations around single axis, and compose them by multiplication any way you need. – minorlogic Apr 25 '18 at 06:42
  • Yeah that's definitely the most versatile way and is how i'm working atm. Just looking for a more preferment method. – treeseal7 Apr 25 '18 at 11:39

1 Answers1

3

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

treeseal7
  • 739
  • 8
  • 22