当前位置: 首页>>代码示例>>Python>>正文


Python Quaternion.from_x_rotation方法代码示例

本文整理汇总了Python中pyrr.objects.quaternion.Quaternion.from_x_rotation方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.from_x_rotation方法的具体用法?Python Quaternion.from_x_rotation怎么用?Python Quaternion.from_x_rotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyrr.objects.quaternion.Quaternion的用法示例。


在下文中一共展示了Quaternion.from_x_rotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_operators_quaternion

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_operators_quaternion(self):
        q1 = Quaternion()
        q2 = Quaternion.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: q1 + q2)

        # subtract
        # we had to add this to enable np.array_equal to work
        # as it uses subtraction
        #self.assertRaises(ValueError, lambda: q1 - q2)

        # multiply
        self.assertTrue(np.array_equal(q1 * q2, quaternion.cross(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: q1 / q2)

        # or
        self.assertTrue(np.array_equal(q1 | q2, quaternion.dot(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # inverse
        self.assertTrue(np.array_equal(~q2, quaternion.conjugate(quaternion.create_from_x_rotation(0.5))))

        # ==
        self.assertTrue(Quaternion() == Quaternion())
        self.assertFalse(Quaternion() == Quaternion([0., 0., 0., 0.]))

        # !=
        self.assertTrue(Quaternion() != Quaternion([1., 1., 1., 1.]))
        self.assertFalse(Quaternion() != Quaternion())
开发者ID:adamlwgriffiths,项目名称:Pyrr,代码行数:33,代码来源:test_quaternion.py

示例2: test_from_x_rotation

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_from_x_rotation(self):
        # 180 degree turn around X axis
        q = Quaternion.from_x_rotation(np.pi)
        self.assertTrue(np.allclose(q, [1., 0., 0., 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 X axis
        q = Quaternion.from_x_rotation(np.pi / 2.)
        self.assertTrue(np.allclose(q, [np.sqrt(0.5), 0., 0., np.sqrt(0.5)]))
        self.assertTrue(np.allclose(q * Vector3([1., 0., 0.]), [1., 0., 0.]))
        self.assertTrue(np.allclose(q * Vector3([0., 1., 0.]), [0., 0., 1.]))
        self.assertTrue(np.allclose(q * Vector3([0., 0., 1.]), [0.,-1., 0.]))

        # -90 degree rotation around X axis
        q = Quaternion.from_x_rotation(-np.pi / 2.)
        self.assertTrue(np.allclose(q, [-np.sqrt(0.5), 0., 0., np.sqrt(0.5)]))
        self.assertTrue(np.allclose(q * Vector3([1., 0., 0.]), [1., 0., 0.]))
        self.assertTrue(np.allclose(q * Vector3([0., 1., 0.]), [0., 0.,-1.]))
        self.assertTrue(np.allclose(q * Vector3([0., 0., 1.]), [0., 1., 0.]))
开发者ID:RazerM,项目名称:Pyrr,代码行数:23,代码来源:test_quaternion.py

示例3: test_apply_to_vector_non_unit

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_apply_to_vector_non_unit(self):
        q = Quaternion.from_x_rotation(np.pi)

        # zero length
        v = Vector3([0., 0., 0.])
        self.assertTrue(np.allclose(q * v, quaternion.apply_to_vector(quaternion.create_from_x_rotation(np.pi), [0., 0., 0.])))

        # >1 length
        v = Vector3([2., 0., 0.])
        self.assertTrue(np.allclose(q * v, quaternion.apply_to_vector(quaternion.create_from_x_rotation(np.pi), [2., 0., 0.])))
        v = Vector3([0., 2., 0.])
        self.assertTrue(np.allclose(q * v, quaternion.apply_to_vector(quaternion.create_from_x_rotation(np.pi), [0., 2., 0.])))
        v = Vector3([0., 0., 2.])
        self.assertTrue(np.allclose(q * v, quaternion.apply_to_vector(quaternion.create_from_x_rotation(np.pi), [0., 0., 2.])))
开发者ID:adamlwgriffiths,项目名称:Pyrr,代码行数:16,代码来源:test_quaternion.py

示例4: test_operators_quaternion

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_operators_quaternion(self):
        v = Vector3()
        q = Quaternion.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: v + q)

        # subtract
        self.assertRaises(ValueError, lambda: v - q)

        # multiply
        self.assertRaises(ValueError, lambda: v * q)

        # divide
        self.assertRaises(ValueError, lambda: v / q)
开发者ID:RazerM,项目名称:Pyrr,代码行数:17,代码来源:test_vector3.py

示例5: test_operators_quaternion

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_operators_quaternion(self):
        m = Matrix33.identity()
        q = Quaternion.from_x_rotation(0.7)
        
        # add
        self.assertRaises(ValueError, lambda: m + q)

        # subtract
        self.assertRaises(ValueError, lambda: m - q)

        # multiply
        self.assertTrue(np.array_equal(m * q, matrix33.multiply(matrix33.create_identity(), matrix33.create_from_quaternion(quaternion.create_from_x_rotation(0.7)))))

        # divide
        self.assertRaises(ValueError, lambda: m / q)
开发者ID:RazerM,项目名称:Pyrr,代码行数:17,代码来源:test_matrix33.py

示例6: test_operators_vector4

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_operators_vector4(self):
        q = Quaternion.from_x_rotation(0.5)
        v = Vector4([1.,0.,0.,1.])

        # add
        self.assertRaises(ValueError, lambda: q + v)

        # subtract
        self.assertRaises(ValueError, lambda: q - v)

        # multiply
        self.assertTrue(np.array_equal(q * v, quaternion.apply_to_vector(quaternion.create_from_x_rotation(0.5), [1.,0.,0.,1.])))

        # divide
        self.assertRaises(ValueError, lambda: q / v)
开发者ID:abarch,项目名称:Pyrr,代码行数:17,代码来源:test_quaternion.py

示例7: test_operators_quaternion

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
    def test_operators_quaternion(self):
        q1 = Quaternion()
        q2 = Quaternion.from_x_rotation(0.5)

        # add
        self.assertRaises(ValueError, lambda: q1 + q2)

        # subtract
        self.assertRaises(ValueError, lambda: q1 - q2)

        # multiply
        self.assertTrue(np.array_equal(q1 * q2, quaternion.cross(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # divide
        self.assertRaises(ValueError, lambda: q1 / q2)

        # or
        self.assertTrue(np.array_equal(q1 | q2, quaternion.dot(quaternion.create(), quaternion.create_from_x_rotation(0.5))))

        # inverse
        self.assertTrue(np.array_equal(~q2, quaternion.conjugate(quaternion.create_from_x_rotation(0.5))))
开发者ID:abarch,项目名称:Pyrr,代码行数:23,代码来源:test_quaternion.py

示例8: test_create_from_inverse_quaternion

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_create_from_inverse_quaternion(self):
     q = Quaternion.from_x_rotation(0.5)
     m = Matrix33.from_inverse_of_quaternion(q)
     expected = matrix33.create_from_quaternion(quaternion.inverse(quaternion.create_from_x_rotation(0.5)))
     np.testing.assert_almost_equal(np.array(m), expected, decimal=5)
开发者ID:RazerM,项目名称:Pyrr,代码行数:7,代码来源:test_matrix33.py

示例9: test_axis

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_axis(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q.axis, quaternion.rotation_axis(q)))
开发者ID:abarch,项目名称:Pyrr,代码行数:5,代码来源:test_quaternion.py

示例10: test_angle

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_angle(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertEqual(q.angle, quaternion.rotation_angle(q))
开发者ID:abarch,项目名称:Pyrr,代码行数:5,代码来源:test_quaternion.py

示例11: test_length

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_length(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q.length, quaternion.length(q)))
开发者ID:abarch,项目名称:Pyrr,代码行数:5,代码来源:test_quaternion.py

示例12: test_from_x_rotation

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_from_x_rotation(self):
     q = Quaternion.from_x_rotation(np.pi / 2.)
     self.assertTrue(np.allclose(q*Vector3([1.,0.,0.]), [1.,0.,0.]))
     self.assertTrue(np.allclose(q*Vector3([0.,1.,0.]), [0.,0.,-1.]))
     self.assertTrue(np.allclose(q*Vector3([0.,0.,1.]), [0.,1.,0.]))
开发者ID:abarch,项目名称:Pyrr,代码行数:7,代码来源:test_quaternion.py

示例13: test_dot

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_dot(self):
     q1 = Quaternion.from_x_rotation(np.pi / 2.0)
     q2 = Quaternion.from_y_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q1.dot(q2), quaternion.dot(q1, q2)))
开发者ID:abarch,项目名称:Pyrr,代码行数:6,代码来源:test_quaternion.py

示例14: test_matrix44

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_matrix44(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q.matrix44, matrix44.create_from_quaternion(q)))
开发者ID:abarch,项目名称:Pyrr,代码行数:5,代码来源:test_quaternion.py

示例15: test_negative

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_x_rotation [as 别名]
 def test_negative(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q.negative, quaternion.negate(q)))
开发者ID:abarch,项目名称:Pyrr,代码行数:5,代码来源:test_quaternion.py


注:本文中的pyrr.objects.quaternion.Quaternion.from_x_rotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。