RoboDK Plug-In Interface
Loading...
Searching...
No Matches
Matrix4x4 Class Reference

The Matrix4x4 class represents a 4x4 transformation matrix in 3D space. More...

#include <matrix4x4.h>

Inheritance diagram for Matrix4x4:

Public Member Functions

 Matrix4x4 ()
 Constructs an identity matrix.
 
 Matrix4x4 (bool valid)
 Constructs a valid or an invalid identity matrix.
 
 Matrix4x4 (const Matrix4x4 &matrix)
 Constructs this Matrix4x4 object as a copy of matrix.
 
 Matrix4x4 (const double *values)
 Constructs a matrix from the given 16 double-precision values.
 
 Matrix4x4 (const float *values)
 Constructs a matrix from the given 16 single-precision values.
 
 Matrix4x4 (double x, double y, double z)
 Constructs a matrix that translates coordinates by the components x, y, and z.
 
 Matrix4x4 (double nx, double ox, double ax, double tx, double ny, double oy, double ay, double ty, double nz, double oz, double az, double tz)
 Constructs a matrix from the N, O, A, T vector components.
 
void SetVX (const Vector3 &n)
 Sets the X vector (N vector).
 
void SetVY (const Vector3 &o)
 Sets the Y vector (O vector).
 
void SetVZ (const Vector3 &a)
 Sets the Z vector (A vector).
 
void SetVX (double x, double y, double z)
 Sets the X vector values (N vector).
 
void SetVY (double x, double y, double z)
 Sets the Y vector values (O vector).
 
void SetVZ (double x, double y, double z)
 Sets the Z vector values (A vector).
 
void SetPos (double x, double y, double z)
 Sets the position (T).
 
void SetVX (const double *xyz)
 Sets the X vector values (N vector).
 
void SetVY (const double *xyz)
 Sets the Y vector values (O vector).
 
void SetVZ (const double *xyz)
 Sets the Z vector values (A vector).
 
void SetPos (const double *xyz)
 Sets the position (T).
 
void SetValues (const double *values)
 Sets the elements of matrix from the given 16 double-precision values.
 
Vector3 VX () const
 Returns the X vector (N vector).
 
Vector3 VY () const
 Returns the Y vector (O vector).
 
Vector3 VZ () const
 Returns the Z vector (A vector).
 
void VX (double *xyz) const
 Writes the X vector (N vector) into array of 3 double-precision xyz values.
 
void VY (double *xyz) const
 Writes the Y vector (O vector) into array of 3 double-precision xyz values.
 
void VZ (double *xyz) const
 Writes the Z vector (A vector) into array of 3 double-precision xyz values.
 
void Pos (double *xyz) const
 Writes the position (T vector) into array of 3 double-precision xyz values.
 
void Set (int row, int column, double value)
 Sets a new value to the element at position (row, column) in this matrix.
 
double Get (int row, int column) const
 Returns the value of the element at position (row, column) in this matrix.
 
Matrix4x4 Inverted (bool *invertible=nullptr) const
 Returns the inverse of this matrix.
 
bool IsHomogeneous () const
 Returns true if the matrix is homogeneous; false otherwise.
 
bool MakeHomogeneous ()
 Forces this matrix to be homogeneous.
 
void ToXYZRPW (double *xyzwpr) const
 Calculates the position and euler angles ([x,y,z,r,p,w] vector) from this matrix.
 
void FromXYZRPW (const double *xyzwpr)
 Calculates this matrix from the position and euler angles ([x,y,z,r,p,w] vector).
 
const double * ValuesD () const
 Returns a constant pointer to the raw data of this matrix as 16 double-precision numbers.
 
const float * ValuesF () const
 Returns a constant pointer to the raw data of this matrix as 16 single-precision numbers.
 
const double * Values () const
 Returns a constant pointer to the raw data of this matrix as 16 double- or single-precision numbers.
 
void Values (double *values) const
 Writes the contents of this matrix into array of 16 double-precision values.
 
void Values (float *values) const
 Writes the contents of this matrix into array of 16 single-precision values.
 
bool Valid () const
 Returns true if the matrix is marked as valid; false otherwise.
 
Matrix4x4operator= (const Matrix4x4 &matrix)
 Sets this Matrix4x4 object as a copy of matrix.
 
Matrix4x4 inv ()
 
void setPos (double x, double y, double z)
 

Static Public Member Functions

static Matrix4x4 XYZRPW_2_Mat (double x, double y, double z, double r, double p, double w)
 Constructs a matrix from the position and euler angles ([x,y,z,r,p,w] vector).
 
static Matrix4x4 XYZRPW_2_Mat (const double *xyzwpr)
 Constructs a matrix from the position and euler angles ([x,y,z,r,p,w] vector).
 
static Matrix4x4 transl (double x, double y, double z)
 Constructs a matrix that translates coordinates by the components x, y, and z.
 
static Matrix4x4 rotx (double rx)
 Constructs a matrix that rotates coordinates around X axis.
 
static Matrix4x4 roty (double ry)
 Constructs a matrix that rotates coordinates around Y axis.
 
static Matrix4x4 rotz (double rz)
 Constructs a matrix that rotates coordinates around Z axis.
 

Detailed Description

The Matrix4x4 class represents a 4x4 transformation matrix in 3D space.

The Matrix4x4 class in general is treated as a row-major matrix, in that the constructors and operator() functions take data in row-major format, as is familiar in C-style usage.

Internally the data is stored as column-major format.

When using these functions be aware that they return data in column-major format:

Definition at line 69 of file matrix4x4.h.

Constructor & Destructor Documentation

◆ Matrix4x4() [1/7]

Matrix4x4 ( )

Constructs an identity matrix.

Definition at line 41 of file matrix4x4.cpp.

◆ Matrix4x4() [2/7]

Matrix4x4 ( bool valid)
explicit

Constructs a valid or an invalid identity matrix.

Definition at line 48 of file matrix4x4.cpp.

◆ Matrix4x4() [3/7]

Matrix4x4 ( const Matrix4x4 & matrix)

Constructs this Matrix4x4 object as a copy of matrix.

Definition at line 55 of file matrix4x4.cpp.

◆ Matrix4x4() [4/7]

Matrix4x4 ( const double * values)

Constructs a matrix from the given 16 double-precision values.

The contents of the array values is assumed to be in column-major order.

Parameters
values\( \begin{bmatrix} v_1 & v_2 & v_3 & v_4 & v_5 & v_6 & v_7 & v_8 & v_9 & v_{10} & v_{11} & v_{12} & v_{13} & v_{14} & v_{15} & v_{16} \end{bmatrix} \)
Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} v_1 & v_5 & v_9 & v_{13} \\ v_2 & v_6 & v_{10} & v_{14} \\ v_3 & v_7 & v_{11} & v_{15} \\ v_4 & v_8 & v_{12} & v_{16} \end{bmatrix} \)

Definition at line 61 of file matrix4x4.cpp.

◆ Matrix4x4() [5/7]

Matrix4x4 ( const float * values)

Constructs a matrix from the given 16 single-precision values.

The contents of the array values is assumed to be in column-major order.

Parameters
values\( \begin{bmatrix} v_1 & v_2 & v_3 & v_4 & v_5 & v_6 & v_7 & v_8 & v_9 & v_{10} & v_{11} & v_{12} & v_{13} & v_{14} & v_{15} & v_{16} \end{bmatrix} \)
Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} v_1 & v_5 & v_9 & v_{13} \\ v_2 & v_6 & v_{10} & v_{14} \\ v_3 & v_7 & v_{11} & v_{15} \\ v_4 & v_8 & v_{12} & v_{16} \end{bmatrix} \)

Definition at line 71 of file matrix4x4.cpp.

◆ Matrix4x4() [6/7]

Matrix4x4 ( double x,
double y,
double z )

Constructs a matrix that translates coordinates by the components x, y, and z.

Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 1 & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 81 of file matrix4x4.cpp.

◆ Matrix4x4() [7/7]

Matrix4x4 ( double nx,
double ox,
double ax,
double tx,
double ny,
double oy,
double ay,
double ty,
double nz,
double oz,
double az,
double tz )

Constructs a matrix from the N, O, A, T vector components.

Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} n_x & o_x & a_x & t_x \\ n_y & o_y & a_y & t_y \\ n_z & o_z & a_z & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 96 of file matrix4x4.cpp.

Member Function Documentation

◆ FromXYZRPW()

void FromXYZRPW ( const double * xyzwpr)

Calculates this matrix from the position and euler angles ([x,y,z,r,p,w] vector).

The result is the same as: H = transl(x, y, z) * rotz(w * pi / 180) * roty(p * pi / 180) * rotx(r * pi / 180)

See also
ToXYZRPW()

Definition at line 402 of file matrix4x4.cpp.

◆ Get()

double Get ( int row,
int column ) const

Returns the value of the element at position (row, column) in this matrix.

Definition at line 275 of file matrix4x4.cpp.

◆ inv()

Matrix4x4 inv ( )
inline

Definition at line 507 of file matrix4x4.h.

◆ Inverted()

Matrix4x4 Inverted ( bool * invertible = nullptr) const

Returns the inverse of this matrix.

Returns the identity if this matrix cannot be inverted; i.e. determinant() is zero.

Definition at line 280 of file matrix4x4.cpp.

◆ IsHomogeneous()

bool IsHomogeneous ( ) const

Returns true if the matrix is homogeneous; false otherwise.

Definition at line 285 of file matrix4x4.cpp.

◆ MakeHomogeneous()

bool MakeHomogeneous ( )

Forces this matrix to be homogeneous.

The vx, vy, vz must be unitary vectors and respect: vx x vy = vz. Returns true if the matrix was not homogeneous and it was modified to be homogeneous.

Definition at line 321 of file matrix4x4.cpp.

◆ operator=()

Matrix4x4 & operator= ( const Matrix4x4 & matrix)

Sets this Matrix4x4 object as a copy of matrix.

Definition at line 463 of file matrix4x4.cpp.

◆ Pos()

void Pos ( double * xyz) const

Writes the position (T vector) into array of 3 double-precision xyz values.

Definition at line 240 of file matrix4x4.cpp.

◆ rotx()

Matrix4x4 rotx ( double rx)
static

Constructs a matrix that rotates coordinates around X axis.

Parameters
rxrotation angle in radians.
Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos rx & - \sin rx & 0 \\ 0 & \sin rx & \cos rx & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 478 of file matrix4x4.cpp.

◆ roty()

Matrix4x4 roty ( double ry)
static

Constructs a matrix that rotates coordinates around Y axis.

Parameters
ryrotation angle in radians.
Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} \cos ry & 0 & \sin ry & 0 \\ 0 & 1 & 0 & 0 \\ - \sin ry & 0 & \cos ry & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 485 of file matrix4x4.cpp.

◆ rotz()

Matrix4x4 rotz ( double rz)
static

Constructs a matrix that rotates coordinates around Z axis.

Parameters
rzrotation angle in radians.
Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} \cos rz & - \sin rz & 0 & 0 \\ \sin rz & \cos rx & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 492 of file matrix4x4.cpp.

◆ Set()

void Set ( int row,
int column,
double value )

Sets a new value to the element at position (row, column) in this matrix.

Definition at line 270 of file matrix4x4.cpp.

◆ SetPos() [1/2]

void SetPos ( const double * xyz)

Sets the position (T).

Definition at line 188 of file matrix4x4.cpp.

◆ SetPos() [2/2]

void SetPos ( double x,
double y,
double z )

Sets the position (T).

Definition at line 160 of file matrix4x4.cpp.

◆ setPos()

void setPos ( double x,
double y,
double z )
inline

Definition at line 510 of file matrix4x4.h.

◆ SetValues()

void SetValues ( const double * values)

Sets the elements of matrix from the given 16 double-precision values.

The contents of the array values is assumed to be in column-major order.

\( \begin{bmatrix} v_1 & v_5 & v_9 & v_{13} \\ v_2 & v_6 & v_{10} & v_{14} \\ v_3 & v_7 & v_{11} & v_{15} \\ v_4 & v_8 & v_{12} & v_{16} \end{bmatrix} \)

Parameters
values\( \begin{bmatrix} v_1 & v_2 & v_3 & v_4 & v_5 & v_6 & v_7 & v_8 & v_9 & v_{10} & v_{11} & v_{12} & v_{13} & v_{14} & v_{15} & v_{16} \end{bmatrix} \)

Definition at line 247 of file matrix4x4.cpp.

◆ SetVX() [1/3]

void SetVX ( const double * xyz)

Sets the X vector values (N vector).

Definition at line 167 of file matrix4x4.cpp.

◆ SetVX() [2/3]

void SetVX ( const Vector3 & n)

Sets the X vector (N vector).

Definition at line 118 of file matrix4x4.cpp.

◆ SetVX() [3/3]

void SetVX ( double x,
double y,
double z )

Sets the X vector values (N vector).

Definition at line 139 of file matrix4x4.cpp.

◆ SetVY() [1/3]

void SetVY ( const double * xyz)

Sets the Y vector values (O vector).

Definition at line 174 of file matrix4x4.cpp.

◆ SetVY() [2/3]

void SetVY ( const Vector3 & o)

Sets the Y vector (O vector).

Definition at line 125 of file matrix4x4.cpp.

◆ SetVY() [3/3]

void SetVY ( double x,
double y,
double z )

Sets the Y vector values (O vector).

Definition at line 146 of file matrix4x4.cpp.

◆ SetVZ() [1/3]

void SetVZ ( const double * xyz)

Sets the Z vector values (A vector).

Definition at line 181 of file matrix4x4.cpp.

◆ SetVZ() [2/3]

void SetVZ ( const Vector3 & a)

Sets the Z vector (A vector).

Definition at line 132 of file matrix4x4.cpp.

◆ SetVZ() [3/3]

void SetVZ ( double x,
double y,
double z )

Sets the Z vector values (A vector).

Definition at line 153 of file matrix4x4.cpp.

◆ ToXYZRPW()

void ToXYZRPW ( double * xyzwpr) const

Calculates the position and euler angles ([x,y,z,r,p,w] vector) from this matrix.

Note: transl(x, y, z) * rotz(w * pi / 180) * roty(p * pi / 180) * rotx(r * pi / 180)

Returns
The XYZWPR translation and rotation in the length units and degrees.
See also
FromXYZRPW()

Definition at line 347 of file matrix4x4.cpp.

◆ transl()

Matrix4x4 transl ( double x,
double y,
double z )
static

Constructs a matrix that translates coordinates by the components x, y, and z.

Returns
New Matrix4x4 object with the following structure: \( \begin{bmatrix} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 1 & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 470 of file matrix4x4.cpp.

◆ Valid()

bool Valid ( ) const

Returns true if the matrix is marked as valid; false otherwise.

Definition at line 458 of file matrix4x4.cpp.

◆ Values() [1/3]

const double * Values ( ) const

Returns a constant pointer to the raw data of this matrix as 16 double- or single-precision numbers.

This raw data is stored in column-major format.

See also
ValuesF(), ValuesD()

Definition at line 436 of file matrix4x4.cpp.

◆ Values() [2/3]

void Values ( double * values) const

Writes the contents of this matrix into array of 16 double-precision values.

See also
Values(), ValuesF(), ValuesD()

Definition at line 442 of file matrix4x4.cpp.

◆ Values() [3/3]

void Values ( float * values) const

Writes the contents of this matrix into array of 16 single-precision values.

See also
Values(), ValuesF(), ValuesD()

Definition at line 450 of file matrix4x4.cpp.

◆ ValuesD()

const double * ValuesD ( ) const

Returns a constant pointer to the raw data of this matrix as 16 double-precision numbers.

This raw data is stored in column-major format.

See also
Values(), ValuesF()

Definition at line 416 of file matrix4x4.cpp.

◆ ValuesF()

const float * ValuesF ( ) const

Returns a constant pointer to the raw data of this matrix as 16 single-precision numbers.

This raw data is stored in column-major format.

See also
Values(), ValuesD()

Definition at line 425 of file matrix4x4.cpp.

◆ VX() [1/2]

Vector3 VX ( ) const

Returns the X vector (N vector).

Definition at line 195 of file matrix4x4.cpp.

◆ VX() [2/2]

void VX ( double * xyz) const

Writes the X vector (N vector) into array of 3 double-precision xyz values.

Definition at line 219 of file matrix4x4.cpp.

◆ VY() [1/2]

Vector3 VY ( ) const

Returns the Y vector (O vector).

Definition at line 203 of file matrix4x4.cpp.

◆ VY() [2/2]

void VY ( double * xyz) const

Writes the Y vector (O vector) into array of 3 double-precision xyz values.

Definition at line 226 of file matrix4x4.cpp.

◆ VZ() [1/2]

Vector3 VZ ( ) const

Returns the Z vector (A vector).

Definition at line 211 of file matrix4x4.cpp.

◆ VZ() [2/2]

void VZ ( double * xyz) const

Writes the Z vector (A vector) into array of 3 double-precision xyz values.

Definition at line 233 of file matrix4x4.cpp.

◆ XYZRPW_2_Mat() [1/2]

Matrix4x4 XYZRPW_2_Mat ( const double * xyzwpr)
static

Constructs a matrix from the position and euler angles ([x,y,z,r,p,w] vector).

The result is the same as: H = transl(x, y, z) * rotz(w * pi / 180) * roty(p * pi / 180) * rotx(r * pi / 180)

Returns
New homogeneous Matrix4x4 object.
See also
FromXYZRPW()

Definition at line 397 of file matrix4x4.cpp.

◆ XYZRPW_2_Mat() [2/2]

Matrix4x4 XYZRPW_2_Mat ( double x,
double y,
double z,
double r,
double p,
double w )
static

Constructs a matrix from the position and euler angles ([x,y,z,r,p,w] vector).

The result is the same as: H = transl(x, y, z) * rotz(w * pi / 180) * roty(p * pi / 180) * rotx(r * pi / 180)

Returns
New homogeneous Matrix4x4 object.
See also
FromXYZRPW()

Definition at line 381 of file matrix4x4.cpp.


The documentation for this class was generated from the following files: