dual_quaternion.py
Go to the documentation of this file.
1 import sympy
2 import sys
3 import unittest
4 import sophus
5 
6 
8  """ Dual quaternion class """
9 
10  def __init__(self, real_q, inf_q):
11  """ Dual quaternion consists of a real quaternion, and an infinitesimal
12  quaternion """
13  self.real_q = real_q
14  self.inf_q = inf_q
15 
16  def __mul__(self, right):
17  """ dual quaternion multiplication """
18  return DualQuaternion(self.real_q * right.real_q,
19  self.real_q * right.inf_q +
20  self.inf_q * right.real_q)
21 
22  def __truediv__(self, scalar):
23  """ scalar division """
24  return DualQuaternion(self.real_q / scalar, self.inf_q / scalar)
25 
26  def __repr__(self):
27  return "( " + repr(self.real_q) + \
28  " + " + repr(self.inf_q) + ")"
29 
30  def __getitem__(self, key):
31  assert (key >= 0 and key < 8)
32  if key < 4:
33  return self.real_q[i]
34  else:
35  return self.inf_q[i - 4]
36 
37  def squared_norm(self):
38  """ squared norm when considering the dual quaternion as 8-tuple """
39  return self.real_q.squared_norm() + self.inf_q.squared_norm()
40 
41  def conj(self):
42  """ dual quaternion conjugate """
43  return DualQuaternion(self.real_q.conj(), self.inf_q.conj())
44 
45  def inv(self):
46  """ dual quaternion inverse """
47  return DualQuaternion(self.real_q.inv(),
48  -self.real_q.inv() * self.inf_q *
49  self.real_q.inv())
50 
51  def simplify(self):
52  return DualQuaternion(self.real_q.simplify(),
53  self.inf_q.simplify())
54 
55  @staticmethod
56  def identity():
57  return DualQuaternion(sophus.Quaternion.identity(),
58  sophus.Quaternion.zero())
59 
60  def __eq__(self, other):
61  if isinstance(self, other.__class__):
62  return self.real_q == other.real_q and self.inf_q == other.inf_q
63  return False
64 
65 
66 class TestDualQuaternion(unittest.TestCase):
67  def setUp(self):
68  w, s0, s1, s2 = sympy.symbols('w s0 s1 s2', real=True)
69  x, t0, t1, t2 = sympy.symbols('x t0 t1 t2', real=True)
70  y, u0, u1, u2 = sympy.symbols('y u0 u1 u2', real=True)
71  z, v0, v1, v2 = sympy.symbols('z v0 v1 v2', real=True)
72 
73  s = sophus.Vector3(s0, s1, s2)
74  t = sophus.Vector3(t0, t1, t2)
75  u = sophus.Vector3(u0, u1, u2)
76  v = sophus.Vector3(v0, v1, v2)
78  sophus.Quaternion(x, t))
80  sophus.Quaternion(z, v))
81 
83  product = self.a * self.a.inv()
84  self.assertEqual(product.simplify(),
85  DualQuaternion.identity())
86  product = self.a.inv() * self.a
87  self.assertEqual(product.simplify(),
88  DualQuaternion.identity())
89 
90 
91 if __name__ == '__main__':
92  unittest.main()
sophus.dual_quaternion.DualQuaternion.__truediv__
def __truediv__(self, scalar)
Definition: dual_quaternion.py:22
sophus.dual_quaternion.TestDualQuaternion.b
b
Definition: dual_quaternion.py:79
sophus.dual_quaternion.DualQuaternion.__repr__
def __repr__(self)
Definition: dual_quaternion.py:26
sophus.dual_quaternion.TestDualQuaternion.a
a
Definition: dual_quaternion.py:77
sophus.dual_quaternion.DualQuaternion.__eq__
def __eq__(self, other)
Definition: dual_quaternion.py:60
sophus.dual_quaternion.TestDualQuaternion.setUp
def setUp(self)
Definition: dual_quaternion.py:67
sophus.dual_quaternion.TestDualQuaternion
Definition: dual_quaternion.py:66
sophus.dual_quaternion.DualQuaternion.simplify
def simplify(self)
Definition: dual_quaternion.py:51
sophus.dual_quaternion.DualQuaternion.identity
def identity()
Definition: dual_quaternion.py:56
sophus.dual_quaternion.DualQuaternion.real_q
real_q
Definition: dual_quaternion.py:13
sophus.dual_quaternion.DualQuaternion.__mul__
def __mul__(self, right)
Definition: dual_quaternion.py:16
sophus.quaternion.Quaternion
Definition: quaternion.py:9
sophus.dual_quaternion.DualQuaternion
Definition: dual_quaternion.py:7
sophus.dual_quaternion.DualQuaternion.squared_norm
def squared_norm(self)
Definition: dual_quaternion.py:37
sophus.dual_quaternion.DualQuaternion.__getitem__
def __getitem__(self, key)
Definition: dual_quaternion.py:30
sophus.dual_quaternion.TestDualQuaternion.test_muliplications
def test_muliplications(self)
Definition: dual_quaternion.py:82
sophus.dual_quaternion.DualQuaternion.conj
def conj(self)
Definition: dual_quaternion.py:41
sophus.dual_quaternion.DualQuaternion.inv
def inv(self)
Definition: dual_quaternion.py:45
sophus.dual_quaternion.DualQuaternion.__init__
def __init__(self, real_q, inf_q)
Definition: dual_quaternion.py:10
sophus.dual_quaternion.DualQuaternion.inf_q
inf_q
Definition: dual_quaternion.py:14


sophus
Author(s): Hauke Strasdat
autogenerated on Wed Mar 2 2022 01:01:47