Main MRPT website > C++ reference
MRPT logo
base/include/mrpt/math/jacobians.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2014, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef mrpt_math_jacobians_H
10 #define mrpt_math_jacobians_H
11 
12 #include <mrpt/math/num_jacobian.h>
13 #include <mrpt/math/CQuaternion.h>
14 #include <mrpt/poses/CPose3D.h>
15 #include <mrpt/poses/CPosePDF.h>
17 #include <mrpt/poses/CPose3DPDF.h>
18 
19 namespace mrpt
20 {
21  namespace math
22  {
23  /** A collection of functions to compute jacobians of diverse transformations, etc (some functions are redirections to existing methods elsewhere, so this namespace is actually used with grouping purposes).
24  * Since most functions in this namespace are inline, their use implies no execution time overload and the code may be more clear to read, so it's recommended to use them where needed.
25  * \ingroup mrpt_base_grp
26  */
27  namespace jacobians
28  {
31 
32  /** Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw pitch roll) into a Quaternion, that is, the Jacobian of:
33  * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2) \cos (\psi /2) + \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin (\phi /2) \cos (\theta /2) \cos (\psi /2) - \cos (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) + \sin (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2) \sin (\psi /2) - \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\ \end{array}\right) \f]
34  * With : \f$ \phi = roll \f$, \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
35  * \sa jacob_yawpitchroll_from_quat, mrpt::poses::CPose3D::getAsQuaternion
36  */
39  const double yaw,
40  const double pitch,
41  const double roll
42  )
43  {
45  CPose3D p(0,0,0,yaw,pitch,roll);
46  p.getAsQuaternion(q,&out_dq_dr);
47  }
48 
49  /** Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw pitch roll) into a Quaternion, that is, the Jacobian of:
50  * \f[ \mathbf{q} = \left( \begin{array}{c} \cos (\phi /2) \cos (\theta /2) \cos (\psi /2) + \sin (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \sin (\phi /2) \cos (\theta /2) \cos (\psi /2) - \cos (\phi /2) \sin (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \sin (\theta /2) \cos (\psi /2) + \sin (\phi /2) \cos (\theta /2) \sin (\psi /2) \\ \cos (\phi /2) \cos (\theta /2) \sin (\psi /2) - \sin (\phi /2) \sin (\theta /2) \cos (\psi /2) \\ \end{array}\right) \f]
51  * With : \f$ \phi = roll \f$, \f$ \theta = pitch \f$ and \f$ \psi = yaw \f$.
52  * \sa jacob_yawpitchroll_from_quat, mrpt::poses::CPose3D::getAsQuaternion
53  */
56  const CPose3D &in_pose
57  )
58  {
60  in_pose.getAsQuaternion(q,&out_dq_dr);
61  }
62 
63 
64  /** Computes the 3x4 Jacobian of the transformation from a quaternion (qr qx qy qz) to 3D pose angles (yaw pitch roll).
65  * \sa jacob_quat_from_yawpitchroll
66  */
69  )
70  {
71  MRPT_UNUSED_PARAM(out_dr_dq);
72  THROW_EXCEPTION("TO DO")
73  }
74 
75  /** Compute the Jacobian of the rotation composition operation \f$ p = f(\cdot) = q_{this} \times r \f$, that is the 4x4 matrix \f$ \frac{\partial f}{\partial q_{this} } \f$.
76  * The output matrix can be a dynamic or fixed size (4x4) matrix. The input quaternion can be mrpt::math::CQuaternionFloat or mrpt::math::CQuaternionDouble.
77  */
78  template <class QUATERNION,class MATRIXLIKE>
79  inline void jacob_quat_rotation(const QUATERNION& quaternion, MATRIXLIKE &out_mat4x4)
80  {
81  quaternion.rotationJacobian(out_mat4x4);
82  }
83 
84  /** Given the 3D(6D) pose composition \f$ f(x,u) = x \oplus u \f$, compute the two 6x6 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$ \frac{\partial f}{\partial u} \f$.
85  * For the equations, see CPose3DPDF::jacobiansPoseComposition
86  */
87  inline void jacobs_6D_pose_comp(
88  const CPose3D &x,
89  const CPose3D &u,
90  CMatrixDouble66 &out_df_dx,
91  CMatrixDouble66 &out_df_du)
92  {
94  }
95 
96  /** Given the 3D(6D) pose composition \f$ f(x,u) = x \oplus u \f$, compute the two 6x6 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$ \frac{\partial f}{\partial u} \f$.
97  * For the equations, see CPose3DQuatPDF::jacobiansPoseComposition
98  */
99  inline void jacobs_6D_pose_comp(
100  const mrpt::poses::CPose3DQuat &x,
101  const mrpt::poses::CPose3DQuat &u,
102  CMatrixDouble77 &out_df_dx,
103  CMatrixDouble77 &out_df_du)
104  {
106  }
107 
108  /** Given the 2D pose composition \f$ f(x,u) = x \oplus u \f$, compute the two 3x3 Jacobians \f$ \frac{\partial f}{\partial x} \f$ and \f$ \frac{\partial f}{\partial u} \f$.
109  * For the equations, see CPosePDF::jacobiansPoseComposition
110  */
111  inline void jacobs_2D_pose_comp(
114  CMatrixDouble33 &out_df_dx,
115  CMatrixDouble33 &out_df_du)
116  {
117  mrpt::poses::CPosePDF::jacobiansPoseComposition(x,u,out_df_dx,out_df_du);
118  }
119 
120  /** Numerical estimation of the Jacobian of a user-supplied function - this template redirects to mrpt::math::estimateJacobian, see that function for documentation. */
121  template <class VECTORLIKE,class VECTORLIKE2, class VECTORLIKE3, class MATRIXLIKE, class USERPARAM >
123  const VECTORLIKE &x,
124  void (*functor) (const VECTORLIKE &x,const USERPARAM &y, VECTORLIKE3 &out),
125  const VECTORLIKE2 &increments,
126  const USERPARAM &userParam,
127  MATRIXLIKE &out_Jacobian )
128  {
129  mrpt::math::estimateJacobian(x,functor,increments,userParam,out_Jacobian);
130  }
131 
132 
133  } // End of jacobians namespace
134 
135  } // End of MATH namespace
136 
137 } // End of namespace
138 
139 #endif
#define THROW_EXCEPTION(msg)
void getAsQuaternion(mrpt::math::CQuaternionDouble &q, mrpt::math::CMatrixFixedNumeric< double, 4, 3 > *out_dq_dr=NULL) const
Returns the quaternion associated to the rotation of this object (NOTE: XYZ translation is ignored) ...
CQuaternion< double > CQuaternionDouble
A quaternion of data type "double".
Definition: CQuaternion.h:405
A numeric matrix of compile-time fixed size.
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
void jacob_quat_from_yawpitchroll(mrpt::math::CMatrixFixedNumeric< double, 4, 3 > &out_dq_dr, const double yaw, const double pitch, const double roll)
Computes the 4x3 Jacobian of the transformation from a 3D pose angles (yaw pitch roll) into a Quatern...
static void jacobiansPoseComposition(const CPose3D &x, const CPose3D &u, mrpt::math::CMatrixDouble66 &df_dx, mrpt::math::CMatrixDouble66 &df_du)
This static method computes the pose composition Jacobians.
void jacobs_6D_pose_comp(const CPose3D &x, const CPose3D &u, CMatrixDouble66 &out_df_dx, CMatrixDouble66 &out_df_du)
Given the 3D(6D) pose composition , compute the two 6x6 Jacobians and .
A class used to store a 3D pose as a translation (x,y,z) and a quaternion (qr,qx,qy,qz).
Definition: CPose3DQuat.h:41
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:69
void jacob_quat_rotation(const QUATERNION &quaternion, MATRIXLIKE &out_mat4x4)
Compute the Jacobian of the rotation composition operation , that is the 4x4 matrix ...
static void jacobiansPoseComposition(const CPose2D &x, const CPose2D &u, mrpt::math::CMatrixDouble33 &df_dx, mrpt::math::CMatrixDouble33 &df_du, const bool compute_df_dx=true, const bool compute_df_du=true)
This static method computes the pose composition Jacobians, with these formulas:
void jacob_numeric_estimate(const VECTORLIKE &x, void(*functor)(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out), const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Numerical estimation of the Jacobian of a user-supplied function - this template redirects to mrpt::m...
void estimateJacobian(const VECTORLIKE &x, void(*functor)(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out), const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of...
Definition: num_jacobian.h:26
void jacob_yawpitchroll_from_quat(mrpt::math::CMatrixFixedNumeric< double, 3, 4 > &out_dr_dq)
Computes the 3x4 Jacobian of the transformation from a quaternion (qr qx qy qz) to 3D pose angles (ya...
void jacobs_2D_pose_comp(const mrpt::poses::CPosePDFGaussian &x, const mrpt::poses::CPosePDFGaussian &u, CMatrixDouble33 &out_df_dx, CMatrixDouble33 &out_df_du)
Given the 2D pose composition , compute the two 3x3 Jacobians and .
static void jacobiansPoseComposition(const CPose3DQuat &x, const CPose3DQuat &u, mrpt::math::CMatrixDouble77 &df_dx, mrpt::math::CMatrixDouble77 &df_du, CPose3DQuat *out_x_oplus_u=NULL)
This static method computes the two Jacobians of a pose composition operation $f(x,u)= x u$.



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014