RoboDK Plug-In Interface
Mat Class Reference

The Mat class represents a 4x4 pose matrix. The main purpose of this object is to represent a pose in the 3D space (position and orientation). In other words, a pose is a 4x4 matrix that represents the position and orientation of one reference frame with respect to another one, in the 3D space. Poses are commonly used in robotics to place objects, reference frames and targets with respect to each other.
\( transl(x,y,z) rotx(r) roty(p) rotz(w) = \\ \begin{bmatrix} n_x & o_x & a_x & x \\ n_y & o_y & a_y & y \\ n_z & o_z & a_z & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \). More...

#include <robodktypes.h>

Inheritance diagram for Mat:

Public Member Functions

 Mat ()
 Create the identity matrix. More...
 
 Mat (bool valid)
 Create a valid or an invalid matrix. More...
 
 Mat (const QMatrix4x4 &matrix)
 Create a copy of the matrix. More...
 
 Mat (const Mat &matrix)
 Create a copy of the matrix. More...
 
 Mat (double nx, double ox, double ax, double tx, double ny, double oy, double ay, double ty, double nz, double oz, double az, double tz)
 Matrix class constructor for a 4x4 homogeneous matrix given N, O, A & T vectors More...
 
 Mat (const double values[16])
 Create a homogeneoux matrix given a one dimensional 16-value array (doubles) More...
 
 Mat (const float values[16])
 Create a homogeneoux matrix given a one dimensional 16-value array (floats) More...
 
 Mat (double x, double y, double z)
 Create a translation matrix. More...
 
 operator QString () const
 To String operator (use with qDebug() << tJoints;. More...
 
void setVX (double x, double y, double z)
 Set the X vector values (N vector) More...
 
void setVY (double x, double y, double z)
 Set the Y vector values (O vector) More...
 
void setVZ (double x, double y, double z)
 Set the Z vector values (A vector) More...
 
void setPos (double x, double y, double z)
 Set the position (T position) in mm. More...
 
void setVX (double xyz[3])
 Set the X vector values (N vector) More...
 
void setVY (double xyz[3])
 Set the Y vector values (O vector) More...
 
void setVZ (double xyz[3])
 Set the Z vector values (A vector) More...
 
void setPos (double xyz[3])
 Set the position (T position) in mm. More...
 
void setValues (double pose[16])
 Set the pose values. More...
 
void VX (tXYZ xyz) const
 Get the X vector (N vector) More...
 
void VY (tXYZ xyz) const
 Get the Y vector (O vector) More...
 
void VZ (tXYZ xyz) const
 Get the Z vector (A vector) More...
 
void Pos (tXYZ xyz) const
 Get the position (T position), in mm. More...
 
void Set (int r, int c, double value)
 Set a matrix value. More...
 
double Get (int r, int c) const
 Get a matrix value. More...
 
Mat inv () const
 Invert the pose (homogeneous matrix assumed) More...
 
bool isHomogeneous () const
 Returns true if the matrix is homogeneous, otherwise it returns false. More...
 
bool MakeHomogeneous ()
 Forces 4x4 matrix to be homogeneous (vx,vy,vz must be unitary vectors and respect: vx x vy = vz). Returns True if the matrix was not homogeneous and it was be modified to make it homogeneous. More...
 
void ToXYZRPW (tXYZWPR xyzwpr) const
 Calculates the equivalent position and euler angles ([x,y,z,r,p,w] vector) of the given pose Note: transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180) See also: FromXYZRPW() More...
 
QString ToString (const QString &separator=", ", int precision=3, bool xyzrpw_only=false) const
 Retrieve a string representation of the pose. More...
 
bool FromString (const QString &str)
 Set the matrix given a XYZRPW string array (6-values) More...
 
void FromXYZRPW (tXYZWPR xyzwpr)
 Calculates the pose 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) More...
 
const double * ValuesD () const
 Get a pointer to the 16-digit double array. More...
 
const float * ValuesF () const
 Get a pointer to the 16-digit array as an array of floats. More...
 
const double * Values () const
 Get a pointer to the 16-digit array (doubles or floats if ROBODK_API_FLOATS is defined). More...
 
void Values (double values[16]) const
 Copy the 16-values of the 4x4 matrix to a double array. More...
 
void Values (float values[16]) const
 Copy the 16-values of the 4x4 matrix to a double array. More...
 
bool Valid () const
 Check if the matrix is valid. More...
 

Static Public Member Functions

static Mat XYZRPW_2_Mat (double x, double y, double z, double r, double p, double w)
 Calculates the pose 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) More...
 
static Mat XYZRPW_2_Mat (tXYZWPR xyzwpr)
 
static Mat transl (double x, double y, double z)
 Return a translation matrix. More...
 
static Mat rotx (double rx)
 Return the X-axis rotation matrix. More...
 
static Mat roty (double ry)
 Return a Y-axis rotation matrix More...
 
static Mat rotz (double rz)
 Return a Z-axis rotation matrix. More...
 

Private Attributes

double _valid
 Flags if a matrix is not valid. More...
 
double _ddata16 [16]
 Copy of the data as a double array. More...
 

Detailed Description

The Mat class represents a 4x4 pose matrix. The main purpose of this object is to represent a pose in the 3D space (position and orientation). In other words, a pose is a 4x4 matrix that represents the position and orientation of one reference frame with respect to another one, in the 3D space. Poses are commonly used in robotics to place objects, reference frames and targets with respect to each other.
\( transl(x,y,z) rotx(r) roty(p) rotz(w) = \\ \begin{bmatrix} n_x & o_x & a_x & x \\ n_y & o_y & a_y & y \\ n_z & o_z & a_z & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \).

Definition at line 361 of file robodktypes.h.

Constructor & Destructor Documentation

◆ Mat() [1/8]

Mat ( )

Create the identity matrix.

Definition at line 158 of file robodktypes.cpp.

◆ Mat() [2/8]

Mat ( bool  valid)

Create a valid or an invalid matrix.

Definition at line 162 of file robodktypes.cpp.

◆ Mat() [3/8]

Mat ( const QMatrix4x4 &  matrix)

Create a copy of the matrix.

Definition at line 167 of file robodktypes.cpp.

◆ Mat() [4/8]

Mat ( const Mat matrix)

Create a copy of the matrix.

Parameters
matrix

Definition at line 171 of file robodktypes.cpp.

◆ Mat() [5/8]

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

Matrix class constructor for a 4x4 homogeneous matrix given N, O, A & T vectors

Parameters
nxMatrix[0,0]
oxMatrix[0,1]
axMatrix[0,2]
txMatrix[0,3]
nyMatrix[1,0]
oyMatrix[1,1]
ayMatrix[1,2]
tyMatrix[1,3]
nzMatrix[2,0]
ozMatrix[2,1]
azMatrix[2,2]
tzMatrix[2,3]
Returns
\( \begin{bmatrix} n_x & o_x & a_x & x \\ n_y & o_y & a_y & y \\ n_z & o_z & a_z & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 176 of file robodktypes.cpp.

◆ Mat() [6/8]

Mat ( const double  values[16])

Create a homogeneoux matrix given a one dimensional 16-value array (doubles)

Parameters
values[nx,ny,nz,0, ox,oy,oz,0, ax,ay,az,0, tx,ty,tz,1]
Returns
\( \begin{bmatrix} n_x & o_x & a_x & x \\ n_y & o_y & a_y & y \\ n_z & o_z & a_z & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 181 of file robodktypes.cpp.

◆ Mat() [7/8]

Mat ( const float  values[16])

Create a homogeneoux matrix given a one dimensional 16-value array (floats)

Parameters
values[nx,ny,nz,0, ox,oy,oz,0, ax,ay,az,0, tx,ty,tz,1]
Returns
\( transl(x,y,z) rotx(r) roty(p) rotz(w) = \\ \begin{bmatrix} n_x & o_x & a_x & x \\ n_y & o_y & a_y & y \\ n_z & o_z & a_z & z \\ 0 & 0 & 0 & 1 \end{bmatrix} \)

Definition at line 186 of file robodktypes.cpp.

◆ Mat() [8/8]

Mat ( double  x,
double  y,
double  z 
)

Create a translation matrix.

Parameters
xtranslation along X (mm)
ytranslation along Y (mm)
ztranslation along Z (mm)
Returns
\( rotx(\theta) = \begin{bmatrix} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 1 & z \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \)

Definition at line 192 of file robodktypes.cpp.

◆ ~Mat()

~Mat ( )

Definition at line 199 of file robodktypes.cpp.

Member Function Documentation

◆ FromString()

bool FromString ( const QString &  str)

Set the matrix given a XYZRPW string array (6-values)

Definition at line 440 of file robodktypes.cpp.

◆ FromXYZRPW()

void FromXYZRPW ( tXYZWPR  xyzwpr)

Calculates the pose 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
Homogeneous matrix (4x4)

Definition at line 475 of file robodktypes.cpp.

◆ Get()

double Get ( int  r,
int  c 
) const

Get a matrix value.

Parameters
rrow
ccolumn
Returns
value

Definition at line 299 of file robodktypes.cpp.

◆ inv()

Mat inv ( ) const

Invert the pose (homogeneous matrix assumed)

Definition at line 305 of file robodktypes.cpp.

◆ isHomogeneous()

bool isHomogeneous ( ) const

Returns true if the matrix is homogeneous, otherwise it returns false.

Definition at line 310 of file robodktypes.cpp.

◆ MakeHomogeneous()

bool MakeHomogeneous ( )

Forces 4x4 matrix to be homogeneous (vx,vy,vz must be unitary vectors and respect: vx x vy = vz). Returns True if the matrix was not homogeneous and it was be modified to make it homogeneous.

Definition at line 351 of file robodktypes.cpp.

◆ operator QString()

operator QString ( ) const
inline

To String operator (use with qDebug() << tJoints;.

Definition at line 437 of file robodktypes.h.

◆ Pos()

void Pos ( tXYZ  xyz) const

Get the position (T position), in mm.

Definition at line 218 of file robodktypes.cpp.

◆ rotx()

Mat rotx ( double  rx)
static

Return the X-axis rotation matrix.

Parameters
rxRotation around X axis (in radians).
Returns
\( rotx(\theta) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & c_\theta & -s_\theta & 0 \\ 0 & s_\theta & c_\theta & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \)

Definition at line 529 of file robodktypes.cpp.

◆ roty()

Mat roty ( double  ry)
static

Return a Y-axis rotation matrix

Parameters
ryRotation around Y axis (in radians)
Returns
\( roty(\theta) = \begin{bmatrix} c_\theta & 0 & s_\theta & 0 \\ 0 & 1 & 0 & 0 \\ -s_\theta & 0 & c_\theta & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \)

Definition at line 535 of file robodktypes.cpp.

◆ rotz()

Mat rotz ( double  rz)
static

Return a Z-axis rotation matrix.

Parameters
rzRotation around Z axis (in radians)
Returns
\( rotz(\theta) = \begin{bmatrix} c_\theta & -s_\theta & 0 & 0 \\ s_\theta & c_\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \)

Definition at line 541 of file robodktypes.cpp.

◆ Set()

void Set ( int  r,
int  c,
double  value 
)

Set a matrix value.

Parameters
rrow
ccolumn
valuevalue

Definition at line 290 of file robodktypes.cpp.

◆ setPos() [1/2]

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

Set the position (T position) in mm.

Definition at line 239 of file robodktypes.cpp.

◆ setPos() [2/2]

void setPos ( double  xyz[3])

Set the position (T position) in mm.

Definition at line 260 of file robodktypes.cpp.

◆ setValues()

void setValues ( double  pose[16])

Set the pose values.

Definition at line 267 of file robodktypes.cpp.

◆ setVX() [1/2]

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

Set the X vector values (N vector)

Definition at line 224 of file robodktypes.cpp.

◆ setVX() [2/2]

void setVX ( double  xyz[3])

Set the X vector values (N vector)

Definition at line 245 of file robodktypes.cpp.

◆ setVY() [1/2]

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

Set the Y vector values (O vector)

Definition at line 229 of file robodktypes.cpp.

◆ setVY() [2/2]

void setVY ( double  xyz[3])

Set the Y vector values (O vector)

Definition at line 250 of file robodktypes.cpp.

◆ setVZ() [1/2]

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

Set the Z vector values (A vector)

Definition at line 234 of file robodktypes.cpp.

◆ setVZ() [2/2]

void setVZ ( double  xyz[3])

Set the Z vector values (A vector)

Definition at line 255 of file robodktypes.cpp.

◆ ToString()

QString ToString ( const QString &  separator = ", ",
int  precision = 3,
bool  xyzrpw_only = false 
) const

Retrieve a string representation of the pose.

Parameters
separatorString separator
precisionNumber of decimals
in_xyzwprif set to true (default), the pose will be represented as XYZWPR 6-dimensional array using ToXYZRPW
Returns

Definition at line 405 of file robodktypes.cpp.

◆ ToXYZRPW()

void ToXYZRPW ( tXYZWPR  xyzwpr) const

Calculates the equivalent position and euler angles ([x,y,z,r,p,w] vector) of the given pose Note: transl(x,y,z)*rotz(w*pi/180)*roty(p*pi/180)*rotx(r*pi/180) See also: FromXYZRPW()

Returns
XYZWPR translation and rotation in mm and degrees

Definition at line 380 of file robodktypes.cpp.

◆ transl()

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

Return a translation matrix.

Parameters
xtranslation along X (mm)
ytranslation along Y (mm)
ztranslation along Z (mm)
Returns
\( rotx(\theta) = \begin{bmatrix} 1 & 0 & 0 & x \\ 0 & 1 & 0 & y \\ 0 & 0 & 1 & z \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \)

Definition at line 522 of file robodktypes.cpp.

◆ Valid()

bool Valid ( ) const

Check if the matrix is valid.

Definition at line 518 of file robodktypes.cpp.

◆ Values() [1/3]

const double * Values ( ) const

Get a pointer to the 16-digit array (doubles or floats if ROBODK_API_FLOATS is defined).

Definition at line 500 of file robodktypes.cpp.

◆ Values() [2/3]

void Values ( double  values[16]) const

Copy the 16-values of the 4x4 matrix to a double array.

Definition at line 508 of file robodktypes.cpp.

◆ Values() [3/3]

void Values ( float  values[16]) const

Copy the 16-values of the 4x4 matrix to a double array.

Definition at line 513 of file robodktypes.cpp.

◆ ValuesD()

const double * ValuesD ( ) const

Get a pointer to the 16-digit double array.

Definition at line 484 of file robodktypes.cpp.

◆ ValuesF()

const float * ValuesF ( ) const

Get a pointer to the 16-digit array as an array of floats.

Definition at line 491 of file robodktypes.cpp.

◆ VX()

void VX ( tXYZ  xyz) const

Get the X vector (N vector)

Definition at line 203 of file robodktypes.cpp.

◆ VY()

void VY ( tXYZ  xyz) const

Get the Y vector (O vector)

Definition at line 208 of file robodktypes.cpp.

◆ VZ()

void VZ ( tXYZ  xyz) const

Get the Z vector (A vector)

Definition at line 213 of file robodktypes.cpp.

◆ XYZRPW_2_Mat() [1/2]

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

Calculates the pose 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
Homogeneous matrix (4x4)

Definition at line 459 of file robodktypes.cpp.

◆ XYZRPW_2_Mat() [2/2]

Mat XYZRPW_2_Mat ( tXYZWPR  xyzwpr)
static

Definition at line 471 of file robodktypes.cpp.

Member Data Documentation

◆ _ddata16

double _ddata16[16]
private

Copy of the data as a double array.

Definition at line 622 of file robodktypes.h.

◆ _valid

double _valid
private

Flags if a matrix is not valid.

Definition at line 617 of file robodktypes.h.


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