ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
attitudemath.hpp
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Matrix math header file
18-----------------------
19This file defines basic functions for mathematical operations on
20the matrix class
21Rather than raising an error on fail cases (i.e. divide by zero),
22the following libraries are designed to check for errors and return
23corresponding codes.
24
25Note: The naming convention observed for matrix math is as follows:
26- Capital letters represent matrices
27- Lowercase letters represent scalars
28- All vectors are 1-dimensional matrices for the purpose of math
29- Pass by reference return values are all named "result"
30- The letter used in math indicates the order of operations - A/a
31 comes first, then B/b. A/a or B/b always represent the "other"
32 value in an operation
33
34Author: Alex Reynolds
35*/
36
37#ifndef ATTITUDEMATH_HPP
38#define ATTITUDEMATH_HPP
39
40#include "core/Matrix.hpp"
41#include "core/clockwerkerrors.h"
42#include "core/matrixmath.hpp"
43#include "core/vectormath.hpp"
44#include "DCM.hpp"
45#include "Quaternion.hpp"
46#include "Euler321.hpp"
47#include "MRP.hpp"
48
49namespace clockwerk {
50
51 /// ------------------------------------------------------------------------------------------------------
52 /// Operator overloads -- NOTE: May be less efficient than equivalent PBR function in some cases due to
53 /// return by value. Where overload is less efficient, it is explicitly noted.
54 /// ------------------------------------------------------------------------------------------------------
55 /// @brief Overload of DCM multiplication - Two DCMs
56 /// @note Returns value -- less efficient in some cases
57 template<typename T>
58 DCM<T> operator*(const DCM<T> &A, const DCM<T> &B) {
59 DCM<T> result;
60 multiply(A, B, result);
61 return result;
62 }
63 /// @brief Overload of Quaternion multiplication - Two Quaternions
64 /// @note Returns value -- less efficient in some cases
65 /// @note TODO: Update with more efficient multiplication rather than using DCM
66 template<typename T>
67 Quaternion<T> operator*(const Quaternion<T> &a, const Quaternion<T> &b) {
68 /// Call our function to add two matrices and return the result
69 DCM<T> result;
70 multiply(a.toDCM(), b.toDCM(), result);
71 return result.toQuaternion();
72 }
73 /// @brief Overload of Euler321 multiplication - Two Euler321s
74 /// @note Returns value -- less efficient in some cases
75 /// @note TODO: Update with more efficient multiplication rather than using DCM
76 template<typename T>
77 MRP<T> operator*(const Euler321<T> &a, const Euler321<T> &b) {
78 DCM<T> result;
79 multiply(a.toDCM(), b.toDCM(), result);
80 return result.toEuler321();
81 }
82 /// @brief Overload of MRP multiplication - Two MRPs
83 /// @note Returns value -- less efficient in some cases
84 /// @note TODO: Update with more efficient multiplication rather than using DCM
85 template<typename T>
86 MRP<T> operator*(const MRP<T> &a, const MRP<T> &b) {
87 DCM<T> result;
88 multiply(a.toDCM(), b.toDCM(), result);
89 return result.toMRP();
90 }
91
92 /// @brief Attitude rotation of vector via DCM
93 /// @note Returns value -- less efficient in some cases
94 template<typename T>
95 CartesianVector<T, 3> operator*(const DCM<T> &A, const CartesianVector<T, 3> &b) {
96 /// Call our function to add two matrices and return the result
97 CartesianVector<T, 3> result;
98 multiply(A, b, result);
99 return result;
100 }
101 /// @brief Attitude rotation of vector via Quaternion
102 /// @note Returns value -- less efficient in some cases
103 template<typename T>
104 CartesianVector<T, 3> operator*(const Quaternion<T> &a, const CartesianVector<T, 3> &b) {
105 /// Call our function to add two matrices and return the result
106 CartesianVector<T, 3> result;
107 multiply(a.toDCM(), b, result);
108 return result;
109 }
110 /// @brief Attitude rotation of vector via Euler321
111 /// @note Returns value -- less efficient in some cases
112 template<typename T>
113 CartesianVector<T, 3> operator*(const Euler321<T> &a, const CartesianVector<T, 3> &b) {
114 /// Call our function to add two matrices and return the result
115 CartesianVector<T, 3> result;
116 multiply(a.toDCM(), b, result);
117 return result;
118 }
119 /// @brief Attitude rotation of vector via MRP
120 /// @note Returns value -- less efficient in some cases
121 template<typename T>
122 CartesianVector<T, 3> operator*(const MRP<T> &a, const CartesianVector<T, 3> &b) {
123 /// Call our function to add two matrices and return the result
124 CartesianVector<T, 3> result;
125 multiply(a.toDCM(), b, result);
126 return result;
127 }
128
129}
130
131#endif
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
Class defining a direction cosine matrix inherited from Matrix.
Definition DCM.hpp:71