FrameVector.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_FRAME_VECTOR_HPP__
9 #define __RDL_FRAME_VECTOR_HPP__
10 
19 
20 namespace RobotDynamics
21 {
22 namespace Math
23 {
33 class FrameVector : public FrameObject, public Math::Vector3d
34 {
35  public:
39  FrameVector() : FrameObject(nullptr), Math::Vector3d(0., 0., 0.)
40  {
41  }
42 
47  explicit FrameVector(ReferenceFramePtr referenceFrame) : FrameObject(referenceFrame), Math::Vector3d()
48  {
49  }
50 
58  FrameVector(ReferenceFramePtr referenceFrame, const double& x, const double& y, const double& z) : FrameObject(referenceFrame), Math::Vector3d(x, y, z)
59  {
60  }
61 
67  FrameVector(ReferenceFramePtr referenceFrame, const Eigen::Vector3d& vector) : FrameObject(referenceFrame), Math::Vector3d(vector[0], vector[1], vector[2])
68  {
69  }
70 
74  virtual ~FrameVector()
75  {
76  }
77 
84  {
85  return this;
86  }
87 
94  {
95  FrameVector p = *this;
96  p.changeFrame(referenceFrame);
97  return p;
98  }
99 
103  inline void setToZero()
104  {
105  set(0., 0., 0.);
106  }
107 
116  inline void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
117  {
118  if (!referenceFrame)
119  {
120  throw ReferenceFrameException("Reference frame cannot be nullptr!");
121  }
122 
123  set(x, y, z);
124  this->referenceFrame = referenceFrame;
125  }
126 
133  inline void setIncludingFrame(const Eigen::Vector3d& vector, ReferenceFramePtr referenceFrame)
134  {
135  if (!referenceFrame)
136  {
137  throw ReferenceFrameException("Reference frame cannot be nullptr!");
138  }
139 
140  set(vector[0], vector[1], vector[2]);
141  this->referenceFrame = referenceFrame;
142  }
143 
150  inline double dot(const FrameVector& frameVector) const
151  {
152  checkReferenceFramesMatch(&frameVector);
153 
154  return this->x() * frameVector.x() + this->y() * frameVector.y() + this->z() * frameVector.z();
155  }
156 
163  inline FrameVector cross(const FrameVector& vector) const
164  {
165  checkReferenceFramesMatch(&vector);
166  return FrameVector(this->referenceFrame, this->y() * vector.z() - this->z() * vector.y(), vector.x() * this->z() - vector.z() * this->x(),
167  this->x() * vector.y() - this->y() * vector.x());
168  }
169 
175  inline Vector3d cross(const Vector3d& vector) const
176  {
177  return RobotDynamics::Math::Vector3d::cross(vector);
178  }
179 
185  inline double getAngleBetweenVectors(const FrameVector& frameVector) const
186  {
187  checkReferenceFramesMatch(&frameVector);
188 
189  return acos(std::max(-1., std::min(this->dot(frameVector) / (this->norm() * frameVector.norm()), 1.)));
190  }
191 
192  inline Vector3d vec() const
193  {
194  return Math::Vector3d(x(), y(), z());
195  }
196 
197  void operator+=(const Vector3d& v)
198  {
199  this->x() += v.x();
200  this->y() += v.y();
201  this->z() += v.z();
202  }
203 
204  void operator-=(const Vector3d& v)
205  {
206  this->x() -= v.x();
207  this->y() -= v.y();
208  this->z() -= v.z();
209  }
210 
215  void operator+=(const FrameVector& v)
216  {
217  this->checkReferenceFramesMatch(&v);
218  this->x() += v.x();
219  this->y() += v.y();
220  this->z() += v.z();
221  }
222 
227  void operator-=(const FrameVector& v)
228  {
229  this->checkReferenceFramesMatch(&v);
230  this->x() -= v.x();
231  this->y() -= v.y();
232  this->z() -= v.z();
233  }
234 
240  template <typename T>
241  void operator*=(const T scale)
242  {
243  this->x() *= scale;
244  this->y() *= scale;
245  this->z() *= scale;
246  }
247 };
248 
249 template <typename T>
250 inline FrameVector operator*(FrameVector v1, const T scale)
251 {
252  v1 *= scale;
253  return v1;
254 }
255 
256 template <typename T>
257 inline FrameVector operator*(const T scale, FrameVector v1)
258 {
259  v1 *= scale;
260  return v1;
261 }
262 
264 {
265  v1 += v2;
266  return v1;
267 }
268 
270 {
271  v1 -= v2;
272  return v1;
273 }
274 
281 // cppcheck-suppress passedByValue
283 {
284  v1 += v2;
285  return v1;
286 }
287 
294 // cppcheck-suppress passedByValue
296 {
297  v1 -= v2;
298  return v1;
299 }
300 typedef std::vector<FrameVector, Eigen::aligned_allocator<FrameVector>> FrameVectorV;
301 } // namespace Math
302 } // namespace RobotDynamics
303 
304 #endif // ifndef __RDL_FRAME_VECTOR_HPP__
void operator+=(const FrameVector &v)
Plus euals operator that performs runtime frame checks, .
Math::TransformableGeometricObject * getTransformableGeometricObject()
Return pointer to this object as type TransformableGeometricObject. See FrameObject::changeFrame for ...
Definition: FrameVector.hpp:83
void operator*=(const T scale)
Times euals operator that performs runtime frame checks, .
void operator+=(const Vector3d &v)
ForceVector operator*(const SpatialTransform &X, ForceVector f)
Operator for transforming a ForceVector. Calls the ForceVector::transform method. ...
A custom exception for frame operations.
void setToZero()
Set x, y, and z components to 0.
virtual ~FrameVector()
Destructor.
Definition: FrameVector.hpp:74
ReferenceFramePtr referenceFrame
Definition: FrameObject.hpp:81
Vector3d cross(const Vector3d &vector) const
Cross product, i.e. .
FrameVector changeFrameAndCopy(ReferenceFramePtr referenceFrame) const
copy into new frame vector and change the frame of that
Definition: FrameVector.hpp:93
FramePoint operator+(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:295
void setIncludingFrame(const Eigen::Vector3d &vector, ReferenceFramePtr referenceFrame)
Set the x, y, and z components and the ReferenceFrame these components are expressed in...
void checkReferenceFramesMatch(const FrameObject *frameObject) const
Check if two ReferenceFrameHolders hold the same ReferenceFrame.
Definition: FrameObject.hpp:70
FrameVector cross(const FrameVector &vector) const
Cross product between two FrameVectors, i.e. .
The TransformableGeometricObject class is an essential interface because it forces all geometric obje...
Definition: rdl_eigenmath.h:43
std::shared_ptr< ReferenceFrame > ReferenceFramePtr
FrameVector(ReferenceFramePtr referenceFrame, const Eigen::Vector3d &vector)
Constructor.
Definition: FrameVector.hpp:67
virtual void changeFrame(ReferenceFramePtr desiredFrame)
Change the ReferenceFrame this FrameObject is expressed in.
Definition: FrameObject.cpp:12
void setIncludingFrame(const double x, const double y, const double z, ReferenceFramePtr referenceFrame)
Set the x, y, and z components and the ReferenceFrame these components are expressed in...
A FrameVector is a 3D vector with a ReferenceFrame, and all operations between FrameVectors and other...
Definition: FrameVector.hpp:33
void operator-=(const FrameVector &v)
Minus euals operator that performs runtime frame checks, .
FrameVector()
Default constructor. Initializes its ReferenceFrame to nullptr.
Definition: FrameVector.hpp:39
FramePoint operator-(FramePoint p, const FrameVector &v)
Definition: FramePoint.hpp:301
std::vector< FrameVector, Eigen::aligned_allocator< FrameVector > > FrameVectorV
double dot(const FrameVector &frameVector) const
Dot product between two FrameVectors, i.e. .
FrameVector(ReferenceFramePtr referenceFrame)
Constructor.
Definition: FrameVector.hpp:47
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
void operator-=(const Vector3d &v)
double getAngleBetweenVectors(const FrameVector &frameVector) const
Computer the angle between two FrameVectors, .
FrameVector(ReferenceFramePtr referenceFrame, const double &x, const double &y, const double &z)
Constructor.
Definition: FrameVector.hpp:58


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