matrixN.h 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * N dimensional matrix operations
  3. */
  4. #pragma once
  5. #include "math.h"
  6. #include <stdint.h>
  7. #include "vectorN.h"
  8. template <typename T, uint8_t N>
  9. class VectorN;
  10. template <typename T, uint8_t N>
  11. class MatrixN {
  12. friend class VectorN<T,N>;
  13. public:
  14. // constructor from zeros
  15. MatrixN<T,N>(void) {
  16. memset(v, 0, sizeof(v));
  17. }
  18. // constructor from 4 diagonals
  19. MatrixN<T,N>(const float d[N]) {
  20. memset(v, 0, sizeof(v));
  21. for (uint8_t i = 0; i < N; i++) {
  22. v[i][i] = d[i];
  23. }
  24. }
  25. // multiply two vectors to give a matrix, in-place
  26. void mult(const VectorN<T,N> &A, const VectorN<T,N> &B);
  27. // subtract B from the matrix
  28. MatrixN<T,N> &operator -=(const MatrixN<T,N> &B);
  29. // add B to the matrix
  30. MatrixN<T,N> &operator +=(const MatrixN<T,N> &B);
  31. // Matrix symmetry routine
  32. void force_symmetry(void);
  33. private:
  34. T v[N][N];
  35. };