92 Matrix3(
const std::vector<std::vector<double>> &m) {
93 for (
size_t i=0; i<3; i++)
94 for (
size_t j=0; j<3; j++)
104 for (
size_t i=0; i<3; i++)
105 for (
size_t j=0; j<3; j++)
116 std::string
printStr(
int nt = 0,
int lvl = 0)
const {
118 std::string tabS =
"";
119 for (
int i = 0; i < nt; i++)
122 std::ostringstream oss;
123 for (
size_t i=0; i<3; i++)
124 oss << tabS <<
"[" << (*
this)(i, 0) <<
", " << (*
this)(i, 1) <<
", "
125 << (*
this)(i, 2) <<
"]" << std::endl;
137 void print(
int nt = 0,
int lvl = 0)
const { std::cout <<
printStr(nt, lvl); }
178 std::vector<double>
dot(
const std::vector<double> &v)
const {
180 auto r = std::vector<double>(3,0.);
181 for (
size_t i=0; i<3; i++)
182 for (
size_t j=0; j<3; j++)
183 r[i] += (*
this)(i,j) * v[j];
196 return {(*this)(0) * v, (*
this)(1) * v, (*
this)(2) * v};
207 m(0,1) = (*this)(1,0);
208 m(0,2) = (*this)(2,0);
210 m(1,0) = (*this)(0,1);
211 m(1,2) = (*this)(2,1);
213 m(2,0) = (*this)(0,2);
214 m(2,1) = (*this)(1,2);
225 return (*
this)(0,0) * ((*
this)(1,1) * (*
this)(2,2) - (*
this)(2,1) * (*
this)(1,2)) -
226 (*this)(0,1) * ((*
this)(1,0) * (*
this)(2,2) - (*
this)(2,0) * (*
this)(1,2)) +
227 (*this)(0,2) * ((*
this)(1,0) * (*
this)(2,1) - (*
this)(2,0) * (*
this)(1,1));
239 auto det_inv = 1. / this->
det();
242 ((*this)(1,1) * (*
this)(2,2) - (*
this)(2,1) * (*
this)(1,2));
244 ((*this)(0,1) * (*
this)(2,2) - (*
this)(2,1) * (*
this)(0,2));
246 ((*this)(0,1) * (*
this)(1,2) - (*
this)(1,1) * (*
this)(0,2));
249 ((*this)(1,0) * (*
this)(2,2) - (*
this)(2,0) * (*
this)(1,2));
251 ((*this)(0,0) * (*
this)(2,2) - (*
this)(2,0) * (*
this)(0,2));
253 ((*this)(0,0) * (*
this)(1,2) - (*
this)(1,0) * (*
this)(0,2));
256 ((*this)(1,0) * (*
this)(2,1) - (*
this)(2,0) * (*
this)(1,1));
258 ((*this)(0,0) * (*
this)(2,1) - (*
this)(2,0) * (*
this)(0,1));
260 ((*this)(0,0) * (*
this)(1,1) - (*
this)(1,0) * (*
this)(0,1));
325 d_data[3] = 0.5 * (m[1][2] + m[2][1]);
326 d_data[4] = 0.5 * (m[0][2] + m[2][0]);
327 d_data[5] = 0.5 * (m[0][1] + m[1][0]);
355 d_data[3] = 0.5 * (m(1,2) + m(2,1));
356 d_data[4] = 0.5 * (m(0,2) + m(2,0));
357 d_data[5] = 0.5 * (m(0,1) + m(1,0));
367 for (
size_t i=0; i<6; i++)
378 std::string
printStr(
int nt = 0,
int lvl = 0)
const {
380 std::string tabS =
"";
381 for (
int i = 0; i < nt; i++)
384 std::ostringstream oss;
385 for (
size_t i=0; i<3; i++)
386 oss << tabS <<
"[" << (*
this)(i, 0) <<
", " << (*
this)(i, 1) <<
", "
387 << (*
this)(i, 2) <<
"]" << std::endl;
400 void print(
int nt = 0,
int lvl = 0)
const { std::cout <<
printStr(nt, lvl); }
409 return {(*this)(i, 0), (*
this)(i, 1), (*
this)(i, 2)};
418 return {(*this)(i, 0), (*
this)(i, 1), (*
this)(i, 2)};
428 return d_data[i == j ? i : 6 - i - j];
439 return d_data[i == j ? i : 6 - i - j];
446 const float &
get(
size_t i)
const {
464 for (
size_t i=0; i<6; i++)
473 std::vector<double>
dot(
const std::vector<double> &v)
const {
475 auto r = std::vector<double>(3,0.);
476 for (
size_t i=0; i<3; i++)
477 for (
size_t j=0; j<3; j++)
478 r[i] += (*
this)(i,j) * v[j];
490 return {(*this)(0) * v, (*
this)(1) * v, (*
this)(2) * v};
508 return (*
this)(0,0) * ((*
this)(1,1) * (*
this)(2,2) - (*
this)(2,1) * (*
this)(1,2)) -
509 (*this)(0,1) * ((*
this)(1,0) * (*
this)(2,2) - (*
this)(2,0) * (*
this)(1,2)) +
510 (*this)(0,2) * ((*
this)(1,0) * (*
this)(2,1) - (*
this)(2,0) * (*
this)(1,1));
522 auto det_inv = 1. / this->
det();
525 ((*this)(1,1) * (*
this)(2,2) - (*
this)(2,1) * (*
this)(1,2));
527 ((*this)(0,1) * (*
this)(2,2) - (*
this)(2,1) * (*
this)(0,2));
529 ((*this)(0,1) * (*
this)(1,2) - (*
this)(1,1) * (*
this)(0,2));
532 ((*this)(1,0) * (*
this)(2,2) - (*
this)(2,0) * (*
this)(1,2));
534 ((*this)(0,0) * (*
this)(2,2) - (*
this)(2,0) * (*
this)(0,2));
536 ((*this)(0,0) * (*
this)(1,2) - (*
this)(1,0) * (*
this)(0,2));
539 ((*this)(1,0) * (*
this)(2,1) - (*
this)(2,0) * (*
this)(1,1));
541 ((*this)(0,0) * (*
this)(2,1) - (*
this)(2,0) * (*
this)(0,1));
543 ((*this)(0,0) * (*
this)(1,1) - (*
this)(1,0) * (*
this)(0,1));
555 bool checkMatrix(
const std::vector<std::vector<double>> &m);
564 std::vector<double>
dot(
const std::vector<std::vector<double>> &m,
const
565 std::vector<double> &v);
573 std::vector<std::vector<double>>
transpose(
const
574 std::vector<std::vector<double>> &m);
582 double det(
const std::vector<std::vector<double>> &m);
590 std::vector<std::vector<double>>
591 inv(
const std::vector<std::vector<double>> &m);
Collection of methods useful in simulation.
Definition: DataManager.h:50
std::vector< std::vector< double > > transpose(const std::vector< std::vector< double >> &m)
Computes the transpose of matrix.
Definition: matrix.cpp:42
double det(const std::vector< std::vector< double >> &m)
Computes the determinant of matrix.
Definition: matrix.cpp:69
std::vector< std::vector< double > > inv(const std::vector< std::vector< double >> &m)
Computes the determinant of matrix.
Definition: matrix.cpp:85
bool checkMatrix(const std::vector< std::vector< double >> &m)
Checks matrix.
Definition: matrix.cpp:12
std::vector< double > dot(const std::vector< std::vector< double >> &m, const std::vector< double > &v)
Computes the dot product between matrix and vector.
Definition: matrix.cpp:30
A structure to represent 3d matrices.
Definition: matrix.h:17
Matrix3 transpose() const
Computes the transpose of matrix.
Definition: matrix.h:203
Matrix3()
Constructor.
Definition: matrix.h:32
Matrix3(const Matrix3 &m)
Constructor.
Definition: matrix.h:103
Matrix3(const util::Point3 &a1, const util::Point3 &a2, const util::Point3 &a3)
Constructor.
Definition: matrix.h:74
const float & operator()(size_t i, size_t j) const
Access operator of the Matrix element M(i,j)
Definition: matrix.h:171
Point3 operator()(size_t i)
Access operator of the i-th element.
Definition: matrix.h:144
Point3 operator()(size_t i) const
Access operator of the i-th element.
Definition: matrix.h:153
void print(int nt=0, int lvl=0) const
Prints the information.
Definition: matrix.h:137
float d_data[3][3]
data
Definition: matrix.h:25
util::Point3 dot(const util::Point3 &v)
Computes the dot product of the matrix and the vector v.
Definition: matrix.h:194
Matrix3(const util::Point3 &diagonal)
Constructor.
Definition: matrix.h:52
std::string printStr(int nt=0, int lvl=0) const
Prints the information.
Definition: matrix.h:116
Matrix3(const std::vector< std::vector< double >> &m)
Constructor.
Definition: matrix.h:92
float & operator()(size_t i, size_t j)
Access operator of the Matrix element M(i,j)
Definition: matrix.h:163
double det() const
Computes the determinant of matrix.
Definition: matrix.h:224
Matrix3 inv() const
Computes the determinant of matrix.
Definition: matrix.h:235
std::vector< double > dot(const std::vector< double > &v) const
Computes the dot product between matrix and vector.
Definition: matrix.h:178
A structure to represent 3d vectors.
Definition: point.h:29
double d_x
the x coordinate
Definition: point.h:32
double d_y
the y coordinate
Definition: point.h:35
double d_z
the z coordinate
Definition: point.h:38
A structure to represent 3d matrices.
Definition: matrix.h:267
float d_data[6]
data
Definition: matrix.h:282
const float & get(size_t i) const
Return the i-th element.
Definition: matrix.h:446
void print(int nt=0, int lvl=0) const
Prints the information.
Definition: matrix.h:400
const float & operator()(size_t i, size_t j) const
Access operator of the Matrix element M(i,j)
Definition: matrix.h:438
std::vector< double > dot(const std::vector< double > &v) const
Computes the dot product of this matrix with another vector.
Definition: matrix.h:473
SymMatrix3()
Constructor.
Definition: matrix.h:289
Point3 operator()(size_t i) const
Access operator of the i-th element.
Definition: matrix.h:417
float & operator()(size_t i, size_t j)
Access operator of the Matrix element M(i,j)
Definition: matrix.h:427
Point3 operator()(size_t i)
Access operator of the i-th element.
Definition: matrix.h:408
std::string printStr(int nt=0, int lvl=0) const
Prints the information.
Definition: matrix.h:378
SymMatrix3(const std::vector< double > &m)
Constructor.
Definition: matrix.h:335
double det() const
Computes the determinant of matrix.
Definition: matrix.h:507
void copy(double m[6]) const
Copy.
Definition: matrix.h:462
SymMatrix3(const SymMatrix3 &m)
Constructor.
Definition: matrix.h:365
float & get(size_t i)
Return the i-th element.
Definition: matrix.h:454
util::Point3 dot(const util::Point3 &v)
Computes the dot product of this matrix with another vector.
Definition: matrix.h:488
SymMatrix3(const Matrix3 &m)
Constructor.
Definition: matrix.h:350
SymMatrix3 transpose() const
Computes the transpose of matrix.
Definition: matrix.h:497
SymMatrix3(const util::Point3 &diagonal)
Constructor.
Definition: matrix.h:304
SymMatrix3 inv() const
Computes the determinant of matrix.
Definition: matrix.h:518
SymMatrix3(const std::vector< std::vector< double >> &m)
Constructor.
Definition: matrix.h:320