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


Python Quaternion.from_y_rotation方法代码示例

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


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

示例1: test_from_y_rotation

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

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

示例2: test_decompose

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_y_rotation [as 别名]
    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,代码行数:52,代码来源:test_matrix44.py

示例3: test_from_y_rotation

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

示例4: test_dot

# 需要导入模块: from pyrr.objects.quaternion import Quaternion [as 别名]
# 或者: from pyrr.objects.quaternion.Quaternion import from_y_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


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