Jet
v1.3.3
|
2-D matrix class. More...
#include <jet/matrix2x2.h>
Public Member Functions | |
Matrix () | |
Constructs identity matrix. More... | |
Matrix (T s) | |
Constructs constant value matrix. More... | |
Matrix (T m00, T m01, T m10, T m11) | |
template<typename U > | |
Matrix (const std::initializer_list< std::initializer_list< U >> &lst) | |
Constructs a matrix with given initializer list lst . More... | |
Matrix (const Matrix &m) | |
Constructs a matrix with input matrix. More... | |
Matrix (const T *arr) | |
void | set (T s) |
Sets whole matrix with input scalar. More... | |
void | set (T m00, T m01, T m10, T m11) |
template<typename U > | |
void | set (const std::initializer_list< std::initializer_list< U >> &lst) |
Sets this matrix with given initializer list lst . More... | |
void | set (const Matrix &m) |
Copies from input matrix. More... | |
void | set (const T *arr) |
void | setDiagonal (T s) |
Sets diagonal elements with input scalar. More... | |
void | setOffDiagonal (T s) |
Sets off-diagonal elements with input scalar. More... | |
void | setRow (size_t i, const Vector2< T > &row) |
Sets i-th row with input vector. More... | |
void | setColumn (size_t i, const Vector2< T > &col) |
Sets i-th column with input vector. More... | |
bool | isSimilar (const Matrix &m, double tol=std::numeric_limits< double >::epsilon()) const |
bool | isSquare () const |
Returns true if this matrix is a square matrix. More... | |
size_t | rows () const |
Returns number of rows of this matrix. More... | |
size_t | cols () const |
Returns number of columns of this matrix. More... | |
T * | data () |
Returns data pointer of this matrix. More... | |
const T * | data () const |
Returns constant pointer of this matrix. More... | |
Matrix | add (T s) const |
Returns this matrix + input scalar. More... | |
Matrix | add (const Matrix &m) const |
Returns this matrix + input matrix (element-wise). More... | |
Matrix | sub (T s) const |
Returns this matrix - input scalar. More... | |
Matrix | sub (const Matrix &m) const |
Returns this matrix - input matrix (element-wise). More... | |
Matrix | mul (T s) const |
Returns this matrix * input scalar. More... | |
Vector2< T > | mul (const Vector2< T > &v) const |
Returns this matrix * input vector. More... | |
Matrix | mul (const Matrix &m) const |
Returns this matrix * input matrix. More... | |
Matrix | div (T s) const |
Returns this matrix / input scalar. More... | |
Matrix | radd (T s) const |
Returns input scalar + this matrix. More... | |
Matrix | radd (const Matrix &m) const |
Returns input matrix + this matrix (element-wise). More... | |
Matrix | rsub (T s) const |
Returns input scalar - this matrix. More... | |
Matrix | rsub (const Matrix &m) const |
Returns input matrix - this matrix (element-wise). More... | |
Matrix | rmul (T s) const |
Returns input scalar * this matrix. More... | |
Matrix | rmul (const Matrix &m) const |
Returns input matrix * this matrix. More... | |
Matrix | rdiv (T s) const |
Returns input scalar / this matrix. More... | |
void | iadd (T s) |
Adds input scalar to this matrix. More... | |
void | iadd (const Matrix &m) |
Adds input matrix to this matrix (element-wise). More... | |
void | isub (T s) |
Subtracts input scalar from this matrix. More... | |
void | isub (const Matrix &m) |
Subtracts input matrix from this matrix (element-wise). More... | |
void | imul (T s) |
Multiplies input scalar to this matrix. More... | |
void | imul (const Matrix &m) |
Multiplies input matrix to this matrix. More... | |
void | idiv (T s) |
Divides this matrix with input scalar. More... | |
void | transpose () |
Transposes this matrix. More... | |
void | invert () |
Inverts this matrix. More... | |
T | sum () const |
Returns sum of all elements. More... | |
T | avg () const |
Returns average of all elements. More... | |
T | min () const |
Returns minimum among all elements. More... | |
T | max () const |
Returns maximum among all elements. More... | |
T | absmin () const |
Returns absolute minimum among all elements. More... | |
T | absmax () const |
Returns absolute maximum among all elements. More... | |
T | trace () const |
Returns sum of all diagonal elements. More... | |
T | determinant () const |
Returns determinant of this matrix. More... | |
Matrix | diagonal () const |
Returns diagonal part of this matrix. More... | |
Matrix | offDiagonal () const |
Returns off-diagonal part of this matrix. More... | |
Matrix | strictLowerTri () const |
Returns strictly lower triangle part of this matrix. More... | |
Matrix | strictUpperTri () const |
Returns strictly upper triangle part of this matrix. More... | |
Matrix | lowerTri () const |
Returns lower triangle part of this matrix (including the diagonal). More... | |
Matrix | upperTri () const |
Returns upper triangle part of this matrix (including the diagonal). More... | |
Matrix | transposed () const |
Returns transposed matrix. More... | |
Matrix | inverse () const |
Returns inverse matrix. More... | |
T | frobeniusNorm () const |
Returns Frobenius norm. More... | |
template<typename U > | |
Matrix< U, 2, 2 > | castTo () const |
Matrix & | operator= (const Matrix &m) |
Assigns input matrix. More... | |
Matrix & | operator+= (T s) |
Addition assignment with input scalar. More... | |
Matrix & | operator+= (const Matrix &m) |
Addition assignment with input matrix (element-wise). More... | |
Matrix & | operator-= (T s) |
Subtraction assignment with input scalar. More... | |
Matrix & | operator-= (const Matrix &m) |
Subtraction assignment with input matrix (element-wise). More... | |
Matrix & | operator*= (T s) |
Multiplication assignment with input scalar. More... | |
Matrix & | operator*= (const Matrix &m) |
Multiplication assignment with input matrix. More... | |
Matrix & | operator/= (T s) |
Division assignment with input scalar. More... | |
T & | operator[] (size_t i) |
Returns reference of i-th element. More... | |
const T & | operator[] (size_t i) const |
Returns constant reference of i-th element. More... | |
T & | operator() (size_t i, size_t j) |
Returns reference of (i,j) element. More... | |
const T & | operator() (size_t i, size_t j) const |
Returns constant reference of (i,j) element. More... | |
bool | operator== (const Matrix &m) const |
Returns true if is equal to m. More... | |
bool | operator!= (const Matrix &m) const |
Returns true if is not equal to m. More... | |
Static Public Member Functions | |
static Matrix | makeZero () |
Sets all matrix entries to zero. More... | |
static Matrix | makeIdentity () |
Makes all diagonal elements to 1, and other elements to 0. More... | |
static Matrix | makeScaleMatrix (T sx, T sy) |
Makes scale matrix. More... | |
static Matrix | makeScaleMatrix (const Vector2< T > &s) |
Makes scale matrix. More... | |
static Matrix | makeRotationMatrix (const T &rad) |
2-D matrix class.
This class is a row-major 2-D matrix class, which means each element of the matrix is stored in order of (0, 0), (0, 1), (1, 0) and (1, 1).
T | - Type of the element. |
jet::Matrix< T, 2, 2 >::Matrix | ( | ) |
Constructs identity matrix.
|
explicit |
Constructs constant value matrix.
jet::Matrix< T, 2, 2 >::Matrix | ( | T | m00, |
T | m01, | ||
T | m10, | ||
T | m11 | ||
) |
Constructs a matrix with input elements.
jet::Matrix< T, 2, 2 >::Matrix | ( | const std::initializer_list< std::initializer_list< U >> & | lst | ) |
Constructs a matrix with given initializer list lst
.
This constructor will build a matrix with given initializer list lst
such as
Note the initializer also has 2x2 structure.
lst | Initializer list that should be copy to the new matrix. |
jet::Matrix< T, 2, 2 >::Matrix | ( | const Matrix< T, 2, 2 > & | m | ) |
Constructs a matrix with input matrix.
|
explicit |
Constructs a matrix with input array.
T jet::Matrix< T, 2, 2 >::absmax | ( | ) | const |
Returns absolute maximum among all elements.
T jet::Matrix< T, 2, 2 >::absmin | ( | ) | const |
Returns absolute minimum among all elements.
Matrix jet::Matrix< T, 2, 2 >::add | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns this matrix + input matrix (element-wise).
Matrix jet::Matrix< T, 2, 2 >::add | ( | T | s | ) | const |
Returns this matrix + input scalar.
T jet::Matrix< T, 2, 2 >::avg | ( | ) | const |
Returns average of all elements.
Matrix<U, 2, 2> jet::Matrix< T, 2, 2 >::castTo | ( | ) | const |
size_t jet::Matrix< T, 2, 2 >::cols | ( | ) | const |
Returns number of columns of this matrix.
T* jet::Matrix< T, 2, 2 >::data | ( | ) |
Returns data pointer of this matrix.
const T* jet::Matrix< T, 2, 2 >::data | ( | ) | const |
Returns constant pointer of this matrix.
T jet::Matrix< T, 2, 2 >::determinant | ( | ) | const |
Returns determinant of this matrix.
Matrix jet::Matrix< T, 2, 2 >::diagonal | ( | ) | const |
Returns diagonal part of this matrix.
Matrix jet::Matrix< T, 2, 2 >::div | ( | T | s | ) | const |
Returns this matrix / input scalar.
T jet::Matrix< T, 2, 2 >::frobeniusNorm | ( | ) | const |
Returns Frobenius norm.
void jet::Matrix< T, 2, 2 >::iadd | ( | const Matrix< T, 2, 2 > & | m | ) |
Adds input matrix to this matrix (element-wise).
void jet::Matrix< T, 2, 2 >::iadd | ( | T | s | ) |
Adds input scalar to this matrix.
void jet::Matrix< T, 2, 2 >::idiv | ( | T | s | ) |
Divides this matrix with input scalar.
void jet::Matrix< T, 2, 2 >::imul | ( | const Matrix< T, 2, 2 > & | m | ) |
Multiplies input matrix to this matrix.
void jet::Matrix< T, 2, 2 >::imul | ( | T | s | ) |
Multiplies input scalar to this matrix.
Matrix jet::Matrix< T, 2, 2 >::inverse | ( | ) | const |
Returns inverse matrix.
void jet::Matrix< T, 2, 2 >::invert | ( | ) |
Inverts this matrix.
bool jet::Matrix< T, 2, 2 >::isSimilar | ( | const Matrix< T, 2, 2 > & | m, |
double | tol = std::numeric_limits< double >::epsilon() |
||
) | const |
Returns true if this matrix is similar to the input matrix within the given tolerance.
bool jet::Matrix< T, 2, 2 >::isSquare | ( | ) | const |
Returns true if this matrix is a square matrix.
void jet::Matrix< T, 2, 2 >::isub | ( | const Matrix< T, 2, 2 > & | m | ) |
Subtracts input matrix from this matrix (element-wise).
void jet::Matrix< T, 2, 2 >::isub | ( | T | s | ) |
Subtracts input scalar from this matrix.
Matrix jet::Matrix< T, 2, 2 >::lowerTri | ( | ) | const |
Returns lower triangle part of this matrix (including the diagonal).
|
static |
Makes all diagonal elements to 1, and other elements to 0.
|
static |
Makes rotation matrix.
|
static |
Makes scale matrix.
|
static |
Makes scale matrix.
|
static |
Sets all matrix entries to zero.
T jet::Matrix< T, 2, 2 >::max | ( | ) | const |
Returns maximum among all elements.
T jet::Matrix< T, 2, 2 >::min | ( | ) | const |
Returns minimum among all elements.
Matrix jet::Matrix< T, 2, 2 >::mul | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns this matrix * input matrix.
Vector2<T> jet::Matrix< T, 2, 2 >::mul | ( | const Vector2< T > & | v | ) | const |
Returns this matrix * input vector.
Matrix jet::Matrix< T, 2, 2 >::mul | ( | T | s | ) | const |
Returns this matrix * input scalar.
Matrix jet::Matrix< T, 2, 2 >::offDiagonal | ( | ) | const |
Returns off-diagonal part of this matrix.
bool jet::Matrix< T, 2, 2 >::operator!= | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns true if is not equal to m.
T& jet::Matrix< T, 2, 2 >::operator() | ( | size_t | i, |
size_t | j | ||
) |
Returns reference of (i,j) element.
const T& jet::Matrix< T, 2, 2 >::operator() | ( | size_t | i, |
size_t | j | ||
) | const |
Returns constant reference of (i,j) element.
Matrix& jet::Matrix< T, 2, 2 >::operator*= | ( | const Matrix< T, 2, 2 > & | m | ) |
Multiplication assignment with input matrix.
Matrix& jet::Matrix< T, 2, 2 >::operator*= | ( | T | s | ) |
Multiplication assignment with input scalar.
Matrix& jet::Matrix< T, 2, 2 >::operator+= | ( | const Matrix< T, 2, 2 > & | m | ) |
Addition assignment with input matrix (element-wise).
Matrix& jet::Matrix< T, 2, 2 >::operator+= | ( | T | s | ) |
Addition assignment with input scalar.
Matrix& jet::Matrix< T, 2, 2 >::operator-= | ( | const Matrix< T, 2, 2 > & | m | ) |
Subtraction assignment with input matrix (element-wise).
Matrix& jet::Matrix< T, 2, 2 >::operator-= | ( | T | s | ) |
Subtraction assignment with input scalar.
Matrix& jet::Matrix< T, 2, 2 >::operator/= | ( | T | s | ) |
Division assignment with input scalar.
Matrix& jet::Matrix< T, 2, 2 >::operator= | ( | const Matrix< T, 2, 2 > & | m | ) |
Assigns input matrix.
bool jet::Matrix< T, 2, 2 >::operator== | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns true if is equal to m.
T& jet::Matrix< T, 2, 2 >::operator[] | ( | size_t | i | ) |
Returns reference of i-th element.
const T& jet::Matrix< T, 2, 2 >::operator[] | ( | size_t | i | ) | const |
Returns constant reference of i-th element.
Matrix jet::Matrix< T, 2, 2 >::radd | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns input matrix + this matrix (element-wise).
Matrix jet::Matrix< T, 2, 2 >::radd | ( | T | s | ) | const |
Returns input scalar + this matrix.
Matrix jet::Matrix< T, 2, 2 >::rdiv | ( | T | s | ) | const |
Returns input scalar / this matrix.
Matrix jet::Matrix< T, 2, 2 >::rmul | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns input matrix * this matrix.
Matrix jet::Matrix< T, 2, 2 >::rmul | ( | T | s | ) | const |
Returns input scalar * this matrix.
size_t jet::Matrix< T, 2, 2 >::rows | ( | ) | const |
Returns number of rows of this matrix.
Matrix jet::Matrix< T, 2, 2 >::rsub | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns input matrix - this matrix (element-wise).
Matrix jet::Matrix< T, 2, 2 >::rsub | ( | T | s | ) | const |
Returns input scalar - this matrix.
void jet::Matrix< T, 2, 2 >::set | ( | const Matrix< T, 2, 2 > & | m | ) |
Copies from input matrix.
void jet::Matrix< T, 2, 2 >::set | ( | const std::initializer_list< std::initializer_list< U >> & | lst | ) |
Sets this matrix with given initializer list lst
.
This function will fill the matrix with given initializer list lst
such as
Note the initializer also has 2x2 structure.
lst | Initializer list that should be copy to the matrix. |
void jet::Matrix< T, 2, 2 >::set | ( | const T * | arr | ) |
Copies from input array.
void jet::Matrix< T, 2, 2 >::set | ( | T | m00, |
T | m01, | ||
T | m10, | ||
T | m11 | ||
) |
Sets this matrix with input elements.
void jet::Matrix< T, 2, 2 >::set | ( | T | s | ) |
Sets whole matrix with input scalar.
void jet::Matrix< T, 2, 2 >::setColumn | ( | size_t | i, |
const Vector2< T > & | col | ||
) |
Sets i-th column with input vector.
void jet::Matrix< T, 2, 2 >::setDiagonal | ( | T | s | ) |
Sets diagonal elements with input scalar.
void jet::Matrix< T, 2, 2 >::setOffDiagonal | ( | T | s | ) |
Sets off-diagonal elements with input scalar.
void jet::Matrix< T, 2, 2 >::setRow | ( | size_t | i, |
const Vector2< T > & | row | ||
) |
Sets i-th row with input vector.
Matrix jet::Matrix< T, 2, 2 >::strictLowerTri | ( | ) | const |
Returns strictly lower triangle part of this matrix.
Matrix jet::Matrix< T, 2, 2 >::strictUpperTri | ( | ) | const |
Returns strictly upper triangle part of this matrix.
Matrix jet::Matrix< T, 2, 2 >::sub | ( | const Matrix< T, 2, 2 > & | m | ) | const |
Returns this matrix - input matrix (element-wise).
Matrix jet::Matrix< T, 2, 2 >::sub | ( | T | s | ) | const |
Returns this matrix - input scalar.
T jet::Matrix< T, 2, 2 >::sum | ( | ) | const |
Returns sum of all elements.
T jet::Matrix< T, 2, 2 >::trace | ( | ) | const |
Returns sum of all diagonal elements.
void jet::Matrix< T, 2, 2 >::transpose | ( | ) |
Transposes this matrix.
Matrix jet::Matrix< T, 2, 2 >::transposed | ( | ) | const |
Returns transposed matrix.
Matrix jet::Matrix< T, 2, 2 >::upperTri | ( | ) | const |
Returns upper triangle part of this matrix (including the diagonal).