本文整理汇总了Python中quaternion.Quaternion.random方法的典型用法代码示例。如果您正苦于以下问题:Python Quaternion.random方法的具体用法?Python Quaternion.random怎么用?Python Quaternion.random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quaternion.Quaternion
的用法示例。
在下文中一共展示了Quaternion.random方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_quaternion
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def generate_quaternion():
q1 = Quaternion.random()
q2 = Quaternion.random()
while True:
for q in Quaternion.intermediates(q1, q2, 20, include_endpoints=True):
yield q
#q1, q2 = q2, q1
q1 = q2
q2 = Quaternion.random()
示例2: test_differentiation
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_differentiation(self):
q = Quaternion.random()
omega = np.random.uniform(-1, 1, 3) # Random angular velocity
q_dash = 0.5 * q * Quaternion(vector=omega)
self.assertEqual(q_dash, q.derivative(omega))
示例3: test_conjugate
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_conjugate(self):
a, b, c, d = randomElements()
q1 = Quaternion(a, b, c, d)
q2 = Quaternion.random()
self.assertEqual(q1.conjugate(), Quaternion(a, -b, -c, -d))
self.assertEqual((q1 * q2).conjugate(), q2.conjugate() * q1.conjugate())
self.assertEqual((q1 + q1.conjugate()) / 2, Quaternion(scalar=q1.scalar()))
self.assertEqual((q1 - q1.conjugate()) / 2, Quaternion(vector=q1.vector()))
示例4: test_init_copy
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_init_copy(self):
q1 = Quaternion.random()
q2 = Quaternion(q1)
self.assertIsInstance(q2, Quaternion)
self.assertEqual(q2, q1)
with self.assertRaises(TypeError):
q3 = Quaternion(None)
with self.assertRaises(ValueError):
q4 = Quaternion("String")
示例5: test_inverse
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_inverse(self):
q1 = Quaternion(randomElements())
q2 = Quaternion.random()
if q1:
self.assertEqual(q1 * q1.inverse(), Quaternion(1.0, 0.0, 0.0, 0.0))
else:
with self.assertRaises(ZeroDivisionError):
q1 * q1.inverse()
self.assertEqual(q2 * q2.inverse(), Quaternion(1.0, 0.0, 0.0, 0.0))
示例6: test_norm
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_norm(self):
r = randomElements()
q1 = Quaternion(*r)
q2 = Quaternion.random()
self.assertEqual(q1.norm(), np.linalg.norm(np.array(r)))
self.assertEqual(q1.magnitude(), np.linalg.norm(np.array(r)))
# Multiplicative norm
self.assertAlmostEqual((q1 * q2).norm(), q1.norm() * q2.norm(), ALMOST_EQUAL_TOLERANCE)
# Scaled norm
for s in [30.0, 0.3, -2, -4.7]:
self.assertAlmostEqual((q1 * s).norm(), q1.norm() * abs(s), ALMOST_EQUAL_TOLERANCE)
示例7: test_matrix_io
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_matrix_io(self):
v = np.random.uniform(-100, 100, 3)
for i in range(10):
q0 = Quaternion.random()
R = q0.rotation_matrix()
q1 = Quaternion(matrix=R)
np.testing.assert_almost_equal(q0.rotate(v), np.dot(R, v), decimal=ALMOST_EQUAL_TOLERANCE)
np.testing.assert_almost_equal(q0.rotate(v), q1.rotate(v), decimal=ALMOST_EQUAL_TOLERANCE)
np.testing.assert_almost_equal(q1.rotate(v), np.dot(R, v), decimal=ALMOST_EQUAL_TOLERANCE)
self.assertTrue((q0 == q1) or (q0 == -q1)) # q1 and -q1 are equivalent rotations
示例8: test_power
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_power(self):
q1 = Quaternion.random()
q2 = Quaternion(q1)
self.assertEqual(q1 ** 0, Quaternion())
self.assertEqual(q1 ** 1, q1)
q2 **= 4
self.assertEqual(q2, q1 * q1 * q1 * q1)
self.assertEqual((q1 ** 0.5) * (q1 ** 0.5), q1)
self.assertEqual(q1 ** -1, q1.inverse())
self.assertEqual(4 ** Quaternion(2), Quaternion(16))
with self.assertRaises(TypeError):
q1 ** None
with self.assertRaises(ValueError):
q1 ** 's'
示例9: test_conversion_to_matrix
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_conversion_to_matrix(self):
q = Quaternion.random()
a, b, c, d = tuple(q.elements())
R = np.array([
[a**2 + b**2 - c**2 - d**2, 2 * (b * c - a * d), 2 * (a * c + b * d)],
[2 * (b * c + a * d), a**2 - b**2 + c**2 - d**2, 2 * (c * d - a * b)],
[2 * (b * d - a * c), 2 * (a * b + c * d), a**2 - b**2 - c**2 + d**2]])
t = np.array([[0],[0],[0]])
T = np.vstack([np.hstack([R,t]), np.array([0,0,0,1])])
np.testing.assert_almost_equal(R, q.rotation_matrix(), decimal=ALMOST_EQUAL_TOLERANCE)
np.testing.assert_almost_equal(T, q.transformation_matrix(), decimal=ALMOST_EQUAL_TOLERANCE)
# Test no scaling of rotated vectors
v1 = np.array([1, 0, 0])
v2 = np.hstack((np.random.uniform(-10, 10, 3), 1.0))
v1_ = np.dot(q.rotation_matrix(), v1)
v2_ = np.dot(q.transformation_matrix(), v2)
self.assertAlmostEqual(np.linalg.norm(v1_), 1.0, ALMOST_EQUAL_TOLERANCE)
self.assertAlmostEqual(np.linalg.norm(v2_), np.linalg.norm(v2), ALMOST_EQUAL_TOLERANCE)
# Test transformation of vectors is equivalent for quaternion & matrix
np.testing.assert_almost_equal(v1_, q.rotate(v1), decimal=ALMOST_EQUAL_TOLERANCE)
np.testing.assert_almost_equal(v2_[0:3], q.rotate(v2[0:3]), decimal=ALMOST_EQUAL_TOLERANCE)
示例10: test_init_random
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_init_random(self):
r1 = Quaternion.random()
r2 = Quaternion.random()
self.assertAlmostEqual(r1.norm(), 1.0, ALMOST_EQUAL_TOLERANCE)
self.assertIsInstance(r1, Quaternion)
示例11: test_double_conjugate
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_double_conjugate(self):
q = Quaternion.random()
self.assertEqual(q, q.conjugate().conjugate())
示例12: test_noncommutative
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_noncommutative(self):
q1 = Quaternion.random()
q2 = Quaternion.random()
if not q1 == q2: # Small chance of this happening with random initialisation
self.assertNotEqual(q1 * q2, q2 * q1)
示例13: test_distributive
# 需要导入模块: from quaternion import Quaternion [as 别名]
# 或者: from quaternion.Quaternion import random [as 别名]
def test_distributive(self):
q1 = Quaternion.random()
q2 = Quaternion.random()
q3 = Quaternion.random()
self.assertEqual(q1 * ( q2 + q3 ), q1 * q2 + q1 * q3)