0

So, imagine my situation. I need to handle rotation conversions in Python with no prior knowledge of the subject. I stumbled upon the scipy.spatial.transform.Rotation class and thought "Neat! That is all taken care of for me!". But as I did a few tests with the conversions I noticed something odd. When I take a random quaternion and convert it to a rotation matrix and back, the new quaternion is completely different from the original one, like beyond any plausible rounding errors.

Can anybody explain this difference?

Code:

from scipy.spatial.transform import Rotation as R

quat = [0.40, 0.27, 0.29, 0.14]

print("\nOriginal Quaternion")
print(quat)

matrix_from_quat = R.from_quat(quat).as_matrix()

print("\nMatrix from Quaternion")
print(matrix_from_quat)

quat_from_matrix = R.from_matrix(matrix_from_quat).as_quat()

print("\nQuaternion from Matrix")
print(quat_from_matrix)

Output:

Original Quaternion
[0.4, 0.27, 0.29, 0.14]

Matrix from Quaternion
[[ 0.06714201  0.40047534  0.91384433]
 [ 0.88294712 -0.45038622  0.13250149]
 [ 0.46464646  0.7979798  -0.38383838]]

Quaternion from Matrix
[0.68945025 0.46537892 0.49985143 0.24130759]

1 Answer 1

2

Convert your quaternion to a unit quaternion (by dividing by the norm), then it should work

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

2 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
Thank you that worked! Scipy was just giving me back the unit quaternion of my original one

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.