MRPT  1.9.9
TTwist3D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/math/TPoseOrPoint.h>
12 
13 namespace mrpt::math
14 {
15 /** 3D twist: 3D velocity vector (vx,vy,vz) + angular velocity (wx,wy,wz)
16  * \sa mrpt::math::TTwist2D, mrpt::math::TPose3D
17  */
18 struct TTwist3D : public internal::ProvideStaticResize<TTwist3D>
19 {
20  enum
21  {
23  };
24 
25  /** Velocity components: X,Y (m/s) */
26  double vx{.0}, vy{.0}, vz{.0};
27  /** Angular velocity (rad/s) */
28  double wx{.0}, wy{.0}, wz{.0};
29 
30  /** Constructor from components */
31  constexpr TTwist3D(
32  double vx_, double vy_, double vz_, double wx_, double wy_, double wz_)
33  : vx(vx_), vy(vy_), vz(vz_), wx(wx_), wy(wy_), wz(wz_)
34  {
35  }
36  /** Default fast constructor. Initializes to zeros */
37  TTwist3D() = default;
38  /** Coordinate access using operator[]. Order: vx,vy,vz, wx, wy, wz */
39  double& operator[](size_t i)
40  {
41  switch (i)
42  {
43  case 0:
44  return vx;
45  case 1:
46  return vy;
47  case 2:
48  return vz;
49  case 3:
50  return wx;
51  case 4:
52  return wy;
53  case 5:
54  return wz;
55  default:
56  throw std::out_of_range("index out of range");
57  }
58  }
59  /// \overload
60  constexpr const double& operator[](size_t i) const
61  {
62  switch (i)
63  {
64  case 0:
65  return vx;
66  case 1:
67  return vy;
68  case 2:
69  return vz;
70  case 3:
71  return wx;
72  case 4:
73  return wy;
74  case 5:
75  return wz;
76  default:
77  throw std::out_of_range("index out of range");
78  }
79  }
80 
81  /** (i,0) access operator (provided for API compatibility with matrices).
82  * \sa operator[] */
83  double& operator()(int row, int col)
84  {
85  ASSERT_EQUAL_(col, 0);
86  return (*this)[row];
87  }
88  /// \overload
89  constexpr const double& operator()(int row, int col) const
90  {
91  ASSERT_EQUAL_(col, 0);
92  return (*this)[row];
93  }
94 
95  /** Transformation into vector [vx vy vz wx wy wz] */
96  template <typename VECTORLIKE>
97  void asVector(VECTORLIKE& v) const
98  {
99  v.resize(6);
100  for (int i = 0; i < 6; i++) v[i] = (*this)[i];
101  }
102  template <typename VECTORLIKE>
103  VECTORLIKE asVector() const
104  {
105  VECTORLIKE v;
106  asVector(v);
107  return v;
108  }
109 
110  /** Sets from a vector [vx vy vz wx wy wz] */
111  template <typename VECTORLIKE>
112  void fromVector(const VECTORLIKE& v)
113  {
114  ASSERT_EQUAL_(v.size(), 6);
115  for (int i = 0; i < 6; i++) (*this)[i] = v[i];
116  }
117  bool operator==(const TTwist3D& o) const;
118  bool operator!=(const TTwist3D& o) const;
119  /** Returns a human-readable textual representation of the object (eg: "[vx
120  * vy vz wx wy wz]", omegas in deg/s)
121  * \sa fromString
122  */
123  void asString(std::string& s) const;
125  {
126  std::string s;
127  asString(s);
128  return s;
129  }
130 
131  /** Transform all 6 components for a change of reference frame from "A" to
132  * another frame "B" whose rotation with respect to "A" is given by `rot`.
133  * The translational part of the pose is ignored */
134  void rotate(const mrpt::math::TPose3D& rot);
135 
136  /** Set the current object value from a string generated by 'asString' (eg:
137  * "[vx vy vz wx wy wz]" )
138  * \sa asString
139  * \exception std::exception On invalid format
140  */
141  void fromString(const std::string& s);
142 };
143 
148 
149 } // namespace mrpt::math
150 
151 namespace mrpt::typemeta
152 {
153 // Specialization must occur in the same namespace
155 
156 } // namespace mrpt::typemeta
constexpr const double & operator[](size_t i) const
Definition: TTwist3D.h:60
void asVector(VECTORLIKE &v) const
Transformation into vector [vx vy vz wx wy wz].
Definition: TTwist3D.h:97
constexpr const double & operator()(int row, int col) const
Definition: TTwist3D.h:89
bool operator==(const TTwist3D &o) const
GLdouble s
Definition: glext.h:3682
constexpr TTwist3D(double vx_, double vy_, double vz_, double wx_, double wy_, double wz_)
Constructor from components.
Definition: TTwist3D.h:31
void fromString(const std::string &s)
Set the current object value from a string generated by &#39;asString&#39; (eg: "[vx vy vz wx wy wz]" ) ...
double & operator[](size_t i)
Coordinate access using operator[].
Definition: TTwist3D.h:39
3D twist: 3D velocity vector (vx,vy,vz) + angular velocity (wx,wy,wz)
Definition: TTwist3D.h:18
This base provides a set of functions for maths stuff.
#define ASSERT_EQUAL_(__A, __B)
Assert comparing two values, reporting their actual values upon failure.
Definition: exceptions.h:137
TTwist3D()=default
Default fast constructor.
#define MRPT_DECLARE_TTYPENAME_NO_NAMESPACE(_TYPE, __NS)
Declares a typename to be "type" (without the NS prefix)
Definition: TTypeName.h:128
void rotate(const mrpt::math::TPose3D &rot)
Transform all 6 components for a change of reference frame from "A" to another frame "B" whose rotati...
GLsizei const GLchar ** string
Definition: glext.h:4116
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
void fromVector(const VECTORLIKE &v)
Sets from a vector [vx vy vz wx wy wz].
Definition: TTwist3D.h:112
VECTORLIKE asVector() const
Definition: TTwist3D.h:103
const GLdouble * v
Definition: glext.h:3684
double wx
Angular velocity (rad/s)
Definition: TTwist3D.h:28
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:53
double vx
Velocity components: X,Y (m/s)
Definition: TTwist3D.h:26
Provided for STL and matrices/vectors compatibility.
Definition: TPoseOrPoint.h:54
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
Definition: math.cpp:630
GLenum GLenum GLvoid * row
Definition: glext.h:3580
bool operator!=(const TTwist3D &o) const
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: TPose3D.h:23
GLuint in
Definition: glext.h:7391
double & operator()(int row, int col)
(i,0) access operator (provided for API compatibility with matrices).
Definition: TTwist3D.h:83
std::string asString() const
Definition: TTwist3D.h:124



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019