本文整理匯總了Python中mathutils.Quaternion.to_axis_angle方法的典型用法代碼示例。如果您正苦於以下問題:Python Quaternion.to_axis_angle方法的具體用法?Python Quaternion.to_axis_angle怎麽用?Python Quaternion.to_axis_angle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mathutils.Quaternion
的用法示例。
在下文中一共展示了Quaternion.to_axis_angle方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_from_expmap
# 需要導入模塊: from mathutils import Quaternion [as 別名]
# 或者: from mathutils.Quaternion import to_axis_angle [as 別名]
def test_from_expmap(self):
e = Vector((1, 1, 0))
q = Quaternion(e)
axis, angle = q.to_axis_angle()
self.assertAlmostEqual(angle, math.sqrt(2), 6)
self.assertAlmostEqual(axis.x, math.sqrt(0.5), 6)
self.assertAlmostEqual(axis.y, math.sqrt(0.5), 6)
self.assertAlmostEqual(axis.z, 0)
示例2: extract_current_pose
# 需要導入模塊: from mathutils import Quaternion [as 別名]
# 或者: from mathutils.Quaternion import to_axis_angle [as 別名]
def extract_current_pose():
"""
Convert current object's pose to OpenCV's "rvec" and "tvec".
"""
ob = bpy.context.object
if ob.rotation_mode == "QUATERNION":
q = ob.rotation_quaternion
elif ob.rotation_mode == "AXIS_ANGLE":
q = Quaternion(ob.rotation_axis_angle[1:4], ob.rotation_axis_angle[0])
else:
assert ob.rotation_mode in ("XYZ", "XZY", "YXZ", "YZX", "ZXY", "ZYX")
q = ob.rotation_euler.to_quaternion()
# Rotate 180 deg around local X because a blender camera has Y and Z axes opposite to OpenCV's
q *= Quaternion((1.0, 0.0, 0.0), radians(180.0))
aa = q.to_axis_angle()
rvec = [c * -aa[1] for c in aa[0]]
tvec = list(q.inverted() * (-ob.location))
return rvec, tvec