• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python quaternion.Quaternion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_decompose

    def test_decompose(self):
        # define expectations for multiple cases
        testsets = [
            (
                Vector3([1, 1, 2], dtype='f4'),
                Quaternion.from_y_rotation(np.pi, dtype='f4'),
                Vector3([10, 0, -5], dtype='f4'),
                Matrix44([
                    [-1, 0, 0, 0],
                    [0, 1, 0, 0],
                    [0, 0, -2, 0],
                    [10, 0, -5, 1],
                ], dtype='f4')
            ),
            (
                Vector3([-1, 3, .5], dtype='f4'),
                Quaternion.from_axis_rotation(Vector3([.75, .75, 0], dtype='f4').normalized, np.pi, dtype='f4').normalized,
                Vector3([1, -1, 1], dtype='f4'),
                Matrix44([
                    [0, -1, 0, 0],
                    [3, 0, 0, 0],
                    [0, 0, -.5, 0],
                    [1, -1, 1, 1],
                ], dtype='f4')
            ),
        ]

        for expected_scale, expected_rotation, expected_translation, expected_model in testsets:
            # compose model matrix using original inputs
            s = Matrix44.from_scale(expected_scale, dtype='f4')
            r = Matrix44.from_quaternion(expected_rotation, dtype='f4')
            t = Matrix44.from_translation(expected_translation, dtype='f4')
            m = t * r * s

            # check that it's the same as the expected matrix
            np.testing.assert_almost_equal(np.array(m), np.array(expected_model))
            self.assertTrue(m.dtype == expected_model.dtype)
            self.assertTrue(isinstance(m, expected_model.__class__))

            # decompose this matrix and recompose the model matrix from the decomposition
            ds, dr, dt = m.decompose()
            ds = Matrix44.from_scale(ds, dtype='f4')
            dr = Matrix44.from_quaternion(dr, dtype='f4')
            dt = Matrix44.from_translation(dt, dtype='f4')
            dm = dt * dr * ds

            # check that it's the same as the original matrix
            np.testing.assert_almost_equal(np.array(m), np.array(dm))
            self.assertTrue(m.dtype == dm.dtype)
            self.assertTrue(isinstance(dm, m.__class__))
开发者ID:adamlwgriffiths,项目名称:Pyrr,代码行数:50,代码来源:test_matrix44.py


示例2: test_from_axis

    def test_from_axis(self):
        source = np.array([np.pi / 2, 0, 0])
        result = Quaternion.from_axis(source)
        expected = np.array([np.sqrt(0.5), 0, 0, np.sqrt(0.5)])
        self.assertTrue(np.allclose(result, expected))

        source = np.array([0, np.pi, 0])
        result = Quaternion.from_axis(source)
        expected = np.array([0, 1, 0, 0])
        self.assertTrue(np.allclose(result, expected))

        source = np.array([0, 0, 2 * np.pi])
        result = Quaternion.from_axis(source)
        expected = np.array([0, 0, 0, -1])
        self.assertTrue(np.allclose(result, expected))
开发者ID:adamlwgriffiths,项目名称:Pyrr,代码行数:15,代码来源:test_quaternion.py


示例3: test_operators_quaternion

    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,代码行数:31,代码来源:test_quaternion.py


示例4: test_from_z_rotation

    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.]))
开发者ID:RazerM,项目名称:Pyrr,代码行数:21,代码来源:test_quaternion.py


示例5: test_accessors

    def test_accessors(self):
        q = Quaternion(np.arange(self._size))
        self.assertTrue(np.array_equal(q.xy,[0,1]))
        self.assertTrue(np.array_equal(q.xyz,[0,1,2]))
        self.assertTrue(np.array_equal(q.xyzw,[0,1,2,3]))

        self.assertTrue(np.array_equal(q.xz,[0,2]))
        self.assertTrue(np.array_equal(q.xyz,[0,1,2]))
        self.assertTrue(np.array_equal(q.xyw,[0,1,3]))
        self.assertTrue(np.array_equal(q.xw,[0,3]))

        self.assertEqual(q.x, 0)
        self.assertEqual(q.y, 1)
        self.assertEqual(q.z, 2)
        self.assertEqual(q.w, 3)

        q.x = 1
        self.assertEqual(q.x, 1)
        self.assertEqual(q[0], 1)
        q.x += 1
        self.assertEqual(q.x, 2)
        self.assertEqual(q[0], 2)
开发者ID:abarch,项目名称:Pyrr,代码行数:22,代码来源:test_quaternion.py


示例6: test_apply_to_vector_non_unit

    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,代码行数:14,代码来源:test_quaternion.py


示例7: test_operators_quaternion

    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,代码行数:15,代码来源:test_vector3.py


示例8: test_operators_quaternion

    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,代码行数:15,代码来源:test_matrix33.py


示例9: test_operators_vector4

    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,代码行数:15,代码来源:test_quaternion.py


示例10: test_operators_quaternion

    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,代码行数:21,代码来源:test_quaternion.py


示例11: test_create_from_inverse_quaternion

 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,代码行数:5,代码来源:test_matrix33.py


示例12: test_dot

 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,代码行数:4,代码来源:test_quaternion.py


示例13: test_axis

 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,代码行数:3,代码来源:test_quaternion.py


示例14: test_angle

 def test_angle(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertEqual(q.angle, quaternion.rotation_angle(q))
开发者ID:abarch,项目名称:Pyrr,代码行数:3,代码来源:test_quaternion.py


示例15: test_normalise

 def test_normalise(self):
     q = Quaternion([1.,2.,3.,4.])
     self.assertFalse(np.allclose(q.length, 1.))
     
     q.normalise()
     self.assertTrue(np.allclose(q.length, 1.))
开发者ID:abarch,项目名称:Pyrr,代码行数:6,代码来源:test_quaternion.py


示例16: test_length

 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,代码行数:3,代码来源:test_quaternion.py


示例17: test_from_axis_rotation

 def test_from_axis_rotation(self):
     q = Quaternion.from_axis_rotation([1.,0.,0.], 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,代码行数:5,代码来源:test_quaternion.py


示例18: test_conjugate

 def test_conjugate(self):
     q = Quaternion.from_x_rotation(np.pi / 2.0)
     self.assertTrue(np.allclose(q.conjugate, quaternion.conjugate(q)))
开发者ID:abarch,项目名称:Pyrr,代码行数:3,代码来源:test_quaternion.py


示例19: test_exp

 def test_exp(self):
     source = Quaternion.from_eulers([0, np.pi / 2, 0])
     result = source.exp()
     expected = np.array([0, 1.31753841, 0, 1.54186346])
     self.assertTrue(np.allclose(result, expected))
开发者ID:adamlwgriffiths,项目名称:Pyrr,代码行数:5,代码来源:test_quaternion.py


示例20: test_matrix44

 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,代码行数:3,代码来源:test_quaternion.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rrd.RRD类代码示例发布时间:2022-05-27
下一篇:
Python pyrr.Matrix44类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap