2017-02-26 19:24:35 -04:00
|
|
|
/*
|
|
|
|
* N dimensional matrix operations
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "vectorN.h"
|
|
|
|
|
|
|
|
template <typename T, uint8_t N>
|
|
|
|
class VectorN;
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T, uint8_t N>
|
|
|
|
class MatrixN {
|
|
|
|
|
|
|
|
friend class VectorN<T,N>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor from zeros
|
2022-06-27 00:56:24 -03:00
|
|
|
MatrixN(void) {
|
2017-02-26 19:24:35 -04:00
|
|
|
memset(v, 0, sizeof(v));
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor from 4 diagonals
|
2022-06-27 00:56:24 -03:00
|
|
|
MatrixN(const float d[N]) {
|
2017-02-26 19:24:35 -04:00
|
|
|
memset(v, 0, sizeof(v));
|
|
|
|
for (uint8_t i = 0; i < N; i++) {
|
|
|
|
v[i][i] = d[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// multiply two vectors to give a matrix, in-place
|
|
|
|
void mult(const VectorN<T,N> &A, const VectorN<T,N> &B);
|
|
|
|
|
|
|
|
// subtract B from the matrix
|
|
|
|
MatrixN<T,N> &operator -=(const MatrixN<T,N> &B);
|
|
|
|
|
|
|
|
// add B to the matrix
|
|
|
|
MatrixN<T,N> &operator +=(const MatrixN<T,N> &B);
|
|
|
|
|
|
|
|
// Matrix symmetry routine
|
|
|
|
void force_symmetry(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
T v[N][N];
|
|
|
|
};
|