Polygon Mesh Processing Library
Loading...
Searching...
No Matches
Matrix< Scalar, M, N > Class Template Reference

Generic class for \( M \times N \) matrices. More...

#include <pmp/mat_vec.h>

Public Types

using value_type = Scalar
 The scalar type of the matrix.
 

Public Member Functions

 Matrix ()=default
 Default constructor.
 
 Matrix (Scalar s)
 Construct with all entries initialized to Scalar s.
 
 Matrix (const std::initializer_list< Scalar > &&values)
 Construct from row-wise initializer list of M*N entries.
 
 Matrix (const std::initializer_list< Matrix< Scalar, M, 1 > > &&columns)
 constructor with N column vectors of dimension M
 
 Matrix (Scalar x, Scalar y)
 constructor for 2D vectors
 
 Matrix (Scalar x, Scalar y, Scalar z)
 constructor for 3D vectors
 
 Matrix (Scalar x, Scalar y, Scalar z, Scalar w)
 constructor for 4D vectors
 
 Matrix (Matrix< Scalar, 3, 1 > xyz, Scalar w)
 constructor for 4D vectors
 
 Matrix (Matrix< Scalar, 3, 1 > c0, Matrix< Scalar, 3, 1 > c1, Matrix< Scalar, 3, 1 > c2)
 construct 3x3 matrix from 3 column vectors
 
 Matrix (Matrix< Scalar, 4, 1 > c0, Matrix< Scalar, 4, 1 > c1, Matrix< Scalar, 4, 1 > c2, Matrix< Scalar, 4, 1 > c3)
 construct 4x4 matrix from 4 column vectors
 
 Matrix (Scalar m00, Scalar m01, Scalar m02, Scalar m03, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m20, Scalar m21, Scalar m22, Scalar m23, Scalar m30, Scalar m31, Scalar m32, Scalar m33)
 construct 4x4 matrix from 16 (row-wise) entries
 
template<typename Derived >
 Matrix (const Eigen::MatrixBase< Derived > &m)
 construct from Eigen
 
template<typename OtherScalarType >
 Matrix (const Matrix< OtherScalarType, M, N > &m)
 copy constructor from other scalar type is also invoked for type-casting
 
template<typename Derived >
Matrix< Scalar, M, N > & operator= (const Eigen::MatrixBase< Derived > &m)
 assign from Eigen
 
template<typename OtherScalar >
 operator Eigen::Matrix< OtherScalar, M, N > () const
 cast to Eigen
 
Scalaroperator() (unsigned int i, unsigned int j)
 access entry at row i and column j
 
const Scalaroperator() (unsigned int i, unsigned int j) const
 const-access entry at row i and column j
 
Scalaroperator[] (unsigned int i)
 access i'th entry (use for vectors)
 
Scalar operator[] (unsigned int i) const
 const-access i'th entry (use for vectors)
 
const Scalardata () const
 const-access as scalar array
 
Scalardata ()
 access as scalar array
 
void normalize ()
 normalize matrix/vector by dividing through Frobenius/Euclidean norm
 
Matrix< Scalar, M, N > & operator/= (const Scalar s)
 divide matrix by scalar
 
Matrix< Scalar, M, N > & operator*= (const Scalar s)
 multiply matrix by scalar
 
Matrix< Scalar, M, N > & operator-= (const Matrix< Scalar, M, N > &m)
 subtract other matrix from this matrix
 
bool operator== (const Matrix< Scalar, M, N > &other) const
 component-wise comparison
 
bool operator!= (const Matrix< Scalar, M, N > &other) const
 component-wise comparison
 

Static Public Member Functions

static constexpr int rows ()
 Return the number of rows of the matrix.
 
static constexpr int cols ()
 Return the number of columns of the matrix.
 
static constexpr int size ()
 Return the size (rows*cols) of the matrix.
 
static Matrix< Scalar, M, N > identity ()
 return identity matrix (only for square matrices, N==M)
 

Detailed Description

template<typename Scalar, int M, int N>
class pmp::Matrix< Scalar, M, N >

Generic class for \( M \times N \) matrices.