Belle II Software development
Vector2D Class Reference

A two dimensional vector which is equipped with functions for correct handling
of orientation related issues in addition to the expected vector methods. More...

#include <Vector2D.h>

Public Member Functions

 Vector2D ()
 Default constructor for ROOT compatibility.
 
 Vector2D (const double x, const double y)
 Constructor from two coordinates.
 
 Vector2D (const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
 Constructs a vector from a unit coordinate system vector and the coordinates in that system.
 
bool operator== (const Vector2D &rhs) const
 Equality comparison with both coordinates.
 
bool operator< (const Vector2D &rhs) const
 Total ordering based on cylindrical radius first and azimuth angle second.
 
bool isNull () const
 Checks if the vector is the null vector.
 
bool hasNAN () const
 Checks if one of the coordinates is NAN.
 
std::string __str__ () const
 Output operator for python.
 
double dot (const Vector2D &rhs) const
 Calculates the two dimensional dot product.
 
double cross (const Vector2D &rhs) const
 Calculated the two dimensional cross product.
 
double normSquared () const
 Calculates $ x^2 + y^2 $ .
 
double norm () const
 Calculates the length of the vector.
 
double distance (const Vector2D &rhs=Vector2D(0.0, 0.0)) const
 Calculates the distance of this point to the rhs.
 
Vector2Dscale (const double factor)
 Scales the vector in place by the given factor.
 
Vector2Doperator*= (const double factor)
 Same as scale()
 
Vector2D scaled (const double factor) const
 Returns a scaled copy of the vector.
 
Vector2Ddivide (const double denominator)
 Divides all coordinates by a common denominator in place.
 
Vector2Doperator/= (const double denominator)
 Same as divide()
 
Vector2D divided (const double denominator) const
 Returns a copy where all coordinates got divided by a common denominator.
 
Vector2D operator/ (const double denominator) const
 Same as divided()
 
Vector2Dadd (const Vector2D &rhs)
 Adds a vector to this in place.
 
Vector2Doperator+= (const Vector2D &rhs)
 Same as add()
 
Vector2Dsubtract (const Vector2D &rhs)
 Subtracts a vector from this in place.
 
Vector2Doperator-= (const Vector2D &rhs)
 Same as subtract()
 
Vector2D orthogonal () const
 Orthogonal vector to the counterclockwise direction.
 
Vector2D orthogonal (const ERotation ccwInfo) const
 Orthogonal vector to the direction given by the counterclockwise info.
 
double normalize ()
 Normalizes the vector to unit length.
 
double normalizeTo (const double toLength)
 Normalizes the vector to the given length.
 
Vector2D unit () const
 Returns a unit vector colaligned with this.
 
Vector2Dreverse ()
 Reverses the direction of the vector in place.
 
Vector2D reversed () const
 Returns a vector pointing in the opposite direction.
 
Vector2D operator- () const
 Same as reversed()
 
void flipFirst ()
 Flips the first coordinate inplace (no difference between active and passive)
 
void flipSecond ()
 Flips the first coordinate inplace (no difference between active and passive)
 
Vector2D flippedFirst () const
 Makes a copy of the vector with the first coordinate flipped (no difference between active and passive)
 
Vector2D flippedSecond () const
 Makes a copy of the vector with the second coordinate flipped (no difference between active and passive)
 
Vector2D flippedOver (const Vector2D &reflectionLine) const
 Reflects this vector over line designated by the given vector.
 
Vector2D flippedAlong (const Vector2D &flippingDirection) const
 Reflects this vector along line designated by the given vector.
 
void conformalTransform ()
 Transforms the vector to conformal space inplace.
 
Vector2D conformalTransformed () const
 Returns a copy of the vector transformed in conformal space.
 
Vector2D operator+ (const Vector2D &rhs) const
 Returns a new vector as sum of this and rhs.
 
Vector2D operator- (const Vector2D &rhs) const
 Returns a new vector as differenc of this and rhs.
 
double parallelComp (const Vector2D &relativTo) const
 Calculates the component parallel to the given vector.
 
Vector2D parallelVector (const Vector2D &relativTo) const
 Calculates the part of this vector that is parallel to the given vector.
 
double unnormalizedParallelComp (const Vector2D &relativTo) const
 Same as parallelComp() but assumes the given vector to be of unit length.
 
double orthogonalComp (const Vector2D &relativTo) const
 Calculates the component orthogonal to the given vector.
 
Vector2D orthogonalVector (const Vector2D &relativTo) const
 Calculates the part of this vector that is parallel to the given vector.
 
double unnormalizedOrthogonalComp (const Vector2D &relativTo) const
 Same as orthogonalComp() but assumes the given vector to be of unit length.
 
ERightLeft isRightOrLeftOf (const Vector2D &rhs) const
 Indicates if the given vector is more left or more right if you looked in the direction of this vector.
 
bool isLeftOf (const Vector2D &rhs) const
 Indicates if the given vector is more left if you looked in the direction of this vector.
 
bool isRightOf (const Vector2D &rhs) const
 Indicates if the given vector is more right if you looked in the direction of this vector.
 
ERotation isCCWOrCWOf (const Vector2D &rhs) const
 Indicates if the given vector is more counterclockwise or more clockwise if you looked in the direction of this vector.
 
bool isCCWOf (const Vector2D &rhs) const
 Indicates if the given vector is more counterclockwise if you looked in the direction of this vector.
 
bool isCWOf (const Vector2D &rhs) const
 Indicates if the given vector is more clockwise if you looked in the direction of this vector.
 
EForwardBackward isForwardOrBackwardOf (const Vector2D &rhs) const
 Indicates if the given vector is more coaligned or reverse if you looked in the direction of this vector.
 
bool isForwardOf (const Vector2D &rhs) const
 Indicates if the given vector is more coaligned if you looked in the direction of this vector.
 
bool isBackwardOf (const Vector2D &rhs) const
 Indicates if the given vector is more Reverse if you looked in the direction of this vector.
 
bool isBetween (const Vector2D &lower, const Vector2D &upper) const
 Checks if this vector is between two other vectors Between means here that when rotating the lower vector (first argument) mathematically positively it becomes coaligned with this vector before it becomes coalgined with the other vector.
 
void swapCoordinates ()
 Swaps the coordinates in place.
 
double cylindricalR () const
 Gives the cylindrical radius of the vector. Same as norm()
 
void setCylindricalR (const double cylindricalR)
 Set the cylindrical radius while keeping the azimuth angle phi the same.
 
double phi () const
 Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
 
void passiveMoveBy (const Vector2D &by)
 Passivelly moves the vector inplace by the given vector.
 
Vector2D passiveMovedBy (const Vector2D &by) const
 Returns a transformed vector passivelly moved by the given vector.
 
Vector2D passiveRotatedBy (const Vector2D &phiVec) const
 Returns a transformed vector version rotated by the given vector.
 
double x () const
 Getter for the x coordinate.
 
void setX (const double x)
 Setter for the x coordinate.
 
double y () const
 Getter for the y coordinate.
 
void setY (const double y)
 Setter for the y coordinate.
 
void setXY (const double x, const double y)
 Setter for both coordinate.
 
void setXY (const Vector2D &xy)
 Setter for both coordinate by an other vector.
 
double first () const
 Getter for the first coordinate.
 
void setFirst (const double first)
 Setter for the first coordinate.
 
double second () const
 Getter for the second coordinate.
 
void setSecond (const double second)
 Setter for the second coordinate.
 
void set (const double first, const double second)
 Setter for both coordinate.
 
void set (const Vector2D &both)
 Setter for both coordinate by an other vector.
 
Angle functions

These functions measure the angle between two vectors from this to rhs in the mathematical positive counterclockwise direction.

So a positive angle means rhs is more counterclockwise than this.

double cosWith (const Vector2D &rhs) const
 
double sinWith (const Vector2D &rhs) const
 Sine of the angle between this and rhs.
 
double angleWith (const Vector2D &rhs) const
 The angle between this and rhs.
 

Static Public Member Functions

static Vector2D Phi (const double phi)
 Constructs a unit vector with azimuth angle equal to phi.
 
static Vector2D compose (const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
 Constructs a vector from a unit coordinate system vector and the coordinates in that system.
 
static Vector2D average (const Vector2D &one, const Vector2D &two)
 Constructs the average of two vectors.
 
static Vector2D average (const Vector2D &one, const Vector2D &two, const Vector2D &three)
 Constructs the average of three vectors.
 
static Vector2D getLowest ()
 Getter for the lowest possible vector.
 

Static Private Member Functions

static bool sameSign (float n1, float n2, float n3)
 Check if three values have the same sign.
 

Private Attributes

double m_x
 Memory for the first coordinate.
 
double m_y
 Memory for the second coordinate.
 

Friends

Vector2D operator* (const Vector2D &vec2D, const double factor)
 Same as scaled()
 

Detailed Description

A two dimensional vector which is equipped with functions for correct handling
of orientation related issues in addition to the expected vector methods.


Definition at line 32 of file Vector2D.h.

Constructor & Destructor Documentation

◆ Vector2D() [1/3]

Vector2D ( )
inline

Default constructor for ROOT compatibility.

Definition at line 36 of file Vector2D.h.

37 : m_x(0.0)
38 , m_y(0.0)
39 {
40 }
double m_x
Memory for the first coordinate.
Definition: Vector2D.h:664
double m_y
Memory for the second coordinate.
Definition: Vector2D.h:667

◆ Vector2D() [2/3]

Vector2D ( const double  x,
const double  y 
)
inline

Constructor from two coordinates.

Definition at line 43 of file Vector2D.h.

44 : m_x(x)
45 , m_y(y)
46 {
47 }
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:595
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:605

◆ Vector2D() [3/3]

Vector2D ( const Vector2D coordinateVec,
const double  parallelCoor,
const double  orthoCoor 
)
inline

Constructs a vector from a unit coordinate system vector and the coordinates in that system.

Same as compose() See compose() for details.

Definition at line 55 of file Vector2D.h.

56 : m_x(coordinateVec.x() * parallelCoor - coordinateVec.y() * orthoCoor)
57 , m_y(coordinateVec.y() * parallelCoor + coordinateVec.x() * orthoCoor)
58 {
59 }

Member Function Documentation

◆ __str__()

std::string __str__ ( ) const

Output operator for python.

Definition at line 22 of file Vector2D.cc.

23{
24 std::stringstream sstream;
25 sstream << *this;
26 return sstream.str();
27}

◆ add()

Vector2D & add ( const Vector2D rhs)
inline

Adds a vector to this in place.

Definition at line 262 of file Vector2D.h.

263 {
264 m_x += rhs.x();
265 m_y += rhs.y();
266 return *this;
267 }

◆ angleWith()

double angleWith ( const Vector2D rhs) const
inline

The angle between this and rhs.

Definition at line 197 of file Vector2D.h.

198 {
199 return atan2(cross(rhs), dot(rhs));
200 }
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
Definition: Vector2D.h:158
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
Definition: Vector2D.h:163

◆ average() [1/2]

static Vector2D average ( const Vector2D one,
const Vector2D two 
)
inlinestatic

Constructs the average of two vectors.

Computes the average of two vectors If one vector contains NAN the average is the other vector, since the former is not considered a valid value.

Definition at line 84 of file Vector2D.h.

85 {
86 if (one.hasNAN()) {
87 return two;
88 } else if (two.hasNAN()) {
89 return one;
90 } else {
91 return Vector2D((one.x() + two.x()) / 2.0, (one.y() + two.y()) / 2.0);
92 }
93 }
Vector2D()
Default constructor for ROOT compatibility.
Definition: Vector2D.h:36

◆ average() [2/2]

static Vector2D average ( const Vector2D one,
const Vector2D two,
const Vector2D three 
)
inlinestatic

Constructs the average of three vectors.

Computes the average of three vectors. In case one of the two dimensional vectors contains an NAN, it is not considered a valid value for the average and is therefore left out. The average() of the other two vectors is then returned.

Definition at line 101 of file Vector2D.h.

102 {
103
104 if (one.hasNAN()) {
105 return average(two, three);
106 } else if (two.hasNAN()) {
107 return average(one, three);
108 } else if (three.hasNAN()) {
109 return average(one, two);
110 } else {
111 return Vector2D((one.x() + two.x() + three.x()) / 3.0,
112 (one.y() + two.y() + three.y()) / 3.0);
113 }
114 }
static Vector2D average(const Vector2D &one, const Vector2D &two)
Constructs the average of two vectors.
Definition: Vector2D.h:84

◆ compose()

static Vector2D compose ( const Vector2D coordinateVec,
const double  parallelCoor,
const double  orthoCoor 
)
inlinestatic

Constructs a vector from a unit coordinate system vector and the coordinates in that system.

Combines a coordinate system vector expressed in laboratory coordinates
with the parallel and orthogonal components in the coordinate system
to a vector in laboratory coordinates. The coordinate system vector
is assumed the unit of the coordinate system

Definition at line 74 of file Vector2D.h.

75 {
76 return Vector2D(coordinateVec, parallelCoor, orthoCoor);
77 }

◆ conformalTransform()

void conformalTransform ( )
inline

Transforms the vector to conformal space inplace.

Applies the conformal map in the self-inverse from X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) inplace

Definition at line 385 of file Vector2D.h.

386 {
388 }
Vector2D & divide(const double denominator)
Divides all coordinates by a common denominator in place.
Definition: Vector2D.h:237
double normSquared() const
Calculates .
Definition: Vector2D.h:169

◆ conformalTransformed()

Vector2D conformalTransformed ( ) const
inline

Returns a copy of the vector transformed in conformal space.

Applies the conformal map in the self-inverse from X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) and returns the result as a new Vector2D

Definition at line 393 of file Vector2D.h.

394 {
395 return divided(normSquared());
396 }
Vector2D divided(const double denominator) const
Returns a copy where all coordinates got divided by a common denominator.
Definition: Vector2D.h:251

◆ cosWith()

double cosWith ( const Vector2D rhs) const
inline

Cosine of the angle between this and rhs

Definition at line 187 of file Vector2D.h.

188 {
189 return dot(rhs) / (norm() * rhs.norm());
190 }
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:175

◆ cross()

double cross ( const Vector2D rhs) const
inline

Calculated the two dimensional cross product.

Definition at line 163 of file Vector2D.h.

164 {
165 return x() * rhs.y() - y() * rhs.x();
166 }

◆ cylindricalR()

double cylindricalR ( ) const
inline

Gives the cylindrical radius of the vector. Same as norm()

Definition at line 557 of file Vector2D.h.

558 {
559 return hypot2(x(), y());
560 }

◆ distance()

double distance ( const Vector2D rhs = Vector2D(0.0, 0.0)) const
inline

Calculates the distance of this point to the rhs.

Definition at line 204 of file Vector2D.h.

205 {
206 double deltaX = x() - rhs.x();
207 double deltaY = y() - rhs.y();
208 return hypot2(deltaX, deltaY);
209 }

◆ divide()

Vector2D & divide ( const double  denominator)
inline

Divides all coordinates by a common denominator in place.

Definition at line 237 of file Vector2D.h.

238 {
239 m_x /= denominator;
240 m_y /= denominator;
241 return *this;
242 }

◆ divided()

Vector2D divided ( const double  denominator) const
inline

Returns a copy where all coordinates got divided by a common denominator.

Definition at line 251 of file Vector2D.h.

252 {
253 return Vector2D(x() / denominator, y() / denominator);
254 }

◆ dot()

double dot ( const Vector2D rhs) const
inline

Calculates the two dimensional dot product.

Definition at line 158 of file Vector2D.h.

159 {
160 return x() * rhs.x() + y() * rhs.y();
161 }

◆ first()

double first ( ) const
inline

Getter for the first coordinate.

Definition at line 629 of file Vector2D.h.

630 {
631 return m_x;
632 }

◆ flipFirst()

void flipFirst ( )
inline

Flips the first coordinate inplace (no difference between active and passive)

Definition at line 345 of file Vector2D.h.

346 {
347 m_x = -x();
348 }

◆ flippedAlong()

Vector2D flippedAlong ( const Vector2D flippingDirection) const
inline

Reflects this vector along line designated by the given vector.

Definition at line 377 of file Vector2D.h.

378 {
379 return *this - parallelVector(flippingDirection) * 2;
380 }
Vector2D parallelVector(const Vector2D &relativTo) const
Calculates the part of this vector that is parallel to the given vector.
Definition: Vector2D.h:417

◆ flippedFirst()

Vector2D flippedFirst ( ) const
inline

Makes a copy of the vector with the first coordinate flipped (no difference between active and passive)

Definition at line 358 of file Vector2D.h.

359 {
360 return Vector2D(-x(), y());
361 }

◆ flippedOver()

Vector2D flippedOver ( const Vector2D reflectionLine) const
inline

Reflects this vector over line designated by the given vector.

Definition at line 371 of file Vector2D.h.

372 {
373 return *this - orthogonalVector(reflectionLine) * 2;
374 }
Vector2D orthogonalVector(const Vector2D &relativTo) const
Calculates the part of this vector that is parallel to the given vector.
Definition: Vector2D.h:438

◆ flippedSecond()

Vector2D flippedSecond ( ) const
inline

Makes a copy of the vector with the second coordinate flipped (no difference between active and passive)

Definition at line 365 of file Vector2D.h.

366 {
367 return Vector2D(x(), -y());
368 }

◆ flipSecond()

void flipSecond ( )
inline

Flips the first coordinate inplace (no difference between active and passive)

Definition at line 351 of file Vector2D.h.

352 {
353 m_y = -y();
354 }

◆ getLowest()

static Vector2D getLowest ( )
inlinestatic

Getter for the lowest possible vector.

The lowest possible vector according to the comparison is the null vector

Definition at line 137 of file Vector2D.h.

138 {
139 return Vector2D(0.0, 0.0);
140 }

◆ hasNAN()

bool hasNAN ( ) const
inline

Checks if one of the coordinates is NAN.

Definition at line 149 of file Vector2D.h.

150 {
151 return std::isnan(x()) or std::isnan(y());
152 }
STL namespace.

◆ isBackwardOf()

bool isBackwardOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more Reverse if you looked in the direction of this vector.

Definition at line 507 of file Vector2D.h.

508 {
509 return isForwardOrBackwardOf(rhs) == EForwardBackward::c_Backward;
510 }
EForwardBackward isForwardOrBackwardOf(const Vector2D &rhs) const
Indicates if the given vector is more coaligned or reverse if you looked in the direction of this vec...
Definition: Vector2D.h:493

◆ isBetween()

bool isBetween ( const Vector2D lower,
const Vector2D upper 
) const
inline

Checks if this vector is between two other vectors Between means here that when rotating the lower vector (first argument) mathematically positively it becomes coaligned with this vector before it becomes coalgined with the other vector.

Definition at line 525 of file Vector2D.h.

526 {
527 // Set up a linear (nonorthogonal) transformation that maps
528 // lower -> (1, 0)
529 // upper -> (0, 1)
530 // Check whether this transformation is orientation conserving
531 // If yes this vector must lie in the first quadrant to be between lower and upper
532 // If no it must lie in some other quadrant.
533 double det = lower.cross(upper);
534 if (det == 0) {
535 // lower and upper are coaligned
536 return isRightOf(lower) and isLeftOf(upper);
537 } else {
538 bool flipsOrientation = det < 0;
539
540 double transformedX = cross(upper);
541 double transformedY = -cross(lower);
542 bool inFirstQuadrant = sameSign(det, transformedX, transformedY);
543 if (flipsOrientation) {
544 inFirstQuadrant = not inFirstQuadrant;
545 }
546 return inFirstQuadrant;
547 }
548 }
static bool sameSign(float n1, float n2, float n3)
Check if three values have the same sign.
Definition: Vector2D.h:514
bool isRightOf(const Vector2D &rhs) const
Indicates if the given vector is more right if you looked in the direction of this vector.
Definition: Vector2D.h:465
bool isLeftOf(const Vector2D &rhs) const
Indicates if the given vector is more left if you looked in the direction of this vector.
Definition: Vector2D.h:459

◆ isCCWOf()

bool isCCWOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more counterclockwise if you looked in the direction of this vector.

Definition at line 479 of file Vector2D.h.

480 {
481 return isCCWOrCWOf(rhs) == ERotation::c_CounterClockwise;
482 }
ERotation isCCWOrCWOf(const Vector2D &rhs) const
Indicates if the given vector is more counterclockwise or more clockwise if you looked in the directi...
Definition: Vector2D.h:472

◆ isCCWOrCWOf()

ERotation isCCWOrCWOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more counterclockwise or more clockwise if you looked in the direction of this vector.

Definition at line 472 of file Vector2D.h.

473 {
474 return static_cast<ERotation>(sign(unnormalizedOrthogonalComp(rhs)));
475 }
double unnormalizedOrthogonalComp(const Vector2D &relativTo) const
Same as orthogonalComp() but assumes the given vector to be of unit length.
Definition: Vector2D.h:446
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:25

◆ isCWOf()

bool isCWOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more clockwise if you looked in the direction of this vector.

Definition at line 486 of file Vector2D.h.

487 {
488 return isCCWOrCWOf(rhs) == ERotation::c_Clockwise;
489 }

◆ isForwardOf()

bool isForwardOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more coaligned if you looked in the direction of this vector.

Definition at line 500 of file Vector2D.h.

501 {
502 return isForwardOrBackwardOf(rhs) == EForwardBackward::c_Forward;
503 }

◆ isForwardOrBackwardOf()

EForwardBackward isForwardOrBackwardOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more coaligned or reverse if you looked in the direction of this vector.

Definition at line 493 of file Vector2D.h.

494 {
495 return static_cast<EForwardBackward>(sign(unnormalizedParallelComp(rhs)));
496 }
double unnormalizedParallelComp(const Vector2D &relativTo) const
Same as parallelComp() but assumes the given vector to be of unit length.
Definition: Vector2D.h:425
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.

◆ isLeftOf()

bool isLeftOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more left if you looked in the direction of this vector.

Definition at line 459 of file Vector2D.h.

460 {
461 return isRightOrLeftOf(rhs) == ERightLeft::c_Left;
462 }
ERightLeft isRightOrLeftOf(const Vector2D &rhs) const
Indicates if the given vector is more left or more right if you looked in the direction of this vecto...
Definition: Vector2D.h:453

◆ isNull()

bool isNull ( ) const
inline

Checks if the vector is the null vector.

Definition at line 143 of file Vector2D.h.

144 {
145 return x() == 0.0 and y() == 0.0;
146 }

◆ isRightOf()

bool isRightOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more right if you looked in the direction of this vector.

Definition at line 465 of file Vector2D.h.

466 {
467 return isRightOrLeftOf(rhs) == ERightLeft::c_Right;
468 }

◆ isRightOrLeftOf()

ERightLeft isRightOrLeftOf ( const Vector2D rhs) const
inline

Indicates if the given vector is more left or more right if you looked in the direction of this vector.

Definition at line 453 of file Vector2D.h.

454 {
455 return static_cast<ERightLeft>(-sign(unnormalizedOrthogonalComp(rhs)));
456 }
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25

◆ norm()

double norm ( ) const
inline

Calculates the length of the vector.

Definition at line 175 of file Vector2D.h.

176 {
177 return hypot2(x(), y());
178 }

◆ normalize()

double normalize ( )
inline

Normalizes the vector to unit length.

Normalizes the vector to unit length and returns the length the vector had before.
The null vector is not transformed.

Definition at line 303 of file Vector2D.h.

304 {
305 double originalLength = norm();
306 if (originalLength != 0.0) divide(originalLength);
307 return originalLength;
308 }

◆ normalizeTo()

double normalizeTo ( const double  toLength)
inline

Normalizes the vector to the given length.

Normalizes the vector to the given length and returns the length the vector had before.
The null vector is not transformed.

Definition at line 313 of file Vector2D.h.

314 {
315 double originalLength = norm();
316 if (originalLength != 0.0) scale(toLength / originalLength);
317 return originalLength;
318 }
Vector2D & scale(const double factor)
Scales the vector in place by the given factor.
Definition: Vector2D.h:212

◆ normSquared()

double normSquared ( ) const
inline

Calculates $ x^2 + y^2 $ .

Definition at line 169 of file Vector2D.h.

170 {
171 return x() * x() + y() * y();
172 }

◆ operator*=()

Vector2D & operator*= ( const double  factor)
inline

Same as scale()

Definition at line 219 of file Vector2D.h.

220 {
221 return scale(factor);
222 }

◆ operator+()

Vector2D operator+ ( const Vector2D rhs) const
inline

Returns a new vector as sum of this and rhs.

Definition at line 399 of file Vector2D.h.

400 {
401 return Vector2D(x() + rhs.x(), y() + rhs.y());
402 }

◆ operator+=()

Vector2D & operator+= ( const Vector2D rhs)
inline

Same as add()

Definition at line 270 of file Vector2D.h.

271 {
272 return add(rhs);
273 }
Vector2D & add(const Vector2D &rhs)
Adds a vector to this in place.
Definition: Vector2D.h:262

◆ operator-() [1/2]

Vector2D operator- ( ) const
inline

Same as reversed()

Definition at line 339 of file Vector2D.h.

340 {
341 return reversed();
342 }
Vector2D reversed() const
Returns a vector pointing in the opposite direction.
Definition: Vector2D.h:334

◆ operator-() [2/2]

Vector2D operator- ( const Vector2D rhs) const
inline

Returns a new vector as differenc of this and rhs.

Definition at line 405 of file Vector2D.h.

406 {
407 return Vector2D(x() - rhs.x(), y() - rhs.y());
408 }

◆ operator-=()

Vector2D & operator-= ( const Vector2D rhs)
inline

Same as subtract()

Definition at line 283 of file Vector2D.h.

284 {
285 return subtract(rhs);
286 }
Vector2D & subtract(const Vector2D &rhs)
Subtracts a vector from this in place.
Definition: Vector2D.h:276

◆ operator/()

Vector2D operator/ ( const double  denominator) const
inline

Same as divided()

Definition at line 256 of file Vector2D.h.

257 {
258 return divided(denominator);
259 }

◆ operator/=()

Vector2D & operator/= ( const double  denominator)
inline

Same as divide()

Definition at line 245 of file Vector2D.h.

246 {
247 return divide(denominator);
248 }

◆ operator<()

bool operator< ( const Vector2D rhs) const
inline

Total ordering based on cylindrical radius first and azimuth angle second.

Total order achieving a absolute lower bound Vector2D(0.0, 0.0). By first taking the cylindrical radius
for comparison the null vector is smaller than all other possible
vectors. Secondly the azimuth angle is considered to have a total ordering
for all vectors.

Definition at line 129 of file Vector2D.h.

130 {
131 return normSquared() < rhs.normSquared() or
132 (normSquared() == rhs.normSquared() and (phi() < rhs.phi()));
133 }
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition: Vector2D.h:569

◆ operator==()

bool operator== ( const Vector2D rhs) const
inline

Equality comparison with both coordinates.

Definition at line 117 of file Vector2D.h.

118 {
119 return x() == rhs.x() and y() == rhs.y();
120 }

◆ orthogonal() [1/2]

Vector2D orthogonal ( ) const
inline

Orthogonal vector to the counterclockwise direction.

Definition at line 289 of file Vector2D.h.

290 {
291 return Vector2D(-y(), x());
292 }

◆ orthogonal() [2/2]

Vector2D orthogonal ( const ERotation  ccwInfo) const
inline

Orthogonal vector to the direction given by the counterclockwise info.

Definition at line 295 of file Vector2D.h.

296 {
297 return isValid(ccwInfo) ? Vector2D(-static_cast<double>(ccwInfo) * y(), static_cast<double>(ccwInfo) * x()) : Vector2D();
298 }
bool isValid(EForwardBackward eForwardBackward)
Check whether the given enum instance is one of the valid values.

◆ orthogonalComp()

double orthogonalComp ( const Vector2D relativTo) const
inline

Calculates the component orthogonal to the given vector.

The orthogonal component is the component parallel to relativeTo.orthogonal()

Definition at line 432 of file Vector2D.h.

433 {
434 return relativTo.cross(*this) / relativTo.norm();
435 }

◆ orthogonalVector()

Vector2D orthogonalVector ( const Vector2D relativTo) const
inline

Calculates the part of this vector that is parallel to the given vector.

Definition at line 438 of file Vector2D.h.

439 {
440 return relativTo.scaled(relativTo.cross(*this) / relativTo.normSquared()).orthogonal();
441 }

◆ parallelComp()

double parallelComp ( const Vector2D relativTo) const
inline

Calculates the component parallel to the given vector.

Definition at line 411 of file Vector2D.h.

412 {
413 return relativTo.dot(*this) / relativTo.norm();
414 }

◆ parallelVector()

Vector2D parallelVector ( const Vector2D relativTo) const
inline

Calculates the part of this vector that is parallel to the given vector.

Definition at line 417 of file Vector2D.h.

418 {
419 return relativTo.scaled(relativTo.dot(*this) / relativTo.normSquared());
420 }

◆ passiveMoveBy()

void passiveMoveBy ( const Vector2D by)
inline

Passivelly moves the vector inplace by the given vector.

Definition at line 575 of file Vector2D.h.

576 {
577 subtract(by);
578 }

◆ passiveMovedBy()

Vector2D passiveMovedBy ( const Vector2D by) const
inline

Returns a transformed vector passivelly moved by the given vector.

Definition at line 581 of file Vector2D.h.

582 {
583 return *this - by;
584 }

◆ passiveRotatedBy()

Vector2D passiveRotatedBy ( const Vector2D phiVec) const
inline

Returns a transformed vector version rotated by the given vector.

The rotated coordinates are such that the given phiVec becomes the new x axes.

Parameters
phiVecUnit vector marking the x axes of the new rotated coordinate system

Definition at line 589 of file Vector2D.h.

590 {
592 }

◆ phi()

double phi ( ) const
inline

Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )

Definition at line 569 of file Vector2D.h.

570 {
571 return isNull() ? NAN : atan2(y(), x());
572 }
bool isNull() const
Checks if the vector is the null vector.
Definition: Vector2D.h:143

◆ Phi()

static Vector2D Phi ( const double  phi)
inlinestatic

Constructs a unit vector with azimuth angle equal to phi.

Definition at line 62 of file Vector2D.h.

63 {
64 return std::isnan(phi) ? Vector2D(0.0, 0.0) : Vector2D(cos(phi), sin(phi));
65 }

◆ reverse()

Vector2D & reverse ( )
inline

Reverses the direction of the vector in place.

Definition at line 327 of file Vector2D.h.

328 {
329 scale(-1.0);
330 return *this;
331 }

◆ reversed()

Vector2D reversed ( ) const
inline

Returns a vector pointing in the opposite direction.

Definition at line 334 of file Vector2D.h.

335 {
336 return scaled(-1.0);
337 }
Vector2D scaled(const double factor) const
Returns a scaled copy of the vector.
Definition: Vector2D.h:225

◆ sameSign()

static bool sameSign ( float  n1,
float  n2,
float  n3 
)
inlinestaticprivate

Check if three values have the same sign.

Definition at line 514 of file Vector2D.h.

515 {
516 return ((n1 > 0 and n2 > 0 and n3 > 0) or (n1 < 0 and n2 < 0 and n3 < 0));
517 }

◆ scale()

Vector2D & scale ( const double  factor)
inline

Scales the vector in place by the given factor.

Definition at line 212 of file Vector2D.h.

213 {
214 m_x *= factor;
215 m_y *= factor;
216 return *this;
217 }

◆ scaled()

Vector2D scaled ( const double  factor) const
inline

Returns a scaled copy of the vector.

Definition at line 225 of file Vector2D.h.

226 {
227 return Vector2D(x() * factor, y() * factor);
228 }

◆ second()

double second ( ) const
inline

Getter for the second coordinate.

Definition at line 639 of file Vector2D.h.

640 {
641 return m_y;
642 }

◆ set() [1/2]

void set ( const double  first,
const double  second 
)
inline

Setter for both coordinate.

Definition at line 650 of file Vector2D.h.

651 {
652 setX(first);
653 setY(second);
654 }
double second() const
Getter for the second coordinate.
Definition: Vector2D.h:639
void setY(const double y)
Setter for the y coordinate.
Definition: Vector2D.h:610
double first() const
Getter for the first coordinate.
Definition: Vector2D.h:629
void setX(const double x)
Setter for the x coordinate.
Definition: Vector2D.h:600

◆ set() [2/2]

void set ( const Vector2D both)
inline

Setter for both coordinate by an other vector.

Definition at line 656 of file Vector2D.h.

657 {
658 m_x = both.x();
659 m_y = both.y();
660 }

◆ setCylindricalR()

void setCylindricalR ( const double  cylindricalR)
inline

Set the cylindrical radius while keeping the azimuth angle phi the same.

Definition at line 563 of file Vector2D.h.

564 {
566 }
double cylindricalR() const
Gives the cylindrical radius of the vector. Same as norm()
Definition: Vector2D.h:557

◆ setFirst()

void setFirst ( const double  first)
inline

Setter for the first coordinate.

Definition at line 634 of file Vector2D.h.

635 {
636 m_x = first;
637 }

◆ setSecond()

void setSecond ( const double  second)
inline

Setter for the second coordinate.

Definition at line 644 of file Vector2D.h.

645 {
646 m_y = second;
647 }

◆ setX()

void setX ( const double  x)
inline

Setter for the x coordinate.

Definition at line 600 of file Vector2D.h.

601 {
602 m_x = x;
603 }

◆ setXY() [1/2]

void setXY ( const double  x,
const double  y 
)
inline

Setter for both coordinate.

Definition at line 616 of file Vector2D.h.

617 {
618 setX(x);
619 setY(y);
620 }

◆ setXY() [2/2]

void setXY ( const Vector2D xy)
inline

Setter for both coordinate by an other vector.

Definition at line 622 of file Vector2D.h.

623 {
624 m_x = xy.x();
625 m_y = xy.y();
626 }

◆ setY()

void setY ( const double  y)
inline

Setter for the y coordinate.

Definition at line 610 of file Vector2D.h.

611 {
612 m_y = y;
613 }

◆ sinWith()

double sinWith ( const Vector2D rhs) const
inline

Sine of the angle between this and rhs.

Definition at line 192 of file Vector2D.h.

193 {
194 return cross(rhs) / (norm() * rhs.norm());
195 }

◆ subtract()

Vector2D & subtract ( const Vector2D rhs)
inline

Subtracts a vector from this in place.

Definition at line 276 of file Vector2D.h.

277 {
278 m_x -= rhs.x();
279 m_y -= rhs.y();
280 return *this;
281 }

◆ swapCoordinates()

void swapCoordinates ( )
inline

Swaps the coordinates in place.

Definition at line 551 of file Vector2D.h.

552 {
553 std::swap(m_x, m_y);
554 }

◆ unit()

Vector2D unit ( ) const
inline

Returns a unit vector colaligned with this.

Definition at line 321 of file Vector2D.h.

322 {
323 return isNull() ? Vector2D(0.0, 0.0) : divided(norm());
324 }

◆ unnormalizedOrthogonalComp()

double unnormalizedOrthogonalComp ( const Vector2D relativTo) const
inline

Same as orthogonalComp() but assumes the given vector to be of unit length.

This assumes the given vector relativeTo to be of unit length and avoids
a costly computation of the vector norm()

Definition at line 446 of file Vector2D.h.

447 {
448 return relativTo.cross(*this);
449 }

◆ unnormalizedParallelComp()

double unnormalizedParallelComp ( const Vector2D relativTo) const
inline

Same as parallelComp() but assumes the given vector to be of unit length.

This assumes the given vector relativeTo to be of unit length and avoids
a costly computation of the vector norm()

Definition at line 425 of file Vector2D.h.

426 {
427 return relativTo.dot(*this);
428 }

◆ x()

double x ( ) const
inline

Getter for the x coordinate.

Definition at line 595 of file Vector2D.h.

596 {
597 return m_x;
598 }

◆ y()

double y ( ) const
inline

Getter for the y coordinate.

Definition at line 605 of file Vector2D.h.

606 {
607 return m_y;
608 }

Friends And Related Function Documentation

◆ operator*

Vector2D operator* ( const Vector2D vec2D,
const double  factor 
)
friend

Same as scaled()

Definition at line 231 of file Vector2D.h.

232 {
233 return vec2D.scaled(factor);
234 }

Member Data Documentation

◆ m_x

double m_x
private

Memory for the first coordinate.

Definition at line 664 of file Vector2D.h.

◆ m_y

double m_y
private

Memory for the second coordinate.

Definition at line 667 of file Vector2D.h.


The documentation for this class was generated from the following files: