8#ifndef SEN_LIBS_SRC_DR_MAT3_H
9#define SEN_LIBS_SRC_DR_MAT3_H
20#include <initializer_list>
23#define INNER_PRODUCT(a, b, r, c) \
24 ((a).v_[r][0] * (b).v_[0][c]) + ((a).v_[r][1] * (b).v_[1][c]) + ((a).v_[r][2] * (b).v_[2][c])
27#define SET_ROW(row, v1, v2, v3) \
28 v_[(row)][0] = (v1); \
29 v_[(row)][1] = (v2); \
48 Mat3(std::initializer_list<std::initializer_list<T>> list);
121 for (
const auto& row: list)
123 for (
const auto& elem: row)
142 return {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
148 const auto psi = eulerAngles.
getX();
149 const auto theta = eulerAngles.
getY();
150 const auto phi = eulerAngles.
getZ();
152 const auto cosPsi = cos(psi);
153 const auto cosTheta = cos(theta);
154 const auto cosPhi = cos(phi);
155 const auto sinPsi = sin(psi);
156 const auto sinTheta = sin(theta);
157 const auto sinPhi = sin(phi);
158 const auto sinPhiTimesSinTheta = sinPhi * sinTheta;
159 const auto cosPhiTimesSinTheta = cosPhi * sinTheta;
163 result(0, 0) = cosTheta * cosPsi;
164 result(0, 1) = cosTheta * sinPsi;
165 result(0, 2) = -sinTheta;
166 result(1, 0) = sinPhiTimesSinTheta * cosPsi - cosPhi * sinPsi;
167 result(1, 1) = sinPhiTimesSinTheta * sinPsi + cosPhi * cosPsi;
168 result(1, 2) = sinPhi * cosTheta;
169 result(2, 0) = cosPhiTimesSinTheta * cosPsi + sinPhi * sinPsi;
170 result(2, 1) = cosPhiTimesSinTheta * sinPsi - sinPhi * cosPsi;
171 result(2, 2) = cosPhi * cosTheta;
180 const auto psi = eulerAngles.
getX();
181 const auto theta = eulerAngles.
getY();
182 const auto phi = eulerAngles.
getZ();
184 const auto cosPsi = cos(psi);
185 const auto cosTheta = cos(theta);
186 const auto cosPhi = cos(phi);
187 const auto sinPsi = sin(psi);
188 const auto sinTheta = sin(theta);
189 const auto sinPhi = sin(phi);
190 const auto sinPhiTimesSinTheta = sinPhi * sinTheta;
191 const auto cosPhiTimesSinTheta = cosPhi * sinTheta;
195 result(0, 0) = cosTheta * cosPsi;
196 result(1, 0) = cosTheta * sinPsi;
197 result(2, 0) = -sinTheta;
198 result(0, 1) = sinPhiTimesSinTheta * cosPsi - cosPhi * sinPsi;
199 result(1, 1) = sinPhiTimesSinTheta * sinPsi + cosPhi * cosPsi;
200 result(2, 1) = sinPhi * cosTheta;
201 result(0, 2) = cosPhiTimesSinTheta * cosPsi + sinPhi * sinPsi;
202 result(1, 2) = cosPhiTimesSinTheta * sinPsi - sinPhi * cosPsi;
203 result(2, 2) = cosPhi * cosTheta;
212 const auto wx = omega.
getX();
213 const auto wy = omega.
getY();
214 const auto wz = omega.
getZ();
215 const auto wxwy = wx * wy;
216 const auto wxwz = wx * wz;
217 const auto wywz = wy * wz;
221 result(0, 0) = wx * wx;
225 result(1, 1) = wy * wy;
229 result(2, 2) = wz * wz;
238 const auto wx = omega.
getX();
239 const auto wy = omega.
getY();
240 const auto wz = omega.
getZ();
277 v_[0][0] = value.v_[0][0];
278 v_[0][1] = value.v_[1][0];
279 v_[0][2] = value.v_[2][0];
280 v_[1][0] = value.v_[0][1];
281 v_[1][1] = value.v_[1][1];
282 v_[1][2] = value.v_[2][1];
283 v_[2][0] = value.v_[0][2];
284 v_[2][1] = value.v_[1][2];
285 v_[2][2] = value.v_[2][2];
319 for (
u32 col = 0; col < 3U; ++col)
324 v_[0][col] = temp[0];
325 v_[1][col] = temp[1];
326 v_[2][col] = temp[2];
336 for (
u32 row = 0; row < 3U; ++row)
341 SET_ROW(row, temp[0], temp[1], temp[2])
349 v_[0][0] * vec.getX() + v_[1][0] * vec.getY() + v_[2][0] * vec.getZ(),
350 v_[0][1] * vec.getX() + v_[1][1] * vec.getY() + v_[2][1] * vec.getZ(),
351 v_[0][2] * vec.getX() + v_[1][2] * vec.getY() + v_[2][2] * vec.getZ(),
358 return {v_[0][0] * vec.getX() + v_[0][1] * vec.getY() + v_[0][2] * vec.getZ(),
359 v_[1][0] * vec.getX() + v_[1][1] * vec.getY() + v_[1][2] * vec.getZ(),
360 v_[2][0] * vec.getX() + v_[2][1] * vec.getY() + v_[2][2] * vec.getZ()};
373 result.
mult(*
this, other);
382 for (
u32 i = 0; i < 3U; ++i)
384 for (
u32 j = 0; j < 3U; ++j)
386 result(i, j) = v_[i][j] * scalar;
397 for (
u32 i = 0; i < 3U; ++i)
399 for (
u32 j = 0; j < 3U; ++j)
401 result(i, j) = v_[i][j] + other(i, j);
Handles all mathematical ops involving 3D Matrices.
Definition mat3.h:39
Mat3 operator*(const Mat3 &other) const noexcept
Operator for post-multiplying the matrix by another matrix.
Definition mat3.h:370
T & operator()(u32 row, u32 col)
Allows read/write access to the elements of the matrix.
Definition mat3.h:258
T operator()(u32 row, u32 col) const
Allows read-only access to the elements of the matrix.
Definition mat3.h:264
static Mat3 makeOmegaOmegaTranspose(const Vec3d &omega)
Returns the matrix generated when multiplying the angular velocity vector by its transpose.
Definition mat3.h:210
void preMult(const Mat3 &other)
Pre-multiplies the matrix given as argument to the current instance.
Definition mat3.h:314
Mat3 operator*(T scalar) const noexcept
Operator for multiplying the matrix by a constant.
Definition mat3.h:378
void mult(const Mat3 &lhs, const Mat3 &rhs)
Performs a matrix multiplication and stores the result in the current instance.
Definition mat3.h:289
void transpose(const Mat3 &value)
Transforms a matrix into its transpose.
Definition mat3.h:270
static Mat3 makeIdentity()
Constructs an identity matrix.
Definition mat3.h:140
void postMult(const Mat3 &other)
Post-multiplies the matrix given as argument to the current instance.
Definition mat3.h:331
static Mat3 makeFromEulerYPB(const Vec3d &eulerAngles)
Returns the world to body transformation matrix given the Euler angles.
Definition mat3.h:146
Vec3< T > operator*(const Vec3< T > &vec) const noexcept
Operator for post-multiplying the matrix by a vector.
Definition mat3.h:364
Vec3< T > postMult(const Vec3< T > &vec) const noexcept
Post-multiplies the vector given as argument to the current instance.
Definition mat3.h:356
static Mat3 makeSkewMatrix(const Vec3d &omega)
Returns the skew matrix given an angular velocity.
Definition mat3.h:236
static Mat3 makeTransposedFromEulerYPB(const Vec3d &eulerAngles)
Returns the world to body transformation matrix given the Euler angles.
Definition mat3.h:178
Mat3 operator+(const Mat3 &other) const noexcept
Operator for summing the matrix with another matrix.
Definition mat3.h:393
Mat3(std::initializer_list< std::initializer_list< T > > list)
Initializer list constructor.
Definition mat3.h:117
Vec3< T > preMult(const Vec3< T > &vec) const noexcept
Pre-multiplies the vector given as argument to the current instance.
Definition mat3.h:346
Handles all mathematical ops involving 3D Vectors.
Definition vec3.h:24
T getY() const noexcept
Definition vec3.h:190
T getX() const noexcept
Definition vec3.h:184
T getZ() const noexcept
Definition vec3.h:196
uint32_t u32
Definition numbers.h:25
#define SET_ROW(row, v1, v2, v3)
Definition mat3.h:27
#define INNER_PRODUCT(a, b, r, c)
Definition mat3.h:23
Definition iterator_adapters.h:16
Mat3< f32 > Mat3f
Definition mat3.h:109
Mat3< f64 > Mat3d
Definition mat3.h:110
Vec3< f64 > Vec3d
Definition vec3.h:115