Point3.hpp
Go to the documentation of this file.
1 /*
2  * RDL - Robot Dynamics Library
3  * Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
4  *
5  * Licensed under the zlib license. See LICENSE for more details.
6  */
7 
8 #ifndef __RDL_POINT_3_HPP__
9 #define __RDL_POINT_3_HPP__
10 
15 #include <math.h>
16 #include <stdexcept>
17 #include <type_traits>
19 
20 namespace RobotDynamics
21 {
22 namespace Math
23 {
29 {
30  public:
31  Point3d(const double x, const double y, const double z)
32  {
33  point[0] = x;
34  point[1] = y;
35  point[2] = z;
36  }
37 
38  Point3d(const Point3d& point) : Point3d(point.x(), point.y(), point.z())
39  {
40  }
41 
42  // cppcheck-suppress noExplicitConstructor
43  explicit Point3d(const Vector3d& vector) : Point3d(vector[0], vector[1], vector[2])
44  {
45  }
46 
47  EIGEN_STRONG_INLINE Point3d() : Point3d(0., 0., 0.)
48  {
49  }
50 
51  virtual ~Point3d()
52  {
53  }
54 
59  inline void transform(const Math::SpatialTransform& X)
60  {
61  set(-X.E * X.r + X.E * this->vec());
62  }
63 
65  {
66  Point3d p = *this;
67  p.transform(X);
68  return p;
69  }
70 
71  EIGEN_STRONG_INLINE void set(const std::vector<double>& vector)
72  {
73  set(vector[0], vector[1], vector[2]);
74  }
75 
76  EIGEN_STRONG_INLINE void set(const Point3d& point)
77  {
78  set(point.x(), point.y(), point.z());
79  }
80 
81  void set(const Math::Vector3d& v)
82  {
83  set(v[0], v[1], v[2]);
84  }
85 
86  void set(const double x, const double y, const double z)
87  {
88  point[0] = x;
89  point[1] = y;
90  point[2] = z;
91  }
92 
93  EIGEN_STRONG_INLINE void setToZero()
94  {
95  set(0., 0., 0.);
96  }
97 
104  EIGEN_STRONG_INLINE bool epsilonEquals(const Point3d& point, const double epsilon) const
105  {
106  return fabs(this->x() - point.x()) < epsilon && fabs(this->y() - point.y()) < epsilon && fabs(this->z() - point.z()) < epsilon;
107  }
108 
113  void clampMin(const double min)
114  {
115  if (x() < min)
116  {
117  x() = min;
118  }
119 
120  if (y() < min)
121  {
122  y() = min;
123  }
124 
125  if (z() < min)
126  {
127  z() = min;
128  }
129  }
130 
135  void clampMax(const double max)
136  {
137  if (x() > max)
138  {
139  x() = max;
140  }
141 
142  if (y() > max)
143  {
144  y() = max;
145  }
146 
147  if (z() > max)
148  {
149  z() = max;
150  }
151  }
152 
158  void clampMinMax(const double min, const double max)
159  {
160  this->clampMin(min);
161  this->clampMax(max);
162  }
163 
168  {
169  this->x() = fabs(this->x());
170  this->y() = fabs(this->y());
171  this->z() = fabs(this->z());
172  }
173 
179  double distanceSquared(const Point3d& point) const
180  {
181  double dx = x() - point.x();
182  double dy = y() - point.y();
183  double dz = z() - point.z();
184 
185  return dx * dx + dy * dy + dz * dz;
186  }
187 
193  double distance(const Point3d& point) const
194  {
195  return sqrt(distanceSquared(point));
196  }
197 
203  double distanceL1(const Point3d& point) const
204  {
205  return fabs(x() - point.x()) + fabs(y() - point.y()) + fabs(z() - point.z());
206  }
207 
214  {
215  return Vector3d(point[1] * v[2] - point[2] * v[1], point[2] * v[0] - point[0] * v[2], point[0] * v[1] - point[1] * v[0]);
216  }
217 
223  double distanceLinf(const Point3d& point) const
224  {
225  double dx = x() - point.x();
226  double dy = y() - point.y();
227  double dz = z() - point.z();
228 
229  double tmp = fabs(dx) > fabs(dy) ? fabs(dx) : fabs(dy);
230 
231  return tmp > fabs(dz) ? tmp : fabs(dz);
232  }
233 
234  EIGEN_STRONG_INLINE double& x()
235  {
236  return point[0];
237  }
238 
239  EIGEN_STRONG_INLINE double x() const
240  {
241  return point[0];
242  }
243 
244  EIGEN_STRONG_INLINE double& y()
245  {
246  return point[1];
247  }
248 
249  EIGEN_STRONG_INLINE double y() const
250  {
251  return point[1];
252  }
253 
254  EIGEN_STRONG_INLINE double& z()
255  {
256  return point[2];
257  }
258 
259  EIGEN_STRONG_INLINE double z() const
260  {
261  return point[2];
262  }
263 
264  EIGEN_STRONG_INLINE double* data()
265  {
266  return point;
267  }
268 
269  EIGEN_STRONG_INLINE Math::Vector3d vec() const
270  {
271  return Math::Vector3d(point[0], point[1], point[2]);
272  }
273 
274  Point3d& operator=(const Point3d& other)
275  {
276  set(other);
277  return *this;
278  }
279 
280  template <typename T>
281  void operator*=(const T scale)
282  {
283  static_assert(std::is_pod<T>::value, "T must be POD");
284  this->x() *= scale;
285  this->y() *= scale;
286  this->z() *= scale;
287  }
288 
289  template <typename T>
290  void operator/=(const T scale)
291  {
292  static_assert(std::is_pod<T>::value, "T must be POD");
293  this->x() /= scale;
294  this->y() /= scale;
295  this->z() /= scale;
296  }
297 
298  bool operator==(const Point3d& rhs)
299  {
300  if ((this->x() != rhs.x()) || (this->y() != rhs.y()) || (this->z() != rhs.z()))
301  {
302  return false;
303  }
304 
305  return true;
306  }
307 
308  bool operator!=(const Point3d& rhs)
309  {
310  return !this->operator==(rhs);
311  }
312 
313  void operator+=(const Vector3d& v)
314  {
315  point[0] += v[0];
316  point[1] += v[1];
317  point[2] += v[2];
318  }
319 
320  void operator-=(const Vector3d& v)
321  {
322  point[0] -= v[0];
323  point[1] -= v[1];
324  point[2] -= v[2];
325  }
326 
327  protected:
328  double point[3];
329 };
330 
331 inline Point3d operator+(Point3d p, const Vector3d& v)
332 {
333  p += v;
334  return p;
335 }
336 
337 inline Point3d operator-(Point3d p, const Vector3d& v)
338 {
339  p -= v;
340  return p;
341 }
342 
343 template <typename T>
344 inline Point3d operator*(Point3d p, const T scale)
345 {
346  static_assert(std::is_pod<T>::value, "T must be POD");
347  p *= scale;
348  return p;
349 }
350 
351 template <typename T>
352 inline Point3d operator*(const T scale, Point3d p)
353 {
354  static_assert(std::is_pod<T>::value, "T must be POD");
355  p *= scale;
356  return p;
357 }
358 
359 inline Vector3d operator-(Point3d p1, const Point3d& p2)
360 {
361  return Vector3d(p1.x() - p2.x(), p1.y() - p2.y(), p1.z() - p2.z());
362 }
363 
364 inline std::ostream& operator<<(std::ostream& os, const Point3d& point)
365 {
366  os << "x: " << point.x() << '\n' << "y: " << point.y() << '\n' << "z: " << point.z() << "\n";
367  return os;
368 }
369 
370 static inline Matrix3d toTildeForm(const Point3d& p)
371 {
372  return Matrix3d(0., -p.z(), p.y(), p.z(), 0., -p.x(), -p.y(), p.x(), 0.);
373 }
374 typedef std::vector<Point3d, Eigen::aligned_allocator<Point3d>> Point3V;
375 } // namespace Math
376 } // namespace RobotDynamics
377 #endif // ifndef __RDL_POINT_3_HPP__
EIGEN_STRONG_INLINE double & x()
Definition: Point3.hpp:234
void transform(const Math::SpatialTransform &X)
Performs in place point transform. Given a point, , this performs .
Definition: Point3.hpp:59
EIGEN_STRONG_INLINE double x() const
Definition: Point3.hpp:239
EIGEN_STRONG_INLINE void setToZero()
Definition: Point3.hpp:93
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method. ...
void absoluteValue()
Set each element to the absolute value.
Definition: Point3.hpp:167
void operator-=(const Vector3d &v)
Definition: Point3.hpp:320
double distanceSquared(const Point3d &point) const
Square of the distance between two ponts, .
Definition: Point3.hpp:179
double distance(const Point3d &point) const
Definition: Point3.hpp:193
void operator*=(const T scale)
Definition: Point3.hpp:281
void clampMax(const double max)
clamp any values that are greater than make to max
Definition: Point3.hpp:135
EIGEN_STRONG_INLINE double y() const
Definition: Point3.hpp:249
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:295
static Matrix3d toTildeForm(const Point3d &p)
Definition: Point3.hpp:370
EIGEN_STRONG_INLINE double z() const
Definition: Point3.hpp:259
The TransformableGeometricObject class is an essential interface because it forces all geometric obje...
Definition: rdl_eigenmath.h:43
std::vector< Point3d, Eigen::aligned_allocator< Point3d > > Point3V
Definition: Point3.hpp:374
EIGEN_STRONG_INLINE Math::Vector3d vec() const
Definition: Point3.hpp:269
EIGEN_STRONG_INLINE double * data()
Definition: Point3.hpp:264
Compact representation of spatial transformations.
void operator+=(const Vector3d &v)
Definition: Point3.hpp:313
double distanceLinf(const Point3d &point) const
Definition: Point3.hpp:223
std::ostream & operator<<(std::ostream &output, const FramePoint &framePoint)
Definition: FramePoint.hpp:375
void operator/=(const T scale)
Definition: Point3.hpp:290
FramePoint operator-(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:301
EIGEN_STRONG_INLINE double & y()
Definition: Point3.hpp:244
Vector3d cross(const Vector3d &v)
Cross product between a point and vector.
Definition: Point3.hpp:213
Point3d & operator=(const Point3d &other)
Definition: Point3.hpp:274
Point3d(const Vector3d &vector)
Definition: Point3.hpp:43
EIGEN_STRONG_INLINE Point3d()
Definition: Point3.hpp:47
EIGEN_STRONG_INLINE bool epsilonEquals(const Point3d &point, const double epsilon) const
Definition: Point3.hpp:104
Point3d(const Point3d &point)
Definition: Point3.hpp:38
void clampMinMax(const double min, const double max)
clamp any values greater than max to max, and any value less than min to min
Definition: Point3.hpp:158
EIGEN_STRONG_INLINE double & z()
Definition: Point3.hpp:254
void clampMin(const double min)
clamp any values that are less than min to min
Definition: Point3.hpp:113
bool operator==(const Point3d &rhs)
Definition: Point3.hpp:298
Point3d transform_copy(const Math::SpatialTransform &X)
Definition: Point3.hpp:64
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
Point3d(const double x, const double y, const double z)
Definition: Point3.hpp:31
bool operator!=(const Point3d &rhs)
Definition: Point3.hpp:308
double distanceL1(const Point3d &point) const
L1 norm of two points.
Definition: Point3.hpp:203


rdl_dynamics
Author(s):
autogenerated on Tue Apr 20 2021 02:25:27