Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
matrixutils.h
Go to the documentation of this file.
1 
18 #ifndef ION_MATH_MATRIXUTILS_H_
19 #define ION_MATH_MATRIXUTILS_H_
20 
26 
27 #include "ion/math/matrix.h"
28 #include "ion/math/utils.h"
29 #include "ion/math/vector.h"
30 
31 namespace ion {
32 namespace math {
33 
35 
38 
39 
40 namespace internal {
41 
44 template <int Dimension, typename T, typename VectorType>
46  const VectorType& v) {
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];
51  }
52  return result;
53 }
54 
55 } // namespace internal
56 
58 
61 
62 
64 template <int Dimension, typename T>
66  Matrix<Dimension, T> result;
67  for (int row = 0; row < Dimension; ++row) {
68  for (int col = 0; col < Dimension; ++col)
69  result(row, col) = m(col, row);
70  }
71  return result;
72 }
73 
76 template <int Dimension, typename T>
78  const Vector<Dimension, T>& v) {
80 }
81 
84 template <int Dimension, typename T>
86  const Point<Dimension, T>& p) {
88 }
89 
91 template <int Dimension, typename T>
93  Vector<Dimension, T> result;
94  for (int col = 0; col < Dimension; ++col)
97  result[col] = m(row, col);
98  return result;
99 }
100 
102 template <int Dimension, typename T>
104  Vector<Dimension, T> result;
105  for (int row = 0; row < Dimension; ++row)
108  result[row] = m(row, col);
109  return result;
110 }
111 
114 template <int Dimension, typename T> ION_API
115 T Determinant(const Matrix<Dimension, T>& m);
116 
119 template <int Dimension, typename T> ION_API
120 Matrix<Dimension, T> CofactorMatrix(const Matrix<Dimension, T>& m);
121 
126 template <int Dimension, typename T> ION_API
127 Matrix<Dimension, T> AdjugateWithDeterminant(
128  const Matrix<Dimension, T>& m, T* determinant);
129 
133 template <int Dimension, typename T>
135  return AdjugateWithDeterminant<Dimension, T>(m, static_cast<T*>(NULL));
136 }
137 
142 template <int Dimension, typename T> ION_API
143 Matrix<Dimension, T> InverseWithDeterminant(
144  const Matrix<Dimension, T>& m, T* determinant);
145 
149 template <int Dimension, typename T>
151  return InverseWithDeterminant<Dimension, T>(m, static_cast<T*>(NULL));
152 }
153 
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)
161  return false;
162  }
163  }
164  return true;
165 }
166 
170 template <int Dimension, typename T>
171 bool MatrixAlmostOrthogonal(const Matrix<Dimension, T>& m, T tolerance);
172 
176 template <typename T>
177 inline static void ScaleTranslationComponent(Matrix<4, T>* matrix, T scale) {
178  (*matrix)(0, 3) *= scale;
179  (*matrix)(1, 3) *= scale;
180  (*matrix)(2, 3) *= scale;
181 }
182 
183 } // namespace math
184 } // namespace ion
185 
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...
Definition: matrixutils.cc:237
Vector< Dimension, T > Row(const Matrix< Dimension, T > &m, int row)
Returns a particular row of a matrix as a vector.
Definition: matrixutils.h:92
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...
Definition: matrixutils.cc:257
Vector< Dimension, T > Column(const Matrix< Dimension, T > &m, int col)
Returns a particular column of a matrix as a vector.
Definition: matrixutils.h:103
The Matrix class defines a square N-dimensional matrix.
Definition: matrix.h:35
T Determinant(const Matrix< Dimension, T > &m)
Public functions.
Definition: matrixutils.cc:227
Matrix< Dimension, T > CofactorMatrix(const Matrix< Dimension, T > &m)
Returns the signed cofactor matrix (adjunct) of the matrix.
Definition: matrixutils.cc:232
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...
Definition: matrixutils.h:77
Vector.
Definition: vector.h:180
Matrix< Dimension, T > InverseWithDeterminant(const Matrix< Dimension, T > &m, T *determinant)
Returns the inverse of the matrix.
Definition: matrixutils.cc:243
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...
Definition: matrixutils.h:45
Point.
Definition: vector.h:296
Matrix< Dimension, T > Inverse(const Matrix< Dimension, T > &m)
Returns the inverse of the matrix.
Definition: matrixutils.h:150
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...
Definition: matrixutils.h:134
const T Abs(const T &val)
Returns the absolute value of a number in a type-safe way.
Definition: utils.h:42
Vector2d scale
Definition: coretextfont.mm:63
Matrix< Dimension, T > Transpose(const Matrix< Dimension, T > &m)
Public functions.
Definition: matrixutils.h:65