本文整理匯總了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.]))