Go to the documentation of this file.
29 template<
int M,
int N,
typename T>
class matMxN
39 c[i][j] = (i == j) ? T(1) : T(0);
49 c[i][j] = (i == j) ? d[i] : T(0);
57 static_assert(((M2 > M) && (
N2 >=
N)) || ((M2 >= M) && (
N2 >
N)),
58 "matrix must have strictly larger dimensions");
65 static_assert(
N == 2,
"wrong #constructor arguments");
72 static_assert(
N == 3,
"wrong #constructor arguments");
73 c[0] =
x; c[1] = y; c[2] = z;
80 static_assert(
N == 4,
"wrong #constructor arguments");
81 c[0] =
x; c[1] = y; c[2] = z; c[3] = w;
120 template<
int M,
int N,
typename T>
123 for (
auto i :
xrange(
N))
if (
A[i] !=
B[i])
return false;
126 template<
int M,
int N,
typename T>
133 template<
int M,
int N,
typename T>
142 template<
int M,
int N,
typename T>
151 template<
int M,
int N,
typename T>
158 template<
int M,
int N,
typename T>
167 template<
int M,
int N,
typename T>
176 template<
int M,
int N,
typename T>
180 for (
auto i :
xrange(
N)) r +=
A[i] *
x[i];
185 template<
int M,
int N,
int O,
typename T>
189 for (
auto i :
xrange(O))
R[i] =
A *
B[i];
194 template<
int M,
int N,
typename T>
199 for (
auto j :
xrange(M)) {
210 return A[0][0] *
A[1][1] -
A[0][1] *
A[1][0];
217 return A[0][0] * (
A[1][1] *
A[2][2] -
A[1][2] *
A[2][1])
218 -
A[1][0] * (
A[0][1] *
A[2][2] -
A[0][2] *
A[2][1])
219 +
A[2][0] * (
A[0][1] *
A[1][2] -
A[0][2] *
A[1][1]);
227 T f0 =
A[2][2] *
A[3][3] -
A[3][2] *
A[2][3];
228 T f1 =
A[2][1] *
A[3][3] -
A[3][1] *
A[2][3];
229 T f2 =
A[2][1] *
A[3][2] -
A[3][1] *
A[2][2];
230 T f3 =
A[2][0] *
A[3][3] -
A[3][0] *
A[2][3];
231 T f4 =
A[2][0] *
A[3][2] -
A[3][0] *
A[2][2];
232 T f5 =
A[2][0] *
A[3][1] -
A[3][0] *
A[2][1];
234 (
A[1][2] * f3 -
A[1][3] * f4 -
A[1][0] * f0),
235 (
A[1][0] * f1 -
A[1][1] * f3 +
A[1][3] * f5),
236 (
A[1][1] * f4 -
A[1][2] * f5 -
A[1][0] * f2));
256 A[0][2] *
A[2][1] -
A[0][1] *
A[2][2],
257 A[0][1] *
A[1][2] -
A[0][2] *
A[1][1]),
259 A[0][0] *
A[2][2] -
A[0][2] *
A[2][0],
260 A[0][2] *
A[1][0] -
A[0][0] *
A[1][2]),
262 A[0][1] *
A[2][0] -
A[0][0] *
A[2][1],
263 A[0][0] *
A[1][1] -
A[0][1] *
A[1][0]));
272 T c00 =
A[2][2] *
A[3][3] -
A[3][2] *
A[2][3];
273 T c02 =
A[1][2] *
A[3][3] -
A[3][2] *
A[1][3];
274 T c03 =
A[1][2] *
A[2][3] -
A[2][2] *
A[1][3];
276 T c04 =
A[2][1] *
A[3][3] -
A[3][1] *
A[2][3];
277 T c06 =
A[1][1] *
A[3][3] -
A[3][1] *
A[1][3];
278 T c07 =
A[1][1] *
A[2][3] -
A[2][1] *
A[1][3];
280 T c08 =
A[2][1] *
A[3][2] -
A[3][1] *
A[2][2];
281 T c10 =
A[1][1] *
A[3][2] -
A[3][1] *
A[1][2];
282 T c11 =
A[1][1] *
A[2][2] -
A[2][1] *
A[1][2];
284 T c12 =
A[2][0] *
A[3][3] -
A[3][0] *
A[2][3];
285 T c14 =
A[1][0] *
A[3][3] -
A[3][0] *
A[1][3];
286 T c15 =
A[1][0] *
A[2][3] -
A[2][0] *
A[1][3];
288 T c16 =
A[2][0] *
A[3][2] -
A[3][0] *
A[2][2];
289 T c18 =
A[1][0] *
A[3][2] -
A[3][0] *
A[1][2];
290 T c19 =
A[1][0] *
A[2][2] -
A[2][0] *
A[1][2];
292 T c20 =
A[2][0] *
A[3][1] -
A[3][0] *
A[2][1];
293 T c22 =
A[1][0] *
A[3][1] -
A[3][0] *
A[1][1];
294 T c23 =
A[1][0] *
A[2][1] -
A[2][0] *
A[1][1];
318 T OneOverDeterminant =
static_cast<T
>(1) /
dot(
A[0], row0);
320 return inverse * OneOverDeterminant;
324 template<
int M,
int N,
typename T>
333 template<
int M,
int N,
typename T>
336 for (
auto j :
xrange(M)) {
338 os <<
A[i][j] <<
' ';
constexpr matMxN & operator-=(const matMxN &x)
constexpr matMxN< N, M, T > transpose(const matMxN< M, N, T > &A)
constexpr bool operator==(const matMxN< M, N, T > &A, const matMxN< M, N, T > &B)
constexpr auto xrange(T e)
constexpr T determinant(const matMxN< 2, 2, T > &A)
constexpr T sum(const vecN< N, T > &x)
constexpr matMxN< M, N, T > operator-(const matMxN< M, N, T > &A, const matMxN< M, N, T > &B)
constexpr T norm2_2(const matMxN< M, N, T > &A)
constexpr matMxN(const vecN< M, T > &x, const vecN< M, T > &y, const vecN< M, T > &z)
std::ostream & operator<<(std::ostream &os, const matMxN< M, N, T > &A)
constexpr bool operator!=(const matMxN< M, N, T > &A, const matMxN< M, N, T > &B)
constexpr matMxN(const vecN< M, T > &x, const vecN< M, T > &y, const vecN< M, T > &z, const vecN< M, T > &w)
constexpr matMxN(const vecN<(M< N ? M :N), T > &d)
constexpr matMxN(const vecN< M, T > &x, const vecN< M, T > &y)
constexpr vecN< M, T > & operator[](unsigned i)
constexpr KeyMatrixPosition x
Keyboard bindings.
constexpr matMxN< M, N, T > operator+(const matMxN< M, N, T > &A, const matMxN< M, N, T > &B)
constexpr matMxN< M, N, T > operator*(T x, const matMxN< M, N, T > &A)
constexpr matMxN & operator+=(const matMxN &x)
imat3 i3(ivec3(1, 2, 3), ivec3(4, 5, 6), ivec3(7, 8, 9))
constexpr T dot(const vecN< N, T > &x, const vecN< N, T > &y)
constexpr matMxN(const matMxN< M2, N2, T > &x)
constexpr matMxN< 2, 2, T > inverse(const matMxN< 2, 2, T > &A)
constexpr const vecN< M, T > & operator[](unsigned i) const
constexpr matMxN & operator*=(const matMxN< N, N, T > &x)
constexpr matMxN & operator*=(T x)