Jameo Core Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
jm::Matrix Struct Reference

An m x n-dimensional matrix. More...

Public Member Functions

 Matrix (size_t rows, size_t cols)
 This constructor creates a matrix and initializes it with zeros.
 
 Matrix (const Vertex3 &c1, const Vertex3 &c2, const Vertex3 &c3, bool rowwise)
 Special constructor for a 3x3 matrix.
 
 Matrix ()=default
 Default constructor.
 
 Matrix (double value)
 Constructor sets up a matrix 1x1 with the numerical value as entry,.
 
 Matrix (const Matrix &other)
 Copy constructor.
 
 Matrix (const Matrix *other)
 Copy constructor.
 
virtual ~Matrix ()
 Destructor.
 
void set (size_t row, size_t col, double value)
 Sets the value of a cell.
 
void add (size_t row, size_t col, double value)
 Adds to the value of a cell the passed value.
 
double get (size_t row, size_t col) const
 Returns the value of a cell.
 
void zeros ()
 This method fills all elements of the matrix with 0.
 
void transpose ()
 This method transposes the matrix,.
 
void insert (const Matrix &A)
 This method inserts the contents of the other matrix into this matrix. Upper left element is 0,0.
 
void insert (const Matrix &A, size_t r, size_t c)
 This method inserts the contents of the Other matrix into this matrix. Upper left element is r,c.
 
void diag (double value)
 This method sets all values on the diagonal elements to the desired value.
 
Status det (double &det) const
 Calculates the determinant of a matrix.
 
Status inverse ()
 Inverts this matrix.
 
const double * ref () const
 This method returns the reference to the data array.
 
double norm (MatrixNorm norm) const
 This method calculates the condition of the matrix according to the corresponding matrix norm.
 
double trace () const
 Returns the sum of the diagonal elements.
 
Vector eigen () const
 Returns the Eigen Values of the matrix.
 
void print () const
 Prints the content of the matrix on std::cout.
 
size_t nonZeroElementCount () const
 This method calculates the number of elements that are not 0.0. Currently this is done without EPS.
 
void initIdentity ()
 Initializes this transformation as an identity matrix.
 
void initWcs (const Vertex3 &extrusion)
 Initializes this matrix as a World Coordinate System (WCS) matrix.
 
void initMirroring (const Vertex3 &planePoint, const Vertex3 &planeNormal)
 Initializes this matrix as a mirroring matrix.
 
void initMoving (const Vertex3 &distance)
 Initializes this matrix as a translation matrix.
 
void initScaling (const Vertex3 &factors)
 Initializes this transformation as scaling by different factors along the x, y, and z axes.
 
void initScaling (const Vertex3 &basePoint, double factor)
 Initializes this transformation as scaling around a base point.
 
void initRotationZ (double angle)
 Initializes this Transform as a rotation matrix around the Z-axis.
 
void initRotation (const Vertex3 &axisPoint, const Vertex3 &axisDirection, double angle)
 Initializes this Transform as a rotation matrix.
 
void initLookAt (const jm::Vertex3 &camera, const jm::Vertex3 &center, const jm::Vertex3 &up)
 Initialize this matrix as a "look-at" matrix.
 
Vertex3 trans (const Vertex3 &vertex) const
 This method transforms the vertex using the 4x4 transformation matrix.
 
double trans (double value) const
 This method transforms the number using the 4x4 transformation matrix. X value is used.
 
double transAngle (double angle) const
 Transform a rotation angle about the Z-Axis of LCS as usually needed by arcs or texts.
 
Matrixoperator= (const Matrix &A)
 
size_t rows () const
 This method returns the number of rows.
 
size_t cols () const
 This method returns the number of columns.
 

Static Public Member Functions

static Matrix generate3x3RotationMatrix (double angle, const Vertex3 &axis)
 This static function generates a 3x3 rotation matrix.
 
static Matrix generate3x3RotationXMatrix (double angle)
 This static function generates a 3x3 rotation matrix for a rotation around the X-axis.
 
static Matrix generate3x3RotationYMatrix (double angle)
 This static function generates a 3x3 rotation matrix for a rotation around the Y-axis.
 
static Matrix generate3x3RotationZMatrix (double angle)
 This static function generates a 3x3 rotation matrix for a rotation around the Z-axis.
 
static Matrix generate3x3RotationMatrix (const Vertex3 &u, const Vertex3 &v)
 This static function generates a 3x3 rotation matrix for a rotation from vector u to vector v.
 

Friends

DllExport friend Matrix operator* (const Matrix &A, const Matrix &B)
 Implementation of the operator M * M (matrix multiplication).
 
DllExport friend Matrix operator* (const double &d, const Matrix &b)
 Implementation of the operator d * M (scalar multiplication).
 
DllExport friend Vertex3 operator* (const Matrix &A, const Vertex3 &b)
 Implementation of the operator M * v (matrix multiplication with a vector). The matrix must be 3x3.
 
DllExport friend Matrix operator+ (const Matrix &A, const Matrix &B)
 Implementation of the operator M + M (matrix addition).
 
DllExport friend Matrix operator- (const Matrix &A, const Matrix &B)
 Implementation of the operator M - M (matrix subtraction).
 
DllExport friend Matrix operator/ (const Matrix &A, const double &d)
 Implementation of the operator M / d (scalar division).
 

Detailed Description

An m x n-dimensional matrix.

Constructor & Destructor Documentation

◆ Matrix() [1/6]

jm::Matrix::Matrix ( size_t  rows,
size_t  cols 
)

This constructor creates a matrix and initializes it with zeros.

Parameters
rowsNumber of rows.
colsNumber of columns.

◆ Matrix() [2/6]

jm::Matrix::Matrix ( const Vertex3 c1,
const Vertex3 c2,
const Vertex3 c3,
bool  rowwise 
)

Special constructor for a 3x3 matrix.

Parameters
c1The 1st column of the matrix
c2The 2nd column of the matrix
c3The 3rd column of the matrix
rowwiseif true, then the matrix is filled row by row otherwise column by column.

◆ Matrix() [3/6]

jm::Matrix::Matrix ( )
default

Default constructor.

◆ Matrix() [4/6]

jm::Matrix::Matrix ( double  value)
explicit

Constructor sets up a matrix 1x1 with the numerical value as entry,.

◆ Matrix() [5/6]

jm::Matrix::Matrix ( const Matrix other)

Copy constructor.

◆ Matrix() [6/6]

jm::Matrix::Matrix ( const Matrix other)

Copy constructor.

◆ ~Matrix()

virtual jm::Matrix::~Matrix ( )
virtual

Destructor.

Member Function Documentation

◆ add()

void jm::Matrix::add ( size_t  row,
size_t  col,
double  value 
)

Adds to the value of a cell the passed value.

Parameters
rowThe 0-based index of the row.
colThe 0-based index of the column.
valueThe value to be added to the cell.

◆ cols()

size_t jm::Matrix::cols ( ) const

This method returns the number of columns.

◆ det()

Status jm::Matrix::det ( double &  det) const

Calculates the determinant of a matrix.

This method is currently limited to a maximum of 4x4 matrices.

◆ diag()

void jm::Matrix::diag ( double  value)

This method sets all values on the diagonal elements to the desired value.

◆ eigen()

Vector jm::Matrix::eigen ( ) const

Returns the Eigen Values of the matrix.

Currentrly this is restricted to matrices of maximum 3x3.

◆ generate3x3RotationMatrix() [1/2]

static Matrix jm::Matrix::generate3x3RotationMatrix ( const Vertex3 u,
const Vertex3 v 
)
static

This static function generates a 3x3 rotation matrix for a rotation from vector u to vector v.

Parameters
uThe start vector
vThe end vector

◆ generate3x3RotationMatrix() [2/2]

static Matrix jm::Matrix::generate3x3RotationMatrix ( double  angle,
const Vertex3 axis 
)
static

This static function generates a 3x3 rotation matrix.

Parameters
angleAngle of rotation in radians
axisRotation axis (must be normalized)

◆ generate3x3RotationXMatrix()

static Matrix jm::Matrix::generate3x3RotationXMatrix ( double  angle)
static

This static function generates a 3x3 rotation matrix for a rotation around the X-axis.

Parameters
angleAngle of rotation in radians

◆ generate3x3RotationYMatrix()

static Matrix jm::Matrix::generate3x3RotationYMatrix ( double  angle)
static

This static function generates a 3x3 rotation matrix for a rotation around the Y-axis.

Parameters
angleAngle of rotation in radians

◆ generate3x3RotationZMatrix()

static Matrix jm::Matrix::generate3x3RotationZMatrix ( double  angle)
static

This static function generates a 3x3 rotation matrix for a rotation around the Z-axis.

Parameters
angleAngle of rotation in radians

◆ get()

double jm::Matrix::get ( size_t  row,
size_t  col 
) const

Returns the value of a cell.

Parameters
rowThe 0-based index of the row.
colThe 0-based index of the column.

◆ initIdentity()

void jm::Matrix::initIdentity ( )

Initializes this transformation as an identity matrix.

An identity matrix is a square matrix in which all the elements of the principal diagonal are ones and all other elements are zeros. When a vector or point is multiplied by an identity matrix, the result is the same vector or point. This method sets the transformation matrix to an identity matrix, effectively resetting any previous transformations applied.

◆ initLookAt()

void jm::Matrix::initLookAt ( const jm::Vertex3 camera,
const jm::Vertex3 center,
const jm::Vertex3 up 
)

Initialize this matrix as a "look-at" matrix.

Parameters
cameraThe camera position
centerThe "target" center of the view
upThe up vector (needed for rotation)

◆ initMirroring()

void jm::Matrix::initMirroring ( const Vertex3 planePoint,
const Vertex3 planeNormal 
)

Initializes this matrix as a mirroring matrix.

Parameters
planePointThe point on the mirror plane.
planeNormalThe normal vector of the mirror plane.

This method initializes the transformation matrix as a mirroring matrix, which reflects points across a mirror plane. The mirror plane is defined by a point on the plane (planePoint) and the normal vector of the plane (planeNormal). The resulting matrix can be used to mirror 3D points and objects.

◆ initMoving()

void jm::Matrix::initMoving ( const Vertex3 distance)

Initializes this matrix as a translation matrix.

Parameters
distanceThe distance to translate by.

◆ initRotation()

void jm::Matrix::initRotation ( const Vertex3 axisPoint,
const Vertex3 axisDirection,
double  angle 
)

Initializes this Transform as a rotation matrix.

Parameters
axisPointThe origin vector of the rotation axis.
axisDirectionThe normalized direction vector of the rotation axis.
angleThe rotation angle in radians.

◆ initRotationZ()

void jm::Matrix::initRotationZ ( double  angle)

Initializes this Transform as a rotation matrix around the Z-axis.

Parameters
angleThe rotation angle in radians.

◆ initScaling() [1/2]

void jm::Matrix::initScaling ( const Vertex3 basePoint,
double  factor 
)

Initializes this transformation as scaling around a base point.

Parameters
basePointThe point around which the scaling is performed.
factorThe scaling factor.

◆ initScaling() [2/2]

void jm::Matrix::initScaling ( const Vertex3 factors)

Initializes this transformation as scaling by different factors along the x, y, and z axes.

Parameters
factorsThe scaling factors along the x, y, and z axes.

◆ initWcs()

void jm::Matrix::initWcs ( const Vertex3 extrusion)

Initializes this matrix as a World Coordinate System (WCS) matrix.

Note
The matrix must be 4x4
Parameters
extrusionThe extrusion vector used for the transformation.

This method initializes the transformation matrix as a WCS matrix, which represents the coordinate system transformation from Object Coordinate System (OCS) to WCS. The extrusion vector is used to define the direction of the Z-axis in the WCS. The resulting matrix can be used to transform 3D points and angles from OCS to WCS.

◆ insert() [1/2]

void jm::Matrix::insert ( const Matrix A)

This method inserts the contents of the other matrix into this matrix. Upper left element is 0,0.

◆ insert() [2/2]

void jm::Matrix::insert ( const Matrix A,
size_t  r,
size_t  c 
)

This method inserts the contents of the Other matrix into this matrix. Upper left element is r,c.

◆ inverse()

Status jm::Matrix::inverse ( )

Inverts this matrix.

This method is currently limited to a maximum of 4x4 matrices.

◆ nonZeroElementCount()

size_t jm::Matrix::nonZeroElementCount ( ) const

This method calculates the number of elements that are not 0.0. Currently this is done without EPS.

◆ norm()

double jm::Matrix::norm ( MatrixNorm  norm) const

This method calculates the condition of the matrix according to the corresponding matrix norm.

◆ operator=()

Matrix & jm::Matrix::operator= ( const Matrix A)

◆ print()

void jm::Matrix::print ( ) const

Prints the content of the matrix on std::cout.

◆ ref()

const double * jm::Matrix::ref ( ) const

This method returns the reference to the data array.

Only needed for efficient access for OpenGL.

◆ rows()

size_t jm::Matrix::rows ( ) const

This method returns the number of rows.

◆ set()

void jm::Matrix::set ( size_t  row,
size_t  col,
double  value 
)

Sets the value of a cell.

Parameters
rowThe 0-based index of the row.
colThe 0-based index of the column.
valueThe value of the cell.

◆ trace()

double jm::Matrix::trace ( ) const

Returns the sum of the diagonal elements.

◆ trans() [1/2]

Vertex3 jm::Matrix::trans ( const Vertex3 vertex) const

This method transforms the vertex using the 4x4 transformation matrix.

Parameters
vertexThe input vertex to be transformed.
Returns
The transformed vertex.

◆ trans() [2/2]

double jm::Matrix::trans ( double  value) const

This method transforms the number using the 4x4 transformation matrix. X value is used.

Parameters
valueThe input number to be transformed.
Returns
The transformed number.

◆ transAngle()

double jm::Matrix::transAngle ( double  angle) const

Transform a rotation angle about the Z-Axis of LCS as usually needed by arcs or texts.

Parameters
angleRotation angle in radians.
Returns
The transformed angle.

◆ transpose()

void jm::Matrix::transpose ( )

This method transposes the matrix,.

◆ zeros()

void jm::Matrix::zeros ( )

This method fills all elements of the matrix with 0.

Friends And Related Symbol Documentation

◆ operator* [1/3]

DllExport friend Matrix operator* ( const double &  d,
const Matrix b 
)
friend

Implementation of the operator d * M (scalar multiplication).

◆ operator* [2/3]

DllExport friend Matrix operator* ( const Matrix A,
const Matrix B 
)
friend

Implementation of the operator M * M (matrix multiplication).

◆ operator* [3/3]

DllExport friend Vertex3 operator* ( const Matrix A,
const Vertex3 b 
)
friend

Implementation of the operator M * v (matrix multiplication with a vector). The matrix must be 3x3.

◆ operator+

DllExport friend Matrix operator+ ( const Matrix A,
const Matrix B 
)
friend

Implementation of the operator M + M (matrix addition).

◆ operator-

DllExport friend Matrix operator- ( const Matrix A,
const Matrix B 
)
friend

Implementation of the operator M - M (matrix subtraction).

◆ operator/

DllExport friend Matrix operator/ ( const Matrix A,
const double &  d 
)
friend

Implementation of the operator M / d (scalar division).