12 #include <mrpt/config.h> 35 #include <Eigen/Dense> 55 m_coords[0] = m_coords[1] = m_coords[2] = 0;
60 const double x,
const double y,
const double z,
const double yaw,
78 : m_ypr_uptodate(false), m_yaw(), m_pitch(), m_roll()
88 for (
int r = 0;
r < 3;
r++)
96 for (
int r = 0;
r < 3;
r++)
121 p.quat().rotationMatrixNoResize(
m_ROT);
129 out <<
q[0] <<
q[1] <<
q[2] <<
q[3] <<
q[4] <<
q[5] <<
q[6];
140 ASSERT_(HM2.rows() == 4 && HM2.isSquare());
168 in >>
p[0] >>
p[1] >>
p[2] >>
p[3] >>
p[4] >>
p[5] >>
p[6];
175 p.quat().rotationMatrixNoResize(
m_ROT);
216 const std::streamsize old_pre = o.precision();
217 const std::ios_base::fmtflags old_flags = o.flags();
218 o <<
"(x,y,z,yaw,pitch,roll)=(" << std::fixed << std::setprecision(4)
219 <<
p.m_coords[0] <<
"," <<
p.m_coords[1] <<
"," <<
p.m_coords[2] <<
"," 220 << std::setprecision(2) <<
RAD2DEG(
p.yaw()) <<
"deg," 223 o.precision(old_pre);
238 const char* fields[] = {
"R",
"t"};
239 mexplus::MxArray pose_struct(
240 mexplus::MxArray::Struct(
sizeof(fields) /
sizeof(fields[0]), fields));
243 return pose_struct.release();
257 const double x0,
const double y0,
const double z0,
const double yaw,
304 const TPoint3D& point,
double& out_range,
double& out_yaw,
305 double& out_pitch)
const 313 out_range =
local.norm();
323 out_pitch = -asin(
local.z / out_range);
369 double lx,
double ly,
double lz,
double& gx,
double& gy,
double& gz,
373 bool use_small_rot_approx)
const 376 if (out_jacobian_df_dpoint) *out_jacobian_df_dpoint =
m_ROT;
379 if (out_jacobian_df_dpose)
381 if (use_small_rot_approx)
384 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
const double nums[3 * 6] = {
385 1, 0, 0, -ly, lz, 0, 0, 1, 0, lx, 0, -lz, 0, 0, 1, 0, -lx, ly};
394 ::sincos(
m_yaw, &sy, &cy);
398 ::sincos(
m_roll, &sr, &cr);
400 const double cy = cos(
m_yaw);
401 const double sy = sin(
m_yaw);
402 const double cp = cos(
m_pitch);
403 const double sp = sin(
m_pitch);
404 const double cr = cos(
m_roll);
405 const double sr = sin(
m_roll);
408 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
const double nums[3 * 6] = {
412 -lx * sy * cp + ly * (-sy * sp * sr - cy * cr) +
413 lz * (-sy * sp * cr + cy * sr),
414 -lx * cy * sp + ly * (cy * cp * sr) +
416 ly * (cy * sp * cr + sy * sr) +
417 lz * (-cy * sp * sr + sy * cr),
421 lx * cy * cp + ly * (cy * sp * sr - sy * cr) +
422 lz * (cy * sp * cr + sy * sr),
423 -lx * sy * sp + ly * (sy * cp * sr) +
425 ly * (sy * sp * cr - cy * sr) +
426 lz * (-sy * sp * sr - cy * cr),
431 -lx * cp - ly * sp * sr - lz * sp * cr,
432 ly * cp * cr - lz * cp * sr
443 if (out_jacobian_df_dse3)
445 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
const double nums[3 * 6] = {
446 1, 0, 0, 0, gz, -gy, 0, 1, 0, -gz, 0, gx, 0, 0, 1, gy, -gx, 0};
472 #if MRPT_HAS_SSE2 && defined(MRPT_USE_SSE2) 504 b.getInverseHomogeneousMatrix(B_INV);
532 .maxCoeff() >= 1e-6);
570 for (
int r = 0;
r < 3;
r++)
572 A.m_ROT(
r, 1) * B_coords[1] +
573 A.m_ROT(
r, 2) * B_coords[2];
577 for (
int r = 0;
r < 3;
r++)
610 (fabs(
m_roll) <= tolerance ||
634 for (
int i = 0; i < 3; i++)
635 m_coords[i] = t_b_inv[i] + R_b_inv(i, 0) *
A.m_coords[0] +
636 R_b_inv(i, 1) *
A.m_coords[1] +
637 R_b_inv(i, 2) *
A.m_coords[2];
640 m_ROT = R_b_inv *
A.m_ROT;
648 const double gx,
const double gy,
const double gz,
double& lx,
double& ly,
658 if (out_jacobian_df_dpoint) *out_jacobian_df_dpoint = R_inv;
661 if (out_jacobian_df_dpose)
669 ::sincos(
m_yaw, &sy, &cy);
673 ::sincos(
m_roll, &sr, &cr);
675 const double cy = cos(
m_yaw);
676 const double sy = sin(
m_yaw);
677 const double cp = cos(
m_pitch);
678 const double sp = sin(
m_pitch);
679 const double cr = cos(
m_roll);
680 const double sr = sin(
m_roll);
683 const double m11_dy = -sy * cp;
684 const double m12_dy = cy * cp;
685 const double m13_dy = 0;
686 const double m11_dp = -cy * sp;
687 const double m12_dp = -sy * sp;
688 const double m13_dp = -cp;
689 const double m11_dr = 0;
690 const double m12_dr = 0;
691 const double m13_dr = 0;
693 const double m21_dy = (-sy * sp * sr - cy * cr);
694 const double m22_dy = (cy * sp * sr - sy * cr);
695 const double m23_dy = 0;
696 const double m21_dp = (cy * cp * sr);
697 const double m22_dp = (sy * cp * sr);
698 const double m23_dp = -sp * sr;
699 const double m21_dr = (cy * sp * cr + sy * sr);
700 const double m22_dr = (sy * sp * cr - cy * sr);
701 const double m23_dr = cp * cr;
703 const double m31_dy = (-sy * sp * cr + cy * sr);
704 const double m32_dy = (cy * sp * cr + sy * sr);
705 const double m33_dy = 0;
706 const double m31_dp = (cy * cp * cr);
707 const double m32_dp = (sy * cp * cr);
708 const double m33_dp = -sp * cr;
709 const double m31_dr = (-cy * sp * sr + sy * cr);
710 const double m32_dr = (-sy * sp * sr - cy * cr);
711 const double m33_dr = -cp * sr;
717 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
const double nums[3 * 6] = {
721 Ax * m11_dy + Ay * m12_dy + Az * m13_dy,
722 Ax * m11_dp + Ay * m12_dp + Az * m13_dp,
723 Ax * m11_dr + Ay * m12_dr + Az * m13_dr,
728 Ax * m21_dy + Ay * m22_dy + Az * m23_dy,
729 Ax * m21_dp + Ay * m22_dp + Az * m23_dp,
730 Ax * m21_dr + Ay * m22_dr + Az * m23_dr,
735 Ax * m31_dy + Ay * m32_dy + Az * m33_dy,
736 Ax * m31_dp + Ay * m32_dp + Az * m33_dp,
737 Ax * m31_dr + Ay * m32_dr + Az * m33_dr,
742 lx = t_inv[0] + R_inv(0, 0) * gx + R_inv(0, 1) * gy + R_inv(0, 2) * gz;
743 ly = t_inv[1] + R_inv(1, 0) * gx + R_inv(1, 1) * gy + R_inv(1, 2) * gz;
744 lz = t_inv[2] + R_inv(2, 0) * gx + R_inv(2, 1) * gy + R_inv(2, 2) * gz;
747 if (out_jacobian_df_dse3)
749 alignas(MRPT_MAX_STATIC_ALIGN_BYTES)
const double nums[3 * 6] = {
750 -1, 0, 0, 0, -lz, ly, 0, -1, 0, lz, 0, -lx, 0, 0, -1, -ly, lx, 0};
757 for (
int i = 0; i < 3; i++)
758 for (
int j = 0; j < 3; j++)
759 m_ROT(i, j) = std::numeric_limits<double>::quiet_NaN();
761 for (
int i = 0; i < 3; i++)
762 m_coords[i] = std::numeric_limits<double>::quiet_NaN();
778 m(0, 0), m(0, 1), m(0, 2),
DEG2RAD(m(0, 3)),
DEG2RAD(m(0, 4)),
791 for (
int i = 0; i < 3; i++) out_HM(i, 3) =
m_coords[i];
792 out_HM(3, 0) = out_HM(3, 1) = out_HM(3, 2) = 0.;
mrpt::math::TPose3D asTPose() const
void inverseComposeFrom(const CPose3D &A, const CPose3D &B)
Makes this method is slightly more efficient than "this= A - B;" since it avoids the temporary objec...
CPose3D getOppositeScalar() const
Return the opposite of the current pose instance by taking the negative of all its components individ...
A compile-time fixed-size numeric matrix container.
This class is a "CSerializable" wrapper for "CMatrixDynamic<double>".
double x
X,Y,Z coordinates.
double RAD2DEG(const double x)
Radians to degrees.
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
#define THROW_EXCEPTION(msg)
mxArray * convertToMatlab(const Eigen::EigenBase< Derived > &mat)
Convert vectors, arrays and matrices into Matlab vectors/matrices.
mrpt::math::CVectorFixedDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods...
mrpt::math::CMatrixDouble33 m_ROT
The 3x3 rotation matrix, access with getRotationMatrix(), setRotationMatrix() (It's not safe to set t...
void setToNaN() override
Set all data fields to quiet NaN.
bool isHorizontal(const double tolerance=0) const
Return true if the 6D pose represents a Z axis almost exactly vertical (upwards or downwards)...
double roll
Roll coordinate (rotation angle over X coordinate).
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
bool m_ypr_uptodate
Whether yaw/pitch/roll members are up-to-date since the last rotation matrix update.
double DEG2RAD(const double x)
Degrees to radians.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
GLdouble GLdouble GLdouble GLdouble q
std::ostream & operator<<(std::ostream &o, const CPoint2D &p)
Dumps a point as a string (x,y)
This file implements several operations that operate element-wise on individual or pairs of container...
double pitch() const
Get the PITCH angle (in radians)
double yaw() const
Get the YAW angle (in radians)
CPose3D operator+(const CPose3D &b) const
The operator is the pose compounding operator.
void rebuildRotationMatrix()
Rebuild the homog matrix from the angles.
double yaw
Yaw coordinate (rotation angle over Z axis).
void updateYawPitchRoll() const
Updates Yaw/pitch/roll members from the m_ROT.
void inverse()
Convert this pose into its inverse, saving the result in itself.
mrpt::math::TVector3D rotateVector(const mrpt::math::TVector3D &local) const
Rotates a vector (i.e.
Virtual base class for "schematic archives" (JSON, XML,...)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
T square(const T x)
Inline function for the square of a number.
double distanceEuclidean6D(const CPose3D &o) const
The euclidean distance between two poses taken as two 6-length vectors (angles in radians)...
#define ASSERT_(f)
Defines an assertion mechanism.
void loadFromArray(const VECTOR &vals)
This base provides a set of functions for maths stuff.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixed< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixed< double, 3, 6 > *out_jacobian_df_dse3=nullptr) const
Computes the 3D point L such as .
void composeFrom(const CPose3D &A, const CPose3D &B)
Makes "this = A (+) B"; this method is slightly more efficient than "this= A + B;" since it avoids th...
auto block(int start_row, int start_col)
non-const block(): Returns an Eigen::Block reference to the block
CPose2D operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
void addComponents(const CPose3D &p)
Scalar sum of all 6 components: This is diferent from poses composition, which is implemented as "+" ...
void getAsQuaternion(mrpt::math::CQuaternionDouble &q, mrpt::math::CMatrixFixed< double, 4, 3 > *out_dq_dr=nullptr) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored) ...
void getAsQuaternion(mrpt::math::CQuaternion< double > &q, mrpt::math::CMatrixFixed< double, 4, 3 > *out_dq_dr=nullptr) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored) ...
void sphericalCoordinates(const mrpt::math::TPoint3D &point, double &out_range, double &out_yaw, double &out_pitch) const
Computes the spherical coordinates of a 3D point as seen from the 6D pose specified by this object...
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
bool fromMatlabStringFormat(const std::string &s, mrpt::optional_ref< std::ostream > dump_errors_here=std::nullopt)
Reads a matrix from a string in Matlab-like format, for example: "[1 0 2; 0 4 -1]" The string must st...
double x() const
Common members of all points & poses classes.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
void asVector(vector_t &v) const
Returns a 6x1 vector with [x y z yaw pitch roll]'.
#define ASSERT_ABOVEEQ_(__A, __B)
GLsizei const GLchar ** string
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
double m_yaw
These variables are updated every time that the object rotation matrix is modified (construction...
size_type rows() const
Number of rows in the matrix.
A class used to store a 2D point.
A class used to store a 3D point.
size_type cols() const
Number of columns in the matrix.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
double roll() const
Get the ROLL angle (in radians)
void fromStringRaw(const std::string &s)
Same as fromString, but without requiring the square brackets in the string.
#define SCHEMA_DESERIALIZE_DATATYPE_VERSION()
For use inside serializeFrom(CSchemeArchiveBase) methods.
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
double pitch
Pitch coordinate (rotation angle over Y axis).
bool operator!=(const CPoint< DERIVEDCLASS, DIM > &p1, const CPoint< DERIVEDCLASS, DIM > &p2)
void operator*=(const double s)
Scalar multiplication of x,y,z,yaw,pitch & roll (angles will be wrapped to the ]-pi,pi] interval).
void getYawPitchRoll(double &yaw, double &pitch, double &roll) const
Returns the three angles (yaw, pitch, roll), in radians, from the rotation matrix.
mrpt::math::TVector3D inverseRotateVector(const mrpt::math::TVector3D &global) const
Inverse of rotateVector(), i.e.
This class is a "CSerializable" wrapper for "CMatrixFloat".
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void fromString(const std::string &s)
Set the current object value from a string generated by 'asString' (eg: "[x y z yaw pitch roll]"...
bool operator==(const CPoint< DERIVEDCLASS, DIM > &p1, const CPoint< DERIVEDCLASS, DIM > &p2)
Virtual base class for "archives": classes abstracting I/O streams.
GLdouble GLdouble GLdouble r
void homogeneousMatrixInverse(const MATRIXLIKE1 &M, MATRIXLIKE2 &out_inverse_M)
Efficiently compute the inverse of a 4x4 homogeneous matrix by only transposing the rotation 3x3 part...
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
virtual mxArray * writeToMatlab() const
Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class.
This file implements matrix/vector text and binary serialization.
CPose3D()
Default constructor, with all the coordinates set to zero.
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
void normalizeAngles()
Rebuild the internal matrix & update the yaw/pitch/roll angles within the ]-PI,PI] range (Must be cal...
#define SCHEMA_SERIALIZE_DATATYPE_VERSION(ser_version)
For use inside all serializeTo(CSchemeArchiveBase) methods.
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ...
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Traits for SO(n), rotations in R^n space.
void getHomogeneousMatrix(mrpt::math::CMatrixDouble44 &out_HM) const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.