Kindr
Kinematics and Dynamics for Robotics
Vector.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Christian Gehring, Hannes Sommer, Paul Furgale, Remo Diethelm
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the Autonomous Systems Lab, ETH Zurich nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL Christian Gehring, Hannes Sommer, Paul Furgale,
20  * Remo Diethelm BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27 */
28 
29 #pragma once
30 
31 #include <Eigen/Core>
32 #include <Eigen/Geometry>
33 
34 #include "kindr/common/common.hpp"
38 
39 namespace kindr {
40 
51 template<enum PhysicalType PhysicalType_, typename PrimType_, int Dimension_>
52 class Vector : public VectorBase<Vector<PhysicalType_, PrimType_, Dimension_> >, private Eigen::Matrix<PrimType_, Dimension_, 1> {
53  private:
57 
60  static constexpr int DynamicDimension = -1;
61 
62  public:
63  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
64 
69  typedef Eigen::Matrix<PrimType_, Dimension_, 1> Implementation;
70 
73  typedef PrimType_ Scalar;
74 
77  static constexpr int Dimension = Dimension_;
78 
81  template<int DimensionCopy_ = Dimension_>
82  Vector(typename std::enable_if<DimensionCopy_ != DynamicDimension>::type* = nullptr)
83  : Implementation(Implementation::Zero()) {
84  }
85 
88  template<int DimensionCopy_ = Dimension_>
89  Vector(typename std::enable_if<DimensionCopy_ == DynamicDimension>::type* = nullptr)
90  : Implementation() {
91  }
92 
96  template<enum PhysicalType OtherPhysicalType_, typename OtherPrimType_>
98  : Implementation(other.toImplementation().template cast<PrimType_>()) {
99  }
100 
104  template<int DimensionOther_, int DimensionCopy_ = Dimension_>
105  Vector(const Vector<PhysicalType_, PrimType_, DimensionOther_>& other, typename std::enable_if<DimensionCopy_ == DynamicDimension>::type* = nullptr)
106  : Implementation(other.toImplementation()) {
107  }
108 
112  explicit Vector(const Implementation& other)
113  : Implementation(other) {
114  }
115 
121  template<int DimensionCopy_ = Dimension_>
122  Vector(Scalar x, Scalar y, Scalar z, typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr)
123  : Implementation(x,y,z) {
124  }
125 
130  return Vector<PhysicalType_, PrimType_, Dimension_>(Implementation::Zero());
131  }
132 
137  Implementation::setZero();
138  return *this;
139  }
140 
145  return Vector<PhysicalType_, PrimType_, Dimension_>(Implementation::Random());
146  }
147 
152  Implementation::setRandom();
153  return *this;
154  }
155 
160  return Vector<PhysicalType_, PrimType_, Dimension_>(Implementation::UnitX());
161  }
162 
167  return Vector<PhysicalType_, PrimType_, Dimension_>(Implementation::UnitY());
168  }
169 
174  return Vector<PhysicalType_, PrimType_, Dimension_>(Implementation::UnitZ());
175  }
176 
179  using Implementation::operator<<;
180 
183  using Implementation::operator();
184 
188  template<int DimensionOutput_>
190  return Vector<PhysicalType_, PrimType_, DimensionOutput_>(this->toImplementation().template head<DimensionOutput_>());
191  }
192 
198  }
199 
203  template<int DimensionOutput_>
205  return Vector<PhysicalType_, PrimType_, DimensionOutput_>(this->toImplementation().template tail<DimensionOutput_>());
206  }
207 
213  }
214 
218  template<int DimensionOutput_>
220  return Vector<PhysicalType_, PrimType_, DimensionOutput_>(this->toImplementation().template segment<DimensionOutput_>(start));
221  }
222 
227  return Vector<PhysicalType_, PrimType_, DynamicDimension>(this->toImplementation().segment(start, length));
228  }
229 
232  template<int DimensionInput_>
234  this->toImplementation().template head<DimensionInput_>() = input.toImplementation();
235  }
236 
239  template<int DimensionInput_>
241  this->toImplementation().template tail<DimensionInput_>() = input.toImplementation();
242  }
243 
246  template<int DimensionInput_>
248  this->toImplementation().template segment<DimensionInput_>(start) = input.toImplementation();
249  }
250 
254  template<int DimensionCopy_ = Dimension_>
255  Scalar x(typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) const {
256  return this->toImplementation().x();
257  }
258 
262  template<int DimensionCopy_ = Dimension_>
263  Scalar& x(typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) {
264  return this->toImplementation().x();
265  }
266 
270  template<int DimensionCopy_ = Dimension_>
271  Scalar y(typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) const {
272  return this->toImplementation().y();
273  }
274 
278  template<int DimensionCopy_ = Dimension_>
279  Scalar& y(typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) {
280  return this->toImplementation().y();
281  }
282 
286  template<int DimensionCopy_ = Dimension_>
287  Scalar z(typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) const {
288  return this->toImplementation().z();
289  }
290 
294  template<int DimensionCopy_ = Dimension_>
295  Scalar& z(typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) {
296  return this->toImplementation().z();
297  }
298 
302  inline Implementation& toImplementation() {
303  return static_cast<Implementation&>(*this);
304  }
305 
309  inline const Implementation& toImplementation() const {
310  return static_cast<const Implementation&>(*this);
311  }
312 
316  inline Implementation& vector() {
317  return static_cast<Implementation&>(*this);
318  }
319 
323  inline const Implementation& vector() const {
324  return static_cast<const Implementation&>(*this);
325  }
326 
331  Vector<PhysicalType_, PrimType_, Dimension_> & operator=(const Vector<PhysicalType_, PrimType_, Dimension_>& other) { // (The assignment of a static to a dynamic vector does not work because the amount of parameters must be one and SFINAE leads to two parameters. Workaround: cast the static vector into a dynamic one, then assign.)
332  this->toImplementation() = other.toImplementation();
333  return *this;
334  }
335 
342  }
343 
350  }
351 
356  template<typename PrimTypeFactor_>
358  return Vector<PhysicalType_, PrimType_, Dimension_>(this->toImplementation()*(PrimType_)factor);
359  }
360 
365  template<typename PrimTypeDivisor_>
366  Vector<PhysicalType_, PrimType_, Dimension_> operator/(PrimTypeDivisor_ divisor) const {
367  return Vector<PhysicalType_, PrimType_, Dimension_>(this->toImplementation()/(PrimType_)divisor);
368  }
369 
375  this->toImplementation() += other.toImplementation();
376  return *this;
377  }
378 
384  this->toImplementation() -= other.toImplementation();
385  return *this;
386  }
387 
392  template<typename PrimTypeFactor_>
394  this->toImplementation() *= (PrimType_)factor;
395  return *this;
396  }
397 
402  template<typename PrimTypeDivisor_>
404  this->toImplementation() /= (PrimType_)divisor;
405  return *this;
406  }
407 
413  }
414 
420  return this->toImplementation() == other.toImplementation();
421  }
422 
428  return this->toImplementation() != other.toImplementation();
429  }
430 
436  bool isSimilarTo(const Vector<PhysicalType_, PrimType_, Dimension_>& other, Scalar tol) const {
437  if((*this - other).abs().max() < tol) {
438  return true;
439  } else {
440  return false;
441  }
442  }
443 
447  Scalar norm() const {
448  return this->toImplementation().norm();
449  }
450 
454  Scalar squaredNorm() const {
455  return this->toImplementation().squaredNorm();
456  }
457 
462  this->toImplementation().normalize();
463  return *this;
464  }
465 
471  }
472 
477  template<enum PhysicalType PhysicalTypeOther_>
479  return this->toImplementation().dot(other.toImplementation());
480  }
481 
486  template<enum PhysicalType PhysicalTypeOther_, int DimensionCopy_ = Dimension_>
487  typename internal::MultiplicationReturnTypeTrait<Vector<PhysicalType_, PrimType_, Dimension_>, Vector<PhysicalTypeOther_, PrimType_, Dimension_>>::ReturnType
488  cross(const Vector<PhysicalTypeOther_, PrimType_, Dimension_>& other, typename std::enable_if<DimensionCopy_ == 3>::type* = nullptr) const {
489  return typename internal::MultiplicationReturnTypeTrait<Vector<PhysicalType_, PrimType_, Dimension_>, Vector<PhysicalTypeOther_, PrimType_, Dimension_>>::ReturnType(this->toImplementation().cross(other.toImplementation()));
490  }
491 
502  template<enum PhysicalType PhysicalTypeOther_>
504  return other * (this->dot(other)/other.squaredNorm());
505  }
506 
507 
512  template<enum PhysicalType PhysicalTypeOther_>
513  typename internal::MultiplicationReturnTypeTrait<Vector<PhysicalType_, PrimType_, Dimension_>, Vector<PhysicalTypeOther_, PrimType_, Dimension_>>::ReturnType
515  return typename internal::MultiplicationReturnTypeTrait<Vector<PhysicalType_, PrimType_, Dimension_>, Vector<PhysicalTypeOther_, PrimType_, Dimension_>>::ReturnType(this->toImplementation().cwiseProduct(other.toImplementation()));
516  }
517 
522  template<enum PhysicalType PhysicalTypeOther_>
523  typename internal::DivisionReturnTypeTrait<Vector<PhysicalType_, PrimType_, Dimension_>, Vector<PhysicalTypeOther_, PrimType_, Dimension_>>::ReturnType
525  return typename internal::DivisionReturnTypeTrait<Vector<PhysicalType_, PrimType_, Dimension_>, Vector<PhysicalTypeOther_, PrimType_, Dimension_>>::ReturnType(this->toImplementation().cwiseQuotient(other.toImplementation()));
526  }
527 
533  }
534 
538  Scalar max() const {
539  return this->toImplementation().maxCoeff();
540  }
541 
545  Scalar min() const {
546  return this->toImplementation().minCoeff();
547  }
548 
552  Scalar sum() const {
553  return this->toImplementation().sum();
554  }
555 
559  Scalar mean() const {
560  return this->toImplementation().mean();
561  }
562 
566  friend std::ostream& operator << (std::ostream& out, const Vector<PhysicalType_, PrimType_, Dimension_>& vector) {
567  out << vector.transpose();
568  return out;
569  }
570 };
571 
572 
577 template<enum PhysicalType PhysicalType_, typename PrimTypeFactor_, typename PrimType_, int Dimension_>
579  return vector*(PrimType_)factor;
580 }
581 
582 
583 namespace internal {
584 
587 template<enum PhysicalType PhysicalType_, typename PrimType_, int Dimension_>
588 class get_scalar<Vector<PhysicalType_, PrimType_, Dimension_>> {
589  public:
590  typedef PrimType_ Scalar;
591 };
592 
595 template<enum PhysicalType PhysicalType_, typename PrimType_, int Dimension_>
596 class get_dimension<Vector<PhysicalType_, PrimType_, Dimension_>> {
597  public:
598  static constexpr int Dimension = Dimension_;
599 };
600 
603 template<enum PhysicalType PhysicalType1_, enum PhysicalType PhysicalType2_, typename PrimType_, int Dimension_>
604 class MultiplicationReturnTypeTrait<Vector<PhysicalType1_, PrimType_, Dimension_>, Vector<PhysicalType2_, PrimType_, Dimension_>>
605 {
606  public:
608 };
609 
612 template<enum PhysicalType PhysicalType1_, enum PhysicalType PhysicalType2_, typename PrimType_, int Dimension_>
613 class DivisionReturnTypeTrait<Vector<PhysicalType1_, PrimType_, Dimension_>, Vector<PhysicalType2_, PrimType_, Dimension_>>
614 {
615  public:
617 };
618 
621 #define KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(FACTOR1, FACTOR2, PRODUCT) \
622  template<typename PrimType_, int Dimension_> \
623  class MultiplicationReturnTypeTrait<Vector<PhysicalType::FACTOR1, PrimType_, Dimension_>, Vector<PhysicalType::FACTOR2, PrimType_, Dimension_>> \
624  { \
625  public: \
626  typedef Vector<PhysicalType::PRODUCT, PrimType_, Dimension_> ReturnType; \
627  }; \
628  template<typename PrimType_, int Dimension_> \
629  class MultiplicationReturnTypeTrait<Vector<PhysicalType::FACTOR2, PrimType_, Dimension_>, Vector<PhysicalType::FACTOR1, PrimType_, Dimension_>> \
630  { \
631  public: \
632  typedef Vector<PhysicalType::PRODUCT, PrimType_, Dimension_> ReturnType; \
633  }; \
634  template<typename PrimType_, int Dimension_> \
635  class DivisionReturnTypeTrait<Vector<PhysicalType::PRODUCT, PrimType_, Dimension_>, Vector<PhysicalType::FACTOR1, PrimType_, Dimension_>> \
636  { \
637  public: \
638  typedef Vector<PhysicalType::FACTOR2, PrimType_, Dimension_> ReturnType; \
639  }; \
640  template<typename PrimType_, int Dimension_> \
641  class DivisionReturnTypeTrait<Vector<PhysicalType::PRODUCT, PrimType_, Dimension_>, Vector<PhysicalType::FACTOR2, PrimType_, Dimension_>> \
642  { \
643  public: \
644  typedef Vector<PhysicalType::FACTOR1, PrimType_, Dimension_> ReturnType; \
645  };
646 
649 #define KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_B(FACTOR1AND2, PRODUCT) \
650  template<typename PrimType_, int Dimension_> \
651  class MultiplicationReturnTypeTrait<Vector<PhysicalType::FACTOR1AND2, PrimType_, Dimension_>, Vector<PhysicalType::FACTOR1AND2, PrimType_, Dimension_>> \
652  { \
653  public: \
654  typedef Vector<PhysicalType::PRODUCT, PrimType_, Dimension_> ReturnType; \
655  }; \
656  template<typename PrimType_, int Dimension_> \
657  class DivisionReturnTypeTrait<Vector<PhysicalType::PRODUCT, PrimType_, Dimension_>, Vector<PhysicalType::FACTOR1AND2, PrimType_, Dimension_>> \
658  { \
659  public: \
660  typedef Vector<PhysicalType::FACTOR1AND2, PrimType_, Dimension_> ReturnType; \
661  };
662 
664 
666 
670 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Typeless, Position, Position) // Position/Position = Typeless
673 
680 
681 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Position, AngularJerk, Jerk)
682 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Position, AngularAcceleration, Acceleration)
683 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Position, AngularVelocity, Velocity)
684 //KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Position, Angle, Position) // Position/Position = Angle -> ambiguous, explicit cast to Angle if needed
685 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Position, Force, Torque)
686 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Position, Momentum, AngularMomentum)
687 
688 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, Jerk, Acceleration)
689 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, Acceleration, Velocity)
690 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, Velocity, Position)
691 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, Force, Momentum)
692 
693 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, AngularJerk, AngularAcceleration)
694 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, AngularAcceleration, AngularVelocity)
695 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, AngularVelocity, Angle)
696 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Time, Torque, AngularMomentum)
697 
699 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Mass, Velocity, Momentum)
700 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Inertia, AngularAcceleration, Torque)
701 KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(Inertia, AngularVelocity, AngularMomentum)
702 
703 
704 
705 } // namespace internal
706 } // namespace kindr
707 
708 
709 
710 
void setTail(const Vector< PhysicalType_, PrimType_, DimensionInput_ > &input)
Set the tail of the vector.
Definition: Vector.hpp:240
bool operator==(const Vector< PhysicalType_, PrimType_, Dimension_ > &other) const
Comparison operator.
Definition: Vector.hpp:419
Vector in n-dimensional-space.
Definition: Vector.hpp:52
Vector(const Implementation &other)
Constructor using Eigen::Matrix.
Definition: Vector.hpp:112
Scalar mean() const
Mean of the components.
Definition: Vector.hpp:559
Vector< PhysicalType_, PrimType_, DynamicDimension > getSegment(int start, int length) const
Get a segment of the vector (copy)
Definition: Vector.hpp:226
Scalar norm() const
Norm of the vector.
Definition: Vector.hpp:447
Scalar min() const
Minimum of the components.
Definition: Vector.hpp:545
Vector(const Vector< OtherPhysicalType_, OtherPrimType_, Dimension_ > &other)
Constructor using other vector with generic type.
Definition: Vector.hpp:97
PrimType_ Scalar
The primitive type of the coordinates.
Definition: Vector.hpp:73
Vector(Scalar x, Scalar y, Scalar z, typename std::enable_if< DimensionCopy_==3 >::type *=nullptr)
Constructor using three scalars.
Definition: Vector.hpp:122
Scalar & y(typename std::enable_if< DimensionCopy_==3 >::type *=nullptr)
Get y-coordinate of the vector (reference)
Definition: Vector.hpp:279
void setSegment(int start, const Vector< PhysicalType_, PrimType_, DimensionInput_ > &input)
Set a segment of the vector.
Definition: Vector.hpp:247
Vector< PhysicalType_, PrimType_, Dimension_ > operator*(PrimTypeFactor_ factor) const
Multiplies vector with a scalar.
Definition: Vector.hpp:357
Scalar sum() const
Sum of the components.
Definition: Vector.hpp:552
Scalar dot(const Vector< PhysicalTypeOther_, PrimType_, Dimension_ > &other) const
Dot product with other vector.
Definition: Vector.hpp:478
Vector< PhysicalType_, PrimType_, Dimension_ > & setRandom()
Sets all components of the vector to random.
Definition: Vector.hpp:151
static Vector< PhysicalType_, PrimType_, Dimension_ > UnitX()
Get the unity vector in x.
Definition: Vector.hpp:159
static constexpr int Dimension
The dimension of the vector.
Definition: Vector.hpp:77
static Vector< PhysicalType_, PrimType_, Dimension_ > UnitZ()
Get the unity vector in z.
Definition: Vector.hpp:173
#define KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_B(FACTOR1AND2, PRODUCT)
Specializes multiplication and division traits for the triple (factor1 == factor2) ...
Definition: Vector.hpp:649
Vector< PhysicalType_, PrimType_, DimensionOutput_ > getHead() const
Get the head of the vector (copy)
Definition: Vector.hpp:189
Implementation & vector()
Cast to Eigen::Matrix<PrimType_, Dimension_, 1>.
Definition: Vector.hpp:316
Scalar squaredNorm() const
Squared norm of the vector.
Definition: Vector.hpp:454
#define KINDR_SPECIALIZE_PHYS_QUANT_RETURN_TYPE_A(FACTOR1, FACTOR2, PRODUCT)
Specializes multiplication and division traits for the triple (factor1 != factor2) ...
Definition: Vector.hpp:621
internal::MultiplicationReturnTypeTrait< Vector< PhysicalType_, PrimType_, Dimension_ >, Vector< PhysicalTypeOther_, PrimType_, Dimension_ > >::ReturnType elementwiseMultiplication(const Vector< PhysicalTypeOther_, PrimType_, Dimension_ > &other) const
Elementwise product with other vector.
Definition: Vector.hpp:514
void setHead(const Vector< PhysicalType_, PrimType_, DimensionInput_ > &input)
Set the head of the vector.
Definition: Vector.hpp:233
static Vector< PhysicalType_, PrimType_, Dimension_ > Random()
Get random element.
Definition: Vector.hpp:144
Vector(typename std::enable_if< DimensionCopy_==DynamicDimension >::type *=nullptr)
Default constructor for dynamic sized vectors.
Definition: Vector.hpp:89
Vector< PhysicalType_, PrimType_, Dimension_ > operator-() const
Negation of a vector.
Definition: Vector.hpp:411
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef Eigen::Matrix< PrimType_, Dimension_, 1 > Implementation
The implementation type.
Definition: Vector.hpp:69
const Implementation & vector() const
Cast to Eigen::Matrix<PrimType_, Dimension_, 1>.
Definition: Vector.hpp:323
Scalar z(typename std::enable_if< DimensionCopy_==3 >::type *=nullptr) const
Get z-coordinate of the vector (copy)
Definition: Vector.hpp:287
static Vector< PhysicalType_, PrimType_, Dimension_ > UnitY()
Get the unity vector in y.
Definition: Vector.hpp:166
Vector< PhysicalType_, PrimType_, Dimension_ > & operator+=(const Vector< PhysicalType_, PrimType_, Dimension_ > &other)
Addition and assignment of two vectors.
Definition: Vector.hpp:374
Vector< PhysicalType_, PrimType_, DynamicDimension > getTail(int length) const
Get the tail of the vector (copy)
Definition: Vector.hpp:211
Vector< PhysicalType_, PrimType_, DimensionOutput_ > getSegment(int start) const
Get a segment of the vector (copy)
Definition: Vector.hpp:219
const Implementation & toImplementation() const
Cast to the implementation type.
Definition: Vector.hpp:309
Vector< PhysicalType_, PrimType_, Dimension_ > & operator-=(const Vector< PhysicalType_, PrimType_, Dimension_ > &other)
Subtraction and assignment of two vectors.
Definition: Vector.hpp:383
Vector< PhysicalType_, PrimType_, DynamicDimension > getHead(int length) const
Get the head of the vector (copy)
Definition: Vector.hpp:196
Vector< PhysicalType_, PrimType_, Dimension_ > & normalize()
Normalizes the vector.
Definition: Vector.hpp:461
internal::MultiplicationReturnTypeTrait< Vector< PhysicalType_, PrimType_, Dimension_ >, Vector< PhysicalTypeOther_, PrimType_, Dimension_ > >::ReturnType cross(const Vector< PhysicalTypeOther_, PrimType_, Dimension_ > &other, typename std::enable_if< DimensionCopy_==3 >::type *=nullptr) const
Cross product with other vector.
Definition: Vector.hpp:488
Scalar x(typename std::enable_if< DimensionCopy_==3 >::type *=nullptr) const
Get x-coordinate of the vector (copy)
Definition: Vector.hpp:255
Vector(const Vector< PhysicalType_, PrimType_, DimensionOther_ > &other, typename std::enable_if< DimensionCopy_==DynamicDimension >::type *=nullptr)
Constructor of a dynamic vector using a static vector.
Definition: Vector.hpp:105
Vector< PhysicalType_, PrimType_, Dimension_ > operator+(const Vector< PhysicalType_, PrimType_, Dimension_ > &other) const
Addition of two vectors.
Definition: Vector.hpp:340
Vector< PhysicalType_, PrimType_, DimensionOutput_ > getTail() const
Get the tail of the vector (copy)
Definition: Vector.hpp:204
internal::DivisionReturnTypeTrait< Vector< PhysicalType_, PrimType_, Dimension_ >, Vector< PhysicalTypeOther_, PrimType_, Dimension_ > >::ReturnType elementwiseDivision(const Vector< PhysicalTypeOther_, PrimType_, Dimension_ > &other) const
Elementwise division by other vector.
Definition: Vector.hpp:524
Scalar max() const
Maximum of the components.
Definition: Vector.hpp:538
Vector< PhysicalType_, PrimType_, Dimension_ > & operator*=(PrimTypeFactor_ factor)
Multiplication with a scalar and assignment.
Definition: Vector.hpp:393
Scalar y(typename std::enable_if< DimensionCopy_==3 >::type *=nullptr) const
Get y-coordinate of the vector (copy)
Definition: Vector.hpp:271
static constexpr int DynamicDimension
The size if the vector has dynamic dimension (must be equal to Eigen::Dynamic).
Definition: Vector.hpp:60
Scalar & z(typename std::enable_if< DimensionCopy_==3 >::type *=nullptr)
Get z-coordinate of the vector (reference)
Definition: Vector.hpp:295
Vector< PhysicalType_, PrimType_, Dimension_ > projectOn(const Vector< PhysicalTypeOther_, PrimType_, Dimension_ > &other) const
Projects this vector (a) on the other vector (b). The result is proj = b/|b| * |a| * cos(angle) = b/|...
Definition: Vector.hpp:503
bool operator!=(const Vector< PhysicalType_, PrimType_, Dimension_ > &other) const
Comparison operator.
Definition: Vector.hpp:427
Vector< PhysicalType_, PrimType_, Dimension_ > operator-(const Vector< PhysicalType_, PrimType_, Dimension_ > &other) const
Subtraction of two vectors.
Definition: Vector.hpp:348
Vector< PhysicalType_, PrimType_, Dimension_ > & setZero()
Sets all components of the vector to zero.
Definition: Vector.hpp:136
Vector< PhysicalType_, PrimType_, Dimension_ > & operator=(const Vector< PhysicalType_, PrimType_, Dimension_ > &other)
Assignment operator.
Definition: Vector.hpp:331
Implementation & toImplementation()
Cast to the implementation type.
Definition: Vector.hpp:302
Interface for a vector.
Definition: VectorBase.hpp:71
Vector< PhysicalType_, PrimType_, Dimension_ > normalized() const
Get a normalized version of the vector.
Definition: Vector.hpp:469
Vector(typename std::enable_if< DimensionCopy_!=DynamicDimension >::type *=nullptr)
Default constructor for static sized vectors which initializes all components with zero...
Definition: Vector.hpp:82
static Vector< PhysicalType_, PrimType_, Dimension_ > Zero()
Get zero element.
Definition: Vector.hpp:129
bool isSimilarTo(const Vector< PhysicalType_, PrimType_, Dimension_ > &other, Scalar tol) const
Comparison function.
Definition: Vector.hpp:436
Vector< PhysicalType_, PrimType_, Dimension_ > & operator/=(PrimTypeDivisor_ divisor)
Division by a scalar and assignment.
Definition: Vector.hpp:403
Scalar & x(typename std::enable_if< DimensionCopy_==3 >::type *=nullptr)
Get x-coordinate of the vector (reference)
Definition: Vector.hpp:263
Vector< PhysicalType_, PrimType_, Dimension_ > abs() const
Absolute components.
Definition: Vector.hpp:531
Vector< PhysicalType_, PrimType_, Dimension_ > operator/(PrimTypeDivisor_ divisor) const
Divides vector by a scalar.
Definition: Vector.hpp:366
VectorBase< Vector< PhysicalType_, PrimType_, Dimension_ > > Base
The base type.
Definition: Vector.hpp:56