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;
122 template<
int M,
int N,
typename T>
131 template<
int M,
int N,
typename T>
140 template<
int M,
int N,
typename T>
147 template<
int M,
int N,
typename T>
156 template<
int M,
int N,
typename T>
165 template<
int M,
int N,
typename T>
169 for (
auto i :
xrange(
N)) r +=
A[i] *
x[i];
174 template<
int M,
int N,
int O,
typename T>
178 for (
auto i :
xrange(O))
R[i] =
A *
B[i];
183 template<
int M,
int N,
typename T>
188 for (
auto j :
xrange(M)) {
199 return A[0][0] *
A[1][1] -
A[0][1] *
A[1][0];
206 return A[0][0] * (
A[1][1] *
A[2][2] -
A[1][2] *
A[2][1])
207 -
A[1][0] * (
A[0][1] *
A[2][2] -
A[0][2] *
A[2][1])
208 +
A[2][0] * (
A[0][1] *
A[1][2] -
A[0][2] *
A[1][1]);
216 T f0 =
A[2][2] *
A[3][3] -
A[3][2] *
A[2][3];
217 T f1 =
A[2][1] *
A[3][3] -
A[3][1] *
A[2][3];
218 T f2 =
A[2][1] *
A[3][2] -
A[3][1] *
A[2][2];
219 T f3 =
A[2][0] *
A[3][3] -
A[3][0] *
A[2][3];
220 T f4 =
A[2][0] *
A[3][2] -
A[3][0] *
A[2][2];
221 T f5 =
A[2][0] *
A[3][1] -
A[3][0] *
A[2][1];
223 (
A[1][2] * f3 -
A[1][3] * f4 -
A[1][0] * f0),
224 (
A[1][0] * f1 -
A[1][1] * f3 +
A[1][3] * f5),
225 (
A[1][1] * f4 -
A[1][2] * f5 -
A[1][0] * f2));
245 A[0][2] *
A[2][1] -
A[0][1] *
A[2][2],
246 A[0][1] *
A[1][2] -
A[0][2] *
A[1][1]),
248 A[0][0] *
A[2][2] -
A[0][2] *
A[2][0],
249 A[0][2] *
A[1][0] -
A[0][0] *
A[1][2]),
251 A[0][1] *
A[2][0] -
A[0][0] *
A[2][1],
252 A[0][0] *
A[1][1] -
A[0][1] *
A[1][0]));
261 T c00 =
A[2][2] *
A[3][3] -
A[3][2] *
A[2][3];
262 T c02 =
A[1][2] *
A[3][3] -
A[3][2] *
A[1][3];
263 T c03 =
A[1][2] *
A[2][3] -
A[2][2] *
A[1][3];
265 T c04 =
A[2][1] *
A[3][3] -
A[3][1] *
A[2][3];
266 T c06 =
A[1][1] *
A[3][3] -
A[3][1] *
A[1][3];
267 T c07 =
A[1][1] *
A[2][3] -
A[2][1] *
A[1][3];
269 T c08 =
A[2][1] *
A[3][2] -
A[3][1] *
A[2][2];
270 T c10 =
A[1][1] *
A[3][2] -
A[3][1] *
A[1][2];
271 T c11 =
A[1][1] *
A[2][2] -
A[2][1] *
A[1][2];
273 T c12 =
A[2][0] *
A[3][3] -
A[3][0] *
A[2][3];
274 T c14 =
A[1][0] *
A[3][3] -
A[3][0] *
A[1][3];
275 T c15 =
A[1][0] *
A[2][3] -
A[2][0] *
A[1][3];
277 T c16 =
A[2][0] *
A[3][2] -
A[3][0] *
A[2][2];
278 T c18 =
A[1][0] *
A[3][2] -
A[3][0] *
A[1][2];
279 T c19 =
A[1][0] *
A[2][2] -
A[2][0] *
A[1][2];
281 T c20 =
A[2][0] *
A[3][1] -
A[3][0] *
A[2][1];
282 T c22 =
A[1][0] *
A[3][1] -
A[3][0] *
A[1][1];
283 T c23 =
A[1][0] *
A[2][1] -
A[2][0] *
A[1][1];
307 T OneOverDeterminant =
static_cast<T
>(1) /
dot(
A[0], row0);
309 return inverse * OneOverDeterminant;
313 template<
int M,
int N,
typename T>
322 template<
int M,
int N,
typename T>
325 for (
auto j :
xrange(M)) {
327 os <<
A[i][j] <<
' ';
constexpr matMxN(const vecN< M, T > &x, const vecN< M, T > &y, const vecN< M, T > &z, const vecN< M, T > &w)
constexpr const vecN< M, T > & operator[](unsigned i) const
constexpr matMxN & operator-=(const matMxN &x)
constexpr matMxN(const vecN<(M< N ? M :N), T > &d)
constexpr matMxN & operator*=(const matMxN< N, N, T > &x)
constexpr matMxN & operator+=(const matMxN &x)
constexpr matMxN(const matMxN< M2, N2, T > &x)
constexpr bool operator==(const matMxN &) const =default
constexpr vecN< M, T > & operator[](unsigned i)
constexpr matMxN & operator*=(T x)
constexpr matMxN(const vecN< M, T > &x, const vecN< M, T > &y, const vecN< M, T > &z)
constexpr matMxN(const vecN< M, T > &x, const vecN< M, T > &y)
imat3 i3(ivec3(1, 2, 3), ivec3(4, 5, 6), ivec3(7, 8, 9))
constexpr T norm2_2(const matMxN< M, N, T > &A)
constexpr matMxN< 2, 2, T > inverse(const matMxN< 2, 2, T > &A)
constexpr T dot(const vecN< N, T > &x, const vecN< N, T > &y)
std::ostream & operator<<(std::ostream &os, const matMxN< M, N, T > &A)
constexpr matMxN< M, N, T > operator-(const matMxN< M, N, T > &A, const matMxN< M, N, T > &B)
constexpr matMxN< N, M, T > transpose(const matMxN< M, N, T > &A)
constexpr T sum(const vecN< N, T > &x)
constexpr T determinant(const matMxN< 2, 2, T > &A)
constexpr matMxN< M, N, T > operator*(T x, const matMxN< M, N, T > &A)
constexpr matMxN< M, N, T > operator+(const matMxN< M, N, T > &A, const matMxN< M, N, T > &B)
constexpr KeyMatrixPosition x
Keyboard bindings.
constexpr auto xrange(T e)