41 m_rotvec = rotVecFromRotMat( m );
51 m_rotvec = rotVecFromRotMat(
R );
57 m_coords[0]=_x; m_coords[1]=_y; m_coords[2]=_z;
58 const double a = sqrt(
q.x()*
q.x() +
q.y()*
q.y() +
q.z()*
q.z() );
59 const double TH = 0.001;
60 const double k =
a < TH ? 2 : 2*acos(
q.r())/sqrt(1-
q.r()*
q.r());
61 m_rotvec[0] = k*
q.x();
62 m_rotvec[1] = k*
q.y();
63 m_rotvec[2] = k*
q.z();
76 out << m_coords[0] << m_coords[1] << m_coords[2] << m_rotvec[0] << m_rotvec[1] << m_rotvec[2];
90 in >> m_coords[0] >> m_coords[1] >> m_coords[2] >> m_rotvec[0] >> m_rotvec[1] >> m_rotvec[2];
100 this->m_coords[0] = aux.
m_coords[0];
101 this->m_coords[1] = aux.
m_coords[1];
102 this->m_coords[2] = aux.
m_coords[2];
119 const std::streamsize old_pre = o.precision();
120 const std::ios_base::fmtflags old_flags = o.flags();
121 o <<
"(x,y,z,vx,vy,vz)=(" << std::fixed << std::setprecision(4) <<
p.m_coords[0] <<
"," <<
p.m_coords[1] <<
"," <<
p.m_coords[2] <<
","
122 <<
p.m_rotvec[0] <<
"," <<
p.m_rotvec[1] <<
"," <<
p.m_rotvec[2] <<
")";
124 o.precision(old_pre);
143 double &out_pitch )
const
150 out_range =
local.norm();
159 out_pitch = -asin(
local.z / out_range );
170 const double angle = this->m_rotvec.norm();
171 const double K1 = sin(angle)/angle;
172 const double K2 = (1-cos(angle))/(angle*angle);
174 const double tx = this->m_coords[0];
175 const double ty = this->m_coords[1];
176 const double tz = this->m_coords[2];
178 const double w1 = this->m_rotvec[0];
179 const double w2 = this->m_rotvec[1];
180 const double w3 = this->m_rotvec[2];
182 const double w1_2 =
w1*
w1;
183 const double w2_2 =
w2*
w2;
184 const double w3_2 = w3*w3;
186 gx = lx*(1-K2*(w2_2+w3_2)) + ly*(K2*
w1*
w2-K1*w3) + lz*(K1*
w2+K2*
w1*w3) + tx;
187 gy = lx*(K1*w3+K2*
w1*
w2) + ly*(1-K2*(w1_2+w3_2)) + lz*(K2*
w2*w3-K1*
w1) +
ty;
188 gz = lx*(K2*
w1*w3-K1*
w2) + ly*(K1*
w1+K2*
w2*w3) + lz*(1-K2*(w1_2+w2_2)) +
tz;
190 if (out_jacobian_df_dpoint || out_jacobian_df_dpose)
203 b.getInverseHomogeneousMatrix(B_INV);
224 this->composePoint(
b.m_coords[0],
b.m_coords[1],
b.m_coords[2],
239 this->composePoint(
b.m_coords[0],
252 q.m_coords[0] = this->m_coords[0];
253 q.m_coords[1] = this->m_coords[1];
254 q.m_coords[2] = this->m_coords[2];
256 const double a = sqrt( this->m_rotvec[0]*this->m_rotvec[0]+this->m_rotvec[1]*this->m_rotvec[1]+this->m_rotvec[2]*this->m_rotvec[2] );
260 q.m_quat.x(0.5*this->m_rotvec[0]);
261 q.m_quat.y(0.5*this->m_rotvec[1]);
262 q.m_quat.z(0.5*this->m_rotvec[2]);
268 q.m_quat.fromRodriguesVector( this->m_rotvec );
303 if(
a1 < 0.01 &&
a2 < 0.01 )
310 if( out_jacobian_drvtC_drvtA || out_jacobian_drvtC_drvtB )
312 if( out_jacobian_drvtC_drvtA )
314 out_jacobian_drvtC_drvtA->setIdentity(6,6);
318 if( out_jacobian_drvtC_drvtB )
320 out_jacobian_drvtC_drvtB->setIdentity(6,6);
322 (*out_jacobian_drvtC_drvtB)(3,3) =
323 (*out_jacobian_drvtC_drvtB)(4,4) =
324 (*out_jacobian_drvtC_drvtB)(5,5) = 1;
336 this->m_coords[0] =
coords[0];
337 this->m_coords[1] =
coords[1];
338 this->m_coords[2] =
coords[2];
342 else if (A_is_small) this->m_rotvec = B.
m_rotvec;
343 else if (B_is_small) this->m_rotvec = A.
m_rotvec;
346 const double a1_inv = 1/
a1;
347 const double a2_inv = 1/
a2;
349 const double sin_a1_2 = sin(0.5*
a1);
350 const double cos_a1_2 = cos(0.5*
a1);
351 const double sin_a2_2 = sin(0.5*
a2);
352 const double cos_a2_2 = cos(0.5*
a2);
354 const double KA = sin_a1_2*sin_a2_2;
355 const double KB = sin_a1_2*cos_a2_2;
356 const double KC = cos_a1_2*sin_a2_2;
357 const double KD = cos_a1_2*cos_a2_2;
359 const double r11 = a1_inv*A.
m_rotvec[0];
360 const double r12 = a1_inv*A.
m_rotvec[1];
361 const double r13 = a1_inv*A.
m_rotvec[2];
363 const double r21 = a2_inv*B.
m_rotvec[0];
364 const double r22 = a2_inv*B.
m_rotvec[1];
365 const double r23 = a2_inv*B.
m_rotvec[2];
367 const double q3[] = {
368 KD - KA*(r11*r21+r12*r22+r13*r23),
369 KC*r21 + KB*r11 + KA*(r22*r13-r23*r12),
370 KC*r22 + KB*r12 + KA*(r23*r11-r21*r13),
371 KC*r23 + KB*r13 + KA*(r21*r12-r22*r11)
374 const double param = 2*acos(q3[0])/sqrt(1-q3[0]*q3[0]);
375 this->m_rotvec[0] =
param*q3[1];
376 this->m_rotvec[1] =
param*q3[2];
377 this->m_rotvec[2] =
param*q3[3];
393 if( out_jacobian_drvtC_drvtA || out_jacobian_drvtC_drvtB )
398 const double &qCr = qC.
m_quat[0];
399 const double &qCx = qC.
m_quat[1];
400 const double &qCy = qC.
m_quat[2];
401 const double &qCz = qC.
m_quat[3];
403 const double &r1 = this->m_rotvec[0];
404 const double &r2 = this->m_rotvec[1];
405 const double &r3 = this->m_rotvec[2];
407 const double C = 1/(1-qCr*qCr);
408 const double D = acos(qCr)/sqrt(1-qCr*qCr);
411 2*C*qCx*(D*qCr-1), 2*D, 0, 0,
412 2*C*qCy*(D*qCr-1), 0, 2*D, 0,
413 2*C*qCz*(D*qCr-1), 0, 0, 2*D
418 const double alpha = sqrt(r1*r1+r2*r2+r3*r3);
423 -r1*alpha2*sin(
alpha/2), -r2*alpha2*sin(
alpha/2), -r3*alpha2*sin(
alpha/2),
424 2*alpha2*sin(
alpha/2)+r1*r1*KA, r1*r2*KA, r1*r3*KA,
425 r1*r2*KA, 2*alpha2*sin(
alpha/2)+r2*r2*KA, r2*r3*KA,
426 r1*r3*KA, r2*r3*KA, 2*alpha2*sin(
alpha/2)+r3*r3*KA
431 if( out_jacobian_drvtC_drvtB )
435 const double &qAr = qA.
m_quat[0];
436 const double &qAx = qA.
m_quat[1];
437 const double &qAy = qA.
m_quat[2];
438 const double &qAz = qA.
m_quat[3];
440 MRPT_ALIGN16 const double aux_valsQA[] = {qAr, -qAx, -qAy, -qAz, qAx, qAr, qAz, -qAy, qAy, -qAz, qAr, qAx, qAz, qAy, -qAx, qAr};
444 jac_rot_B.multiply_ABC(H,QA,G);
446 out_jacobian_drvtC_drvtB->fill(0);
447 out_jacobian_drvtC_drvtB->insertMatrix(0,0,jac_rot_B);
448 out_jacobian_drvtC_drvtB->insertMatrix(3,3,RA);
450 if( out_jacobian_drvtC_drvtA )
454 const double &qBr = qB.
m_quat[0];
455 const double &qBx = qB.
m_quat[1];
456 const double &qBy = qB.
m_quat[2];
457 const double &qBz = qB.
m_quat[3];
459 MRPT_ALIGN16 const double aux_valsQB[] = {qBr, -qBx, -qBy, -qBz, qBx, qBr, -qBz, qBy, qBy, qBz, qBr, -qBx, qBz, -qBy, qBx, qBr};
463 jac_rot_A.multiply_ABC(H,QB,G);
466 out_jacobian_drvtC_drvtA->fill(0);
467 out_jacobian_drvtC_drvtA->insertMatrix(0,0,jac_rot_A);
468 out_jacobian_drvtC_drvtB->insertMatrix(3,3,id3);
477 this->getInverseHomogeneousMatrix(B_INV);
478 this->setFromTransformationMatrix(B_INV);
486 this->getInverseHomogeneousMatrix(B_INV);
512 HM_C.multiply_AB(HM_B_inv,HM_A);
514 this->m_rotvec = this->rotVecFromRotMat(HM_C);
516 this->m_coords[0] = HM_C(0,3);
517 this->m_coords[1] = HM_C(1,3);
518 this->m_coords[2] = HM_C(2,3);
553 result.head<3>() = m_coords;
554 result.tail<3>() = m_rotvec;
559 for (
int i=0;i<3;i++) {
560 m_coords[i] = std::numeric_limits<double>::quiet_NaN();
561 m_rotvec[i] = std::numeric_limits<double>::quiet_NaN();
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
A numeric matrix of compile-time fixed size.
A quaternion, which can represent a 3D rotation as pair , with a real part "r" and a 3D vector ,...
A class used to store a 2D point.
A class used to store a 3D point.
mrpt::math::CArrayDouble< 3 > m_coords
[x,y,z]
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
mrpt::math::CArrayDouble< 3 > m_coords
The translation vector [x,y,z] access directly or with x(), y(), z() setter/getter methods.
mrpt::math::CArrayDouble< 3 > ln_rotation() const
Take the logarithm of the 3x3 rotation matrix, generating the corresponding vector in the Lie Algebra...
void setRotationMatrix(const mrpt::math::CMatrixDouble33 &ROT)
Sets the 3x3 rotation matrix.
static mrpt::math::CMatrixDouble33 exp_rotation(const mrpt::math::CArrayNumeric< double, 3 > &vect)
Exponentiate a vector in the Lie algebra to generate a new SO(3) (a 3x3 rotation matrix).
void getHomogeneousMatrix(mrpt::math::CMatrixDouble44 &out_HM) const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,...
mrpt::math::CQuaternionDouble m_quat
The quaternion.
A 3D pose, with a 3D translation and a rotation in 3D parameterized in rotation-vector form (equivale...
void inverseComposeFrom(const CPose3DRotVec &A, const CPose3DRotVec &B)
Makes this method is slightly more efficient than "this= A - B;" since it avoids the temporary objec...
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
void setToNaN() MRPT_OVERRIDE
Set all data fields to quiet NaN.
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream.
void inverseComposePoint(const double gx, const double gy, const double gz, double &lx, double &ly, double &lz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL) const
Computes the 3D point L such as .
void inverse()
Convert this pose into its inverse, saving the result in itself.
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.
static CPose3DRotVec exp(const mrpt::math::CArrayDouble< 6 > &vect)
Exponentiate a Vector in the SE(3) Lie Algebra to generate a new CPose3DRotVec (static method).
void getHomogeneousMatrix(mrpt::math::CMatrixDouble44 &out_HM) const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
CPose3DRotVec getInverse() const
Compute the inverse of this pose and return the result.
void toQuatXYZ(CPose3DQuat &q) const
Convert this RVT into a quaternion + XYZ.
void ln(mrpt::math::CArrayDouble< 6 > &out_ln) const
Take the logarithm of the 3x4 matrix defined by this pose, generating the corresponding vector in the...
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=NULL, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=NULL) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
CPose3DRotVec operator+(const CPose3DRotVec &b) const
The operator is the pose compounding operator.
mrpt::math::CArrayDouble< 3 > ln_rotation() const
Take the logarithm of the 3x3 rotation matrix part of this pose, generating the corresponding vector ...
const mrpt::math::CMatrixDouble33 getRotationMatrix() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
CPose3DRotVec()
Default constructor, with all the coordinates set to zero.
void composeFrom(const CPose3DRotVec &A, const CPose3DRotVec &B, mrpt::math::CMatrixFixedNumeric< double, 6, 6 > *out_jacobian_drvtC_drvtA=NULL, mrpt::math::CMatrixFixedNumeric< double, 6, 6 > *out_jacobian_drvtC_drvtB=NULL)
Makes "this = A (+) B"; this method is slightly more efficient than "this= A + B;" since it avoids th...
mrpt::math::CArrayDouble< 3 > rotVecFromRotMat(const math::CMatrixDouble44 &m)
Create a vector with 3 components according to the input transformation matrix (only the rotation wil...
void setFromXYZAndAngles(const double x, const double y, const double z, const double yaw=0, const double pitch=0, const double roll=0)
mrpt::math::CArrayDouble< 3 > m_rotvec
The rotation vector [vx,vy,vz].
void setFromTransformationMatrix(const mrpt::math::CMatrixDouble44 &m)
mrpt::math::CArrayDouble< 3 > m_coords
The translation vector [x,y,z].
double x() const
Common members of all points & poses classes.
void getInverseHomogeneousMatrix(mrpt::math::CMatrixDouble44 &out_HM) const
Returns the corresponding 4x4 inverse homogeneous transformation matrix for this point or pose.
The virtual base class which provides a unified interface for all persistent objects in MRPT.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble GLdouble w2
GLclampf GLclampf GLclampf alpha
GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint GLdouble w1
GLubyte GLubyte GLubyte a
GLdouble GLdouble GLdouble GLdouble q
void skew_symmetric3(const VECTOR &v, MATRIX &M)
Computes the 3x3 skew symmetric matrix from a 3-vector or 3-array:
void skew_symmetric3_neg(const VECTOR &v, MATRIX &M)
Computes the negative version of a 3x3 skew symmetric matrix from a 3-vector or 3-array:
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define THROW_EXCEPTION(msg)
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This base provides a set of functions for maths stuff.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
bool operator!=(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
CPose2D BASE_IMPEXP operator-(const CPose2D &p)
Unary - operator: return the inverse pose "-p" (Note that is NOT the same than a pose with negative x...
std::ostream & operator<<(std::ostream &o, const CPoint< DERIVEDCLASS > &p)
Dumps a point as a string [x,y] or [x,y,z]
bool operator==(const CPoint< DERIVEDCLASS > &p1, const CPoint< DERIVEDCLASS > &p2)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double z
X,Y,Z coordinates.