RoboDK Plug-In Interface
Loading...
Searching...
No Matches
matrix4x4.h
1/****************************************************************************
2**
3** Copyright (c) 2015-2026 RoboDK Global.
4** Contact: https://robodk.com/
5**
6** This file is part of the RoboDK API.
7**
8** Permission is hereby granted, free of charge, to any person obtaining a copy
9** of this software and associated documentation files (the "Software"), to deal
10** in the Software without restriction, including without limitation the rights
11** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12** copies of the Software, and to permit persons to whom the Software is
13** furnished to do so, subject to the following conditions:
14**
15** The above copyright notice and this permission notice shall be included in all
16** copies or substantial portions of the Software.
17**
18** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24** SOFTWARE.
25**
26** RoboDK is a registered trademark of RoboDK Global.
27**
28****************************************************************************/
29
30#ifndef ROBODK_MATRIX4X4_H
31#define ROBODK_MATRIX4X4_H
32
33
34#include "deprecated.h"
35#include "vector3.h"
36
37
38#ifdef QT_GUI_LIB
39#include <QString>
40#include <QMatrix4x4>
41
42namespace robodk
43{
44typedef ::QMatrix4x4 BaseMatrix4x4;
45}
46#else // QT_GUI_LIB
47#error "This class cannot yet be used without the Qt Framework"
48#endif // QT_GUI_LIB
49
50
51namespace robodk
52{
53
69class Matrix4x4 : public BaseMatrix4x4
70{
71public:
75 Matrix4x4();
76
80 explicit Matrix4x4(bool valid);
81
85 Matrix4x4(const Matrix4x4& matrix);
86
106 Matrix4x4(const double* values);
107
127 Matrix4x4(const float* values);
128
141 Matrix4x4(double x, double y, double z);
142
154 Matrix4x4(
155 double nx,
156 double ox,
157 double ax,
158 double tx,
159 double ny,
160 double oy,
161 double ay,
162 double ty,
163 double nz,
164 double oz,
165 double az,
166 double tz);
167
168 ~Matrix4x4() = default;
169
173 void SetVX(const Vector3& n);
174
178 void SetVY(const Vector3& o);
179
183 void SetVZ(const Vector3& a);
184
188 void SetVX(double x, double y, double z);
189
193 void SetVY(double x, double y, double z);
194
198 void SetVZ(double x, double y, double z);
199
203 void SetPos(double x, double y, double z);
204
208 void SetVX(const double* xyz);
209
213 void SetVY(const double* xyz);
214
218 void SetVZ(const double* xyz);
219
223 void SetPos(const double* xyz);
224
243 void SetValues(const double* values);
244
248 Vector3 VX() const;
249
253 Vector3 VY() const;
254
258 Vector3 VZ() const;
259
263 void VX(double* xyz) const;
264
268 void VY(double* xyz) const;
269
273 void VZ(double* xyz) const;
274
278 void Pos(double* xyz) const;
279
283 void Set(int row, int column, double value);
284
288 double Get(int row, int column) const;
289
294 Matrix4x4 Inverted(bool* invertible = nullptr) const;
295
299 bool IsHomogeneous() const;
300
306 bool MakeHomogeneous();
307
316 void ToXYZRPW(double* xyzwpr) const;
317
326 void FromXYZRPW(const double* xyzwpr);
327
328
339 static Matrix4x4 XYZRPW_2_Mat(double x, double y, double z, double r, double p, double w);
340
351 static Matrix4x4 XYZRPW_2_Mat(const double* xyzwpr);
352
359 const double* ValuesD() const;
360
367 const float* ValuesF() const;
368
369#ifdef ROBODK_API_FLOATS
377 const float* Values() const;
378#else
386 const double* Values() const;
387#endif
388
394 void Values(double* values) const;
395
401 void Values(float* values) const;
402
406 bool Valid() const;
407
411 Matrix4x4& operator=(const Matrix4x4& matrix);
412
425 static Matrix4x4 transl(double x, double y, double z);
426
439 static Matrix4x4 rotx(double rx);
440
453 static Matrix4x4 roty(double ry);
454
467 static Matrix4x4 rotz(double rz);
468
469#ifdef QT_GUI_LIB
473 Matrix4x4(const BaseMatrix4x4& matrix);
474
479 inline operator QString() const { return ToString(); }
480
482 bool FromString(const QString& str);
483
484
493 QString ToString(
494 const ::QString& separator = QLatin1String(", "),
495 int precision = 3,
496 bool xyzrpwOnly = false) const;
497
501 Matrix4x4& operator=(const QMatrix4x4& matrix);
502#endif
503
504 /* Deprecated methods */
505public:
506 ROBODK_DEPRECATED("Use Inverted() instead")
507 inline Matrix4x4 inv() { return Inverted(); }
508
509 ROBODK_DEPRECATED("Use SetPos() instead")
510 inline void setPos(double x, double y, double z) { SetPos(x, y, z); }
511
512
513
514private:
517 double _valid;
518 mutable double _md[16];
519
521};
522
523} // namespace robodk
524
525
526#endif // ROBODK_MATRIX4X4_H
The Matrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition matrix4x4.h:70
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.
Definition matrix4x4.cpp:41
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.
Definition vector3.h:49