-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
from math3d.matrixN import Matrix3
m = Matrix3([1,0,0,0,-1,0,0,0,-1])
print(m.asQuaternion())
# [0.000000e+00 0.000000e+00 0.000000e+00 6.123234e-17]
# This is basically (0,0,0,0) which is not a valid quaternionI found an alternate algorithm for Matrix3 to Quaternion which gave me the correct result
from math import sqrt
m = [[1,0,0],[0,-1,0],[0,0,-1]]
tr = m[0][0] + m[1][1] + m[2][2]
if tr > 0:
S = sqrt(tr+1.0) * 2
qw = 0.25 * S
qx = (m[2][1] - m[1][2]) / S
qy = (m[0][2] - m[2][0]) / S
qz = (m[1][0] - m[0][1]) / S
elif (m[0][0] > m[1][1]) and (m[0][0] > m[2][2]):
S = sqrt(1.0 + m[0][0] - m[1][1] - m[2][2]) * 2
qw = (m[2][1] - m[1][2]) / S
qx = 0.25 * S
qy = (m[0][1] + m[1][0]) / S
qz = (m[0][2] + m[2][0]) / S
elif m[1][1] > m[2][2]:
S = sqrt(1.0 + m[1][1] - m[0][0] - m[2][2]) * 2
qw = (m[0][2] - m[2][0]) / S
qx = (m[0][1] + m[1][0]) / S
qy = 0.25 * S
qz = (m[1][2] + m[2][1]) / S
else:
S = sqrt(1.0 + m[2][2] - m[0][0] - m[1][1]) * 2
qw = (m[1][0] - m[0][1]) / S
qx = (m[0][2] + m[2][0]) / S
qy = (m[1][2] + m[2][1]) / S
qz = 0.25 * S
print (qx, qy, qz, qw)
# (1,0,0,0)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels