24 #ifndef MT_MATRIX3X3_H
25 #define MT_MATRIX3X3_H
31 #include <mt/util/assert/assert_template.h>
66 Matrix3x3(
const Scalar& xx,
const Scalar& xy,
const Scalar& xz,
67 const Scalar& yx,
const Scalar& yy,
const Scalar& yz,
68 const Scalar& zx,
const Scalar& zy,
const Scalar& zz);
93 Scalar
tdot(
size_t c,
132 void setValue(
const Scalar& xx,
const Scalar& xy,
const Scalar& xz,
133 const Scalar& yx,
const Scalar& yy,
const Scalar& yz,
134 const Scalar& zx,
const Scalar& zy,
const Scalar& zz);
159 Scalar cofac(
size_t r1,
size_t c1,
160 size_t r2,
size_t c2)
const;
180 std::ostream& operator<<(std::ostream& os,
223 const Scalar& yx,
const Scalar& yy,
const Scalar& yz,
224 const Scalar& zx,
const Scalar& zy,
const Scalar& zz)
249 m.
tdot(0, m_el[1]), m.
tdot(1, m_el[1]), m.
tdot(2, m_el[1]),
250 m.
tdot(0, m_el[2]), m.
tdot(1, m_el[2]), m.
tdot(2, m_el[2]));
260 return (m_el[0][c] * v[0] + m_el[1][c] * v[1] + m_el[2][c] * v[2]);
266 return triple((*
this)[0], (*
this)[1], (*
this)[2]);
272 return Matrix3x3(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2),
273 cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0),
274 cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1));
280 return Matrix3x3(m_el[0][0], m_el[1][0], m_el[2][0],
281 m_el[0][1], m_el[1][1], m_el[2][1],
282 m_el[0][2], m_el[1][2], m_el[2][2]);
289 const Vector3 co(cofac(1, 1, 2, 2),
294 const Scalar det((*
this)[0].dot(co));
297 const Scalar s = Scalar(1.0) / det;
298 return Matrix3x3(co[0] * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
299 co[1] * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,
300 co[2] * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s);
307 m_el[0][0] * m[0][0] + m_el[1][0] * m[1][0] + m_el[2][0] * m[2][0],
308 m_el[0][0] * m[0][1] + m_el[1][0] * m[1][1] + m_el[2][0] * m[2][1],
309 m_el[0][0] * m[0][2] + m_el[1][0] * m[1][2] + m_el[2][0] * m[2][2],
310 m_el[0][1] * m[0][0] + m_el[1][1] * m[1][0] + m_el[2][1] * m[2][0],
311 m_el[0][1] * m[0][1] + m_el[1][1] * m[1][1] + m_el[2][1] * m[2][1],
312 m_el[0][1] * m[0][2] + m_el[1][1] * m[1][2] + m_el[2][1] * m[2][2],
313 m_el[0][2] * m[0][0] + m_el[1][2] * m[1][0] + m_el[2][2] * m[2][0],
314 m_el[0][2] * m[0][1] + m_el[1][2] * m[1][1] + m_el[2][2] * m[2][1],
315 m_el[0][2] * m[0][2] + m_el[1][2] * m[1][2] + m_el[2][2] * m[2][2]);
321 return Matrix3x3(m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]),
322 m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]),
323 m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2]));
329 setValue(m_el[0][0] * v[0], m_el[0][1] * v[1], m_el[0][2] * v[2],
330 m_el[1][0] * v[0], m_el[1][1] * v[1], m_el[1][2] * v[2],
331 m_el[2][0] * v[0], m_el[2][1] * v[1], m_el[2][2] * v[2]);
340 util::Assert(n < 3, std::range_error(
"Index out of range"));
347 util::Assert(n < 3, std::range_error(
"Index out of range"));
354 (m_el[0][0] * m_el[0][0] + m_el[1][0] * m_el[1][0] + m_el[2][0] * m_el[2][0],
355 m_el[0][1] * m_el[0][1] + m_el[1][1] * m_el[1][1] + m_el[2][1] * m_el[2][1],
356 m_el[0][2] * m_el[0][2] + m_el[1][2] * m_el[1][2] + m_el[2][2] * m_el[2][2]);
362 const Scalar& yx,
const Scalar& yy,
const Scalar& yz,
363 const Scalar& zx,
const Scalar& zy,
const Scalar& zz)
379 setValue(Scalar(1.0), Scalar(0.0), Scalar(0.0),
380 Scalar(0.0), Scalar(1.0), Scalar(0.0),
381 Scalar(0.0), Scalar(0.0), Scalar(1.0));
387 inline Scalar Matrix3x3::cofac(
size_t r1,
size_t c1,
388 size_t r2,
size_t c2)
const
390 return (m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1]);
398 inline Vector3 operator*(
const Matrix3x3& m,
401 return Vector3(m[0].dot(v),
407 inline Vector3 operator*(
const Vector3& v,
410 return Vector3(m.tdot(0, v),
416 inline Matrix3x3 operator*(
const Matrix3x3& m1,
424 inline std::ostream& operator<<(std::ostream& os,
436 inline Matrix3x3 abs(
const Matrix3x3& m)
438 return Matrix3x3(abs(m[0][0]), abs(m[0][1]), abs(m[0][2]),
439 abs(m[1][0]), abs(m[1][1]), abs(m[1][2]),
440 abs(m[2][0]), abs(m[2][1]), abs(m[2][2]));
444 inline Matrix3x3 scale(
const Matrix3x3 m,
452 inline Scalar determinant(
const Matrix3x3& m)
454 return m.determinant();
458 inline Matrix3x3 adjoint(
const Matrix3x3& m)
464 inline Matrix3x3 transpose(
const Matrix3x3& m)
470 inline Matrix3x3 inverse(
const Matrix3x3& m)
476 inline Matrix3x3 transposeTimes(
const Matrix3x3& m1,
483 inline Matrix3x3 timesTranspose(
const Matrix3x3& m1,
492 #endif // MT_MATRIX3X3_H