27#ifndef EASY3D_CORE_MAT_H
28#define EASY3D_CORE_MAT_H
33#include <easy3d/core/vec.h>
34#include <easy3d/core/constant.h>
35#include <easy3d/util/logging.h>
46 template <
typename T>
class Mat2;
47 template <
typename T>
class Mat3;
48 template <
typename T>
class Mat4;
64 template <
size_t N,
size_t M,
typename T>
92 template <
size_t rN,
size_t rM>
96 explicit Mat(
const T *m);
125 operator const T*()
const;
234 template <
size_t N,
size_t M,
typename T>
240 template <
typename T>
244 template <
typename T>
248 template <
typename T>
257 template <
typename T>
264 template <
typename T>
270 template <
typename T>
275 template <
typename T>
280 template <
typename T>
286 template <
size_t N,
typename T>
294 template <
size_t N,
typename T,
size_t A>
298 template <
size_t N,
size_t M,
typename T>
306 template <
size_t N,
typename T>
313 template <
size_t M,
size_t N,
typename T>
325 template<
size_t N,
size_t M,
typename T>
326 bool gauss_jordan_elimination(
const Mat<N, N, T> &a,
const Mat<N, M, T> &b,
Mat<N, N, T> *ainv,
Mat<N, M, T> *x);
341 template<
size_t N,
typename T>
401 template <
size_t N,
typename T>
411 template<
size_t N,
typename FT>
420 template <
size_t N,
typename FT>
430 template<
size_t N,
size_t M,
typename T>
434 template <
size_t N,
size_t M,
typename T>
437 template <
size_t N,
size_t M,
typename T>
449 template <
size_t N,
size_t M,
typename T>
451 for (
size_t i = 0; i < N; ++i) {
452 for (
size_t j = 0; j < M; ++j)
454 (*this)(i, j) = T(s);
456 (*
this)(i, j) = T(0);
461 template <
size_t N,
size_t M,
typename T>
462 template <
size_t rN,
size_t rM>
467 for (
size_t i = 0; i < N; ++i)
468 for (
size_t j = 0; j < M; ++j)
469 (*
this)(i, j) = rhs(i, j);
473 template <
size_t N,
size_t M,
typename T>
477 for (
size_t i = 0; i < N * M; ++i)
482 template <
size_t N,
size_t M,
typename T>
485 for (
size_t i = 0; i < N; ++i) {
486 for (
size_t j = 0; j < M; ++j)
497 template <
size_t N,
size_t M,
typename T>
502 for (
size_t i = 0; i < M; ++i)
503 result[i] = (*
this)(r, i);
508 template <
size_t N,
size_t M,
typename T>
513 for (
size_t i = 0; i < N; ++i)
514 result[i] = (*
this)(i, c);
519 template <
size_t N,
size_t M,
typename T>
525 for (
size_t i = 0; i < M; ++i)
526 (*
this)(r, i) = v[i];
530 template <
size_t N,
size_t M,
typename T>
536 for (
size_t i = 0; i < N; ++i)
537 (*
this)(i, c) = v[i];
541 template <
size_t N,
size_t M,
typename T>
546 for (
size_t i = 0; i < M; ++i) {
547 T tmp = (*this)(a, i);
548 (*this)(a, i) = (*
this)(b, i);
554 template <
size_t N,
size_t M,
typename T>
557 for (
size_t i = 0; i < size; ++i)
562 template <
size_t N,
size_t M,
typename T>
564 for (
size_t i = 0; i < N; ++i) {
565 for (
size_t j = 0; j < M; ++j)
567 (*this)(i, j) = T(s);
569 (*
this)(i, j) = T(0);
574 template <
size_t N,
size_t M,
typename T>
579 for (
size_t i = 0; i < N; ++i) {
580 T tmp = (*this)(i, a);
581 (*this)(i, a) = (*
this)(i, b);
587 template <
size_t N,
size_t M,
typename T>
593 template <
size_t N,
size_t M,
typename T>
599 template <
size_t N,
size_t M,
typename T>
604 #ifdef MATRIX_ROW_MAJOR
605 return m_[row * M + col];
607 return m_[col * N + row];
612 template <
size_t N,
size_t M,
typename T>
617 #ifdef MATRIX_ROW_MAJOR
618 return m_[row * M + col];
620 return m_[col * N + row];
625 template <
size_t N,
size_t M,
typename T>
628 for (
size_t i = 0; i < N * M; ++i)
629 result &= equal(m_[i], rhs[i]);
634 template <
size_t N,
size_t M,
typename T>
636 return !(*
this == rhs);
641 template <
size_t N,
size_t M,
typename T>
645 for (
size_t i = 0; i < N; ++i) {
646 for (
size_t j = 0; j < rM; ++j) {
648 for (
size_t k = 0; k < M; ++k) {
649 result(i, j) += (*this)(i, k) * rhs(k, j);
657 template <
size_t N,
size_t M,
typename T>
660 for (
size_t i = 0; i < N * M; ++i)
661 result[i] = m_[i] + rhs[i];
666 template <
size_t N,
size_t M,
typename T>
669 for (
size_t i = 0; i < N * M; ++i)
670 result[i] = m_[i] - rhs[i];
675 template <
size_t N,
size_t M,
typename T>
678 for (
size_t i = 0; i < N * M; ++i)
687 template <
size_t N,
size_t M,
typename T>
690 for (
size_t i = 0; i < N; ++i) {
692 for (
size_t j = 0; j < M; ++j) {
693 result[i] += (*this)(i, j) * rhs[j];
703 template <
size_t N,
size_t M,
typename T>
706 for (
size_t i = 0; i < N * M; ++i)
707 result[i] = m_[i] * rhs;
712 template <
size_t N,
size_t M,
typename T>
715 for (
size_t i = 0; i < N * M; ++i)
716 result[i] = m_[i] / rhs;
723 template <
size_t N,
size_t M,
typename T>
732 template <
size_t N,
size_t M,
typename T>
734 for (
size_t i = 0; i < N * M; ++i)
740 template <
size_t N,
size_t M,
typename T>
742 for (
size_t i = 0; i < N * M; ++i)
751 template <
size_t N,
size_t M,
typename T>
753 for (
size_t i = 0; i < N * M; ++i)
759 template <
size_t N,
size_t M,
typename T>
761 for (
size_t i = 0; i < N * M; ++i)
767 template <
size_t N,
size_t M,
typename T>
769 for (
size_t i = 0; i < N * M; ++i)
775 template <
size_t N,
size_t M,
typename T>
777 for (
size_t i = 0; i < N * M; ++i)
786 template <
size_t N,
size_t M,
typename T>
789 for (
size_t i = 0; i < N * M; ++i)
790 result[i] = lhs * rhs[i];
797 template <
typename T>
800 for (
size_t i = 0; i < 2; ++i) {
801 for (
size_t j = 0; j < 2; ++j) {
803 for (
size_t k = 0; k < 2; ++k) {
804 result(i, j) += lhs(i, k) * rhs(k, j);
811 template <
typename T>
814 for (
size_t i = 0; i < 3; ++i) {
815 for (
size_t j = 0; j < 3; ++j) {
817 for (
size_t k = 0; k < 3; ++k) {
818 result(i, j) += lhs(i, k) * rhs(k, j);
825 template <
typename T>
828 for (
size_t i = 0; i < 4; ++i) {
829 for (
size_t j = 0; j < 4; ++j) {
831 for (
size_t k = 0; k < 4; ++k) {
832 result(i, j) += lhs(i, k) * rhs(k, j);
842 template <
typename T>
851 template <
typename T>
861 template <
typename T>
864 for (
size_t i = 0; i < 2; ++i) {
866 for (
size_t j = 0; j < 2; ++j) {
867 result[i] += lhs(i, j) * rhs[j];
875 template <
typename T>
878 for (
size_t i = 0; i < 3; ++i) {
880 for (
size_t j = 0; j < 3; ++j) {
881 result[i] += lhs(i, j) * rhs[j];
889 template <
typename T>
892 for (
size_t i = 0; i < 4; ++i) {
894 for (
size_t j = 0; j < 4; ++j) {
895 result[i] += lhs(i, j) * rhs[j];
906 template <
size_t N,
size_t M,
typename T>
909 for (
size_t i = 0; i < N; ++i) {
910 for (
size_t j = 0; j < M; ++j) {
911 result(j, i) = m(i, j);
919 template <
size_t D,
typename T>
922 for (
size_t i = 1; i < D; ++i)
929 template <
size_t N,
typename T>
936 for (
size_t i = 0; i < N; ++i)
942 template <
typename T>
944 return m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0);
948 template <
typename T>
951 m(0, 0) * (m(1, 1) * m(2, 2) - m(2, 1) * m(1, 2)) +
952 m(0, 1) * (m(2, 0) * m(1, 2) - m(1, 0) * m(2, 2)) +
953 m(0, 2) * (m(1, 0) * m(2, 1) - m(2, 0) * m(1, 1));
957 template <
typename T>
960 m(0, 3) * m(1, 2) * m(2, 1) * m(3, 0) - m(0, 2) * m(1, 3) * m(2, 1) * m(3, 0) -
961 m(0, 3) * m(1, 1) * m(2, 2) * m(3, 0) + m(0, 1) * m(1, 3) * m(2, 2) * m(3, 0) +
962 m(0, 2) * m(1, 1) * m(2, 3) * m(3, 0) - m(0, 1) * m(1, 2) * m(2, 3) * m(3, 0) -
963 m(0, 3) * m(1, 2) * m(2, 0) * m(3, 1) + m(0, 2) * m(1, 3) * m(2, 0) * m(3, 1) +
964 m(0, 3) * m(1, 0) * m(2, 2) * m(3, 1) - m(0, 0) * m(1, 3) * m(2, 2) * m(3, 1) -
965 m(0, 2) * m(1, 0) * m(2, 3) * m(3, 1) + m(0, 0) * m(1, 2) * m(2, 3) * m(3, 1) +
966 m(0, 3) * m(1, 1) * m(2, 0) * m(3, 2) - m(0, 1) * m(1, 3) * m(2, 0) * m(3, 2) -
967 m(0, 3) * m(1, 0) * m(2, 1) * m(3, 2) + m(0, 0) * m(1, 3) * m(2, 1) * m(3, 2) +
968 m(0, 1) * m(1, 0) * m(2, 3) * m(3, 2) - m(0, 0) * m(1, 1) * m(2, 3) * m(3, 2) -
969 m(0, 2) * m(1, 1) * m(2, 0) * m(3, 3) + m(0, 1) * m(1, 2) * m(2, 0) * m(3, 3) +
970 m(0, 2) * m(1, 0) * m(2, 1) * m(3, 3) - m(0, 0) * m(1, 2) * m(2, 1) * m(3, 3) -
971 m(0, 1) * m(1, 0) * m(2, 2) * m(3, 3) + m(0, 0) * m(1, 1) * m(2, 2) * m(3, 3);
976 template <
size_t N,
typename T>
980 size_t indxc[N], indxr[N], ipiv[N];
984 for (
size_t i = 0; i < N; ++i)
987 for (
size_t i = 0; i < N; ++i) {
990 for (
size_t j = 0; j < N; ++j) {
992 for (
size_t k = 0; k < N; ++k) {
994 T element = std::abs(result(j, k));
1013 if (std::abs(result(maxc, maxc)) < epsilon<T>()) {
1014 LOG(ERROR) <<
"input matrix is singular";
1019 T rpivot = T(1) / result(maxc, maxc);
1020 result(maxc, maxc) = T(1);
1021 result.
set_row(maxc, result.
row(maxc) * rpivot);
1024 for (
size_t j = 0; j < N; ++j) {
1026 T dum = result(j, maxc);
1027 result(j, maxc) = T(0);
1028 for (
size_t k = 0; k < N; ++k)
1029 result(j, k) -= result(maxc, k) * dum;
1038 if (indxr[i] != indxc[i])
1046 template <
typename T>
1049 result(0, 0) = m(1, 1);
1050 result(0, 1) = -m(0, 1);
1051 result(1, 0) = -m(1, 0);
1052 result(1, 1) = m(0, 0);
1062 template <
typename T>
1065 result(0, 0) = (m(1, 1) * m(2, 2) - m(2, 1) * m(1, 2));
1066 result(0, 1) = -(m(0, 1) * m(2, 2) - m(0, 2) * m(2, 1));
1067 result(0, 2) = (m(0, 1) * m(1, 2) - m(0, 2) * m(1, 1));
1068 result(1, 0) = -(m(1, 0) * m(2, 2) - m(1, 2) * m(2, 0));
1069 result(1, 1) = (m(0, 0) * m(2, 2) - m(0, 2) * m(2, 0));
1070 result(1, 2) = -(m(0, 0) * m(1, 2) - m(1, 0) * m(0, 2));
1071 result(2, 0) = (m(1, 0) * m(2, 1) - m(2, 0) * m(1, 1));
1072 result(2, 1) = -(m(0, 0) * m(2, 1) - m(2, 0) * m(0, 1));
1073 result(2, 2) = (m(0, 0) * m(1, 1) - m(1, 0) * m(0, 1));
1083 template <
typename T>
1086 result(0, 0) = m(1, 2) * m(2, 3) * m(3, 1) - m(1, 3) * m(2, 2) * m(3, 1) + m(1, 3) * m(2, 1) * m(3, 2) - m(1, 1) * m(2, 3) * m(3, 2) - m(1, 2) * m(2, 1) * m(3, 3) + m(1, 1) * m(2, 2) * m(3, 3);
1087 result(0, 1) = m(0, 3) * m(2, 2) * m(3, 1) - m(0, 2) * m(2, 3) * m(3, 1) - m(0, 3) * m(2, 1) * m(3, 2) + m(0, 1) * m(2, 3) * m(3, 2) + m(0, 2) * m(2, 1) * m(3, 3) - m(0, 1) * m(2, 2) * m(3, 3);
1088 result(0, 2) = m(0, 2) * m(1, 3) * m(3, 1) - m(0, 3) * m(1, 2) * m(3, 1) + m(0, 3) * m(1, 1) * m(3, 2) - m(0, 1) * m(1, 3) * m(3, 2) - m(0, 2) * m(1, 1) * m(3, 3) + m(0, 1) * m(1, 2) * m(3, 3);
1089 result(0, 3) = m(0, 3) * m(1, 2) * m(2, 1) - m(0, 2) * m(1, 3) * m(2, 1) - m(0, 3) * m(1, 1) * m(2, 2) + m(0, 1) * m(1, 3) * m(2, 2) + m(0, 2) * m(1, 1) * m(2, 3) - m(0, 1) * m(1, 2) * m(2, 3);
1090 result(1, 0) = m(1, 3) * m(2, 2) * m(3, 0) - m(1, 2) * m(2, 3) * m(3, 0) - m(1, 3) * m(2, 0) * m(3, 2) + m(1, 0) * m(2, 3) * m(3, 2) + m(1, 2) * m(2, 0) * m(3, 3) - m(1, 0) * m(2, 2) * m(3, 3);
1091 result(1, 1) = m(0, 2) * m(2, 3) * m(3, 0) - m(0, 3) * m(2, 2) * m(3, 0) + m(0, 3) * m(2, 0) * m(3, 2) - m(0, 0) * m(2, 3) * m(3, 2) - m(0, 2) * m(2, 0) * m(3, 3) + m(0, 0) * m(2, 2) * m(3, 3);
1092 result(1, 2) = m(0, 3) * m(1, 2) * m(3, 0) - m(0, 2) * m(1, 3) * m(3, 0) - m(0, 3) * m(1, 0) * m(3, 2) + m(0, 0) * m(1, 3) * m(3, 2) + m(0, 2) * m(1, 0) * m(3, 3) - m(0, 0) * m(1, 2) * m(3, 3);
1093 result(1, 3) = m(0, 2) * m(1, 3) * m(2, 0) - m(0, 3) * m(1, 2) * m(2, 0) + m(0, 3) * m(1, 0) * m(2, 2) - m(0, 0) * m(1, 3) * m(2, 2) - m(0, 2) * m(1, 0) * m(2, 3) + m(0, 0) * m(1, 2) * m(2, 3);
1094 result(2, 0) = m(1, 1) * m(2, 3) * m(3, 0) - m(1, 3) * m(2, 1) * m(3, 0) + m(1, 3) * m(2, 0) * m(3, 1) - m(1, 0) * m(2, 3) * m(3, 1) - m(1, 1) * m(2, 0) * m(3, 3) + m(1, 0) * m(2, 1) * m(3, 3);
1095 result(2, 1) = m(0, 3) * m(2, 1) * m(3, 0) - m(0, 1) * m(2, 3) * m(3, 0) - m(0, 3) * m(2, 0) * m(3, 1) + m(0, 0) * m(2, 3) * m(3, 1) + m(0, 1) * m(2, 0) * m(3, 3) - m(0, 0) * m(2, 1) * m(3, 3);
1096 result(2, 2) = m(0, 1) * m(1, 3) * m(3, 0) - m(0, 3) * m(1, 1) * m(3, 0) + m(0, 3) * m(1, 0) * m(3, 1) - m(0, 0) * m(1, 3) * m(3, 1) - m(0, 1) * m(1, 0) * m(3, 3) + m(0, 0) * m(1, 1) * m(3, 3);
1097 result(2, 3) = m(0, 3) * m(1, 1) * m(2, 0) - m(0, 1) * m(1, 3) * m(2, 0) - m(0, 3) * m(1, 0) * m(2, 1) + m(0, 0) * m(1, 3) * m(2, 1) + m(0, 1) * m(1, 0) * m(2, 3) - m(0, 0) * m(1, 1) * m(2, 3);
1098 result(3, 0) = m(1, 2) * m(2, 1) * m(3, 0) - m(1, 1) * m(2, 2) * m(3, 0) - m(1, 2) * m(2, 0) * m(3, 1) + m(1, 0) * m(2, 2) * m(3, 1) + m(1, 1) * m(2, 0) * m(3, 2) - m(1, 0) * m(2, 1) * m(3, 2);
1099 result(3, 1) = m(0, 1) * m(2, 2) * m(3, 0) - m(0, 2) * m(2, 1) * m(3, 0) + m(0, 2) * m(2, 0) * m(3, 1) - m(0, 0) * m(2, 2) * m(3, 1) - m(0, 1) * m(2, 0) * m(3, 2) + m(0, 0) * m(2, 1) * m(3, 2);
1100 result(3, 2) = m(0, 2) * m(1, 1) * m(3, 0) - m(0, 1) * m(1, 2) * m(3, 0) - m(0, 2) * m(1, 0) * m(3, 1) + m(0, 0) * m(1, 2) * m(3, 1) + m(0, 1) * m(1, 0) * m(3, 2) - m(0, 0) * m(1, 1) * m(3, 2);
1101 result(3, 3) = m(0, 1) * m(1, 2) * m(2, 0) - m(0, 2) * m(1, 1) * m(2, 0) + m(0, 2) * m(1, 0) * m(2, 1) - m(0, 0) * m(1, 2) * m(2, 1) - m(0, 1) * m(1, 0) * m(2, 2) + m(0, 0) * m(1, 1) * m(2, 2);
1111 template <
size_t M,
size_t N,
typename T>
1120 template <
size_t N,
size_t M,
typename T>
1127 size_t indxc[N], indxr[N], ipiv[N];
1134 for (
size_t i = 0; i < N; ++i)
1137 for (
size_t i = 0; i < N; ++i) {
1140 for (
size_t j = 0; j < N; ++j) {
1142 for (
size_t k = 0; k < N; ++k) {
1144 T element = std::abs(amat(j, k));
1145 if (element >
max) {
1165 if (std::abs(amat(maxc, maxc)) < epsilon<T>())
1169 T rpivot = T(1) / amat(maxc, maxc);
1170 amat(maxc, maxc) = T(1);
1175 for (
size_t j = 0; j < N; ++j) {
1177 T dum = amat(j, maxc);
1178 amat(j, maxc) = T(0);
1179 for (
size_t k = 0; k < N; ++k)
1180 amat(j, k) -= amat(maxc, k) * dum;
1181 for (
size_t k = 0; k < M; ++k)
1182 bmat(j, k) -= bmat(maxc, k) * dum;
1191 if (indxr[i] != indxc[i])
1200 template <
size_t N,
typename T>
1212 for (
size_t i = 0; i < N; ++i) {
1215 for (
size_t j = 0; j < N; ++j) {
1216 T element = std::abs(amat(i, j));
1222 if (std::abs(
max) < min<T>())
1225 scalev[i] = T(1) /
max;
1228 for (
size_t j = 0; j < N; ++j) {
1229 for (
size_t i = 0; i < j; ++i) {
1231 for (
size_t k = 0; k < i; ++k)
1232 sum -= amat(i, k) * amat(k, j);
1238 for (
size_t i = j; i < N; ++i) {
1240 for (
size_t k = 0; k < j; ++k)
1241 sum -= amat(i, k) * amat(k, j);
1244 T dum = scalev[i] * std::abs(
sum);
1253 scalev[imax] = scalev[j];
1256 (*rowp)[j] = (T)imax;
1259 if (std::abs(amat(j, j)) < epsilon<T>())
1264 T dum = T(1) / amat(j, j);
1265 for (
size_t i = j + 1; i < N; ++i)
1276 template <
size_t N,
typename T>
1288 for (
size_t i = 0; i < N; ++i) {
1289 size_t ip = (size_t)rowp[i];
1293 result[ip] = result[i];
1295 for (
size_t j = ii - 1; j < i; ++j)
1296 sum -= alu(i, j) * result[j];
1298 else if (std::abs(
sum) > epsilon<T>()) {
1308 for (
size_t j = i + 1; j < N; ++j)
1309 sum -= alu(i, j) * result[j];
1310 result[i] =
sum / alu(i, i);
1317 template<
size_t N,
typename FT>
1320 for (
size_t j = 0; j < N; ++j) {
1322 for (
size_t k = 0; k < j; ++k) {
1324 for (
size_t i = 0; i < k; ++i)
1325 s += L(k, i) * L(j, i);
1327 L(j, k) = s = (A(j, k) - s) / L(k, k);
1329 spd = spd && (A(k, j) == A(j, k));
1333 spd = spd && (d > 0);
1335 L(j, j) = std::sqrt(d > 0 ? d : 0);
1336 for (
size_t k = j + 1; k < N; ++k)
1344 template <
size_t N,
typename FT>
1348 for (
size_t k = 0; k < N; ++k) {
1349 for (
size_t i = 0; i < k; ++i)
1350 x[k] -= x[i] * L(k, i);
1355 for (
int k = N - 1; k >= 0; --k) {
1356 for (
size_t i = k + 1; i < N; ++i)
1357 x[k] -= x[i] * L(i, k);
1362 template<
size_t N,
size_t M,
typename T>
1366 for (
size_t j = 0; j < M; ++j) {
1367 for (
size_t k = 0; k < N; ++k) {
1368 for (
size_t i = 0; i < k; ++i)
1369 X(k, j) -= X(i, j) * L(k, i);
1376 for (
size_t j = 0; j < M; ++j) {
1377 for (
int k = N - 1; k >= 0; --k) {
1378 for (
size_t i = k + 1; i < N; ++i)
1379 X(k, j) -= X(i, j) * L(i, k);
1389 template <
size_t N,
size_t M,
typename T>
inline
1391 output << std::fixed << std::setprecision(8);
1392 const char sep =
' ';
1393 for (
int i = 0; i < N; i++) {
1394 for (
int j = 0; j < M; j++) {
1395 output << sep << std::setw(7) << m(i, j);
1397 output << std::endl;
1399 output << std::resetiosflags(std::ios_base::fixed | std::ios_base::floatfield);
1405 template <
size_t N,
size_t M,
typename T>
1407 for (
int i = 0; i < N; i++) {
1408 for (
int j = 0; j < M; j++) {
1419 template<
size_t N,
typename FT>
1426 template<
size_t N,
typename FT>
1434 template <
size_t N,
size_t M,
typename T>
1436 for (
int i = 0; i < N; i++) {
1437 for (
int j = 0; j < M; j++) {
1438 if (std::isnan(m(i, j)) || std::isinf(m(i, j)))
1458 template <
typename T>
1492 explicit Mat2(
const T *m);
1526 template <
typename T>
1528 for (
size_t i = 0; i < 2; ++i) {
1529 for (
size_t j = 0; j < 2; ++j)
1531 (*this)(i, j) = T(s);
1533 (*
this)(i, j) = T(0);
1538 template <
typename T>
1540 for (
size_t i = 0; i < 4; ++i)
1541 (*this).m_[i] = rhs[i];
1545 template <
typename T>
1547 (*this)(0, 0) = rhs(0, 0); (*this)(0, 1) = rhs(0, 1);
1548 (*this)(1, 0) = rhs(1, 0); (*this)(1, 1) = rhs(1, 1);
1552 template <
typename T>
1557 (*this)(0, 0) = s00; (*this)(0, 1) = s01;
1558 (*this)(1, 0) = s10; (*this)(1, 1) = s11;
1562 template <
typename T>
1566 #ifdef MATRIX_ROW_MAJOR
1567 (*this)(0, 0) = m[0]; (*this)(0, 1) = m[1];
1568 (*this)(1, 0) = m[2]; (*this)(1, 1) = m[3];
1570 (*this)(0, 0) = m[0]; (*this)(0, 1) = m[2];
1571 (*this)(1, 0) = m[1]; (*this)(1, 1) = m[3];
1576 template <
typename T>
1578 #ifdef MATRIX_ROW_MAJOR
1579 (*this).set_row(0, x);
1580 (*this).set_row(1, y);
1582 (*this).set_col(0, x);
1583 (*this).set_col(1, y);
1588 template <
typename T>
1591 std::cos(angle), -std::sin(angle),
1592 std::sin(angle), std::cos(angle)
1597 template <
typename T>
1606 template <
typename T>
1620 template <
typename T>
class Quat;
1627 template <
typename T>
1628 class Mat3 :
public Mat<3, 3, T> {
1655 T s00, T s01, T s02,
1656 T s10, T s11, T s12,
1661 explicit Mat3(
const T *m);
1740 template <
typename T>
1742 for (
size_t i = 0; i < 3; ++i) {
1743 for (
size_t j = 0; j < 3; ++j)
1745 (*this)(i, j) = T(s);
1747 (*
this)(i, j) = T(0);
1752 template <
typename T>
1754 for (
size_t i = 0; i < 9; ++i)
1755 (*this).m_[i] = rhs[i];
1759 template <
typename T>
1761 (*this)(0, 0) = rhs(0, 0); (*this)(0, 1) = rhs(0, 1); (*this)(0, 2) = rhs(0, 2);
1762 (*this)(1, 0) = rhs(1, 0); (*this)(1, 1) = rhs(1, 1); (*this)(1, 2) = rhs(1, 2);
1763 (*this)(2, 0) = rhs(2, 0); (*this)(2, 1) = rhs(2, 1); (*this)(2, 2) = rhs(2, 2);
1767 template <
typename T>
1769 T s00, T s01, T s02,
1770 T s10, T s11, T s12,
1773 (*this)(0, 0) = s00; (*this)(0, 1) = s01; (*this)(0, 2) = s02;
1774 (*this)(1, 0) = s10; (*this)(1, 1) = s11; (*this)(1, 2) = s12;
1775 (*this)(2, 0) = s20; (*this)(2, 1) = s21; (*this)(2, 2) = s22;
1779 template <
typename T>
1783 #ifdef MATRIX_ROW_MAJOR
1784 (*this)(0, 0) = m[0]; (*this)(0, 1) = m[1]; (*this)(0, 2) = m[2];
1785 (*this)(1, 0) = m[3]; (*this)(1, 1) = m[4]; (*this)(1, 2) = m[5];
1786 (*this)(2, 0) = m[6]; (*this)(2, 1) = m[7]; (*this)(2, 2) = m[8];
1788 (*this)(0, 0) = m[0]; (*this)(0, 1) = m[3]; (*this)(0, 2) = m[6];
1789 (*this)(1, 0) = m[1]; (*this)(1, 1) = m[4]; (*this)(1, 2) = m[7];
1790 (*this)(2, 0) = m[2]; (*this)(2, 1) = m[5]; (*this)(2, 2) = m[8];
1795 template <
typename T>
1797 #ifdef MATRIX_ROW_MAJOR
1798 (*this).set_row(0, x);
1799 (*this).set_row(1, y);
1800 (*this).set_row(2, z);
1802 (*this).set_col(0, x);
1803 (*this).set_col(1, y);
1804 (*this).set_col(2, z);
1809 template <
typename T>
1811 (*this)(0, 0) = rhs(0, 1); (*this)(0, 0) = rhs(0, 1); (*this)(0, 2) = T(0);
1812 (*this)(1, 0) = rhs(1, 1); (*this)(1, 0) = rhs(1, 1); (*this)(1, 2) = T(0);
1813 (*this)(2, 0) = T(0); (*this)(2, 0) = T(0); (*this)(2, 2) = T(1);
1817 template <
typename T>
1820 for (
size_t i = 0; i < 2; i++) {
1821 for (
size_t j = 0; j < 2; j++) {
1822 mat(i, j) = (*this)(i, j);
1829 template <
typename T>
1839 template <
typename T>
1849 template <
typename T>
1851 assert(std::abs(axis.length() - 1) < epsilon<T>());
1855 T(0), -axis[2], axis[1],
1856 axis[2], T(0), -axis[0],
1857 -axis[1], axis[0], T(0)
1864 const T c = std::cos(angle);
1865 const T rc = T(1) - c;
1866 const T s = std::sin(angle);
1872 template <
typename T>
1874 const T len = axis_angle.length();
1875 return rotation(axis_angle/len, len);
1879 template <
typename T>
1882 assert(std::abs(q.
length() - 1) < epsilon<T>());
1888 m(0, 0) = 1.0 - 2.0 * (y*y + z*z); m(0, 1) = 2.0 * (x*y - w*z); m(0, 2) = 2.0 * (x*z + w*y);
1889 m(1, 0) = 2.0 * (x*y + w*z); m(1, 1) = 1.0 - 2.0 * (x*x + z*z); m(1, 2) = 2.0 * (y*z - w*x);
1890 m(2, 0) = 2.0 * (x*z - w*y); m(2, 1) = 2.0 * (y*z + w*x); m(2, 2) = 1.0 - 2.0 * (x*x + y*y);
1895 template <
typename T>
1901 rx(0, 0) = T(1); rx(0, 1) = T(0); rx(0, 2) = T(0);
1902 rx(1, 0) = T(0); rx(1, 1) = std::cos(x); rx(1, 2) = -std::sin(x);
1903 rx(2, 0) = T(0); rx(2, 1) = std::sin(x); rx(2, 2) = std::cos(x);
1906 ry(0, 0) = std::cos(y); ry(0, 1) = T(0); ry(0, 2) = std::sin(y);
1907 ry(1, 0) = T(0); ry(1, 1) = T(1); ry(1, 2) = T(0);
1908 ry(2, 0) = -std::sin(y); ry(2, 1) = T(0); ry(2, 2) = std::cos(y);
1911 rz(0, 0) = std::cos(z); rz(0, 1) = -std::sin(z); rz(0, 2) = T(0);
1912 rz(1, 0) = std::sin(z); rz(1, 1) = std::cos(z); rz(1, 2) = T(0);
1913 rz(2, 0) = T(0); rz(2, 1) = T(0); rz(2, 2) = T(1);
1916 case 123:
return rz * ry * rx;
1917 case 132:
return ry * rz * rx;
1918 case 213:
return rz * rx * ry;
1919 case 231:
return rx * rz * ry;
1920 case 312:
return ry * rx * rz;
1921 case 321:
return rx * ry * rz;
1923 LOG(ERROR) <<
"invalid rotation order";
1924 return rx * rz * ry;
1939 template <
typename T>
1961 T s00, T s01, T s02, T s03,
1962 T s10, T s11, T s12, T s13,
1963 T s20, T s21, T s22, T s23,
1964 T s30, T s31, T s32, T s33
2062 template <
typename T>
2064 for (
size_t i = 0; i < 4; ++i) {
2065 for (
size_t j = 0; j < 4; ++j)
2067 (*this)(i, j) = T(s);
2069 (*
this)(i, j) = T(0);
2074 template <
typename T>
2076 for (
size_t i = 0; i < 16; ++i)
2077 (*this).m_[i] = rhs[i];
2081 template <
typename T>
2083 T s00, T s01, T s02, T s03,
2084 T s10, T s11, T s12, T s13,
2085 T s20, T s21, T s22, T s23,
2086 T s30, T s31, T s32, T s33
2088 (*this)(0, 0) = s00; (*this)(0, 1) = s01; (*this)(0, 2) = s02; (*this)(0, 3) = s03;
2089 (*this)(1, 0) = s10; (*this)(1, 1) = s11; (*this)(1, 2) = s12; (*this)(1, 3) = s13;
2090 (*this)(2, 0) = s20; (*this)(2, 1) = s21; (*this)(2, 2) = s22; (*this)(2, 3) = s23;
2091 (*this)(3, 0) = s30; (*this)(3, 1) = s31; (*this)(3, 2) = s32; (*this)(3, 3) = s33;
2095 template <
typename T>
2099 #ifdef MATRIX_ROW_MAJOR
2100 (*this)(0, 0) = m[0]; (*this)(0, 1) = m[1]; (*this)(0, 2) = m[2]; (*this)(0, 3) = m[3];
2101 (*this)(1, 0) = m[4]; (*this)(1, 1) = m[5]; (*this)(1, 2) = m[6]; (*this)(1, 3) = m[7];
2102 (*this)(2, 0) = m[8]; (*this)(2, 1) = m[9]; (*this)(2, 2) = m[10]; (*this)(2, 3) = m[11];
2103 (*this)(3, 0) = m[12]; (*this)(3, 1) = m[13]; (*this)(3, 2) = m[14]; (*this)(3, 3) = m[15];
2105 (*this)(0, 0) = m[0]; (*this)(0, 1) = m[4]; (*this)(0, 2) = m[8]; (*this)(0, 3) = m[12];
2106 (*this)(1, 0) = m[1]; (*this)(1, 1) = m[5]; (*this)(1, 2) = m[9]; (*this)(1, 3) = m[13];
2107 (*this)(2, 0) = m[2]; (*this)(2, 1) = m[6]; (*this)(2, 2) = m[10]; (*this)(2, 3) = m[14];
2108 (*this)(3, 0) = m[3]; (*this)(3, 1) = m[7]; (*this)(3, 2) = m[11]; (*this)(3, 3) = m[15];
2113 template <
typename T>
2121 #ifdef MATRIX_ROW_MAJOR
2122 (*this).set_row(0, x);
2123 (*this).set_row(1, y);
2124 (*this).set_row(2, z);
2125 (*this).set_row(3, w);
2127 (*this).set_col(0, x);
2128 (*this).set_col(1, y);
2129 (*this).set_col(2, z);
2130 (*this).set_col(3, w);
2135 template <
typename T>
2137 (*this)(0, 0) = rhs(0, 0); (*this)(0, 1) = rhs(0, 1); (*this)(0, 2) = rhs(0, 2); (*this)(0, 3) = T(0);
2138 (*this)(1, 0) = rhs(1, 0); (*this)(1, 1) = rhs(1, 1); (*this)(1, 2) = rhs(1, 2); (*this)(1, 3) = T(0);
2139 (*this)(2, 0) = rhs(2, 0); (*this)(2, 1) = rhs(2, 1); (*this)(2, 2) = rhs(2, 2); (*this)(2, 3) = T(0);
2140 (*this)(3, 0) = T(0); (*this)(3, 1) = T(0); (*this)(3, 2) = T(0); (*this)(3, 3) = T(1);
2144 template <
typename T>
2147 for (
size_t i = 0; i < 3; i++) {
2148 for (
size_t j = 0; j < 3; j++) {
2149 mat(i, j) = (*this)(i, j);
2156 template <
typename T>
2158 assert(std::abs(rot.
length() - 1) < epsilon<T>());
2164 r(0, 0) = r(0, 0) * s[0]; r(0, 1) = r(0, 1) * s[1]; r(0, 2) = r(0, 2) * s[2];
2165 r(1, 0) = r(1, 0) * s[0]; r(1, 1) = r(1, 1) * s[1]; r(1, 2) = r(1, 2) * s[2];
2166 r(2, 0) = r(2, 0) * s[0]; r(2, 1) = r(2, 1) * s[1]; r(2, 2) = r(2, 2) * s[2];
2169 (*this)(0, 0) = r(0, 0); (*this)(0, 1) = r(0, 1); (*this)(0, 2) = r(0, 2); (*this)(0, 3) = t[0];
2170 (*this)(1, 0) = r(1, 0); (*this)(1, 1) = r(1, 1); (*this)(1, 2) = r(1, 2); (*this)(1, 3) = t[1];
2171 (*this)(2, 0) = r(2, 0); (*this)(2, 1) = r(2, 1); (*this)(2, 2) = r(2, 2); (*this)(2, 3) = t[2];
2172 (*this)(3, 0) = T(0); (*this)(3, 1) = T(0); (*this)(3, 2) = T(0); (*this)(3, 3) = T(1);
2176 template <
typename T>
2179 s, T(0), T(0), T(0),
2180 T(0), s, T(0), T(0),
2181 T(0), T(0), s, T(0),
2182 T(0), T(0), T(0), T(1)
2187 template <
typename T>
2190 x, T(0), T(0), T(0),
2191 T(0), y, T(0), T(0),
2192 T(0), T(0), z, T(0),
2198 template <
typename T>
2201 s.x, T(0), T(0), T(0),
2202 T(0), s.y, T(0), T(0),
2203 T(0), T(0), s.z, T(0),
2204 T(0), T(0), T(0), s.w
2210 template <
typename T>
2212 assert(std::abs(axis.length() - 1) < epsilon<T>());
2218 template <
typename T>
2220 const T len = axis_angle.length();
2225 template <
typename T>
2228 assert(std::abs(q.
length() - 1) < epsilon<T>());
2234 m(0, 0) = 1.0 - 2.0 * (y*y + z*z); m(0, 1) = 2.0 * (x*y - w*z); m(0, 2) = 2.0 * (x*z + w*y); m(0, 3) = 0.0;
2235 m(1, 0) = 2.0 * (x*y + w*z); m(1, 1) = 1.0 - 2.0 * (x*x + z*z); m(1, 2) = 2.0 * (y*z - w*x); m(1, 3) = 0.0;
2236 m(2, 0) = 2.0 * (x*z - w*y); m(2, 1) = 2.0 * (y*z + w*x); m(2, 2) = 1.0 - 2.0 * (x*x + y*y); m(2, 3) = 0.0;
2237 m(3, 0) = 0.0; m(3, 1) = 0.0; m(3, 2) = 0.0; m(3, 3) = 1.0;
2242 template <
typename T>
2248 rx(0, 0) = T(1); rx(0, 1) = T(0); rx(0, 2) = T(0); rx(0, 3) = T(0);
2249 rx(1, 0) = T(0); rx(1, 1) = std::cos(x); rx(1, 2) = -std::sin(x); rx(1, 3) = T(0);
2250 rx(2, 0) = T(0); rx(2, 1) = std::sin(x); rx(2, 2) = std::cos(x); rx(2, 3) = T(0);
2251 rx(3, 0) = T(0); rx(3, 1) = T(0); rx(3, 2) = T(0); rx(3, 3) = T(1);
2254 ry(0, 0) = std::cos(y); ry(0, 1) = T(0); ry(0, 2) = std::sin(y); ry(0, 3) = T(0);
2255 ry(1, 0) = T(0); ry(1, 1) = T(1); ry(1, 2) = T(0); ry(1, 3) = T(0);
2256 ry(2, 0) = -std::sin(y); ry(2, 1) = T(0); ry(2, 2) = std::cos(y); ry(2, 3) = T(0);
2257 ry(3, 0) = T(0); ry(3, 1) = T(0); ry(3, 2) = T(0); ry(3, 3) = T(1);
2260 rz(0, 0) = std::cos(z); rz(0, 1) = -std::sin(z); rz(0, 2) = T(0); rz(0, 3) = T(0);
2261 rz(1, 0) = std::sin(z); rz(1, 1) = std::cos(z); rz(1, 2) = T(0); rz(1, 3) = T(0);
2262 rz(2, 0) = T(0); rz(2, 1) = T(0); rz(2, 2) = T(1); rz(2, 3) = T(0);
2263 rz(3, 0) = T(0); rz(3, 1) = T(0); rz(3, 2) = T(0); rz(3, 3) = T(1);
2266 case 123:
return rz * ry * rx;
2267 case 132:
return ry * rz * rx;
2268 case 213:
return rz * rx * ry;
2269 case 231:
return rx * rz * ry;
2270 case 312:
return ry * rx * rz;
2271 case 321:
return rx * ry * rz;
2273 LOG(ERROR) <<
"invalid rotation order";
2274 return rx * rz * ry;
2279 template <
typename T>
2282 T(1), T(0), T(0), t[0],
2283 T(0), T(1), T(0), t[1],
2284 T(0), T(0), T(1), t[2],
2285 T(0), T(0), T(0), T(1)
2290 template <
typename T>
2293 T(1), T(0), T(0), x,
2294 T(0), T(1), T(0), y,
2295 T(0), T(0), T(1), z,
2296 T(0), T(0), T(0), T(1)
2 by 2 matrix. Extends Mat with 2D-specific functionality and constructors.
Definition: mat.h:1460
static Mat2< T > scale(T s)
Static constructor return a 2D uniform scale matrix.
Definition: mat.h:1598
static Mat2< T > rotation(T angle)
Static constructor return a 2D rotation matrix.
Definition: mat.h:1589
Mat2()=default
Default constructor.
3x3 matrix. Extends Mat with 3D-specific functionality and constructors.
Definition: mat.h:1620
Mat3()=default
Default constructor.
static Mat3< T > rotation(const Vec< 3, T > &axis, T angle)
Static constructor returning a 3D rotation matrix defined by its axis and angle.
Definition: mat.h:1850
Mat2< T > sub() const
the upper-left 2x2 sub-matrix.
Definition: mat.h:1818
static Mat3< T > scale(T s)
Static constructor returning a 3D uniform scale matrix.
Definition: mat.h:1830
4x4 matrix. Extends Mat with 4D-specific functionality and constructors.
Definition: mat.h:1940
Mat4(const T *m)
Initialize elements from an array of type T.
Definition: mat.h:2096
Mat4()=default
Default constructor.
static Mat4< T > scale(const Vec< 4, T > &s)
Static constructor returning a 4D non-uniform scale matrix,.
Definition: mat.h:2199
Mat4(T s)
Initialized with diagonal as s and others zeros.
Definition: mat.h:2063
static Mat4< T > rotation(const Quat< T > &q)
Static constructor returning a 3D rotation matrix defined by a quaternion.
Definition: mat.h:2226
static Mat4< T > scale(T s)
Static constructor returning a 4D uniform scale matrix.
Definition: mat.h:2177
static Mat4< T > rotation(const Vec< 3, T > &axis, T angle)
Static constructor returning a 3D rotation matrix defined by its axis and angle.
Definition: mat.h:2211
Mat4(const Mat< 4, 4, T > &rhs)
Copy constructor. This provides compatibility with generic operations implemented by Mat.
Definition: mat.h:2075
Mat4(const Mat< 3, 3, T > &rhs)
Initialize from a 3D matrix. rhs forms the upper-left 3x3 sub-matrix, other elements are initialized ...
Definition: mat.h:2136
static Mat4< T > translation(const Vec< 3, T > &t)
Static constructor return a 3D translation matrix (as a 4D affine transformation).
Definition: mat.h:2280
Mat4(const Vec< 4, T > &x, const Vec< 4, T > &y, const Vec< 4, T > &z, const Vec< 4, T > &w)
Initialize elements from four vectors. If MATRIX_ROW_MAJOR is defined, x, y, z and w specify rows of ...
Definition: mat.h:2114
static Mat4< T > rotation(const Vec< 3, T > &axis_angle)
Static constructor returning a 3D rotation matrix defined by the axis–angle representation....
Definition: mat.h:2219
Mat4(const Vec< 3, T > &s, const Quat< T > &r, const Vec< 3, T > &t)
Initialize from scale/rotation/translation.
Definition: mat.h:2157
static Mat4< T > rotation(T x, T y, T z, int order=312)
Static constructor returning a 3D rotation matrix defined by Euler angles. The three rotations are ap...
Definition: mat.h:2243
Mat4(T s00, T s01, T s02, T s03, T s10, T s11, T s12, T s13, T s20, T s21, T s22, T s23, T s30, T s31, T s32, T s33)
Initialize elements from individual scalars. The digits following s in the parameter names indicate t...
Definition: mat.h:2082
Base class for matrix types.
Definition: mat.h:66
T & operator()(size_t r, size_t c)
Non-const row/column access to elements.
Definition: mat.h:613
Mat< N, M, T > & operator*=(T rhs)
Component-wise matrix-scalar multiplication/assignment.
Definition: mat.h:752
void swap_cols(size_t a, size_t b)
Swaps col a with col b.
Definition: mat.h:575
static Mat< N, M, T > identity()
Static constructor return an N x M identity matrix. see also load_identity()
Definition: mat.h:483
Mat()=default
Default constructor.
const T & operator()(size_t r, size_t c) const
Const row/column access to elements.
Definition: mat.h:600
Mat(const Mat< rN, rM, T > &rhs)
Copy constructor for rN >= N, rM >= M. For smaller incoming matrices (i.e, rN < N,...
Definition: mat.h:463
Mat(T s)
Initialized with diagonal as s and others zeros.
Definition: mat.h:450
Mat< N, M, T > & operator-=(const Mat< N, M, T > &rhs)
Component-wise matrix-matrix subtraction/assignment.
Definition: mat.h:741
Mat< N, M, T > & operator*=(const Mat< N, M, T > &rhs)
Matrix-matrix multiplication/assignment.
Definition: mat.h:724
Mat(const T *m)
Initialize elements from an array of type T.
Definition: mat.h:474
size_t num_rows() const
Return the number of rows.
Definition: mat.h:105
Mat< N, M, T > & operator-=(T rhs)
Component-wise matrix-scalar subtraction/assignment.
Definition: mat.h:776
Mat< N, M, T > operator*(T rhs) const
Component-wise matrix-scalar multiplication.
Definition: mat.h:704
void swap_rows(size_t a, size_t b)
Swaps row a with row b.
Definition: mat.h:542
void set_row(size_t r, const Vec< vN, T > &v)
Set row r from vector v. This copies the first M components from v, so vN must be >= M....
Definition: mat.h:521
Vec< M, T > row(size_t r) const
Return row r as a vector.
Definition: mat.h:498
void load_zero()
Set all elements 0.
Definition: mat.h:555
size_t num_columns() const
Return the number of columns.
Definition: mat.h:108
void load_identity(T s=T(1))
Set diagonal elements s and others 0.
Definition: mat.h:563
Mat< N, M, T > operator-(const Mat< N, M, T > &rhs) const
Component-wise matrix-matrix subtraction.
Definition: mat.h:667
Vec< N, T > col(size_t c) const
Return col c as a vector.
Definition: mat.h:509
bool operator!=(const Mat< N, M, T > &rhs) const
Inequality test.
Definition: mat.h:635
Mat< N, M, T > & operator/=(T rhs)
Component-wise matrix-scalar division/assignment.
Definition: mat.h:760
Mat< N, M, T > & operator+=(const Mat< N, M, T > &rhs)
Component-wise matrix-matrix addition/assignment.
Definition: mat.h:733
void set_col(size_t c, const Vec< vN, T > &v)
Set col c from vector v. This copies the first N components from v, so vN must be >= N....
Definition: mat.h:532
Vec< N, T > operator*(const Vec< M, T > &rhs) const
Matrix-vector multiplication. rhs must have the same number of elements as this matrix has columns....
Definition: mat.h:688
Mat< N, M, T > operator/(T rhs) const
Component-wise matrix-scalar division.
Definition: mat.h:713
Mat< N, M, T > & operator+=(T rhs)
Component-wise matrix-scalar addition/assignment.
Definition: mat.h:768
Mat< N, rM, T > operator*(const Mat< M, rM, T > &rhs) const
Matrix-matrix multiplication. rhs must have the same number of rows as this matrix has columns....
Definition: mat.h:643
bool operator==(const Mat< N, M, T > &rhs) const
Equality test.
Definition: mat.h:626
Mat< N, M, T > operator-() const
Component-wise matrix negation.
Definition: mat.h:676
Mat< N, M, T > operator+(const Mat< N, M, T > &rhs) const
Component-wise matrix-matrix addition.
Definition: mat.h:658
The Quaternion class represents 3D rotations and orientations.
Definition: quat.h:107
FT length() const
Return the length of the quaternion.
Definition: quat.h:285
A 2D vector (used for representing 2D points or vectors).
Definition: vec.h:320
A 3D vector (used for representing 3D points or vectors).
Definition: vec.h:439
A 4D vector (used for representing 3D points or vectors in homogeneous coordinates).
Definition: vec.h:584
Base class for vector types. It provides generic functionality for N dimensional vectors.
Definition: vec.h:34
T * data()
Returns the memory address of the vector.
Definition: vec.h:81
Definition: collider.cpp:182
Mat< M, N, T > transpose(const Mat< N, M, T > &m)
Transpose m.
Definition: mat.h:907
FT max()
Function returning maximum representable value for a given type.
T trace(const Mat< N, N, T > &m)
Return the trace (sum of elements on the main diagonal) of N by N (square) matrix m.
T determinant(const Mat< N, N, T > &m)
Return the determinant of N x N (square) matrix m.
bool has_nan(const GenericBox< DIM, FT > &box)
Definition: box.h:284
Mat< N, 1, FT > to_matrix(const Vec< N, FT > &v)
Convert a N-dimensional vector into a N by 1 matrix.
Definition: mat.h:1420
bool cholesky_decompose(const Mat< N, N, FT > &A, Mat< N, N, FT > &L)
Cholesky decomposition of a symmetric, positive definite matrix.
Definition: mat.h:1318
std::istream & operator>>(std::istream &is, GenericLine< DIM, FT > &line)
Definition: line.h:133
std::ostream & operator<<(std::ostream &os, Graph::Vertex v)
Definition: graph.h:920
void lu_back_substitution(const Mat< N, N, T > &alu, const Vec< N, T > &rowp, const Vec< N, T > &b, Vec< N, T > *x)
Solve a set of linear equations using outputs from lu_decomposition() as inputs.
Definition: mat.h:1277
T det(const Vec< 2, T > &v1, const Vec< 2, T > &v2)
Compute the determinant of the 2x2 matrix formed by the two 2D vectors as the two rows.
Definition: vec.h:405
bool lu_decomposition(const Mat< N, N, T > &a, Mat< N, N, T > *alu, Vec< N, T > *rowp, T *d)
Perform LU decomposition of a square matrix.
Definition: mat.h:1201
Mat< N, N, T > inverse(const Mat< N, N, T > &m)
Return the inverse of N x N (square) matrix m.
Definition: mat.h:977
std::vector< FT > sum(const Matrix< FT > &)
Definition: matrix.h:1454
bool gauss_jordan_elimination(const Mat< N, N, T > &a, const Mat< N, M, T > &b, Mat< N, N, T > *ainv, Mat< N, M, T > *x)
Perform Gauss-Jordan elimination to solve a set of linear equations and additionally compute the inve...
Definition: mat.h:1121
void cholesky_solve(const Mat< N, N, FT > &L, const Vec< N, FT > &b, Vec< N, FT > &x)
Definition: mat.h:1345
Mat< N, M, T > operator*(T lhs, const Mat< N, M, T > &rhs)
Component-wise scalar-matrix multiplication.
Definition: mat.h:787
Mat< N, M, T > tensor(const Vec< M, T > &u, const Vec< N, T > &v)
Definition: mat.h:1112