Ion: math/matrixutils.h Source File
18 #ifndef ION_MATH_MATRIXUTILS_H_
19 #define ION_MATH_MATRIXUTILS_H_
40 namespace internal {
44 template <int Dimension, typename T, typename VectorType>
47 VectorType result = VectorType::Zero();
48 for (int row = 0; row < Dimension; ++row) {
49 for (int col = 0; col < Dimension; ++col)
50 result[row] += m(row, col) * v[col];
64 template <int Dimension, typename T>
67 for (int row = 0; row < Dimension; ++row) {
68 for (int col = 0; col < Dimension; ++col)
69 result(row, col) = m(col, row);
76 template <int Dimension, typename T>
84 template <int Dimension, typename T>
91 template <int Dimension, typename T>
94 for (int col = 0; col < Dimension; ++col)
102 template <int Dimension, typename T>
105 for (int row = 0; row < Dimension; ++row)
108 result[row] = m(row, col);
114 template <int Dimension, typename T> ION_API
115 T Determinant(const Matrix<Dimension, T>& m);
119 template <int Dimension, typename T> ION_API
120 Matrix<Dimension, T> CofactorMatrix(const Matrix<Dimension, T>& m);
126 template <int Dimension, typename T> ION_API
128 const Matrix<Dimension, T>& m, T* determinant);
133 template <int Dimension, typename T>
135 return AdjugateWithDeterminant<Dimension, T>(m, static_cast<T*>(NULL));
142 template <int Dimension, typename T> ION_API
144 const Matrix<Dimension, T>& m, T* determinant);
149 template <int Dimension, typename T>
151 return InverseWithDeterminant<Dimension, T>(m, static_cast<T*>(NULL));
155 template <int Dimension, typename T>
156 static bool MatricesAlmostEqual(const Matrix<Dimension, T>& m0,
157 const Matrix<Dimension, T>& m1, T tolerance) {
158 for (int row = 0; row < Dimension; ++row) {
159 for (int col = 0; col < Dimension; ++col) {
160 if (Abs(m0(row, col) - m1(row, col)) > tolerance)
170 template <int Dimension, typename T>
177 inline static void ScaleTranslationComponent(Matrix<4, T>* matrix, T scale) {
186 #endif // ION_MATH_MATRIXUTILS_H_
Matrix< Dimension, T > AdjugateWithDeterminant(const Matrix< Dimension, T > &m, T *determinant)
Returns the adjugate of the matrix, which is defined as the transpose of the cofactor matrix...
Vector< Dimension, T > Row(const Matrix< Dimension, T > &m, int row)
Returns a particular row of a matrix as a vector.
bool MatrixAlmostOrthogonal(const Matrix< Dimension, T > &m, T tolerance)
Returns true if the dot product of all column vector pairs in the matrix is less than a provided tole...
Vector< Dimension, T > Column(const Matrix< Dimension, T > &m, int col)
Returns a particular column of a matrix as a vector.
The Matrix class defines a square N-dimensional matrix.
T Determinant(const Matrix< Dimension, T > &m)
Public functions.
Matrix< Dimension, T > CofactorMatrix(const Matrix< Dimension, T > &m)
Returns the signed cofactor matrix (adjunct) of the matrix.
Vector< Dimension, T > operator*(const Matrix< Dimension, T > &m, const Vector< Dimension, T > &v)
Multiplies a Matrix and a column Vector of the same Dimension to produce another column Vector...
Matrix< Dimension, T > InverseWithDeterminant(const Matrix< Dimension, T > &m, T *determinant)
Returns the inverse of the matrix.
VectorType MultiplyMatrixAndVector(const Matrix< Dimension, T > &m, const VectorType &v)
Multiplies a matrix and some type of column vector (Vector or Point) to produce another column vector...
Matrix< Dimension, T > Inverse(const Matrix< Dimension, T > &m)
Returns the inverse of the matrix.
Matrix< Dimension, T > Adjugate(const Matrix< Dimension, T > &m)
Returns the adjugate of the matrix, which is defined as the transpose of the cofactor matrix...
const T Abs(const T &val)
Returns the absolute value of a number in a type-safe way.
Matrix< Dimension, T > Transpose(const Matrix< Dimension, T > &m)
Public functions.