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


Python Quaternion.angle方法代码示例

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


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

示例1: test_normalisation

# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import angle [as 别名]
    def test_normalisation(self): # normalise to unit quaternion
        r = randomElements()
        q1 = Quaternion(*r)
        v = q1.unit()
        n = q1.normalised()

        if q1 == Quaternion(0): # small chance with random generation
            return # a 0 quaternion does not normalise

        # Test normalised objects are unit quaternions
        np.testing.assert_almost_equal(v.q, q1.elements() / q1.norm(), decimal=ALMOST_EQUAL_TOLERANCE)
        np.testing.assert_almost_equal(n.q, q1.elements() / q1.norm(), decimal=ALMOST_EQUAL_TOLERANCE)
        self.assertAlmostEqual(v.norm(), 1.0, ALMOST_EQUAL_TOLERANCE)
        self.assertAlmostEqual(n.norm(), 1.0, ALMOST_EQUAL_TOLERANCE)
        # Test axis and angle remain the same
        np.testing.assert_almost_equal(q1.axis(), v.axis(), decimal=ALMOST_EQUAL_TOLERANCE)
        np.testing.assert_almost_equal(q1.axis(), n.axis(), decimal=ALMOST_EQUAL_TOLERANCE)
        self.assertAlmostEqual(q1.angle(), v.angle(), ALMOST_EQUAL_TOLERANCE)
        self.assertAlmostEqual(q1.angle(), n.angle(), ALMOST_EQUAL_TOLERANCE)
        # Test special case where q is zero
        q2 = Quaternion(0)
        self.assertEqual(q2, q2.normalised())
开发者ID:timdelbruegger,项目名称:pyquaternion,代码行数:24,代码来源:test_quaternion.py

示例2: validate_axis_angle

# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import angle [as 别名]
    def validate_axis_angle(self, axis, angle):
        
        def wrap_angle(theta):
            """ Wrap any angle to lie between -pi and pi 

            Odd multiples of pi are wrapped to +pi (as opposed to -pi)
            """
            result = ((theta + pi) % (2*pi)) - pi
            if result == -pi: result = pi
            return result

        theta = wrap_angle(angle)
        v = axis

        q = Quaternion(angle=theta, axis=v)

        v_ = q.axis()
        theta_ = q.angle()
        
        if theta == 0.0: # axis is irrelevant (check defaults to x=y=z)
            np.testing.assert_almost_equal(theta_, 0.0, decimal=ALMOST_EQUAL_TOLERANCE)
            np.testing.assert_almost_equal(v_, np.zeros(3), decimal=ALMOST_EQUAL_TOLERANCE)
            return
        elif abs(theta) == pi: # rotation in either direction is equivalent
            self.assertTrue(
                np.isclose(theta, pi) or np.isclose(theta, -pi) 
                and 
                np.isclose(v, v_).all() or np.isclose(v, -v_).all()
                )
        else:
            self.assertTrue(
                np.isclose(theta, theta_) and np.isclose(v, v_).all()
                or
                np.isclose(theta, -theta_) and np.isclose(v, -v_).all()
                )
        # Ensure the returned axis is a unit vector
        np.testing.assert_almost_equal(np.linalg.norm(v_), 1.0, decimal=ALMOST_EQUAL_TOLERANCE)
开发者ID:timdelbruegger,项目名称:pyquaternion,代码行数:39,代码来源:test_quaternion.py


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