WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
vectormath.hpp
Go to the documentation of this file.
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/*
17Vector math header file
18-----------------------
19This file defines basic functions for mathematical operations on
20the vector 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
25Author: Alex Reynolds
26*/
27
28#ifndef CORE_VECTORMATH_HPP
29#define CORE_VECTORMATH_HPP
30
31#include "Matrix.hpp"
32#include "CartesianVector.hpp"
33#include "clockwerkerrors.h"
34#include "matrixmath.hpp"
35
36namespace clockwerk {
37
43 template<uint32 L>
44 void dot(const CartesianVector<L> &a, const CartesianVector<L> &b, floating_point &result) {
45 result = 0.0;
46 for(uint32 i = 0; i < L; i++) {
47 result += a.values[i][0]*b.values[i][0];
48 }
49 }
50 template<uint32 L>
51 floating_point dot(const CartesianVector<L> &a, const CartesianVector<L> &b) {
52 floating_point tmp;
53 dot(a, b, tmp);
54 return tmp;
55 }
56
62 void cross(CartesianVector<3> a, CartesianVector<3> b, CartesianVector<3> &result);
63 CartesianVector<3> cross(const CartesianVector<3> &a, const CartesianVector<3> &b);
64
69 void tilde(const CartesianVector<3> &v, Matrix<3, 3> &t);
70 Matrix<3, 3> tilde(const CartesianVector<3> &v);
71
78 template<uint32 R1, uint32 C1R2>
82 multiply(A, B, result);
83 return result;
84 }
85
88 template<uint32 L>
89 CartesianVector<L> operator*(const floating_point &a, const CartesianVector<L> &A) {
91 CartesianVector<L> result;
92 multiply(a, A, result);
93 return result;
94 }
95 template<uint32 L>
96 CartesianVector<L> operator*(const CartesianVector<L> &A, const floating_point &a) {
98 CartesianVector<L> result;
99 multiply(a, A, result);
100 return result;
101 }
102
105 template<uint32 L>
108 CartesianVector<L> result;
109 eAdd(A, B, result);
110 return result;
111 }
112
115 template<uint32 L>
116 CartesianVector<L> operator+(const floating_point &a, const CartesianVector<L> &A) {
118 CartesianVector<L> result;
119 add(a, A, result);
120 return result;
121 }
122 template<uint32 L>
123 CartesianVector<L> operator+(const CartesianVector<L> &A, const floating_point &a) {
125 CartesianVector<L> result;
126 add(a, A, result);
127 return result;
128 }
129
131 template<uint32 L>
134 CartesianVector<L> result;
135 eSubtract(A, B, result);
136 return result;
137 }
138
139}
140
141#endif
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
Matrix math implementation.
Definition Matrix.hpp:55
std::array< std::array< floating_point, C >, R > values
Definition Matrix.hpp:213
Definition CircularBuffer.hpp:28
void eSubtract(Matrix< R, C > A, Matrix< R, C > B, Matrix< R, C > &result)
Function to subtract B from A, element-wise.
Definition matrixmath.hpp:221
Matrix< R, C > operator+(const Matrix< R, C > &A, const Matrix< R, C > &B)
Overload of matrix addition - Two matrices.
Definition matrixmath.hpp:274
Matrix< R1, C2 > operator*(const Matrix< R1, C1R2 > &A, const Matrix< C1R2, C2 > &B)
Overload of matrix multiplication - Two matrices.
Definition matrixmath.hpp:247
void eAdd(const Matrix< R, C > &A, const Matrix< R, C > &B, Matrix< R, C > &result)
Function to add two matrices element-wise.
Definition matrixmath.hpp:196
void dot(const CartesianVector< L > &a, const CartesianVector< L > &b, floating_point &result)
Definition vectormath.hpp:44
void cross(CartesianVector< 3 > a, CartesianVector< 3 > b, CartesianVector< 3 > &result)
Definition vectormath.cpp:20
Matrix< R, C > operator-(const Matrix< R, C > &A, const Matrix< R, C > &B)
Returns value – less efficient in some cases.
Definition matrixmath.hpp:300
void tilde(const CartesianVector< 3 > &v, Matrix< 3, 3 > &t)
Definition vectormath.cpp:31
void add(const floating_point &a, const Matrix< R, C > &A, Matrix< R, C > &result)
Function to add a scalar to a matrix.
Definition matrixmath.hpp:171
void multiply(const Matrix< R1, C1R2 > &A, const Matrix< C1R2, C2 > &B, Matrix< R1, C2 > &result)
Function to multiply two matrices.
Definition matrixmath.hpp:58