Skip to content

Commit

Permalink
Update sudmodules' and filters' docstrings to use bibtex.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayitzin committed Sep 28, 2024
1 parent def7392 commit d092196
Show file tree
Hide file tree
Showing 23 changed files with 944 additions and 444 deletions.
43 changes: 12 additions & 31 deletions ahrs/common/dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
rotation matrix in :math:`SO(3)`.
`Direction cosines <https://en.wikipedia.org/wiki/Direction_cosine>`_ are
cosines of angles between a vector and a base coordinate frame [WikipediaDCM]_.
In this case, the direction cosines describe the differences between orthogonal
vectors :math:`\\mathbf{r}_i` and the base frame. The matrix containing these
differences is commonly named the **Direction Cosine Matrix**.
cosines of angles between a vector and a base coordinate frame
:cite:p:`Wiki_DirectionCosine`. In this case, the direction cosines describe
the differences between orthogonal vectors :math:`\\mathbf{r}_i` and the base
frame. The matrix containing these differences is commonly named the
**Direction Cosine Matrix**.
These matrices are used for two main purposes:
Expand All @@ -72,32 +73,12 @@
Because of the latter, the DCM is also known as the **rotation matrix**.
DCMs are, therefore, the most common representation of rotations
[WikipediaRotMat]_, especially in real applications of spacecraft tracking and
location.
:cite:p:`Wolfram_RotationMatrix`, especially in real applications of spacecraft
tracking and location.
Throughout this package they will be used to represent the attitudes with
respect to the global frame.
References
----------
.. [WikipediaDCM] Wikipedia: Direction Cosine.
(https://en.wikipedia.org/wiki/Direction_cosine)
.. [WikipediaRotMat] Wikipedia: Rotation Matrix
(https://mathworld.wolfram.com/RotationMatrix.html)
.. [Ma] Yi Ma, Stefano Soatto, Jana Kosecka, and S. Shankar Sastry. An
Invitation to 3-D Vision: From Images to Geometric Models. Springer
Verlag. 2003.
(https://www.eecis.udel.edu/~cer/arv/readings/old_mkss.pdf)
.. [Huyhn] Huynh, D.Q. Metrics for 3D Rotations: Comparison and Analysis. J
Math Imaging Vis 35, 155–164 (2009).
.. [Curtis] Howard D Curtis. Orbital Mechanics for Engineering Students (Third
Edition) Butterworth-Heinemann. 2014.
.. [Kuipers] Kuipers, Jack B. Quaternions and Rotation Sequences: A Primer with
Applications to Orbits, Aerospace and Virtual Reality. Princeton;
Oxford: Princeton University Press, 1999.
.. [Diebel] Diebel, James. Representing Attitude; Euler Angles, Unit
Quaternions, and Rotation. Stanford University. 20 October 2006.
"""

from typing import Tuple
Expand Down Expand Up @@ -1039,14 +1020,14 @@ def to_quaternion(self, method: str='shepperd', **kw) -> np.ndarray:
There are five methods available to obtain a quaternion from a
Direction Cosine Matrix:
* ``'shepperd'`` as described in [Chiaverini]_.
* ``'hughes'`` as described in [Hughes]_.
* ``'itzhack'`` as described in [Bar-Itzhack]_ using version ``3`` by
* ``'chiaverini'`` as described in :cite:p:`Chiaverini1999`.
* ``'hughes'`` as described in :cite:p:`hughes1986spacecraft17`.
* ``'itzhack'`` as described in :cite:p:`BarItzhack2000` using version ``3`` by
default. Possible options are integers ``1``, ``2`` or ``3``.
* ``'sarabandi'`` as described in [Sarabandi]_ with a threshold equal
* ``'sarabandi'`` as described in :cite:p:`sarabandi2019` with a threshold equal
to ``0.0`` by default. Possible threshold values are floats between
``-3.0`` and ``3.0``.
* ``'shepperd'`` as described in [Shepperd]_.
* ``'shepperd'`` as described in :cite:p:`shepperd1978`.
Parameters
----------
Expand Down
21 changes: 9 additions & 12 deletions ahrs/common/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def q_random(size: int = 1) -> np.ndarray:
return q[0]
return q


def q_norm(q: np.ndarray) -> np.ndarray:
"""
Normalize quaternion [WQ1]_ :math:`\\mathbf{q}_u`, also known as a versor
Expand Down Expand Up @@ -1085,7 +1084,7 @@ def slerp(q0: np.ndarray, q1: np.ndarray, t_array: np.ndarray, threshold: float
arc of a great circle passing through any two existing quaternion endpoints
lying on the unit radius hypersphere.
Based on the method detailed in [Wiki_SLERP]_
Based on the method detailed in :cite:p:`Wiki_SLERP`.
Parameters
----------
Expand All @@ -1106,10 +1105,6 @@ def slerp(q0: np.ndarray, q1: np.ndarray, t_array: np.ndarray, threshold: float
q : numpy.ndarray
New quaternion representing the interpolated rotation.
References
----------
.. [Wiki_SLERP] https://en.wikipedia.org/wiki/Slerp
"""
qdot = q0@q1
# Ensure SLERP takes the shortest path
Expand All @@ -1132,7 +1127,7 @@ def slerp(q0: np.ndarray, q1: np.ndarray, t_array: np.ndarray, threshold: float
def chiaverini(dcm: np.ndarray) -> np.ndarray:
"""
Quaternion from a Direction Cosine Matrix with Chiaverini's algebraic
method [Chiaverini]_.
method :cite:p:`Chiaverini1999`.
Defining the unit quaternion as:
Expand Down Expand Up @@ -1218,7 +1213,8 @@ def chiaverini(dcm: np.ndarray) -> np.ndarray:

def hughes(C: np.ndarray) -> np.ndarray:
"""
Quaternion from a Direction Cosine Matrix with Hughes' method [Hughes]_.
Quaternion from a Direction Cosine Matrix with trigonometric Hughes' method
:cite:p:`hughes1986spacecraft17`.
Defining the quaternion (reluctantly called "Euler Parameters" in Hughes'
book) as:
Expand Down Expand Up @@ -1320,7 +1316,7 @@ def hughes(C: np.ndarray) -> np.ndarray:
def sarabandi(dcm: np.ndarray, eta: float = 0.0) -> np.ndarray:
"""
Quaternion from a Direction Cosine Matrix using Sarabandi's method
[Sarabandi]_.
:cite:p:`sarabandi2019`.
A rotation matrix :math:`\\mathbf{R}` can be expressed as:
Expand Down Expand Up @@ -1521,7 +1517,7 @@ def sarabandi(dcm: np.ndarray, eta: float = 0.0) -> np.ndarray:
def itzhack(dcm: np.ndarray, version: int = 3) -> np.ndarray:
"""
Quaternion from a Direction Cosine Matrix with Bar-Itzhack's method
[Bar-Itzhack]_.
:cite:p:`BarItzhack2000`.
This method to compute the quaternion from a Direction Cosine Matrix (DCM)
is based on the eigenvalue decomposition of the matrix :math:`\\mathbf{K}`,
Expand Down Expand Up @@ -1775,13 +1771,14 @@ def itzhack(dcm: np.ndarray, version: int = 3) -> np.ndarray:
q = eigvec[:, np.where(np.isclose(eigval, 1.0))[0]].flatten().real
else:
q = eigvec[:, eigval.argmax()]
q = np.roll(q, 1) # Original implementation uses [qx, qy, qz, qw]
q = np.roll(q, 1) # Re-arrange quaternion to [qw, qx, qy, qz]
q[0] *= -1 # Original implementation computes inverse rotation
return q / np.linalg.norm(q)

def shepperd(dcm: np.ndarray) -> np.ndarray:
"""
Quaternion from a Direction Cosine Matrix with Shepperd's method [Shepperd]_.
Quaternion from a Direction Cosine Matrix with Shepperd's method
:cite:p:`Shepperd1978`.
Since it was proposed in 1978, the Shepperd method has been widely used
in the aerospace industry.
Expand Down
Loading

0 comments on commit d092196

Please sign in to comment.