Main MRPT website > C++ reference for MRPT 1.9.9
xsquaternion.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-2017, 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 XSQUATERNION_H
10 #define XSQUATERNION_H
11 
12 #include "xsmath.h"
13 
14 struct XsEuler;
15 struct XsMatrix;
16 struct XsVector;
17 struct XsQuaternion;
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #else
22 #define XSQUATERNION_INITIALIZER \
23  { \
24  { \
25  { \
26  XsMath_zero, XsMath_zero, XsMath_zero, XsMath_zero \
27  } \
28  } \
29  }
30 typedef struct XsQuaternion XsQuaternion;
31 #endif
32 
36  const XsQuaternion* thisPtr, XsQuaternion* dest);
38  XsQuaternion_normalized(const XsQuaternion* thisPtr, XsQuaternion* dest);
41  XsQuaternion* thisPtr, const struct XsEuler* src);
43  XsQuaternion* thisPtr, const struct XsMatrix* ori);
46  const XsQuaternion* left, const XsQuaternion* right, XsQuaternion* dest);
49  XsQuaternion* copy, XsQuaternion const* src);
51  XsQuaternion const* a, XsQuaternion const* b);
52 
53 #ifdef __cplusplus
54 } // extern "C"
55 #endif
56 
58 {
60  union {
61  struct
62  {
63  /** Stores the w component of the quaternion */
65  /** Stores the x component of the quaternion */
67  /** Stores the y component of the quaternion */
69  /** Stores the z component of the quaternion */
71  };
72  /** Stores the quaternion in an array of four elements */
74  };
75 #ifdef __cplusplus
76  public:
77  //! \brief Construct a quaternion with the supplied values, or zero's by
78  //! default
79  inline explicit XsQuaternion(
82  : m_w(w), m_x(x), m_y(y), m_z(z)
83  {
84  }
85 
86  //! \brief Construct a quaternion with the supplied values from the \a other
87  //! Quaternion
88  inline XsQuaternion(const XsQuaternion& other)
89  : m_w(other.m_w), m_x(other.m_x), m_y(other.m_y), m_z(other.m_z)
90  {
91  }
92 
93  //! \brief Construct a quaternion by converting from an XsEuler object
94  inline explicit XsQuaternion(const XsEuler& euler)
95  {
96  XsQuaternion_fromEulerAngles(this, &euler);
97  }
98 
99  //! \brief Construct a quaternion by converting from an XsMatrix rotation
100  //! matrix object
101  inline explicit XsQuaternion(const XsMatrix& ori)
102  {
104  }
105 
106  //! \brief Assigns the \a other quaternion to this quaternion
107  inline XsQuaternion& operator=(const XsQuaternion& other)
108  {
109  m_w = other.m_w;
110  m_x = other.m_x;
111  m_y = other.m_y;
112  m_z = other.m_z;
113  return *this;
114  }
115 
116  /*! \brief Set the Quaternion to these specific values
117  */
118  inline void assign(XsReal w, XsReal x, XsReal y, XsReal z)
119  {
120  m_w = w;
121  m_x = x;
122  m_y = y;
123  m_z = z;
124  }
125 
126  /*! \brief Set the Quaternion to the specific values in the supplied array.
127  \param values An array that contains at least 4 items. The first four
128  will be interpreted as w,x,y,z
129  */
130  inline void assign(const XsReal* values)
131  {
132  for (int i = 0; i < 4; ++i) m_data[i] = values[i];
133  }
134 
135  //! \brief Returns a reference to the \a index'th component of the
136  //! quaternion
137  inline XsReal& operator[](XsSize index)
138  {
139  assert(index < 4);
140  return m_data[index];
141  }
142 
143  //! \brief Returns the \a index'th component of the quaternion
144  inline XsReal const& operator[](XsSize index) const
145  {
146  assert(index < 4);
147  return m_data[index];
148  }
149 
150  //! \brief Return a const pointer to the internal data
151  inline const XsReal* data() const { return m_data; }
152  //! \brief \copybrief XsQuaternion_inverse \returns The inverse/conjugate of
153  //! the quaternion
154  inline XsQuaternion inverse() const
155  {
156  XsQuaternion tmp;
157  XsQuaternion_inverse(this, &tmp);
158  return tmp;
159  }
160 
161  //! \brief \copybrief XsQuaternion_inverse \returns The inverse/conjugate of
162  //! the quaternion
163  inline XsQuaternion conjugate() const
164  {
165  XsQuaternion tmp;
166  XsQuaternion_inverse(this, &tmp);
167  return tmp;
168  }
169 
170  //! \brief Return a normalized version of the quaternion \sa
171  //! XsQuaternion_normalized \returns The normalized quaternion
172  XsQuaternion normalized() const
173  {
174  XsQuaternion tmp;
175  XsQuaternion_normalized(this, &tmp);
176  return tmp;
177  }
178 
179  //! \brief Normalized the quaternion \sa XsQuaternion_normalized \returns
180  //! The cartesian length of the quaternion before normalization
181  inline XsReal normalize() { return XsQuaternion_normalized(this, this); }
182  //! \brief \copybrief XsQuaternion_empty
183  inline bool empty() const { return 0 != XsQuaternion_empty(this); }
184  //! \brief \copybrief XsQuaternion_fromEulerAngles
185  inline XsQuaternion& fromEulerAngles(const XsEuler& src)
186  {
188  return *this;
189  }
190 
191  //! \brief \copybrief XsQuaternion_fromRotationMatrix
192  inline XsQuaternion& fromRotationMatrix(const XsMatrix& ori)
193  {
195  return *this;
196  }
197 
198  //! \brief \copybrief XsQuaternion_identity
199  inline static const XsQuaternion& identity()
200  {
201  return *XsQuaternion_identity();
202  }
203 
204  /*! \brief In-place multiplication of this quaternion with \a other
205  quaternion
206  \param other The other quaternion to multiply with (right side of
207  multiplication)
208  \sa XsQuaternion_multiply()
209  */
210  inline void operator*=(const XsQuaternion& other)
211  {
212  XsQuaternion_multiply(this, &other, this);
213  }
214 
215  //! \brief Return the w component of the quaternion
216  inline XsReal w() const { return m_w; }
217  //! \brief Return the x component of the quaternion
218  inline XsReal x() const { return m_x; }
219  //! \brief Return the y component of the quaternion
220  inline XsReal y() const { return m_y; }
221  //! \brief Return the z component of the quaternion
222  inline XsReal z() const { return m_z; }
223  //! \brief Return a reference to the w component of the quaternion
224  inline XsReal& w() { return m_w; }
225  //! \brief Return a reference to the x component of the quaternion
226  inline XsReal& x() { return m_x; }
227  //! \brief Return a reference to the y component of the quaternion
228  inline XsReal& y() { return m_y; }
229  //! \brief Return a reference to the z component of the quaternion
230  inline XsReal& z() { return m_z; }
231  //! \brief Swap the contents with \a other
232  inline void swap(XsQuaternion& other) { XsQuaternion_swap(this, &other); }
233  //! \brief Returns true if \a other is numerically identical to this
234  inline bool operator==(const XsQuaternion& other) const
235  {
236  return m_w == other.m_w && m_x == other.m_x && m_y == other.m_y &&
237  m_z == other.m_z;
238  }
239 
240 #endif
241 };
242 
243 #ifdef __cplusplus
244 //! \brief Return the negated version of the Quaternion \a q (w,-x,-y,-z)
245 inline XsQuaternion operator-(const XsQuaternion& q)
246 {
247  return XsQuaternion(q.w(), -q.x(), -q.y(), -q.z());
248 }
249 
250 //! \brief Multiply \a lhs by \a rhs and return the result
251 inline XsQuaternion operator*(const XsQuaternion& lhs, const XsQuaternion& rhs)
252 {
253  XsQuaternion tmp(lhs);
254  tmp *= rhs;
255  return tmp;
256 }
257 #endif
258 
259 #endif // file guard
XSTYPES_DLL_API XsReal XsQuaternion_normalized(const XsQuaternion *thisPtr, XsQuaternion *dest)
bool operator==(const TPoint2D &p1, const TPoint2D &p2)
Exact comparison between 2D points.
EIGEN_STRONG_INLINE bool empty() const
GLdouble GLdouble z
Definition: glext.h:3872
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:3582
XSTYPES_DLL_API const XsReal XsMath_zero
GLdouble GLdouble GLdouble GLdouble q
Definition: glext.h:3721
XsReal m_z
Stores the z component of the quaternion.
Definition: xsquaternion.h:70
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
GLuint src
Definition: glext.h:7278
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
XSTYPES_DLL_API int XsQuaternion_equal(XsQuaternion const *a, XsQuaternion const *b)
XsReal m_data[4]
Stores the quaternion in an array of four elements.
Definition: xsquaternion.h:73
GLuint index
Definition: glext.h:4054
XsReal m_y
Stores the y component of the quaternion.
Definition: xsquaternion.h:68
XSTYPES_DLL_API void XsQuaternion_copy(XsQuaternion *copy, XsQuaternion const *src)
Eigen::Matrix< dataType, 4, 4 > inverse(Eigen::Matrix< dataType, 4, 4 > &pose)
Definition: Miscellaneous.h:82
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn&#39;t exist already.
Definition: ts_hash_map.h:200
XSTYPES_DLL_API void XsQuaternion_inverse(const XsQuaternion *thisPtr, XsQuaternion *dest)
GLubyte GLubyte b
Definition: glext.h:6279
struct XsQuaternion XsQuaternion
Definition: xsquaternion.h:30
#define XSCPPPROTECTED
Definition: xstypesconfig.h:57
EIGEN_STRONG_INLINE void assign(const Scalar v)
Definition: eigen_plugins.h:48
XSTYPES_DLL_API void XsQuaternion_swap(XsQuaternion *a, XsQuaternion *b)
XSTYPES_DLL_API int XsQuaternion_empty(const XsQuaternion *thisPtr)
#define XSTYPES_DLL_API
Definition: xstypesconfig.h:9
void normalize(Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
XSTYPES_DLL_API void XsQuaternion_fromRotationMatrix(XsQuaternion *thisPtr, const struct XsMatrix *ori)
XSTYPES_DLL_API void XsQuaternion_destruct(XsQuaternion *thisPtr)
XSTYPES_DLL_API void XsQuaternion_multiply(const XsQuaternion *left, const XsQuaternion *right, XsQuaternion *dest)
double XsReal
Defines the floating point type used by the Xsens libraries.
Definition: xstypedefs.h:17
GLenum GLint GLint y
Definition: glext.h:3538
XSTYPES_DLL_API XsReal XsQuaternion_normalize(XsQuaternion *thisPtr)
XsReal m_w
Stores the w component of the quaternion.
Definition: xsquaternion.h:64
GLenum GLint x
Definition: glext.h:3538
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
TPoint3D operator-(const TPoint3D &p1)
Unary minus operator for 3D points.
XSTYPES_DLL_API void XsQuaternion_fromEulerAngles(XsQuaternion *thisPtr, const struct XsEuler *src)
std::vector< T1 > & operator*=(std::vector< T1 > &a, const std::vector< T2 > &b)
a*=b (element-wise multiplication)
Definition: ops_vectors.h:43
XsReal m_x
Stores the x component of the quaternion.
Definition: xsquaternion.h:66
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)
Definition: ops_vectors.h:62
GLint GLenum GLboolean normalized
Definition: glext.h:4206
XSTYPES_DLL_API const XsQuaternion * XsQuaternion_identity(void)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019