# Matrix¶

class Matrix

A Matrix is represented by rows and columns. The first index is the row, and the second is the column.

Subclassed by feasst::RotationMatrix

Public Functions

void set_size(const int num_rows, const int num_columns)

Set the size by number of rows and columns.

Matrix(std::vector<std::vector<double>> matrix)

Alternatively, construct with 2d vector data.

int num_rows() const

Return the number of rows.

int num_columns() const

Return the number of columns.

void set_value(const int row, const int column, const double value)

Set the value of an element given by the row and column index.

double value(const int row, const int column) const

Return the value of the element.

const std::vector<std::vector<double>> &matrix() const

Return the entire matrix.

virtual void check() const

Check that each row and column are the same size.

void transpose()

Switch the rows and columns.

void multiply(const double constant)

Multiply all elements by a constant.

void zero()

Set all elements to zero.

Position multiply(const Position &vec) const

Return the vector which is a product of the multiplication of a matrix with the given vector.

void multiply(const Position &vec, Position *result) const

Same as above, but optimized to avoid construction of Position.

bool is_equal(const Matrix &matrix) const

Return true if all elements are equal to the given matrix.

std::string str() const

Return the matrix as a human readable string.

double determinant() const

Return the determinant (only implemented for 2x2 and 3x3 matrices).

void invert()

Invert the matrix (only implemented for 2x2 and 3x3 matrices).

class RotationMatrix : public feasst::Matrix

Rotation matrices represent a rotation of a rigid body. They must be square with a unit determinant.

Public Functions

RotationMatrix &axis_angle(const Position &axis, const double degree_angle)

Parameters
• degree_angle: The angle is in units of degrees.

Compute the rotation matrix given an angle of rotation about a given axis. In 2D, the axis is simply used to specify the number of dimensions.

void axis_angle_opt(const Position &unit_axis, const double degree_angle)

Parameters
• degree_angle: The angle is in units of degrees.

Same as above, but optimized (1) axis is assumed to be unit length and (2) rotation matrix is the correct size and (3) determinant is not checked.

void rotate(const Position &pivot, Position *rotated) const

Rotate a position given a pivot point.

void check() const

Check square matrix, unit derminant, in addition to Matrix::check.