本文整理汇总了Python中pyrr.objects.quaternion.Quaternion.from_z_rotation方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.from_z_rotation方法的具体用法?Python Quaternion.from_z_rotation怎么用?Python Quaternion.from_z_rotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyrr.objects.quaternion.Quaternion
的用法示例。
在下文中一共展示了Quaternion.from_z_rotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_z_rotation
# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_z_rotation [as 别名]
def test_from_z_rotation(self):
# 180 degree turn around Z axis
q = Quaternion.from_z_rotation(np.pi)
self.assertTrue(np.allclose(q, [0., 0., 1., 0.]))
self.assertTrue(np.allclose(q * Vector3([1., 0., 0.]), [-1., 0., 0.]))
self.assertTrue(np.allclose(q * Vector3([0., 1., 0.]), [0.,-1., 0.]))
self.assertTrue(np.allclose(q * Vector3([0., 0., 1.]), [0., 0., 1.]))
# 90 degree rotation around Z axis
q = Quaternion.from_z_rotation(np.pi / 2.)
self.assertTrue(np.allclose(q, [0., 0., np.sqrt(0.5), np.sqrt(0.5)]))
self.assertTrue(np.allclose(q * Vector3([1., 0., 0.]), [0., 1., 0.]))
self.assertTrue(np.allclose(q * Vector3([0., 1., 0.]), [-1., 0., 0.]))
self.assertTrue(np.allclose(q * Vector3([0., 0., 1.]), [0., 0., 1.]))
# -90 degree rotation around Z axis
q = Quaternion.from_z_rotation(-np.pi / 2.)
self.assertTrue(np.allclose(q, [0., 0., -np.sqrt(0.5), np.sqrt(0.5)]))
self.assertTrue(np.allclose(q * Vector3([1., 0., 0.]), [0.,-1., 0.]))
self.assertTrue(np.allclose(q * Vector3([0., 1., 0.]), [1., 0., 0.]))
self.assertTrue(np.allclose(q * Vector3([0., 0., 1.]), [0., 0., 1.]))
示例2: test_from_z_rotation
# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_z_rotation [as 别名]
def test_from_z_rotation(self):
q = Quaternion.from_z_rotation(np.pi / 2.)
self.assertTrue(np.allclose(q*Vector3([1.,0.,0.]), [0.,-1.,0.]))
self.assertTrue(np.allclose(q*Vector3([0.,1.,0.]), [1.,0.,0.]))
self.assertTrue(np.allclose(q*Vector3([0.,0.,1.]), [0.,0.,1.]))