PeriDyno 1.0.0
Loading...
Searching...
No Matches
Matrix3x3.h
Go to the documentation of this file.
1#pragma once
2#include <glm/mat3x3.hpp>
3#include "Vector.h"
4#include "SquareMatrix.h"
5
6namespace dyno {
7
8 template <typename T, int Dim> class Vector;
9
10 /*
11 * SquareMatrix<T,3> are defined for C++ fundamental integers types and floating-point types
12 * Elements are stored in a column-major order
13 */
14 template <typename T>
15 class SquareMatrix<T, 3>
16 {
17 public:
18 typedef T VarType;
19
20 DYN_FUNC SquareMatrix();
21 DYN_FUNC explicit SquareMatrix(T);
22 DYN_FUNC SquareMatrix(T x00, T x01, T x02, T x10, T x11, T x12, T x20, T x21, T x22);
23 DYN_FUNC SquareMatrix(const Vector<T, 3> &row1, const Vector<T, 3> &row2, const Vector<T, 3> &row3);
24
25 DYN_FUNC SquareMatrix(const SquareMatrix<T, 3>&);
26 DYN_FUNC ~SquareMatrix();
27
28 DYN_FUNC static unsigned int rows() { return 3; }
29 DYN_FUNC static unsigned int cols() { return 3; }
30
31 DYN_FUNC T& operator() (unsigned int i, unsigned int j);
32 DYN_FUNC const T& operator() (unsigned int i, unsigned int j) const;
33
34 DYN_FUNC const Vector<T, 3> row(unsigned int i) const;
35 DYN_FUNC const Vector<T, 3> col(unsigned int i) const;
36
37 DYN_FUNC void setRow(unsigned int i, const Vector<T, 3>& vec);
38 DYN_FUNC void setCol(unsigned int j, const Vector<T, 3>& vec);
39
40 DYN_FUNC const SquareMatrix<T, 3> operator+ (const SquareMatrix<T, 3> &) const;
41 DYN_FUNC SquareMatrix<T, 3>& operator+= (const SquareMatrix<T, 3> &);
42 DYN_FUNC const SquareMatrix<T, 3> operator- (const SquareMatrix<T, 3> &) const;
43 DYN_FUNC SquareMatrix<T, 3>& operator-= (const SquareMatrix<T, 3> &);
44 DYN_FUNC const SquareMatrix<T, 3> operator* (const SquareMatrix<T, 3> &) const;
45 DYN_FUNC SquareMatrix<T, 3>& operator*= (const SquareMatrix<T, 3> &);
46 DYN_FUNC const SquareMatrix<T, 3> operator/ (const SquareMatrix<T, 3> &) const;
47 DYN_FUNC SquareMatrix<T, 3>& operator/= (const SquareMatrix<T, 3> &);
48
49 DYN_FUNC SquareMatrix<T, 3>& operator= (const SquareMatrix<T, 3> &);
50
51 DYN_FUNC bool operator== (const SquareMatrix<T, 3> &) const;
52 DYN_FUNC bool operator!= (const SquareMatrix<T, 3> &) const;
53
54 DYN_FUNC const SquareMatrix<T, 3> operator* (const T&) const;
55 DYN_FUNC SquareMatrix<T, 3>& operator*= (const T&);
56 DYN_FUNC const SquareMatrix<T, 3> operator/ (const T&) const;
57 DYN_FUNC SquareMatrix<T, 3>& operator/= (const T&);
58
59 DYN_FUNC const Vector<T, 3> operator* (const Vector<T, 3> &) const;
60
61 DYN_FUNC const SquareMatrix<T, 3> operator- (void) const;
62
63 DYN_FUNC const SquareMatrix<T, 3> transpose() const;
64 DYN_FUNC const SquareMatrix<T, 3> inverse() const;
65
66 DYN_FUNC T determinant() const;
67 DYN_FUNC T trace() const;
68 DYN_FUNC T doubleContraction(const SquareMatrix<T, 3> &) const;//double contraction
69 DYN_FUNC T frobeniusNorm() const;
70 DYN_FUNC T oneNorm() const;
71 DYN_FUNC T infNorm() const;
72
73 DYN_FUNC static const SquareMatrix<T, 3> identityMatrix();
74 DYN_FUNC static const SquareMatrix<T, 3> diagonalMatrix(const Vector<T, 3> vec);
75
76 DYN_FUNC T* getDataPtr() { return &data_[0].x; }
77
78 protected:
79 Vector<T, 3> data_[3]; //default: zero matrix
80 };
81
82 //make * operator commutative
83 template <typename S, typename T>
84 DYN_FUNC const SquareMatrix<T, 3> operator* (S scale, const SquareMatrix<T, 3> &mat)
85 {
86 return mat * scale;
87 }
88
89 template class SquareMatrix<float, 3>;
90 template class SquareMatrix<double, 3>;
91 //convenient typedefs
94
95} //end of namespace dyno
96
97#include "Matrix3x3.inl"
DYN_FUNC T * getDataPtr()
Definition Matrix3x3.h:76
Vector< T, 3 > data_[3]
Definition Matrix3x3.h:79
static DYN_FUNC unsigned int rows()
Definition Matrix3x3.h:28
static DYN_FUNC unsigned int cols()
Definition Matrix3x3.h:29
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
SquareMatrix< float, 3 > Mat3f
Definition Matrix3x3.h:92
SquareMatrix< double, 3 > Mat3d
Definition Matrix3x3.h:93
DYN_FUNC const Complex< T > operator/(S scale, const Complex< T > &complex)
Definition Complex.inl:253
DYN_FUNC const Complex< T > operator*(S scale, const Complex< T > &complex)
Definition Complex.inl:247
DYN_FUNC bool operator==(const priority_queue< T, Container, Compare > &a, const priority_queue< T, Container, Compare > &b)
DYN_FUNC bool operator!=(const priority_queue< T, Container, Compare > &a, const priority_queue< T, Container, Compare > &b)
DYN_FUNC const Complex< T > operator-(S scale, const Complex< T > &complex)
Definition Complex.inl:241
DYN_FUNC const Complex< T > operator+(S scale, const Complex< T > &complex)
Definition Complex.inl:235