# VectorNav C++ Library: include/vn/matrix.h Source File

matrix.h
Go to the documentation of this file.
#ifndef _VN_MATH_MAT_H_
#define _VN_MATH_MAT_H_
#include <cassert>
#include <iostream>
#include "vector.h"
#include "exceptions.h"
namespace vn {
namespace math {
template <size_t m, size_t n = m, typename T = float>
struct mat
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
T e[m * n];
};
// Constructors ///////////////////////////////////////////////////////////
public:
mat() { }
explicit mat(T val)
{
std::fill_n(e, m * n, val);
}
// Helper Methods /////////////////////////////////////////////////////////
public:
static mat zero()
{
return mat<m, n, T>(0);
}
static mat one()
{
return mat<m, n, T>(1);
}
static mat<m, m, T> identity()
{
assert(m == n);
mat<m, m, T> nm(0);
for (size_t i = 0; i < m; i++)
nm.e[i * m + i] = 1;
return nm;
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator()(size_t row, size_t col)
{
return const_cast<T&>(static_cast<const mat&>(*this)(row, col));
}
const T& operator()(size_t row, size_t col) const
{
assert(row < m && col < n);
//return e[col * m + row];
return e[col + row * m];
}
mat operator-() const
{
return neg();
}
template<typename S>
mat& operator*=(const S& rhs)
{
for (size_t i = 0; i < m*n; i++)
e[i] *= rhs;
return *this;
}
template<size_t r, size_t s, typename S>
mat& operator*(const mat<r, s, S>& rhs)
{
// columns from the matrix must match rows of the input matrix
if (m != s)
{
return *this;
}
size_t row = 0;
size_t col = 0;
size_t cell = 0;
mat<r, n, T> return_mat = zero();
// Remember, this matrix is stored in column order
for (size_t row_index = 0; row_index < r; row_index++)
{
for (size_t col_index = 0; col_index < n; col_index++)
{
cell = row_index + (col_index * r);
for (size_t cell_index = 0; cell_index < m; cell_index++)
{
// calculated for the cell in the current row
row = (col_index * m) + cell_index;
// calculated for the cell in the current column
col = (cell_index * r) + row_index;
return_mat.e[cell] += this->e[row] * rhs.e[col];
}
}
}
return return_mat;
}
template<typename S>
mat& operator/=(const T & rhs)
{
for (size_t i = 0; i < m*n; i++)
e[i] /= rhs;
return *this;
}
template<typename S>
mat& operator+=(const mat<m, n, S>& rhs)
{
for (size_t i = 0; i < m*n; i++)
e[i] += rhs.e[i];
return *this;
}
template<typename S>
mat& operator-=(const mat<m, n, S>& rhs)
{
for (size_t i = 0; i < m*n; i++)
e[i] -= rhs.e[i];
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dimRow() const { return m; }
size_t dimCol() const { return n; }
mat neg() const
{
mat nm;
for (size_t i = 0; i < m * n; i++)
nm.e[i] = -e[i];
return nm;
}
mat mult(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < m*n; i++)
nm.e[i] = e[i] * scalar;
return nm;
}
mat div(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < m*n; i++)
nm.e[i] = e[i] / scalar;
return nm;
}
mat add(const mat& toAdd) const
{
mat nm;
for (size_t i = 0; i < m*n; i++)
nm.e[i] = e[i] + toAdd.e[i];
return nm;
}
mat sub(const mat& toSub) const
{
mat nm;
for (size_t i = 0; i < m*n; i++)
nm.e[i] = e[i] - toSub.e[i];
return nm;
}
mat<n, m, T> transpose() const
{
mat<n, m, T> nm;
for (size_t row = 0; row < m; row++)
{
for (size_t col = 0; col < n; col++)
{
nm.e[row * n + col] = e[col * m + row];
}
}
return nm;
}
};
// Specializations ////////////////////////////////////////////////////////////
#if defined(_MSC_VER)
#pragma warning(push)
// Disable warning about 'nonstandard extension used : nameless struct/union'.
#pragma warning(disable:4201)
#endif
template <typename T>
struct mat<2, 2, T>
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
struct
{
T e00;
T e10;
T e01;
T e11;
};
T e[2 * 2];
};
// Constructors ///////////////////////////////////////////////////////////
public:
mat() { }
explicit mat(T val) :
e00(val), e10(val),
e01(val), e11(val)
{ }
mat(T e00v, T e01v,
T e10v, T e11v) :
e00(e00v), e10(e10v),
e01(e01v), e11(e11v)
{ }
mat(vec<2, T> col0, vec<2, T> col1) :
e00(col0.x), e10(col1.x),
e01(col0.y), e11(col1.y)
{}
// Helper Methods /////////////////////////////////////////////////////////
public:
static mat zero()
{
return mat<2, 2, T>(0);
}
static mat one()
{
return mat<2, 2, T>(1);
}
static mat<2, 2, T> identity()
{
return mat<2, 2, T>(
1, 0,
0, 1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator()(size_t row, size_t col)
{
return const_cast<T&>(static_cast<const mat&>(*this)(row, col));
}
const T& operator()(size_t row, size_t col) const
{
assert(row < 2 && col < 2);
return e[col * 2 + row];
}
mat operator-() const
{
return neg();
}
template<typename S>
mat& operator*=(const S& rhs)
{
#if defined(_MSC_VER)
#pragma warning(push)
// The operator*= throws a warning when a mat*f is multiplied by a mat*d.
#pragma warning(disable:4244)
#endif
for (size_t i = 0; i < 2 * 2; i++)
e[i] *= rhs;
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
return *this;
}
template<typename S>
mat& operator*=(const mat<2, 2, S>& rhs)
{
size_t row = 0;
size_t col = 0;
size_t cell = 0;
mat<2, 2, T> return_mat = zero();
// Remember, this matrix is stored in column order
for (size_t row_index = 0; row_index < 2; row_index++)
{
for (size_t col_index = 0; col_index < 2; col_index++)
{
cell = row_index + (col_index * 2);
for (size_t cell_index = 0; cell_index < 2; cell_index++)
{
// calculated for the cell in the current row
row = row_index + (cell_index * 2);
// calculated for the cell in the current column
col = cell_index + (col_index * 2);
return_mat.e[cell] += this->e[row] * rhs.e[col];
}
}
}
*this = return_mat;
return *this;
}
template<typename S>
mat& operator/=(const S& rhs)
{
#if defined(_MSC_VER)
#pragma warning(push)
// The operator/= throws a warning when a mat*f is divided by a double.
#pragma warning(disable:4244)
#endif
for (size_t i = 0; i < 2 * 2; i++)
e[i] /= rhs;
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
return *this;
}
template<typename S>
mat& operator+=(const mat<2, 2, S>& rhs)
{
for (size_t i = 0; i < 2 * 2; i++)
e[i] += rhs.e[i];
return *this;
}
template<typename S>
mat& operator-=(const mat<2, 2, S>& rhs)
{
for (size_t i = 0; i < 2 * 2; i++)
e[i] -= rhs.e[i];
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dimRow() const { return 2; }
size_t dimCol() const { return 2; }
template<typename S>
void copy(const mat<2, 2, S> rhs)
{
*this = rhs;
}
mat neg() const
{
mat nm;
for (size_t i = 0; i < 2 * 2; i++)
nm.e[i] = -e[i];
return nm;
}
mat mult(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < 2 * 2; i++)
nm.e[i] = e[i] * scalar;
return nm;
}
mat div(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < 2 * 2; i++)
nm.e[i] = e[i] / scalar;
return nm;
}
mat add(const mat& toAdd) const
{
mat nm;
for (size_t i = 0; i < 2 * 2; i++)
nm.e[i] = e[i] + toAdd.e[i];
return nm;
}
mat sub(const mat& toSub) const
{
mat nm;
for (size_t i = 0; i < 2 * 2; i++)
nm.e[i] = e[i] - toSub.e[i];
return nm;
}
mat<2, 2, T> transpose() const
{
mat<2, 2, T> nm;
for (size_t row = 0; row < 2; row++)
{
for (size_t col = 0; col < 2; col++)
{
nm.e[row * 2 + col] = e[col * 2 + row];
}
}
return nm;
}
};
template <typename T>
struct mat<3, 3, T>
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
struct
{
T e00;
T e10;
T e20;
T e01;
T e11;
T e21;
T e02;
T e12;
T e22;
};
T e[3 * 3];
};
// Constructors ///////////////////////////////////////////////////////////
public:
mat() { }
explicit mat(T val) :
e00(val), e10(val), e20(val),
e01(val), e11(val), e21(val),
e02(val), e12(val), e22(val)
{ }
mat(T e00v, T e01v, T e02v,
T e10v, T e11v, T e12v,
T e20v, T e21v, T e22v) :
e00(e00v), e10(e10v), e20(e20v),
e01(e01v), e11(e11v), e21(e21v),
e02(e02v), e12(e12v), e22(e22v)
{ }
mat(vec<3, T> col0, vec<3, T> col1, vec<3, T> col2) :
e00(col0.x), e10(col0.y), e20(col0.z),
e01(col1.x), e11(col1.y), e21(col1.z),
e02(col2.x), e12(col2.y), e22(col2.z)
{
}
// Helper Methods /////////////////////////////////////////////////////////
public:
static mat zero()
{
return mat<3, 3, T>(0);
}
static mat one()
{
return mat<3, 3, T>(1);
}
static mat<3, 3, T> identity()
{
return mat<3, 3, T>(
1, 0, 0,
0, 1, 0,
0, 0, 1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator()(size_t row, size_t col)
{
return const_cast<T&>(static_cast<const mat&>(*this)(row, col));
}
const T& operator()(size_t row, size_t col) const
{
assert(row < 3 && col < 3);
return e[col * 3 + row];
}
mat operator-() const
{
return neg();
}
template<typename S>
mat& operator*=(const S& rhs)
{
#if defined(_MSC_VER)
#pragma warning(push)
// The operator*= throws a warning when a mat*f is multiplied by a mat*d.
#pragma warning(disable:4244)
#endif
for (size_t i = 0; i < 3 * 3; i++)
e[i] *= rhs;
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
return *this;
}
template<typename S>
mat& operator*=(const mat<3, 3, S>& rhs)
{
size_t counter = 0;
size_t row = 0;
size_t col = 0;
size_t cell = 0;
mat<3, 3, T> return_mat = zero();
// Remember, this matrix is stored in column order
for(size_t row_index = 0; row_index < 3; row_index++)
{
for(size_t col_index = 0; col_index < 3; col_index++)
{
cell = row_index + (col_index * 3);
for (size_t cell_index = 0; cell_index < 3; cell_index++)
{
// calculated for the cell in the current row
row = row_index + (cell_index * 3);
// calculated for the cell in the current column
col = cell_index + (col_index * 3);
return_mat.e[cell] += this->e[row] * rhs.e[col];
}
}
}
// std::copy(return_mat.e[0], return_mat.e[8], this->e[0]);
// std::copy(return_mat.e, return_mat.e + 7, this->e);
*this = return_mat;
return *this;
}
template<typename S>
mat& operator/=(const S & rhs)
{
#if defined(_MSC_VER)
#pragma warning(push)
// The operator/= throws a warning when a mat*f is divided by a double.
#pragma warning(disable:4244)
#endif
for (size_t i = 0; i < 3 * 3; i++)
e[i] /= rhs;
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
return *this;
}
template<typename S>
mat& operator+=(const mat<3, 3, S>& rhs)
{
for (size_t i = 0; i < 3 * 3; i++)
e[i] += rhs.e[i];
return *this;
}
template<typename S>
mat& operator-=(const mat<3, 3, S>& rhs)
{
for (size_t i = 0; i < 3 * 3; i++)
e[i] -= rhs.e[i];
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dimRow() const { return 3; }
size_t dimCol() const { return 3; }
size_t dimCols() const { return 3; }
template<typename S>
void copy(const mat<3, 3, S>& rhs)
{
*this = rhs;
}
mat neg() const
{
mat nm;
for (size_t i = 0; i < 3 * 3; i++)
nm.e[i] = -e[i];
return nm;
}
mat mult(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < 3 * 3; i++)
nm.e[i] = e[i] * scalar;
return nm;
}
mat div(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < 3 * 3; i++)
nm.e[i] = e[i] / scalar;
return nm;
}
mat add(const mat& toAdd) const
{
mat nm;
for (size_t i = 0; i < 3 * 3; i++)
nm.e[i] = e[i] + toAdd.e[i];
return nm;
}
mat sub(const mat& toSub) const
{
mat nm;
for (size_t i = 0; i < 3 * 3; i++)
nm.e[i] = e[i] - toSub.e[i];
return nm;
}
mat<3, 3, T> transpose() const
{
mat<3, 3, T> nm;
for (size_t row = 0; row < 3; row++)
{
for (size_t col = 0; col < 3; col++)
{
nm.e[row * 3 + col] = e[col * 3 + row];
}
}
return nm;
}
};
template <typename T>
struct mat<4, 4, T>
{
// Public Members /////////////////////////////////////////////////////////
public:
union
{
struct
{
T e00;
T e10;
T e20;
T e30;
T e01;
T e11;
T e21;
T e31;
T e02;
T e12;
T e22;
T e32;
T e03;
T e13;
T e23;
T e33;
};
T e[4*4];
};
// Constructors ///////////////////////////////////////////////////////////
public:
mat() { }
explicit mat(T val) :
e00(val), e01(val), e02(val), e03(val),
e10(val), e11(val), e12(val), e13(val),
e20(val), e21(val), e22(val), e23(val),
e30(val), e31(val), e32(val), e33(val)
{ }
mat(T e00v, T e01v, T e02v, T e03v,
T e10v, T e11v, T e12v, T e13v,
T e20v, T e21v, T e22v, T e23v,
T e30v, T e31v, T e32v, T e33v) :
e00(e00v), e01(e01v), e02(e02v), e03(e03v),
e10(e10v), e11(e11v), e12(e12v), e13(e13v),
e20(e20v), e21(e21v), e22(e22v), e23(e23v),
e30(e30v), e31(e31v), e32(e32v), e33(e33v)
{ }
mat(vec<4, T> col0, vec<4, T> col1, vec<4, T> col2, vec<4, T> col3) :
e00(col0.x), e10(col1.x), e20(col2.x), e30(col3.x),
e01(col0.y), e11(col1.y), e21(col2.y), e31(col3.y),
e02(col0.z), e12(col1.z), e22(col2.z), e32(col3.z),
e03(col0.w), e13(col1.w), e23(col2.w), e33(col3.w)
{
}
// Helper Methods /////////////////////////////////////////////////////////
public:
static mat zero()
{
return mat<4, 4, T>(0);
}
static mat one()
{
return mat<4, 4, T>(1);
}
static mat<4, 4, T> identity()
{
return mat<4, 4, T>(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}
// Operator Overloads /////////////////////////////////////////////////////
public:
T& operator()(size_t row, size_t col)
{
return const_cast<T&>(static_cast<const mat&>(*this)(row, col));
}
const T& operator()(size_t row, size_t col) const
{
assert(row < 4 && col < 4);
return e[col * 4 + row];
}
mat operator-() const
{
return neg();
}
template<typename S>
mat& operator*=(const S& rhs)
{
#if defined(_MSC_VER)
#pragma warning(push)
// The operator*= throws a warning when a mat*f is multiplied by a mat*d.
#pragma warning(disable:4244)
#endif
for (size_t i = 0; i < 4 * 4; i++)
e[i] *= rhs;
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
return *this;
}
template<typename S>
mat& operator*=(const mat<4, 4, S>& rhs)
{
size_t row = 0;
size_t col = 0;
size_t cell = 0;
mat<4, 4, T> return_mat = zero();
// Remember, this matrix is stored in column order
for (size_t row_index = 0; row_index < 4; row_index++)
{
for (size_t col_index = 0; col_index < 4; col_index++)
{
cell = row_index + (col_index * 4);
for (size_t cell_index = 0; cell_index < 4; cell_index++)
{
// calculated for the cell in the current row
row = row_index + (cell_index * 4);
// calculated for the cell in the current column
col = cell_index + (col_index * 4);
return_mat.e[cell] += this->e[row] * rhs.e[col];
}
}
}
*this = return_mat;
return *this;
}
template<typename S>
mat& operator/=(const S& rhs)
{
#if defined(_MSC_VER)
#pragma warning(push)
// The operator/= throws a warning when a mat*f is divided by a double.
#pragma warning(disable:4244)
#endif
for (size_t i = 0; i < 4 * 4; i++)
e[i] /= rhs;
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
return *this;
}
template<typename S>
mat& operator+=(const mat<4, 4, S>& rhs)
{
for (size_t i = 0; i < 4*4; i++)
e[i] += rhs.e[i];
return *this;
}
template<typename S>
mat& operator-=(const mat<4, 4, S>& rhs)
{
for (size_t i = 0; i < 4*4; i++)
e[i] -= rhs.e[i];
return *this;
}
// Public Methods /////////////////////////////////////////////////////////
public:
size_t dimRow() const { return 4; }
size_t dimCol() const { return 4; }
template<typename S>
void copy(const mat<4, 4, S>& rhs)
{
*this = rhs;
}
mat neg() const
{
mat nm;
for (size_t i = 0; i < 4 * 4; i++)
nm.e[i] = -e[i];
return nm;
}
mat mult(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < 4*4; i++)
nm.e[i] = e[i] * scalar;
return nm;
}
//mat mult(const mat& rhs)
mat div(const double& scalar) const
{
mat nm;
for (size_t i = 0; i < 4*4; i++)
nm.e[i] = e[i] / scalar;
return nm;
}
mat add(const mat& toAdd) const
{
mat nm;
for (size_t i = 0; i < 4*4; i++)
nm.e[i] = e[i] + toAdd.e[i];
return nm;
}
mat sub(const mat& toSub) const
{
mat nm;
for (size_t i = 0; i < 4*4; i++)
nm.e[i] = e[i] - toSub.e[i];
return nm;
}
mat<4, 4, T> transpose() const
{
mat<4, 4, T> nm;
for (size_t row = 0; row < 4; row++)
{
for (size_t col = 0; col < 4; col++)
{
nm.e[row * 4 + col] = e[col * 4 + row];
}
}
return nm;
}
};
#if defined (_MSC_VER)
#pragma warning(pop)
#endif
// Operator Overloads /////////////////////////////////////////////////////////
template <size_t m, size_t n, typename T, typename S>
mat<m, n, T> operator*(mat<m, n, T> lhs, const S& rhs)
{
lhs *= rhs;
return lhs;
}
template <size_t m, size_t n, typename T, typename S>
mat<m, n, T> operator*(const S& lhs, mat<m, n, T> rhs)
{
rhs *= lhs;
return rhs;
}
template <size_t m, size_t n, typename T, size_t r, size_t s, typename S>
mat<m, n, T> operator*(mat<m, n, T>&lhs, const mat<r, s, S>& rhs)
{
mat<m, n, T> tmp = lhs;
tmp *= rhs;
return tmp;
}
template <size_t m, size_t n, typename T, typename S>
mat<m, n, T> operator/(mat<m, n, T> lhs, const S& rhs)
{
lhs /= rhs;
return lhs;
}
template <size_t m, size_t n, typename T, typename S>
mat<m, n, T> operator+(mat<m, n, T> lhs, const mat<m, n, S>& rhs)
{
lhs += rhs;
return lhs;
}
template <size_t m, size_t n, typename T, typename S>
mat<m, n, T> operator-(mat<m, n, T> lhs, const mat<m, n, S>& rhs)
{
lhs -= rhs;
return lhs;
}
// Specific Typedefs //////////////////////////////////////////////////////////
typedef mat<2> mat2;
typedef mat<3> mat3;
typedef mat<4> mat4;
typedef mat<2> mat22;
typedef mat<3> mat33;
typedef mat<4> mat44;
typedef mat<2, 2, float> mat2f;
typedef mat<3, 3, float> mat3f;
typedef mat<4, 4, float> mat4f;
typedef mat<2, 2, double> mat2d;
typedef mat<3, 3, double> mat3d;
typedef mat<4, 4, double> mat4d;
typedef mat<2, 2, long double> mat2ld;
typedef mat<3, 3, long double> mat3ld;
typedef mat<4, 4, long double> mat4ld;
typedef mat<2, 2, float> mat22f;
typedef mat<3, 3, float> mat33f;
typedef mat<4, 3, float> mat44f;
typedef mat<2, 2, double> mat22d;
typedef mat<3, 3, double> mat33d;
typedef mat<4, 4, double> mat44d;
typedef mat<2, 2, long double> mat22ld;
typedef mat<3, 3, long double> mat33ld;
typedef mat<4, 4, long double> mat44ld;
// Common functions for working with matrices.
template <size_t mDim, size_t nDim, typename T> std::string str(mat<mDim, nDim, T> m)
{
std::stringstream ss;
ss << "[";
for (size_t row_index = 0; row_index < m.dimRow(); row_index++)
{
ss << "(";
for (size_t col_index = 0; col_index < m.dimCol(); col_index++)
{
ss << m(row_index, col_index);
if (col_index + 1 < m.dimCol())
ss << "; ";
}
ss << ")";
}
ss << "]";
return ss.str();
}
template <size_t mDim, size_t nDim, typename T> std::ostream& operator<<(std::ostream& out, mat<mDim, nDim, T> m)
{
out << str(m);
return out;
}
}
}
#endif
vn::math::mat< 2, 2, T >::mat
mat()
Creates a new matrix with uninitialized elements.
Definition: matrix.h:357
vn::math::mat< 4, 4, T >::e12
T e12
Element 1,2.
Definition: matrix.h:1099
vn::math::mat< 2, 2, T >::one
static mat one()
Matrix with all of its elements set to 1.
Definition: matrix.h:406
vn::math::mat< 4, 4, T >::operator*=
mat & operator*=(const mat< 4, 4, S > &rhs)
Multiplies the matrix by another matrix.
Definition: matrix.h:1279
vn::math::mat::operator()
T & operator()(size_t row, size_t col)
Indexing into the matrix's elements.
Definition: matrix.h:91
vn::math::mat< 4, 4, T >::operator()
const T & operator()(size_t row, size_t col) const
Indexing into the matrix's elements.
Definition: matrix.h:1235
vn::math::mat< 4, 4, T >::identity
static mat< 4, 4, T > identity()
Identity matrix with its diagonal elements set to 1.
Definition: matrix.h:1208
vn::math::mat< 3, 3, T >::mat
mat(vec< 3, T > col0, vec< 3, T > col1, vec< 3, T > col2)
Constructs a matrix from 3 column vectors. Vectors are stored in column order.
Definition: matrix.h:763
vn::math::mat< 4, 4, T >::e02
T e02
Element 0,2.
Definition: matrix.h:1096
vn::math::mat< 4, 4, T >::add
mat add(const mat &toAdd) const
Adds a matrix to this matrix.
Definition: matrix.h:1428
vn::math::mat< 2, 2, T >::mat
mat(T e00v, T e01v, T e10v, T e11v)
Creates a new matrix with its components initialized to the provided values.
Definition: matrix.h:374
vn::math::mat< 2, 2, T >::operator()
const T & operator()(size_t row, size_t col) const
Indexing into the matrix's elements.
Definition: matrix.h:440
vn::math::mat< 4, 4, T >::e33
T e33
Element 3,3.
Definition: matrix.h:1117
vn::math::mat< 3, 3, T >::operator()
T & operator()(size_t row, size_t col)
Indexing into the matrix's elements.
Definition: matrix.h:811
vn::math::mat::operator-=
mat & operator-=(const mat< m, n, S > &rhs)
Subtracts a matrix from this matrix.
Definition: matrix.h:202
vn::math::vec< 4, T >
Vector with 4 component specialization.
Definition: vector.h:869
vn::math::mat< 3, 3, T >::neg
mat neg() const
Negates the matrix.
Definition: matrix.h:973
vn::math::mat::operator+=
mat & operator+=(const mat< m, n, S > &rhs)
Adds a matrix to this matrix.
Definition: matrix.h:189
vn::math::mat< 2, 2, T >::add
mat add(const mat &toAdd) const
Adds a matrix to this matrix.
Definition: matrix.h:632
vn::math::mat< 4, 4, T >::e21
T e21
Element 2,1.
Definition: matrix.h:1090
vn::math::mat< 3, 3, T >::e12
T e12
Element 1,2.
Definition: matrix.h:711
vn::math::mat< 4, 4, T >::div
mat div(const double &scalar) const
Divides the matrix by a scalar.
Definition: matrix.h:1414
vn::math::mat< 3, 3, T >::div
mat div(const double &scalar) const
Divides the matrix by a scalar.
Definition: matrix.h:1001
vn::math::mat< 2, 2, T >::operator/=
mat & operator/=(const S &rhs)
Divides the matrix by a scalar.
Definition: matrix.h:521
vn::math::mat< 3, 3, T >
3x3 matrix specialization.
Definition: matrix.h:678
vn::math::mat< 3, 3, T >::e21
T e21
Element 2,1.
Definition: matrix.h:705
vn::math::mat< 3, 3, T >::e02
T e02
Element 0,2.
Definition: matrix.h:708
vn::math::mat< 3, 3, T >::e01
T e01
Element 0,1.
Definition: matrix.h:699
vn::math::mat< 3, 3, T >::operator*=
mat & operator*=(const mat< 3, 3, S > &rhs)
Multiplies the matrix by another matrix.
Definition: matrix.h:865
vn::math::mat< 4, 4, T >::e01
T e01
Element 0,1.
Definition: matrix.h:1084
vn::math::mat< 4, 4, T >::mult
mat mult(const double &scalar) const
Multiplies the matrix by a scalar.
Definition: matrix.h:1398
vn::math::mat< 2, 2, T >::operator-
mat operator-() const
Negates the matrix.
Definition: matrix.h:450
vn::math::mat< 3, 3, T >::operator*=
mat & operator*=(const S &rhs)
Multiplies the matrix by a scalar.
Definition: matrix.h:841
vn::math::mat< 2, 2, T >::transpose
mat< 2, 2, T > transpose() const
Transposes the matrix.
Definition: matrix.h:659
vn::math::mat< 2, 2, T >
2x2 matrix specialization.
Definition: matrix.h:324
vn::math::mat< 3, 3, T >::add
mat add(const mat &toAdd) const
Adds a matrix to this matrix.
Definition: matrix.h:1015
vn::math::mat< 3, 3, T >::dimRow
size_t dimRow() const
The matrix's row dimension.
Definition: matrix.h:956
vn::math::mat< 3, 3, T >::operator+=
mat & operator+=(const mat< 3, 3, S > &rhs)
Adds a matrix to this matrix.
Definition: matrix.h:928
vn::math::mat< 2, 2, T >::operator()
T & operator()(size_t row, size_t col)
Indexing into the matrix's elements.
Definition: matrix.h:430
vn::math::mat< 2, 2, T >::operator*=
mat & operator*=(const S &rhs)
Multiplies the matrix by a scalar.
Definition: matrix.h:460
vn::math::mat< 3, 3, T >::dimCol
size_t dimCol() const
The matrix's column dimension.
Definition: matrix.h:961
vn::math::mat< 3, 3, T >::transpose
mat< 3, 3, T > transpose() const
Transposes the matrix.
Definition: matrix.h:1042
vn::math::mat< 2, 2, T >::e01
T e01
Element 0,1.
Definition: matrix.h:342
vn::math::mat< 3, 3, T >::zero
static mat zero()
Matrix with all of its elements set to 0.
Definition: matrix.h:778
vn::math::mat< 2, 2, T >::mat
mat(vec< 2, T > col0, vec< 2, T > col1)
Constructs a matrix from 4 column vectors.
Definition: matrix.h:386
vn::math::mat::dimCol
size_t dimCol() const
The matrix's column dimension.
Definition: matrix.h:222
vn::math::mat< 4, 4, T >::one
static mat one()
Matrix with all of its elements set to 1.
Definition: matrix.h:1200
vn::math::mat< 4, 4, T >::e11
T e11
Element 1,1.
Definition: matrix.h:1087
vn::math::mat< 3, 3, T >::e10
T e10
Element 1,0.
Definition: matrix.h:693
vn::math::mat::transpose
mat< n, m, T > transpose() const
Transposes the matrix.
Definition: matrix.h:296
vn::math::mat< 3, 3, T >::mat
mat(T e00v, T e01v, T e02v, T e10v, T e11v, T e12v, T e20v, T e21v, T e22v)
Creates a new matrix with its components intialized to the provided values.
Definition: matrix.h:749
vn::math::mat< 3, 3, T >::e20
T e20
Element 2,0.
Definition: matrix.h:696
vn::math::mat< 4, 4, T >::operator-=
mat & operator-=(const mat< 4, 4, S > &rhs)
Subtracts a matrix from this matrix.
Definition: matrix.h:1353
vn::math::mat< 4, 4, T >::e
T e[4 *4]
The matrix's elements.
Definition: matrix.h:1121
vn::math::mat::operator*=
mat & operator*=(const S &rhs)
Multiplies the matrix by a scalar.
Definition: matrix.h:122
vn::math::mat
Template for a matrix.
Definition: matrix.h:20
vn::math::mat< 3, 3, T >::e22
T e22
Element 2,2.
Definition: matrix.h:714
vn::math::mat< 2, 2, T >::dimCol
size_t dimCol() const
The matrix's column dimension.
Definition: matrix.h:579
vn::math::mat::sub
mat sub(const mat &toSub) const
Subtracts a matrix from this matrix.
Definition: matrix.h:283
vn::math::mat< 2, 2, T >::mult
mat mult(const double &scalar) const
Multiplies the matrix by a scalar.
Definition: matrix.h:604
vn::math::vec< 3, T >
Vector with 3 component specialization.
Definition: vector.h:551
vn::math::mat< 4, 4, T >::e10
T e10
Element 1,0.
Definition: matrix.h:1075
vn::math::mat< 2, 2, T >::mat
mat(T val)
Creates a new matrix with its elements initialized to val.
Definition: matrix.h:362
vn::math::mat< 3, 3, T >::operator/=
mat & operator/=(const S &rhs)
Divides the matrix by a scalar.
Definition: matrix.h:904
vn::math::mat< 3, 3, T >::e00
T e00
Element 0,0.
Definition: matrix.h:690
vn::math::mat< 3, 3, T >::mat
mat()
Creates a new matrix with uninitialized elements.
Definition: matrix.h:726
exceptions.h
vn::math::mat< 2, 2, T >::dimRow
size_t dimRow() const
The matrix's row dimension.
Definition: matrix.h:573
vn::math::mat< 4, 4, T >::e30
T e30
Element 3,0.
Definition: matrix.h:1081
vn::math::mat< 4, 4, T >::dimRow
size_t dimRow() const
The matrix's row dimension.
Definition: matrix.h:1368
vn::math::mat::add
mat add(const mat &toAdd) const
Adds a matrix to this matrix.
Definition: matrix.h:269
vn::math::mat< 2, 2, T >::sub
mat sub(const mat &toSub) const
Subtracts a matrix from this matrix.
Definition: matrix.h:646
vn::math::mat< 3, 3, T >::operator()
const T & operator()(size_t row, size_t col) const
Indexing into the matrix's elements.
Definition: matrix.h:821
vn::math::mat< 2, 2, T >::operator+=
mat & operator+=(const mat< 2, 2, S > &rhs)
Adds a matrix to this matrix.
Definition: matrix.h:545
vn::math::mat< 3, 3, T >::one
static mat one()
Matrix with all of its elements set to 1.
Definition: matrix.h:786
vn::math::mat< 2, 2, T >::operator*=
mat & operator*=(const mat< 2, 2, S > &rhs)
Multiplies the matrix by another matrix.
Definition: matrix.h:484
vn::math::mat::operator-
mat operator-() const
Negates the matrix.
Definition: matrix.h:112
vn::math::mat< 4, 4, T >::e20
T e20
Element 2,0.
Definition: matrix.h:1078
vn::math::mat< 2, 2, T >::div
mat div(const double &scalar) const
Divides the matrix by a scalar.
Definition: matrix.h:618
vn::math::mat< 4, 4, T >::operator*=
mat & operator*=(const S &rhs)
Multiplies the matrix by a scalar.
Definition: matrix.h:1255
vn::math::mat< 4, 4, T >::dimCol
size_t dimCol() const
The matrix's column dimension.
Definition: matrix.h:1373
vn::math::mat< 2, 2, T >::neg
mat neg() const
Negates the matrix.
Definition: matrix.h:590
vn::math::mat::div
mat div(const double &scalar) const
Divides the matrix by a scalar.
Definition: matrix.h:255
vn::math::mat< 4, 4, T >::e22
T e22
Element 2,2.
Definition: matrix.h:1102
vn::math::mat< 3, 3, T >::e
T e[3 *3]
The matrix's elements.
Definition: matrix.h:718
vn::math::mat< 4, 4, T >::e13
T e13
Element 1,3.
Definition: matrix.h:1111
vn::math::mat< 2, 2, T >::e00
T e00
Element 0,0.
Definition: matrix.h:336
vn::math::mat< 4, 4, T >::operator+=
mat & operator+=(const mat< 4, 4, S > &rhs)
Adds a matrix to this matrix.
Definition: matrix.h:1340
vn::math::mat< 4, 4, T >::e31
T e31
Element 3,1.
Definition: matrix.h:1093
vector.h
vn::math::mat::one
static mat one()
Matrix with all of its elements set to 1.
Definition: matrix.h:62
vn::math::mat< 4, 4, T >::transpose
mat< 4, 4, T > transpose() const
Transposes the matrix.
Definition: matrix.h:1455
vn::math::mat< 4, 4, T >::e00
T e00
Element 0,0.
Definition: matrix.h:1072
vn::math::mat< 3, 3, T >::sub
mat sub(const mat &toSub) const
Subtracts a matrix from this matrix.
Definition: matrix.h:1029
vn::math::mat< 3, 3, T >::e11
T e11
Element 1,1.
Definition: matrix.h:702
vn::math::mat::mat
mat()
Creates a new matrix with uninitialized elements.
Definition: matrix.h:37
vn::math::mat< 4, 4, T >::mat
mat(vec< 4, T > col0, vec< 4, T > col1, vec< 4, T > col2, vec< 4, T > col3)
Constructs a matrix from 4 column vectors.
Definition: matrix.h:1176
vn::math::mat< 3, 3, T >::operator-
mat operator-() const
Negates the matrix.
Definition: matrix.h:831
vn::math::mat< 3, 3, T >::operator-=
mat & operator-=(const mat< 3, 3, S > &rhs)
Subtracts a matrix from this matrix.
Definition: matrix.h:941
vn::math::mat::mat
mat(T val)
Creates a new matrix with ints elements initialized to val.
Definition: matrix.h:42
vn::math::mat::operator*
mat & operator*(const mat< r, s, S > &rhs)
Multiplies the matrix by another matrix.
Definition: matrix.h:135
vn::math::mat< 2, 2, T >::e10
T e10
Element 1,0.
Definition: matrix.h:339
vn::math::mat< 2, 2, T >::zero
static mat zero()
Matrix with all of its elements set to 0.
Definition: matrix.h:398
vn::math::mat::neg
mat neg() const
Negates the matrix.
Definition: matrix.h:227
vn::math::mat< 2, 2, T >::operator-=
mat & operator-=(const mat< 2, 2, S > &rhs)
Subtracts a matrix from this matrix.
Definition: matrix.h:558
vn::math::mat< 2, 2, T >::e
T e[2 *2]
The matrix's elements.
Definition: matrix.h:349
vn
Definition: attitude.h:8
vn::math::mat< 4, 4, T >::operator()
T & operator()(size_t row, size_t col)
Indexing into the matrix's elements.
Definition: matrix.h:1225
vn::math::mat::operator()
const T & operator()(size_t row, size_t col) const
Indexing into the matrix's elements.
Definition: matrix.h:101
vn::math::mat< 3, 3, T >::mat
mat(T val)
Creates a new matrix with its elements initialized to val.
Definition: matrix.h:731
vn::math::mat::identity
static mat< m, m, T > identity()
Identity matrix with its diagonal elements set to 1.
Definition: matrix.h:70
vn::math::vec< 2, T >
Vector with 2 component specialization.
Definition: vector.h:279
vn::math::mat< 4, 4, T >::e23
T e23
Element 2,3.
Definition: matrix.h:1114
vn::math::mat< 4, 4, T >
4x4 matrix specialization.
Definition: matrix.h:1060
vn::math::mat< 4, 4, T >::mat
mat()
Creates a new matrix with uninitialized elements.
Definition: matrix.h:1129
vn::math::mat< 4, 4, T >::mat
mat(T e00v, T e01v, T e02v, T e03v, T e10v, T e11v, T e12v, T e13v, T e20v, T e21v, T e22v, T e23v, T e30v, T e31v, T e32v, T e33v)
Creates a new matrix with its components intialized to the provided values.
Definition: matrix.h:1160
vn::math::mat::dimRow
size_t dimRow() const
The matrix's row dimension.
Definition: matrix.h:217
vn::math::mat< 4, 4, T >::e32
T e32
Element 3,2.
Definition: matrix.h:1105
vn::math::mat< 4, 4, T >::mat
mat(T val)
Creates a new matrix with its elements initialized to val.
Definition: matrix.h:1134
vn::math::mat< 3, 3, T >::mult
mat mult(const double &scalar) const
Multiplies the matrix by a scalar.
Definition: matrix.h:987
vn::math::mat< 4, 4, T >::operator/=
mat & operator/=(const S &rhs)
Divides the matrix by a scalar.
Definition: matrix.h:1316
vn::math::mat::mult
mat mult(const double &scalar) const
Multiplies the matrix by a scalar.
Definition: matrix.h:241
vn::math::mat< 4, 4, T >::neg
mat neg() const
Negates the matrix.
Definition: matrix.h:1384
vn::math::mat< 4, 4, T >::zero
static mat zero()
Matrix with all of its elements set to 0.
Definition: matrix.h:1192
vn::math::mat::zero
static mat zero()
Matrix with all of its elements set to 0.
Definition: matrix.h:54
vn::math::mat< 3, 3, T >::identity
static mat< 3, 3, T > identity()
Identity matrix with its diagonal elements set to 1.
Definition: matrix.h:794
vn::math::mat< 4, 4, T >::e03
T e03
Element 0,3.
Definition: matrix.h:1108
vn::math::mat< 2, 2, T >::identity
static mat< 2, 2, T > identity()
Identity matrix with its diagonal elements set to 1.
Definition: matrix.h:414
vn::math::mat< 4, 4, T >::sub
mat sub(const mat &toSub) const
Subtracts a matrix from this matrix.
Definition: matrix.h:1442
vn::math::mat< 4, 4, T >::operator-
mat operator-() const
Negates the matrix.
Definition: matrix.h:1245
vn::math::mat::operator/=
mat & operator/=(const T &rhs)
Divides the matrix by a scalar.
Definition: matrix.h:176
vn::math::mat< 2, 2, T >::e11
T e11
Element 1,1.
Definition: matrix.h:345