2010-04-11 16:22:27 +02:00
|
|
|
import mathutils
|
2011-10-17 04:20:53 +02:00
|
|
|
import math
|
2010-04-11 16:22:27 +02:00
|
|
|
|
2011-10-17 04:20:53 +02:00
|
|
|
# a new rotation 90 degrees about the Y axis
|
|
|
|
quat_a = mathutils.Quaternion((0.7071068, 0.0, 0.7071068, 0.0))
|
|
|
|
|
|
|
|
# passing values to Quaternion's directly can be confusing so axis, angle
|
|
|
|
# is supported for initializing too
|
|
|
|
quat_b = mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(90.0))
|
|
|
|
|
|
|
|
print("Check quaternions match", quat_a == quat_b)
|
|
|
|
|
|
|
|
# like matrices, quaternions can be multiplied to accumulate rotational values
|
|
|
|
quat_a = mathutils.Quaternion((0.0, 1.0, 0.0), math.radians(90.0))
|
|
|
|
quat_b = mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(45.0))
|
2019-06-06 17:12:49 +02:00
|
|
|
quat_out = quat_a @ quat_b
|
2011-10-17 04:20:53 +02:00
|
|
|
|
2018-09-03 16:49:08 +02:00
|
|
|
# print the quat, euler degrees for mere mortals and (axis, angle)
|
2011-10-17 04:20:53 +02:00
|
|
|
print("Final Rotation:")
|
|
|
|
print(quat_out)
|
|
|
|
print("%.2f, %.2f, %.2f" % tuple(math.degrees(a) for a in quat_out.to_euler()))
|
|
|
|
print("(%.2f, %.2f, %.2f), %.2f" % (quat_out.axis[:] +
|
|
|
|
(math.degrees(quat_out.angle), )))
|
2015-02-01 11:58:10 +01:00
|
|
|
|
|
|
|
# multiple rotations can be interpolated using the exponential map
|
|
|
|
quat_c = mathutils.Quaternion((1.0, 0.0, 0.0), math.radians(15.0))
|
|
|
|
exp_avg = (quat_a.to_exponential_map() +
|
|
|
|
quat_b.to_exponential_map() +
|
|
|
|
quat_c.to_exponential_map()) / 3.0
|
|
|
|
quat_avg = mathutils.Quaternion(exp_avg)
|
|
|
|
print("Average rotation:")
|
|
|
|
print(quat_avg)
|