LuciadCPillar 2026.1
Loading...
Searching...
No Matches
luciad::Matrix4x4 Class Referencefinal

A general-purpose 4x4 matrix, defined in a right-handed coordinate system. More...

#include <luciad/cartesian/Matrix4x4.h>

Public Member Functions

 Matrix4x4 ()
 Default constructor.
Matrix4x4 add (const Matrix4x4 &other) const
 Returns the sum of two matrices.
size_t getHash () const
 Returns the hash of this matrix.
double getValue (size_t column, size_t row) const
 Returns the value from the given column and row.
std::optional< Matrix4x4inverse () const
 Returns the inverse of this matrix, or std::nullopt if this matrix is not invertible.
bool isAffineTransformation () const
 Returns whether this arbitrary matrix represents a valid 3D affine transformation.
Coordinate multiply (const Coordinate &point) const
 Applies this matrix as an affine transformation to a point.
Matrix4x4 multiply (const Matrix4x4 &other) const
 Returns the product of two matrices.
Matrix4x4 multiply (double scalar) const
 Returns the element-wise product between this matrix and a scalar.
bool operator!= (const Matrix4x4 &other) const
Coordinate operator* (const Coordinate &point) const
Matrix4x4 operator* (const Matrix4x4 &other) const
Matrix4x4 operator* (double scalar) const
Matrix4x4operator*= (const Matrix4x4 &other)
Matrix4x4operator*= (double scalar)
Matrix4x4 operator+ (const Matrix4x4 &other) const
Matrix4x4operator+= (const Matrix4x4 &other)
Matrix4x4 operator- (const Matrix4x4 &other) const
Matrix4x4operator-= (const Matrix4x4 &other)
bool operator== (const Matrix4x4 &other) const
void setValue (size_t column, size_t row, double value)
 Sets the value at the given column and row.
Matrix4x4 subtract (const Matrix4x4 &other) const
 Returns the difference of two matrices.
Coordinate transformPoint (const Coordinate &point) const
 Applies this matrix as an affine transformation to a point.
Coordinate transformVector (const Coordinate &vector) const
 Applies this matrix as an affine transformation to a vector.
Matrix4x4 transpose () const
 Returns the transpose of this matrix.

Static Public Member Functions

static Matrix4x4 create (const std::vector< double > &values)
 Creates a new 4x4 matrix with the given values.
static Matrix4x4 identity ()
 Creates a new identity matrix.
static Matrix4x4 rotate (const Coordinate &axis, Angle angle)
 Creates a new rotation matrix around a given vector.
static Matrix4x4 rotateX (Angle angle)
 Creates a new rotation matrix around the x-axis.
static Matrix4x4 rotateY (Angle angle)
 Creates a new rotation matrix around the y-axis.
static Matrix4x4 rotateZ (Angle angle)
 Creates a new rotation matrix around the z-axis.
static Matrix4x4 scale (double scalar)
 Creates a new scaling matrix in all 3 dimensions.
static Matrix4x4 scale (double x, double y, double z)
 Creates a new scaling matrix.
static Matrix4x4 translate (const Coordinate &translation)
 Creates a new translation matrix.
static Matrix4x4 translate (double x, double y, double z)
 Creates a new translation matrix.

Detailed Description

A general-purpose 4x4 matrix, defined in a right-handed coordinate system.

A common use case for this class is to represent affine 3D transformations, such as translations, scalings, and rotations.

Since
2026.1

Constructor & Destructor Documentation

◆ Matrix4x4()

luciad::Matrix4x4::Matrix4x4 ( )

Default constructor.

Constructs the identity matrix.

Member Function Documentation

◆ add()

Matrix4x4 luciad::Matrix4x4::add ( const Matrix4x4 & other) const

Returns the sum of two matrices.

Parameters
otherthe other matrix.
Returns
the sum of the two matrices.

◆ create()

Matrix4x4 luciad::Matrix4x4::create ( const std::vector< double > & values)
static

Creates a new 4x4 matrix with the given values.

The values are expected in column-major order. For example, a list like [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] will become the following matrix:

  [ 0   4   8  12 ]
  [ 1   5   9  13 ]
  [ 2   6  10  14 ]
  [ 3   7  11  15 ]
Parameters
valuesa list of 16 values, in column-major order.
Returns
a new 4x4 matrix with the given values.
Exceptions
luciad::InvalidArgumentExceptionwhen the list does not contain exactly 16 values.

◆ getHash()

size_t luciad::Matrix4x4::getHash ( ) const

Returns the hash of this matrix.

Returns
the hash of this matrix.

◆ getValue()

double luciad::Matrix4x4::getValue ( size_t column,
size_t row ) const

Returns the value from the given column and row.

Parameters
columnthe column.
rowthe row.
Returns
the value from the given column and row.

◆ identity()

Matrix4x4 luciad::Matrix4x4::identity ( )
static

Creates a new identity matrix.

  [ 1 0 0 0 ]
  [ 0 1 0 0 ]
  [ 0 0 1 0 ]
  [ 0 0 0 1 ]
Returns
a new identity matrix.

◆ inverse()

std::optional< Matrix4x4 > luciad::Matrix4x4::inverse ( ) const

Returns the inverse of this matrix, or std::nullopt if this matrix is not invertible.

Returns
the inverse of this matrix, or std::nullopt if this matrix is not invertible.

◆ isAffineTransformation()

bool luciad::Matrix4x4::isAffineTransformation ( ) const

Returns whether this arbitrary matrix represents a valid 3D affine transformation.

This is equivalent to checking whether the matrix has the following form:

  [ . . . . ]
  [ . . . . ]
  [ . . . . ]
  [ 0 0 0 1 ]
Returns
whether this matrix is an affine transformation.

◆ multiply() [1/3]

Coordinate luciad::Matrix4x4::multiply ( const Coordinate & point) const

Applies this matrix as an affine transformation to a point.

This method does the same as transformPoint.

Parameters
pointthe point.
Returns
the transformed point.

◆ multiply() [2/3]

Matrix4x4 luciad::Matrix4x4::multiply ( const Matrix4x4 & other) const

Returns the product of two matrices.

Parameters
otherthe other matrix.
Returns
the product of the two matrices.

◆ multiply() [3/3]

Matrix4x4 luciad::Matrix4x4::multiply ( double scalar) const

Returns the element-wise product between this matrix and a scalar.

Parameters
scalarthe scalar.
Returns
the element-wise product between this matrix and the scalar.

◆ operator!=()

bool luciad::Matrix4x4::operator!= ( const Matrix4x4 & other) const

◆ operator*() [1/3]

Coordinate luciad::Matrix4x4::operator* ( const Coordinate & point) const

◆ operator*() [2/3]

Matrix4x4 luciad::Matrix4x4::operator* ( const Matrix4x4 & other) const

◆ operator*() [3/3]

Matrix4x4 luciad::Matrix4x4::operator* ( double scalar) const

◆ operator*=() [1/2]

Matrix4x4 & luciad::Matrix4x4::operator*= ( const Matrix4x4 & other)

◆ operator*=() [2/2]

Matrix4x4 & luciad::Matrix4x4::operator*= ( double scalar)

◆ operator+()

Matrix4x4 luciad::Matrix4x4::operator+ ( const Matrix4x4 & other) const

◆ operator+=()

Matrix4x4 & luciad::Matrix4x4::operator+= ( const Matrix4x4 & other)

◆ operator-()

Matrix4x4 luciad::Matrix4x4::operator- ( const Matrix4x4 & other) const

◆ operator-=()

Matrix4x4 & luciad::Matrix4x4::operator-= ( const Matrix4x4 & other)

◆ operator==()

bool luciad::Matrix4x4::operator== ( const Matrix4x4 & other) const

◆ rotate()

Matrix4x4 luciad::Matrix4x4::rotate ( const Coordinate & axis,
Angle angle )
static

Creates a new rotation matrix around a given vector.

Note: the rotation happens counterclockwise. When imagining the vector as an arrow, looking at the arrowhead coming towards you makes the rotation appear counterclockwise.

Parameters
axisthe vector to rotate around.
anglethe amount to rotate.
Returns
a new rotation matrix around the given vector.

◆ rotateX()

Matrix4x4 luciad::Matrix4x4::rotateX ( Angle angle)
static

Creates a new rotation matrix around the x-axis.

Note: the rotation happens counterclockwise. Looking towards negative infinity on the x-axis makes the rotation appear counterclockwise.

Parameters
anglethe amount to rotate.
Returns
a new rotation matrix around the x-axis.

◆ rotateY()

Matrix4x4 luciad::Matrix4x4::rotateY ( Angle angle)
static

Creates a new rotation matrix around the y-axis.

Note: the rotation happens counterclockwise. Looking towards negative infinity on the y-axis makes the rotation appear counterclockwise.

Parameters
anglethe amount to rotate.
Returns
a new rotation matrix around the y-axis.

◆ rotateZ()

Matrix4x4 luciad::Matrix4x4::rotateZ ( Angle angle)
static

Creates a new rotation matrix around the z-axis.

Note: the rotation happens counterclockwise. Looking towards negative infinity on the z-axis makes the rotation appear counterclockwise.

Parameters
anglethe amount to rotate.
Returns
a new rotation matrix around the z-axis.

◆ scale() [1/2]

Matrix4x4 luciad::Matrix4x4::scale ( double scalar)
static

Creates a new scaling matrix in all 3 dimensions.

Parameters
scalarthe amount to scale.
Returns
a new scaling matrix.

◆ scale() [2/2]

Matrix4x4 luciad::Matrix4x4::scale ( double x,
double y,
double z )
static

Creates a new scaling matrix.

Parameters
xthe amount to scale on the x-axis.
ythe amount to scale on the y-axis.
zthe amount to scale on the z-axis.
Returns
a new scaling matrix.

◆ setValue()

void luciad::Matrix4x4::setValue ( size_t column,
size_t row,
double value )

Sets the value at the given column and row.

Parameters
columnthe column.
rowthe row.
valuethe value.

◆ subtract()

Matrix4x4 luciad::Matrix4x4::subtract ( const Matrix4x4 & other) const

Returns the difference of two matrices.

Parameters
otherthe other matrix.
Returns
the difference of the two matrices.

◆ transformPoint()

Coordinate luciad::Matrix4x4::transformPoint ( const Coordinate & point) const

Applies this matrix as an affine transformation to a point.

This method does the same as the multiply operator.

Parameters
pointthe point.
Returns
the transformed point.

◆ transformVector()

Coordinate luciad::Matrix4x4::transformVector ( const Coordinate & vector) const

Applies this matrix as an affine transformation to a vector.

Note: the main difference between transformVector and transformPoint is that transformVector does NOT apply translations, whereas transformPoint does.

Parameters
vectorthe vector.
Returns
the transformed vector.

◆ translate() [1/2]

Matrix4x4 luciad::Matrix4x4::translate ( const Coordinate & translation)
static

Creates a new translation matrix.

Parameters
translationthe translation.
Returns
a new translation matrix.

◆ translate() [2/2]

Matrix4x4 luciad::Matrix4x4::translate ( double x,
double y,
double z )
static

Creates a new translation matrix.

Parameters
xthe translation on the x-axis.
ythe translation on the y-axis.
zthe translation on the z-axis.
Returns
a new translation matrix.

◆ transpose()

Matrix4x4 luciad::Matrix4x4::transpose ( ) const

Returns the transpose of this matrix.

Returns
the transpose of this matrix.