50 , _valid(valid ? 1.0 : 0.0)
57 , _valid(matrix._valid)
63 values[0], values[4], values[8], values[12],
64 values[1], values[5], values[9], values[13],
65 values[2], values[6], values[10], values[14],
66 values[3], values[7], values[11], values[15])
73 values[0], values[4], values[8], values[12],
74 values[1], values[5], values[9], values[13],
75 values[2], values[6], values[10], values[14],
76 values[3], values[7], values[11], values[15])
86 0.0f, 0.0f, 0.0f, 1.0f)
113 0.0f, 0.0f, 0.0f, 1.0f)
120 (*this)(0, 0) = n.
X();
121 (*this)(1, 0) = n.
Y();
122 (*this)(2, 0) = n.
Z();
127 (*this)(0, 1) = o.
X();
128 (*this)(1, 1) = o.
Y();
129 (*this)(2, 1) = o.
Z();
134 (*this)(0, 2) = a.
X();
135 (*this)(1, 2) = a.
Y();
136 (*this)(2, 2) = a.
Z();
249 Set(0, 0, values[0]);
250 Set(1, 0, values[1]);
251 Set(2, 0, values[2]);
252 Set(3, 0, values[3]);
254 Set(0, 1, values[4]);
255 Set(1, 1, values[5]);
256 Set(2, 1, values[6]);
257 Set(3, 1, values[7]);
259 Set(0, 2, values[8]);
260 Set(1, 2, values[9]);
261 Set(2, 2, values[10]);
262 Set(3, 2, values[11]);
264 Set(0, 3, values[12]);
265 Set(1, 3, values[13]);
266 Set(2, 3, values[14]);
267 Set(3, 3, values[15]);
272 (*this)(row, column) = value;
277 return (*
this)(row, column);
282 return this->inverted(invertible);
291 const double tol = 1e-7;
305 else if (std::fabs(tx.Length() - 1.0) > tol)
309 else if (std::fabs(ty.Length() - 1.0) > tol)
313 else if (std::fabs(tz.Length() - 1.0) > tol)
339 (*this)(3, 0) = 0.0f;
340 (*this)(3, 1) = 0.0f;
341 (*this)(3, 2) = 0.0f;
342 (*this)(3, 3) = 1.0f;
349 double x =
Get(0, 3);
350 double y =
Get(1, 3);
351 double z =
Get(2, 3);
354 if (
Get(2,0) > (1.0 - 1e-6))
356 p = -constants::pi * 0.5;
358 w = atan2(-
Get(1,2),
Get(1,1));
360 else if (
Get(2,0) < -1.0 + 1e-6)
362 p = 0.5 * constants::pi;
364 w = atan2(
Get(1,2),
Get(1,1));
368 p = atan2(-
Get(2, 0), sqrt(
Get(0, 0) *
Get(0, 0) +
Get(1, 0) *
Get(1, 0)));
369 w = atan2(
Get(1, 0),
Get(0, 0));
370 r = atan2(
Get(2, 1),
Get(2, 2));
376 xyzwpr[3] = r * 180.0 / constants::pi;
377 xyzwpr[4] = p * 180.0 / constants::pi;
378 xyzwpr[5] = w * 180.0 / constants::pi;
383 double a = r * constants::pi / 180.0;
384 double b = p * constants::pi / 180.0;
385 double c = w * constants::pi / 180.0;
392 return Matrix4x4(cb * cc, cc * sa * sb - ca * sc, sa * sc + ca * cc * sb, x,
393 cb * sc, ca * cc + sa * sb * sc, ca * sb * sc - cc * sa, y,
394 -sb, cb * sa, ca * cb, z);
399 return XYZRPW_2_Mat(xyzwpr[0], xyzwpr[1], xyzwpr[2], xyzwpr[3], xyzwpr[4], xyzwpr[5]);
405 xyzwpr[3], xyzwpr[4], xyzwpr[5]);
407 for (
int i = 0; i < 4; i++)
409 for (
int j = 0; j < 4; j++)
411 this->
Set(i, j, newmat.
Get(i, j));
418 for(
int i = 0; i < 16; ++i)
420 _md[i] = constData()[i];
430#ifdef ROBODK_API_FLOATS
444 for(
int i = 0; i < 16; ++i)
446 data[i] = constData()[i];
452 for(
int i = 0; i < 16; ++i)
454 data[i] = constData()[i];
465 QMatrix4x4::operator=(matrix);
482 return Matrix4x4(1, 0, 0, 0, 0, cx, -sx, 0, 0, sx, cx, 0);
489 return Matrix4x4(cy, 0, sy, 0, 0, 1, 0, 0, -sy, 0, cy, 0);
496 return Matrix4x4(cz, -sz, 0, 0, sz, cz, 0, 0, 0, 0, 1, 0);
506bool Matrix4x4::FromString(
const QString &pose_str)
508 QString pose_str2 = pose_str.trimmed();
510 const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
511 if (pose_str2.startsWith(
"Mat(", cs))
513 pose_str2.remove(0, 4);
514 pose_str2 = pose_str2.trimmed();
517 if (pose_str2.startsWith(
"XYZRPW_2_Mat(", cs))
519 pose_str2.remove(0, 13);
520 pose_str2 = pose_str2.trimmed();
523 while (pose_str2.endsWith(
')'))
528 const QLatin1Char separator(
',');
529 pose_str2.replace(QLatin1Char(
';'), separator);
530 pose_str2.replace(QLatin1Char(
'\t'), separator);
532#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
533 const QString::SplitBehavior behavior = QString::SkipEmptyParts;
535 const Qt::SplitBehavior behavior = Qt::SkipEmptyParts;
538 QStringList values_list = pose_str2.split(separator, behavior);
539 double xyzwpr[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
541 if (values_list.length() < 6)
547 for (
int i = 0; i < 6; i++)
549 xyzwpr[i] = values_list[i].trimmed().toDouble();
556QString Matrix4x4::ToString(
const QString &separator,
int precision,
bool xyzrpwOnly)
const
560 return "Mat(Invalid)";
566 str.append(
"Warning!! Pose is not homogeneous! Use Matrix4x4::MakeHomogeneous() to make this matrix homogeneous\n");
569 str.append(
"Mat(XYZRPW_2_Mat(");
574 for (
int i = 0; i < 6; i++)
578 str.append(separator);
580 str.append(QString::number(xyzwpr[i],
'f', precision));
591 for (
int i = 0; i < 4; i++)
594 for (
int j = 0; j < 4; j++)
596 str.append(QString::number(row(i)[j],
'f', precision));
599 str.append(separator);
609 QMatrix4x4::operator=(matrix);
The Matrix4x4 class represents a 4x4 transformation matrix in 3D space.
Vector3 VX() const
Returns the X vector (N vector).
void SetVZ(const Vector3 &a)
Sets the Z vector (A vector).
void SetVY(const Vector3 &o)
Sets the Y vector (O vector).
static Matrix4x4 transl(double x, double y, double z)
Constructs a matrix that translates coordinates by the components x, y, and z.
void ToXYZRPW(double *xyzwpr) const
Calculates the position and euler angles ([x,y,z,r,p,w] vector) from this matrix.
void Pos(double *xyz) const
Writes the position (T vector) into array of 3 double-precision xyz values.
Vector3 VY() const
Returns the Y vector (O vector).
static Matrix4x4 rotx(double rx)
Constructs a matrix that rotates coordinates around X axis.
bool Valid() const
Returns true if the matrix is marked as valid; false otherwise.
void FromXYZRPW(const double *xyzwpr)
Calculates this matrix from the position and euler angles ([x,y,z,r,p,w] vector).
static Matrix4x4 rotz(double rz)
Constructs a matrix that rotates coordinates around Z axis.
const double * Values() const
Returns a constant pointer to the raw data of this matrix as 16 double- or single-precision numbers.
Matrix4x4()
Constructs an identity matrix.
Matrix4x4 & operator=(const Matrix4x4 &matrix)
Sets this Matrix4x4 object as a copy of matrix.
void SetValues(const double *values)
Sets the elements of matrix from the given 16 double-precision values.
void SetVX(const Vector3 &n)
Sets the X vector (N vector).
void SetPos(double x, double y, double z)
Sets the position (T).
bool MakeHomogeneous()
Forces this matrix to be homogeneous.
static Matrix4x4 roty(double ry)
Constructs a matrix that rotates coordinates around Y axis.
const double * ValuesD() const
Returns a constant pointer to the raw data of this matrix as 16 double-precision numbers.
Matrix4x4 Inverted(bool *invertible=nullptr) const
Returns the inverse of this matrix.
void Set(int row, int column, double value)
Sets a new value to the element at position (row, column) in this matrix.
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).
Vector3 VZ() const
Returns the Z vector (A vector).
const float * ValuesF() const
Returns a constant pointer to the raw data of this matrix as 16 single-precision numbers.
double Get(int row, int column) const
Returns the value of the element at position (row, column) in this matrix.
bool IsHomogeneous() const
Returns true if the matrix is homogeneous; false otherwise.
The Vector3 class represents a vector or vertex in 3D space.
static double DotProduct(const Vector3 &v1, const Vector3 &v2)
Returns the dot product of v1 and v2.
static Vector3 CrossProduct(const Vector3 &v1, const Vector3 &v2)
Returns the cross-product of vectors v1 and v2, which corresponds to the normal vector of a plane def...
double Z() const
Returns the z coordinate of this vector.
double X() const
Returns the x coordinate of this vector.
double Y() const
Returns the y coordinate of this vector.