Changeset View
Changeset View
Standalone View
Standalone View
doc/python_api/examples/mathutils.Quaternion.py
| Show All 9 Lines | |||||
| print("Check quaternions match", quat_a == quat_b) | print("Check quaternions match", quat_a == quat_b) | ||||
| # like matrices, quaternions can be multiplied to accumulate rotational values | # 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_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)) | quat_b = mathutils.Quaternion((0.0, 0.0, 1.0), math.radians(45.0)) | ||||
| quat_out = quat_a * quat_b | quat_out = quat_a * quat_b | ||||
| # print the quat, euler degrees for mear mortals and (axis, angle) | # print the quat, euler degrees for mere mortals and (axis, angle) | ||||
| print("Final Rotation:") | print("Final Rotation:") | ||||
| print(quat_out) | print(quat_out) | ||||
| print("%.2f, %.2f, %.2f" % tuple(math.degrees(a) for a in quat_out.to_euler())) | print("%.2f, %.2f, %.2f" % tuple(math.degrees(a) for a in quat_out.to_euler())) | ||||
| print("(%.2f, %.2f, %.2f), %.2f" % (quat_out.axis[:] + | print("(%.2f, %.2f, %.2f), %.2f" % (quat_out.axis[:] + | ||||
| (math.degrees(quat_out.angle), ))) | (math.degrees(quat_out.angle), ))) | ||||
| # multiple rotations can be interpolated using the exponential map | # multiple rotations can be interpolated using the exponential map | ||||
| quat_c = mathutils.Quaternion((1.0, 0.0, 0.0), math.radians(15.0)) | quat_c = mathutils.Quaternion((1.0, 0.0, 0.0), math.radians(15.0)) | ||||
| exp_avg = (quat_a.to_exponential_map() + | exp_avg = (quat_a.to_exponential_map() + | ||||
| quat_b.to_exponential_map() + | quat_b.to_exponential_map() + | ||||
| quat_c.to_exponential_map()) / 3.0 | quat_c.to_exponential_map()) / 3.0 | ||||
| quat_avg = mathutils.Quaternion(exp_avg) | quat_avg = mathutils.Quaternion(exp_avg) | ||||
| print("Average rotation:") | print("Average rotation:") | ||||
| print(quat_avg) | print(quat_avg) | ||||