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 ROOT::Math::XYVector &xyVector)
 Constructor translating from a ROOT::Math::XYVector instance.
 
 Vector2D (const double x, const double y)
 Constructor from two coordinates.
 
Vector2Doperator= (const ROOT::Math::XYVector &xyVector)
 Assignment translating from a ROOT::Math::XYVector instance.
 
 operator const ROOT::Math::XYVector () const
 Casting the back to ROOT::Math::XYVector seamlessly.
 
 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.
 
Vector2D operator- (const ROOT::Math::XYVector &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.
 
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.
 
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 34 of file Vector2D.h.

Constructor & Destructor Documentation

◆ Vector2D() [1/4]

Vector2D ( )
inline

Default constructor for ROOT compatibility.

Definition at line 38 of file Vector2D.h.

39 : m_x(0.0)
40 , m_y(0.0)
41 {
42 }

◆ Vector2D() [2/4]

Vector2D ( const ROOT::Math::XYVector & xyVector)

Constructor translating from a ROOT::Math::XYVector instance.

Definition at line 16 of file Vector2D.cc.

17 : m_x(xyVector.X()), m_y(xyVector.Y())
18{
19}
double m_x
Memory for the first coordinate.
Definition Vector2D.h:701
double m_y
Memory for the second coordinate.
Definition Vector2D.h:704

◆ Vector2D() [3/4]

Vector2D ( const double x,
const double y )
inline

Constructor from two coordinates.

Definition at line 55 of file Vector2D.h.

56 : m_x(x)
57 , m_y(y)
58 {
59 }

◆ Vector2D() [4/4]

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 73 of file Vector2D.h.

74 : m_x(coordinateVec.x() * parallelCoor - coordinateVec.y() * orthoCoor)
75 , m_y(coordinateVec.y() * parallelCoor + coordinateVec.x() * orthoCoor)
76 {
77 }

Member Function Documentation

◆ __str__()

std::string __str__ ( ) const

Output operator for python.

Definition at line 39 of file Vector2D.cc.

40{
41 std::stringstream sstream;
42 sstream << *this;
43 return sstream.str();
44}

◆ add()

Vector2D & add ( const Vector2D & rhs)
inline

Adds a vector to this in place.

Definition at line 280 of file Vector2D.h.

281 {
282 m_x += rhs.x();
283 m_y += rhs.y();
284 return *this;
285 }

◆ angleWith()

double angleWith ( const Vector2D & rhs) const
inline

The angle between this and rhs.

Definition at line 215 of file Vector2D.h.

216 {
217 return atan2(cross(rhs), dot(rhs));
218 }
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors

◆ 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 102 of file Vector2D.h.

103 {
104 if (one.hasNAN()) {
105 return two;
106 } else if (two.hasNAN()) {
107 return one;
108 } else {
109 return Vector2D((one.x() + two.x()) / 2.0, (one.y() + two.y()) / 2.0);
110 }
111 }

◆ 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 119 of file Vector2D.h.

120 {
121
122 if (one.hasNAN()) {
123 return average(two, three);
124 } else if (two.hasNAN()) {
125 return average(one, three);
126 } else if (three.hasNAN()) {
127 return average(one, two);
128 } else {
129 return Vector2D((one.x() + two.x() + three.x()) / 3.0,
130 (one.y() + two.y() + three.y()) / 3.0);
131 }
132 }

◆ 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 92 of file Vector2D.h.

93 {
94 return Vector2D(coordinateVec, parallelCoor, orthoCoor);
95 }

◆ 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 403 of file Vector2D.h.

404 {
405 divide(normSquared());
406 }

◆ 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 411 of file Vector2D.h.

412 {
413 return divided(normSquared());
414 }

◆ cosWith()

double cosWith ( const Vector2D & rhs) const
inline

Cosine of the angle between this and rhs

Definition at line 205 of file Vector2D.h.

206 {
207 return dot(rhs) / (norm() * rhs.norm());
208 }

◆ cross()

double cross ( const Vector2D & rhs) const
inline

Calculated the two dimensional cross product.

Definition at line 181 of file Vector2D.h.

182 {
183 return x() * rhs.y() - y() * rhs.x();
184 }

◆ cylindricalR()

double cylindricalR ( ) const
inline

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

Definition at line 584 of file Vector2D.h.

585 {
586 return hypot2(x(), y());
587 }

◆ 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 222 of file Vector2D.h.

223 {
224 double deltaX = x() - rhs.x();
225 double deltaY = y() - rhs.y();
226 return hypot2(deltaX, deltaY);
227 }

◆ divide()

Vector2D & divide ( const double denominator)
inline

Divides all coordinates by a common denominator in place.

Definition at line 255 of file Vector2D.h.

256 {
257 m_x /= denominator;
258 m_y /= denominator;
259 return *this;
260 }

◆ divided()

Vector2D divided ( const double denominator) const
inline

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

Definition at line 269 of file Vector2D.h.

270 {
271 return Vector2D(x() / denominator, y() / denominator);
272 }

◆ dot()

double dot ( const Vector2D & rhs) const
inline

Calculates the two dimensional dot product.

Definition at line 176 of file Vector2D.h.

177 {
178 return x() * rhs.x() + y() * rhs.y();
179 }

◆ first()

double first ( ) const
inline

Getter for the first coordinate.

Definition at line 666 of file Vector2D.h.

667 {
668 return m_x;
669 }

◆ flipFirst()

void flipFirst ( )
inline

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

Definition at line 363 of file Vector2D.h.

364 {
365 m_x = -x();
366 }

◆ flippedAlong()

Vector2D flippedAlong ( const Vector2D & flippingDirection) const
inline

Reflects this vector along line designated by the given vector.

Definition at line 395 of file Vector2D.h.

396 {
397 return *this - parallelVector(flippingDirection) * 2;
398 }

◆ 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 376 of file Vector2D.h.

377 {
378 return Vector2D(-x(), y());
379 }

◆ flippedOver()

Vector2D flippedOver ( const Vector2D & reflectionLine) const
inline

Reflects this vector over line designated by the given vector.

Definition at line 389 of file Vector2D.h.

390 {
391 return *this - orthogonalVector(reflectionLine) * 2;
392 }

◆ 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 383 of file Vector2D.h.

384 {
385 return Vector2D(x(), -y());
386 }

◆ flipSecond()

void flipSecond ( )
inline

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

Definition at line 369 of file Vector2D.h.

370 {
371 m_y = -y();
372 }

◆ 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 155 of file Vector2D.h.

156 {
157 return Vector2D(0.0, 0.0);
158 }

◆ hasNAN()

bool hasNAN ( ) const
inline

Checks if one of the coordinates is NAN.

Definition at line 167 of file Vector2D.h.

168 {
169 return std::isnan(x()) or std::isnan(y());
170 }

◆ 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 534 of file Vector2D.h.

535 {
536 return isForwardOrBackwardOf(rhs) == EForwardBackward::c_Backward;
537 }

◆ 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 552 of file Vector2D.h.

553 {
554 // Set up a linear (nonorthogonal) transformation that maps
555 // lower -> (1, 0)
556 // upper -> (0, 1)
557 // Check whether this transformation is orientation conserving
558 // If yes this vector must lie in the first quadrant to be between lower and upper
559 // If no it must lie in some other quadrant.
560 double det = lower.cross(upper);
561 if (det == 0) {
562 // lower and upper are coaligned
563 return isRightOf(lower) and isLeftOf(upper);
564 } else {
565 bool flipsOrientation = det < 0;
566
567 double transformedX = cross(upper);
568 double transformedY = -cross(lower);
569 bool inFirstQuadrant = sameSign(det, transformedX, transformedY);
570 if (flipsOrientation) {
571 inFirstQuadrant = not inFirstQuadrant;
572 }
573 return inFirstQuadrant;
574 }
575 }
bool sameSign(double expected, double actual)
Predicate checking that two values have the same sign.

◆ 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 506 of file Vector2D.h.

507 {
508 return isCCWOrCWOf(rhs) == ERotation::c_CounterClockwise;
509 }

◆ 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 499 of file Vector2D.h.

500 {
501 return static_cast<ERotation>(sign(unnormalizedOrthogonalComp(rhs)));
502 }
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 513 of file Vector2D.h.

514 {
515 return isCCWOrCWOf(rhs) == ERotation::c_Clockwise;
516 }

◆ 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 527 of file Vector2D.h.

528 {
529 return isForwardOrBackwardOf(rhs) == EForwardBackward::c_Forward;
530 }

◆ 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 520 of file Vector2D.h.

521 {
522 return static_cast<EForwardBackward>(sign(unnormalizedParallelComp(rhs)));
523 }
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 486 of file Vector2D.h.

487 {
488 return isRightOrLeftOf(rhs) == ERightLeft::c_Left;
489 }

◆ isNull()

bool isNull ( ) const
inline

Checks if the vector is the null vector.

Definition at line 161 of file Vector2D.h.

162 {
163 return x() == 0.0 and y() == 0.0;
164 }

◆ 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 492 of file Vector2D.h.

493 {
494 return isRightOrLeftOf(rhs) == ERightLeft::c_Right;
495 }

◆ 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 480 of file Vector2D.h.

481 {
482 return static_cast<ERightLeft>(-sign(unnormalizedOrthogonalComp(rhs)));
483 }
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 193 of file Vector2D.h.

194 {
195 return hypot2(x(), y());
196 }

◆ 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 321 of file Vector2D.h.

322 {
323 double originalLength = norm();
324 if (originalLength != 0.0) divide(originalLength);
325 return originalLength;
326 }

◆ 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 331 of file Vector2D.h.

332 {
333 double originalLength = norm();
334 if (originalLength != 0.0) scale(toLength / originalLength);
335 return originalLength;
336 }

◆ normSquared()

double normSquared ( ) const
inline

Calculates $ x^2 + y^2 $ .

Definition at line 187 of file Vector2D.h.

188 {
189 return x() * x() + y() * y();
190 }

◆ operator const ROOT::Math::XYVector()

operator const ROOT::Math::XYVector ( ) const

Casting the back to ROOT::Math::XYVector seamlessly.

Definition at line 28 of file Vector2D.cc.

29{
30 return ROOT::Math::XYVector(x(), y());
31}
double x() const
Getter for the x coordinate.
Definition Vector2D.h:622
double y() const
Getter for the y coordinate.
Definition Vector2D.h:637

◆ operator*=()

Vector2D & operator*= ( const double factor)
inline

Same as scale()

Definition at line 237 of file Vector2D.h.

238 {
239 return scale(factor);
240 }

◆ operator+()

Vector2D operator+ ( const Vector2D & rhs) const
inline

Returns a new vector as sum of this and rhs.

Definition at line 417 of file Vector2D.h.

418 {
419 return Vector2D(x() + rhs.x(), y() + rhs.y());
420 }

◆ operator+=()

Vector2D & operator+= ( const Vector2D & rhs)
inline

Same as add()

Definition at line 288 of file Vector2D.h.

289 {
290 return add(rhs);
291 }

◆ operator-() [1/3]

Vector2D operator- ( ) const
inline

Same as reversed()

Definition at line 357 of file Vector2D.h.

358 {
359 return reversed();
360 }
EForwardBackward reversed(EForwardBackward eForwardBackward)
Return the reversed forward backward indicator. Leaves EForwardBackward::c_Invalid the same.

◆ operator-() [2/3]

Vector2D operator- ( const ROOT::Math::XYVector & rhs) const
inline

Returns a new vector as differenc of this and rhs.

Definition at line 429 of file Vector2D.h.

430 {
431 return Vector2D(x() - rhs.X(), y() - rhs.Y());
432 }

◆ operator-() [3/3]

Vector2D operator- ( const Vector2D & rhs) const
inline

Returns a new vector as differenc of this and rhs.

Definition at line 423 of file Vector2D.h.

424 {
425 return Vector2D(x() - rhs.x(), y() - rhs.y());
426 }

◆ operator-=()

Vector2D & operator-= ( const Vector2D & rhs)
inline

Same as subtract()

Definition at line 301 of file Vector2D.h.

302 {
303 return subtract(rhs);
304 }

◆ operator/()

Vector2D operator/ ( const double denominator) const
inline

Same as divided()

Definition at line 274 of file Vector2D.h.

275 {
276 return divided(denominator);
277 }

◆ operator/=()

Vector2D & operator/= ( const double denominator)
inline

Same as divide()

Definition at line 263 of file Vector2D.h.

264 {
265 return divide(denominator);
266 }

◆ 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 147 of file Vector2D.h.

148 {
149 return normSquared() < rhs.normSquared() or
150 (normSquared() == rhs.normSquared() and (phi() < rhs.phi()));
151 }

◆ operator=()

Vector2D & operator= ( const ROOT::Math::XYVector & xyVector)

Assignment translating from a ROOT::Math::XYVector instance.

Definition at line 21 of file Vector2D.cc.

22{
23 m_x = xyVector.X();
24 m_y = xyVector.Y();
25 return *this;
26}

◆ operator==()

bool operator== ( const Vector2D & rhs) const
inline

Equality comparison with both coordinates.

Definition at line 135 of file Vector2D.h.

136 {
137 return x() == rhs.x() and y() == rhs.y();
138 }

◆ orthogonal() [1/2]

Vector2D orthogonal ( ) const
inline

Orthogonal vector to the counterclockwise direction.

Definition at line 307 of file Vector2D.h.

308 {
309 return Vector2D(-y(), x());
310 }

◆ orthogonal() [2/2]

Vector2D orthogonal ( const ERotation ccwInfo) const
inline

Orthogonal vector to the direction given by the counterclockwise info.

Definition at line 313 of file Vector2D.h.

314 {
315 return isValid(ccwInfo) ? Vector2D(-static_cast<double>(ccwInfo) * y(), static_cast<double>(ccwInfo) * x()) : Vector2D();
316 }
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 459 of file Vector2D.h.

460 {
461 return relativTo.cross(*this) / relativTo.norm();
462 }

◆ orthogonalVector()

Vector2D orthogonalVector ( const Vector2D & relativTo) const
inline

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

Definition at line 465 of file Vector2D.h.

466 {
467 return relativTo.scaled(relativTo.cross(*this) / relativTo.normSquared()).orthogonal();
468 }

◆ parallelComp()

double parallelComp ( const Vector2D & relativTo) const
inline

Calculates the component parallel to the given vector.

Definition at line 435 of file Vector2D.h.

436 {
437 return relativTo.dot(*this) / relativTo.norm();
438 }

◆ parallelVector()

Vector2D parallelVector ( const Vector2D & relativTo) const
inline

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

Attention
: A generalised version for 2D and 3D vectors is implemented in framework/geometry/include/VectorUtil.h If this class is ever replaced by ROOT::Math::Vector2D, this method can be replaced by that in the basf2 VectorUtil.

Definition at line 444 of file Vector2D.h.

445 {
446 return relativTo.scaled(relativTo.dot(*this) / relativTo.normSquared());
447 }

◆ passiveMoveBy()

void passiveMoveBy ( const Vector2D & by)
inline

Passivelly moves the vector inplace by the given vector.

Definition at line 602 of file Vector2D.h.

603 {
604 subtract(by);
605 }

◆ passiveMovedBy()

Vector2D passiveMovedBy ( const Vector2D & by) const
inline

Returns a transformed vector passivelly moved by the given vector.

Definition at line 608 of file Vector2D.h.

609 {
610 return *this - by;
611 }

◆ 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 616 of file Vector2D.h.

617 {
618 return Vector2D(unnormalizedParallelComp(phiVec), unnormalizedOrthogonalComp(phiVec));
619 }

◆ Phi()

static Vector2D Phi ( const double phi)
inlinestatic

Constructs a unit vector with azimuth angle equal to phi.

Definition at line 80 of file Vector2D.h.

81 {
82 return std::isnan(phi) ? Vector2D(0.0, 0.0) : Vector2D(cos(phi), sin(phi));
83 }

◆ 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 596 of file Vector2D.h.

597 {
598 return isNull() ? NAN : atan2(y(), x());
599 }

◆ reverse()

Vector2D & reverse ( )
inline

Reverses the direction of the vector in place.

Definition at line 345 of file Vector2D.h.

346 {
347 scale(-1.0);
348 return *this;
349 }

◆ reversed()

Vector2D reversed ( ) const
inline

Returns a vector pointing in the opposite direction.

Definition at line 352 of file Vector2D.h.

353 {
354 return scaled(-1.0);
355 }

◆ sameSign()

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

Check if three values have the same sign.

Definition at line 541 of file Vector2D.h.

542 {
543 return ((n1 > 0 and n2 > 0 and n3 > 0) or (n1 < 0 and n2 < 0 and n3 < 0));
544 }

◆ scale()

Vector2D & scale ( const double factor)
inline

Scales the vector in place by the given factor.

Definition at line 230 of file Vector2D.h.

231 {
232 m_x *= factor;
233 m_y *= factor;
234 return *this;
235 }

◆ scaled()

Vector2D scaled ( const double factor) const
inline

Returns a scaled copy of the vector.

Definition at line 243 of file Vector2D.h.

244 {
245 return Vector2D(x() * factor, y() * factor);
246 }

◆ second()

double second ( ) const
inline

Getter for the second coordinate.

Definition at line 676 of file Vector2D.h.

677 {
678 return m_y;
679 }

◆ set() [1/2]

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

Setter for both coordinate.

Definition at line 687 of file Vector2D.h.

688 {
689 setX(first);
690 setY(second);
691 }

◆ set() [2/2]

void set ( const Vector2D & both)
inline

Setter for both coordinate by an other vector.

Definition at line 693 of file Vector2D.h.

694 {
695 m_x = both.x();
696 m_y = both.y();
697 }

◆ setCylindricalR()

void setCylindricalR ( const double cylindricalR)
inline

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

Definition at line 590 of file Vector2D.h.

591 {
592 scale(cylindricalR / norm());
593 }

◆ setFirst()

void setFirst ( const double first)
inline

Setter for the first coordinate.

Definition at line 671 of file Vector2D.h.

672 {
673 m_x = first;
674 }

◆ setSecond()

void setSecond ( const double second)
inline

Setter for the second coordinate.

Definition at line 681 of file Vector2D.h.

682 {
683 m_y = second;
684 }

◆ setX()

void setX ( const double x)
inline

Setter for the x coordinate.

Definition at line 632 of file Vector2D.h.

633 {
634 m_x = x;
635 }

◆ setXY() [1/2]

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

Setter for both coordinate.

Definition at line 653 of file Vector2D.h.

654 {
655 setX(x);
656 setY(y);
657 }

◆ setXY() [2/2]

void setXY ( const Vector2D & xy)
inline

Setter for both coordinate by an other vector.

Definition at line 659 of file Vector2D.h.

660 {
661 m_x = xy.x();
662 m_y = xy.y();
663 }

◆ setY()

void setY ( const double y)
inline

Setter for the y coordinate.

Definition at line 647 of file Vector2D.h.

648 {
649 m_y = y;
650 }

◆ sinWith()

double sinWith ( const Vector2D & rhs) const
inline

Sine of the angle between this and rhs.

Definition at line 210 of file Vector2D.h.

211 {
212 return cross(rhs) / (norm() * rhs.norm());
213 }

◆ subtract()

Vector2D & subtract ( const Vector2D & rhs)
inline

Subtracts a vector from this in place.

Definition at line 294 of file Vector2D.h.

295 {
296 m_x -= rhs.x();
297 m_y -= rhs.y();
298 return *this;
299 }

◆ swapCoordinates()

void swapCoordinates ( )
inline

Swaps the coordinates in place.

Definition at line 578 of file Vector2D.h.

579 {
580 std::swap(m_x, m_y);
581 }

◆ unit()

Vector2D unit ( ) const
inline

Returns a unit vector colaligned with this.

Definition at line 339 of file Vector2D.h.

340 {
341 return isNull() ? Vector2D(0.0, 0.0) : divided(norm());
342 }

◆ 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 473 of file Vector2D.h.

474 {
475 return relativTo.cross(*this);
476 }

◆ 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 452 of file Vector2D.h.

453 {
454 return relativTo.dot(*this);
455 }

◆ X()

double X ( ) const
inline

Getter for the x coordinate.

Definition at line 627 of file Vector2D.h.

628 {
629 return m_x;
630 }

◆ x()

double x ( ) const
inline

Getter for the x coordinate.

Definition at line 622 of file Vector2D.h.

623 {
624 return m_x;
625 }

◆ Y()

double Y ( ) const
inline

Getter for the y coordinate.

Definition at line 642 of file Vector2D.h.

643 {
644 return m_y;
645 }

◆ y()

double y ( ) const
inline

Getter for the y coordinate.

Definition at line 637 of file Vector2D.h.

638 {
639 return m_y;
640 }

Friends And Related Symbol Documentation

◆ operator*

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

Same as scaled()

Definition at line 249 of file Vector2D.h.

250 {
251 return vec2D.scaled(factor);
252 }

Member Data Documentation

◆ m_x

double m_x
private

Memory for the first coordinate.

Definition at line 701 of file Vector2D.h.

◆ m_y

double m_y
private

Memory for the second coordinate.

Definition at line 704 of file Vector2D.h.


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