Skip to main content

Dual quaternion implementation

Project description

Dual Quaternions

test badge last tag version badge

Dual quaternions are a way of representing rigid body transformations, just like homogeneous transformations do. Instead of using a 4x4 matrix, the transformation is represented as two quaternions. This has several advantages, which are listed under Why use dual quaternions?. The term 'dual' refers to dual number theory, which allows representing numbers (or in this case quaternions) very similar to complex numbers, with the difference being that i or j becomes e (epsilon), and instead of i^2 = -1, we have e^2 = 0. This allows, for example, the multiplication of two dual quaternions to work in the same way as homogeneous matrix multiplication.

For more information on dual quaternions, take a look at the References. For conversion from and to common ROS messages, see dual_quaternions_ros.

viz.gif

Why use dual quaternions?

  • dual quaternions have all the advantages of quaternions including unambiguous representation, no gimbal lock, compact representation
  • direct and simple relation with screw theory. Simple and fast Screw Linear Interpolation (ScLERP) which is shortest path on the manifold
  • dual quaternions have an exact tangent / derivative due to dual number theory (higher order taylor series are exactly zero)
  • we want to use quaternions but they can only handle rotation. Dual quaternions are the correct extension to handle translations as well.
  • easy normalization. Homogeneous tranformation matrices are orthogonal and due to floating point errors operations on them often result in matrices that need to be renormalized. This can be done using the Gram-Schmidt method but that is a slow algorithm. Quaternion normalization is very fast.
  • mathematically pleasing

Installation

pip install dual_quaternions

Usage

from dual_quaternions import DualQuaternion

References

  • \K. Daniilidis, E. Bayro-Corrochano, "The dual quaternion approach to hand-eye calibration", IEEE International Conference on Pattern Recognition, 1996
  • Kavan, Ladislav & Collins, Steven & Zara, Jiri & O'Sullivan, Carol. (2007). Skinning with dual quaternions. I3D. 39-46. 10.1145/1230100.1230107.
  • Kenwright, B. (2012). A Beginners Guide to Dual-Quaternions What They Are, How They Work, and How to Use Them for 3D Character Hierarchies.
  • Furrer, Fadri & Fehr, Marius & Novkovic, Tonci & Sommer, Hannes & Gilitschenski, Igor & Siegwart, Roland. (2018). Evaluation of Combined Time-Offset Estimation and Hand-Eye Calibration on Robotic Datasets. 145-159. 10.1007/978-3-319-67361-5_10.

Other dual quaternion libraries

Many libraries focus on efficiency and are written in C++, sometimes with Python bindings. They typically do not include tests and so it's hard to know whether they're accurate. Along with a test suite, this library aims to explain the various functions and why they're implemented that way. As a result it serves as a starting point for those trying to get started with dual quaternions.

  • Hasenpfote/dualquat: C++, header-only using Eigen
  • neka-nat/dq3d: C++ based, using Eigen, with Python bindings including examples for ScLERP and skinning
  • dqrobotics: Matlab, C++11 with Python3 bindings, includes docstrings

Derivations

log and exp

The exponential map is a map from the tangent space at some point x on the manifold onto its Lie group. It maps a vector $s$ such that the geodesic through $x$ is followed. At the identity, $exp_1(s) =: exp(s)$ where $s$ is a pure dual quaternion (real part of $q_r$ and $q_d$ are zero) At some point $x$, using parallel transport the map becomes $\exp_x(s) = x \cdot \exp_1(x^{-1} \cdot s)$ Intuitively, because $\exp$ is only defined at the identity but we're trying to find the map at some other point $x$, we first move it to the origin by premultiplying with $x^{-1}$. Then we map it to the manifold/Lie group using the exponential map, and finally move it back to $x$ by premultiplying by $x$.

  • exp: $\mathfrak{se}(3) \rightarrow SE(3)$
    • takes elements from the Lie algebra to the manifold
  • log: $SE(3) \rightarrow \mathfrak{se}(3)$
    • takes elements from the manifold to the Lie Algebra

In some sources log and exp are derived using the Taylor method first order approximation $f(a+\epsilon b) ~= f(a)+\epsilon b f'(a)$ Applying this to the log and exp functions, you would get:

exp(r+\epsilon d) = exp(r)+\epsilon \cdot exp(r) \cdot d \\
log(r+\epsilon d) = log(r)+\epsilon \cdot r^{-1}\cdot d

where $r^{-1}=r^$ since $r$ is unit. This only gives the same answer as the Lie algebra formulation when the dual part is symmetric with respect to the real part, i.e. $d \cdot r^ = r^* \cdot d$ For nontrivial rotation and translation not aligned with the rotation axis, this is not the case. This is because the Taylor approximation assumes commutativity, which dual quaternion multiplication is not. As a result, the Taylor method can produce non-symmetric, non-pure dual quaternions which is not 'correct'.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dual_quaternions-0.4.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dual_quaternions-0.4.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file dual_quaternions-0.4.0.tar.gz.

File metadata

  • Download URL: dual_quaternions-0.4.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for dual_quaternions-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7623d5964facd7128754633db6aa770363ea096c5fa9ed0260004ffd5d09b6d0
MD5 143e75533f929f17bcc497c37cfcc37f
BLAKE2b-256 f22b49ea06c46f9d2ab0f121684ff7f9f11757a198fbfebdeb222deab058c2c3

See more details on using hashes here.

File details

Details for the file dual_quaternions-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dual_quaternions-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a42945a015c437e0b7c3a6c0232fb80aded04dc49118b11038c3f7abc8d6fdd
MD5 d085b49dc38ead83f151060b388fdae2
BLAKE2b-256 b846a99fe873eb3d120833b6e52ad7d7a4190a60bf2b9480f5a17384db65b781

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page