FramePoint.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 
13 #ifndef __RDL_FRAME_POINT_HPP__
14 #define __RDL_FRAME_POINT_HPP__
15 
18 #include "rdl_dynamics/Point3.hpp"
20 
27 namespace RobotDynamics
28 {
29 namespace Math
30 {
40 class FramePoint : public FrameObject, public Math::Point3d
41 {
42  public:
50  FramePoint(ReferenceFramePtr referenceFrame, const double x, const double y, const double z) : FrameObject(referenceFrame), Math::Point3d(x, y, z)
51  {
52  }
53 
59  FramePoint(ReferenceFramePtr referenceFrame, Math::Vector3d v) : FrameObject(referenceFrame), Math::Point3d(v[0], v[1], v[2])
60  {
61  }
62 
69  {
70  }
71 
76  FramePoint(const FramePoint& framePoint) : FrameObject(framePoint.getReferenceFrame()), Math::Point3d(framePoint.x(), framePoint.y(), framePoint.z())
77  {
78  }
79 
84  explicit FramePoint(ReferenceFramePtr referenceFrame) : FrameObject(referenceFrame), Math::Point3d()
85  {
86  }
87 
91  FramePoint() : FrameObject(nullptr), Math::Point3d()
92  {
93  }
94 
99  {
100  }
101 
106  inline Math::Point3d point() const
107  {
108  return Math::Point3d(x(), y(), z());
109  }
110 
117  {
118  return this;
119  }
120 
127  {
128  FramePoint p = *this;
129  p.changeFrame(referenceFrame);
130  return p;
131  }
132 
139  {
140  setIncludingFrame(v(0), v(1), v(2), referenceFrame);
141  }
142 
150  void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
151  {
152  if (!referenceFrame)
153  {
154  throw ReferenceFrameException("Reference frame is nullptr!");
155  }
156 
157  this->set(x, y, z);
158  this->referenceFrame = referenceFrame;
159  }
160 
167  {
168  if (!referenceFrame)
169  {
170  throw ReferenceFrameException("Reference frame cannot be nullptr!");
171  }
172 
173  this->x() = point.x();
174  this->y() = point.y();
175  this->z() = point.z();
176  this->referenceFrame = referenceFrame;
177  }
178 
185  double distanceSquared(const FramePoint& point) const
186  {
188 
189  double dx = this->x() - point.x();
190  double dy = this->y() - point.y();
191  double dz = this->z() - point.z();
192  return dx * dx + dy * dy + dz * dz;
193  }
194 
201  double distance(const FramePoint& point) const
202  {
204 
205  return sqrt(distanceSquared(point));
206  }
207 
214  double distanceL1(const FramePoint& point) const
215  {
217 
218  return fabs(this->x() - point.x()) + fabs(this->y() - point.y()) + fabs(this->z() - point.z());
219  }
220 
227  double distanceLinf(const FramePoint& point) const
228  {
230 
231  double dx = this->x() - point.x();
232  double dy = this->y() - point.y();
233  double dz = this->z() - point.z();
234 
235  double tmp = fabs(dx) > fabs(dy) ? fabs(dx) : fabs(dy);
236 
237  return tmp > fabs(dz) ? tmp : fabs(dz);
238  }
239 
246  bool epsilonEquals(const FramePoint& point, const double epsilon) const
247  {
249  return fabs(this->x() - point.x()) < epsilon && fabs(this->y() - point.y()) < epsilon && fabs(this->z() - point.z()) < epsilon;
250  }
251 
257  template <typename T>
258  void operator*=(const T scale)
259  {
260  this->x() *= scale;
261  this->y() *= scale;
262  this->z() *= scale;
263  }
264 
270  template <typename T>
271  void operator/=(const T scale)
272  {
273  this->x() /= scale;
274  this->y() /= scale;
275  this->z() /= scale;
276  }
277 
278  void operator+=(const FrameVector& v)
279  {
281  this->x() += v.x();
282  this->y() += v.y();
283  this->z() += v.z();
284  }
285 
286  void operator-=(const FrameVector& v)
287  {
289  this->x() -= v.x();
290  this->y() -= v.y();
291  this->z() -= v.z();
292  }
293 };
294 
296 {
297  p += v;
298  return p;
299 }
300 
302 {
303  p -= v;
304  return p;
305 }
306 
307 template <typename T>
308 inline FrameVector operator*(const T scale, FramePoint p)
309 {
310  p *= scale;
311  return p;
312 }
313 
314 template <typename T>
315 inline FrameVector operator*(FramePoint p, const T scale)
316 {
317  p *= scale;
318  return p;
319 }
320 
328 inline bool operator==(const FramePoint& lhs, const FramePoint& rhs)
329 {
330  lhs.checkReferenceFramesMatch(&rhs);
331 
332  if (lhs.x() != rhs.x())
333  {
334  return false;
335  }
336 
337  if (lhs.y() != rhs.y())
338  {
339  return false;
340  }
341 
342  if (lhs.z() != rhs.z())
343  {
344  return false;
345  }
346 
347  return true;
348 }
349 
358 {
359  p1.getReferenceFrame()->checkReferenceFramesMatch(p2.getReferenceFrame());
360  return FrameVector(p1.getReferenceFrame(), p1.x() - p2.x(), p1.y() - p2.y(), p1.z() - p2.z());
361 }
362 
370 inline bool operator!=(const FramePoint& lhs, const FramePoint& rhs)
371 {
372  return !operator==(lhs, rhs);
373 }
374 
375 inline std::ostream& operator<<(std::ostream& output, const FramePoint& framePoint)
376 {
377  output << "ReferenceFrame = " << framePoint.getReferenceFrame()->getName() << std::endl;
378  output << "x = " << framePoint.x() << " y = " << framePoint.y() << " z = " << framePoint.z() << std::endl;
379  return output;
380 }
381 typedef std::vector<FramePoint, Eigen::aligned_allocator<FramePoint>> FramePointV;
382 } // namespace Math
383 } // namespace RobotDynamics
384 #endif // ifndef __RDL_FRAME_POINT_HPP__
EIGEN_STRONG_INLINE double & x()
Definition: Point3.hpp:234
void operator+=(const FrameVector &v)
Definition: FramePoint.hpp:278
std::vector< FramePoint, Eigen::aligned_allocator< FramePoint > > FramePointV
Definition: FramePoint.hpp:381
ReferenceFramePtr getReferenceFrame() const
Get a pointer to the reference frame this FrameObject is expressed in.
Definition: FrameObject.hpp:52
A FramePoint is a 3D point that is expressed in a ReferenceFrame. To change the ReferenceFrame a Fram...
Definition: FramePoint.hpp:40
double distanceSquared(const FramePoint &point) const
Calculate the distance squared between two FramePoints. .
Definition: FramePoint.hpp:185
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method. ...
FramePoint(const FramePoint &framePoint)
Copy constructor.
Definition: FramePoint.hpp:76
Math::Point3d point() const
Get as point3d.
Definition: FramePoint.hpp:106
double distanceL1(const FramePoint &point) const
Calculate the L1 distance between two FramePoints by .
Definition: FramePoint.hpp:214
FramePoint(ReferenceFramePtr referenceFrame, const double x, const double y, const double z)
Constructor.
Definition: FramePoint.hpp:50
A custom exception for frame operations.
void operator-=(const FrameVector &v)
Definition: FramePoint.hpp:286
ReferenceFramePtr referenceFrame
Definition: FrameObject.hpp:81
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:295
bool epsilonEquals(const FramePoint &point, const double epsilon) const
Return true FramePoint argument is within epsilon of this, false otherwise.
Definition: FramePoint.hpp:246
double distanceLinf(const FramePoint &point) const
Calculate the LInfinity distance between two FramePoints by .
Definition: FramePoint.hpp:227
void checkReferenceFramesMatch(const FrameObject *frameObject) const
Check if two ReferenceFrameHolders hold the same ReferenceFrame.
Definition: FrameObject.hpp:70
The TransformableGeometricObject class is an essential interface because it forces all geometric obje...
Definition: rdl_eigenmath.h:43
FramePoint()
Empty constructor that creates a point with ReferencFrame=nullptr and (x,y,z)=(0,0,0)
Definition: FramePoint.hpp:91
EIGEN_STRONG_INLINE void setIncludingFrame(const Math::Vector3d &v, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame this object is expressed in as well as the (x,y,z) coordinates of the poi...
Definition: FramePoint.hpp:138
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:12
FramePoint(ReferenceFramePtr referenceFrame, Math::Vector3d v)
Constructor.
Definition: FramePoint.hpp:59
FramePoint changeFrameAndCopy(ReferenceFramePtr referenceFrame) const
copy into new frame point and change the frame of that
Definition: FramePoint.hpp:126
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
Definition: FrameVector.hpp:33
Math::TransformableGeometricObject * getTransformableGeometricObject()
Return a pointer to this as base class type Math::TransformableGeometricObject. See FrameObject::chan...
Definition: FramePoint.hpp:116
void setIncludingFrame(const Math::Point3d &point, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame the point is expressed in as well as the (x,y,z) coordinates.
Definition: FramePoint.hpp:166
std::ostream & operator<<(std::ostream &output, const FramePoint &framePoint)
Definition: FramePoint.hpp:375
FramePoint(ReferenceFramePtr referenceFrame)
Constructor that initializes to (x,y,z) = (0,0,0)
Definition: FramePoint.hpp:84
FramePoint operator-(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:301
EIGEN_STRONG_INLINE double & y()
Definition: Point3.hpp:244
double distance(const FramePoint &point) const
Calculate the distance between two FramePoints. .
Definition: FramePoint.hpp:201
void operator*=(const T scale)
Overloaded *= operator, performs this = this*scala.
Definition: FramePoint.hpp:258
EIGEN_STRONG_INLINE double & z()
Definition: Point3.hpp:254
bool operator==(const Point3d &rhs)
Definition: Point3.hpp:298
void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
Set both the ReferenceFrame the point is expressed in as well as the (x,y,z) coordinates.
Definition: FramePoint.hpp:150
void operator/=(const T scale)
Overloaded /= operator, performs this = this*scale.
Definition: FramePoint.hpp:271
An interface that objects with a ReferenceFrame extend to inherit the FrameObject::changeFrame method...
Definition: FrameObject.hpp:28
Namespace for all structures of the RobotDynamics library.
Definition: Body.h:21
bool operator!=(const Point3d &rhs)
Definition: Point3.hpp:308
FramePoint(ReferenceFramePtr referenceFrame, const Math::Point3d &point)
Constructor.
Definition: FramePoint.hpp:68


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