本文整理汇总了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