-
Notifications
You must be signed in to change notification settings - Fork 6
Working with matrices
Martijn Koopman edited this page Mar 9, 2019
·
10 revisions
Required include for working Matrix class:
#include <spatium/Matrix.h>
Method 1: Explicitly by constructor
spatium::Matrix matrix(2, 2);
matrix1(0,0) = 1;
matrix1(0,1) = 2;
matrix1(1,0) = 3;
matrix1(1,1) = 4;
Method2: Constructor with initalizer list
spatium::Matrix matrix({{1, 2}, {3, 4});
Method 3: Implicitly via initalizer list and assignment
spatium::Matrix matrix = {{1, 2}, {3, 4}};
spatium::Matrix matrix(4, 1);
matrix(0,0) = 1;
matrix(1,0) = 2;
matrix(2,0) = 3;
spatium::Vector3 vector = matrix;
A std::out_of_bounds exception can be thrown in many situations.
spatium::Matrix matrix = {
{3 , 3.2, 3},
{3.5, 3.6, 3}
};
try {
double val = matrix(1, 3);
}
catch(std::out_of_range e)
{
// Column range is 0 - 2 (3 is out of bounds)
}
try {
Matrix inv = matrix.inverse();
}
catch(std::out_of_range e)
{
// Matrix has no inverse
}