Quaternion Euclidean Distance#

ahrs.utils.metrics.qdist(q1: ndarray, q2: ndarray) float#

Euclidean distance between two unit quaternions as defined in [Huy09] and [HTDL13]:

\[d(\mathbf{q}_1, \mathbf{q}_2) = \mathrm{min} \{ \|\mathbf{q}_1-\mathbf{q}_2\|, \|\mathbf{q}_1+\mathbf{q}_2\|\}\]

Both quaternions will be normalized before they are compared.

The error lies within [0, \(\sqrt{2}\)], where \(d\) is equal to zero if the quaternions represent the same attitude, and \(\sqrt{2}\) if they are completely divergent.

Parameters:
  • q1 (numpy.ndarray) – First quaternion, or set of quaternions, to compare.

  • q2 (numpy.ndarray) – Second quaternion, or set of quaternions, to compare.

Returns:

d – Euclidean distance between given unit quaternions.

Return type:

float

Raises:
  • ValueError – If given quaternions do not have the same shape.

  • TypeError – If given quaternions are not of type list or numpy.ndarray.

Examples

>>> q1 = ahrs.Quaternion(random=True)
>>> q1.view()
Quaternion([ 0.94185064,  0.04451339, -0.00622856,  0.33301221])
>>> q2 = ahrs.Quaternion(random=True)
>>> q2.view()
Quaternion([-0.51041283, -0.38336653,  0.76929238, -0.0264211 ])
>>> ahrs.utils.qdist(q1, q2)
0.9885466801358284
>>> ahrs.utils.qdist(q1, -q1)
0.0