Search code examples
pythonmatrixquaternions

in python how do I decompose a rotation matrix to a quaternion? (preferrably using the euclid library)


I have started experimenting with the euclid module for python . I am now to the point where I want to take an arbitrary rotation matrix and decompose it into its quaternion form.

The formulas are available in a couple of places on the web (like http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ ), but I was hoping there was an implementation somewhere inside the euclid library.


Solution

  • I eventually discovered the following technique:

    q2 = euclid.Quaternion.new_rotate_matrix(m)
    

    that decomposes a rotation matrix into a quaternion. You might still have to worry about the fact that q and -q both represent the same orientation, especially if you are keyframing rotations in a 3D animation.