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 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 Mag2 () const
 Alias for normSquared.
 
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.
 
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 36 of file Vector2D.h.

Constructor & Destructor Documentation

◆ Vector2D() [1/4]

Vector2D ( )
inline

Default constructor for ROOT compatibility.

Definition at line 40 of file Vector2D.h.

41 : m_x(0.0)
42 , m_y(0.0)
43 {
44 }

◆ 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:705
double m_y
Memory for the second coordinate.
Definition Vector2D.h:708

◆ Vector2D() [3/4]

Vector2D ( const double x,
const double y )
inline

Constructor from two coordinates.

Definition at line 57 of file Vector2D.h.

58 : m_x(x)
59 , m_y(y)
60 {
61 }

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

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

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

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

◆ angleWith()

double angleWith ( const Vector2D & rhs) const
inline

The angle between this and rhs.

Definition at line 228 of file Vector2D.h.

229 {
230 return atan2(cross(rhs), dot(rhs));
231 }
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 104 of file Vector2D.h.

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

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

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

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

95 {
96 return Vector2D(coordinateVec, parallelCoor, orthoCoor);
97 }

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

417 {
418 divide(normSquared());
419 }

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

425 {
426 return divided(normSquared());
427 }

◆ cosWith()

double cosWith ( const Vector2D & rhs) const
inline

Cosine of the angle between this and rhs

Definition at line 218 of file Vector2D.h.

219 {
220 return dot(rhs) / (norm() * rhs.norm());
221 }

◆ cross()

double cross ( const Vector2D & rhs) const
inline

Calculated the two dimensional cross product.

Definition at line 189 of file Vector2D.h.

190 {
191 return x() * rhs.y() - y() * rhs.x();
192 }

◆ cylindricalR()

double cylindricalR ( ) const
inline

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

Definition at line 588 of file Vector2D.h.

589 {
590 return hypot2(x(), y());
591 }

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

236 {
237 double deltaX = x() - rhs.x();
238 double deltaY = y() - rhs.y();
239 return hypot2(deltaX, deltaY);
240 }

◆ divide()

Vector2D & divide ( const double denominator)
inline

Divides all coordinates by a common denominator in place.

Definition at line 268 of file Vector2D.h.

269 {
270 m_x /= denominator;
271 m_y /= denominator;
272 return *this;
273 }

◆ divided()

Vector2D divided ( const double denominator) const
inline

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

Definition at line 282 of file Vector2D.h.

283 {
284 return Vector2D(x() / denominator, y() / denominator);
285 }

◆ Dot()

double Dot ( const Vector2D & rhs) const
inline

Calculates the two dimensional dot product.

Definition at line 183 of file Vector2D.h.

184 {
185 return dot(rhs);
186 }

◆ dot()

double dot ( const Vector2D & rhs) const
inline

Calculates the two dimensional dot product.

Definition at line 178 of file Vector2D.h.

179 {
180 return x() * rhs.x() + y() * rhs.y();
181 }

◆ first()

double first ( ) const
inline

Getter for the first coordinate.

Definition at line 670 of file Vector2D.h.

671 {
672 return m_x;
673 }

◆ flipFirst()

void flipFirst ( )
inline

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

Definition at line 376 of file Vector2D.h.

377 {
378 m_x = -x();
379 }

◆ flippedAlong()

Vector2D flippedAlong ( const Vector2D & flippingDirection) const
inline

Reflects this vector along line designated by the given vector.

Definition at line 408 of file Vector2D.h.

409 {
410 return *this - Belle2::VectorUtil::parallelVector(*this, flippingDirection) * 2;
411 }

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

390 {
391 return Vector2D(-x(), y());
392 }

◆ flippedOver()

Vector2D flippedOver ( const Vector2D & reflectionLine) const
inline

Reflects this vector over line designated by the given vector.

Definition at line 402 of file Vector2D.h.

403 {
404 return *this - orthogonalVector(reflectionLine) * 2;
405 }

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

397 {
398 return Vector2D(x(), -y());
399 }

◆ flipSecond()

void flipSecond ( )
inline

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

Definition at line 382 of file Vector2D.h.

383 {
384 m_y = -y();
385 }

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

158 {
159 return Vector2D(0.0, 0.0);
160 }

◆ hasNAN()

bool hasNAN ( ) const
inline

Checks if one of the coordinates is NAN.

Definition at line 169 of file Vector2D.h.

170 {
171 return std::isnan(x()) or std::isnan(y());
172 }

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

539 {
540 return isForwardOrBackwardOf(rhs) == EForwardBackward::c_Backward;
541 }

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

557 {
558 // Set up a linear (nonorthogonal) transformation that maps
559 // lower -> (1, 0)
560 // upper -> (0, 1)
561 // Check whether this transformation is orientation conserving
562 // If yes this vector must lie in the first quadrant to be between lower and upper
563 // If no it must lie in some other quadrant.
564 double det = lower.cross(upper);
565 if (det == 0) {
566 // lower and upper are coaligned
567 return isRightOf(lower) and isLeftOf(upper);
568 } else {
569 bool flipsOrientation = det < 0;
570
571 double transformedX = cross(upper);
572 double transformedY = -cross(lower);
573 bool inFirstQuadrant = sameSign(det, transformedX, transformedY);
574 if (flipsOrientation) {
575 inFirstQuadrant = not inFirstQuadrant;
576 }
577 return inFirstQuadrant;
578 }
579 }
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 510 of file Vector2D.h.

511 {
512 return isCCWOrCWOf(rhs) == ERotation::c_CounterClockwise;
513 }

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

504 {
505 return static_cast<ERotation>(sign(unnormalizedOrthogonalComp(rhs)));
506 }
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 517 of file Vector2D.h.

518 {
519 return isCCWOrCWOf(rhs) == ERotation::c_Clockwise;
520 }

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

532 {
533 return isForwardOrBackwardOf(rhs) == EForwardBackward::c_Forward;
534 }

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

525 {
526 return static_cast<EForwardBackward>(sign(unnormalizedParallelComp(rhs)));
527 }
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 490 of file Vector2D.h.

491 {
492 return isRightOrLeftOf(rhs) == ERightLeft::c_Left;
493 }

◆ isNull()

bool isNull ( ) const
inline

Checks if the vector is the null vector.

Definition at line 163 of file Vector2D.h.

164 {
165 return x() == 0.0 and y() == 0.0;
166 }

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

497 {
498 return isRightOrLeftOf(rhs) == ERightLeft::c_Right;
499 }

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

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

◆ Mag2()

double Mag2 ( ) const
inline

Alias for normSquared.

Definition at line 200 of file Vector2D.h.

201 {
202 return normSquared();
203 }

◆ norm()

double norm ( ) const
inline

Calculates the length of the vector.

Definition at line 206 of file Vector2D.h.

207 {
208 return hypot2(x(), y());
209 }

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

335 {
336 double originalLength = norm();
337 if (originalLength != 0.0) divide(originalLength);
338 return originalLength;
339 }

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

345 {
346 double originalLength = norm();
347 if (originalLength != 0.0) scale(toLength / originalLength);
348 return originalLength;
349 }

◆ normSquared()

double normSquared ( ) const
inline

Calculates $ x^2 + y^2 $ .

Definition at line 195 of file Vector2D.h.

196 {
197 return x() * x() + y() * y();
198 }

◆ 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:626
double y() const
Getter for the y coordinate.
Definition Vector2D.h:641

◆ operator*=()

Vector2D & operator*= ( const double factor)
inline

Same as scale()

Definition at line 250 of file Vector2D.h.

251 {
252 return scale(factor);
253 }

◆ operator+()

Vector2D operator+ ( const Vector2D & rhs) const
inline

Returns a new vector as sum of this and rhs.

Definition at line 430 of file Vector2D.h.

431 {
432 return Vector2D(x() + rhs.x(), y() + rhs.y());
433 }

◆ operator+=()

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

Same as add()

Definition at line 301 of file Vector2D.h.

302 {
303 return add(rhs);
304 }

◆ operator-() [1/3]

Vector2D operator- ( ) const
inline

Same as reversed()

Definition at line 370 of file Vector2D.h.

371 {
372 return reversed();
373 }
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 442 of file Vector2D.h.

443 {
444 return Vector2D(x() - rhs.X(), y() - rhs.Y());
445 }

◆ operator-() [3/3]

Vector2D operator- ( const Vector2D & rhs) const
inline

Returns a new vector as differenc of this and rhs.

Definition at line 436 of file Vector2D.h.

437 {
438 return Vector2D(x() - rhs.x(), y() - rhs.y());
439 }

◆ operator-=()

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

Same as subtract()

Definition at line 314 of file Vector2D.h.

315 {
316 return subtract(rhs);
317 }

◆ operator/()

Vector2D operator/ ( const double denominator) const
inline

Same as divided()

Definition at line 287 of file Vector2D.h.

288 {
289 return divided(denominator);
290 }

◆ operator/=()

Vector2D & operator/= ( const double denominator)
inline

Same as divide()

Definition at line 276 of file Vector2D.h.

277 {
278 return divide(denominator);
279 }

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

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

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

138 {
139 return x() == rhs.x() and y() == rhs.y();
140 }

◆ orthogonal() [1/2]

Vector2D orthogonal ( ) const
inline

Orthogonal vector to the counterclockwise direction.

Definition at line 320 of file Vector2D.h.

321 {
322 return Vector2D(-y(), x());
323 }

◆ orthogonal() [2/2]

Vector2D orthogonal ( const ERotation ccwInfo) const
inline

Orthogonal vector to the direction given by the counterclockwise info.

Definition at line 326 of file Vector2D.h.

327 {
328 return isValid(ccwInfo) ? Vector2D(-static_cast<double>(ccwInfo) * y(), static_cast<double>(ccwInfo) * x()) : Vector2D();
329 }
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 463 of file Vector2D.h.

464 {
465 return relativTo.cross(*this) / relativTo.norm();
466 }

◆ orthogonalVector()

Vector2D orthogonalVector ( const Vector2D & relativTo) const
inline

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

Definition at line 469 of file Vector2D.h.

470 {
471 return relativTo.scaled(relativTo.cross(*this) / relativTo.normSquared()).orthogonal();
472 }

◆ parallelComp()

double parallelComp ( const Vector2D & relativTo) const
inline

Calculates the component parallel to the given vector.

Definition at line 448 of file Vector2D.h.

449 {
450 return relativTo.dot(*this) / relativTo.norm();
451 }

◆ passiveMoveBy()

void passiveMoveBy ( const Vector2D & by)
inline

Passivelly moves the vector inplace by the given vector.

Definition at line 606 of file Vector2D.h.

607 {
608 subtract(by);
609 }

◆ passiveMovedBy()

Vector2D passiveMovedBy ( const Vector2D & by) const
inline

Returns a transformed vector passivelly moved by the given vector.

Definition at line 612 of file Vector2D.h.

613 {
614 return *this - by;
615 }

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

621 {
622 return Vector2D(unnormalizedParallelComp(phiVec), unnormalizedOrthogonalComp(phiVec));
623 }

◆ Phi()

static Vector2D Phi ( const double phi)
inlinestatic

Constructs a unit vector with azimuth angle equal to phi.

Definition at line 82 of file Vector2D.h.

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

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

601 {
602 return isNull() ? NAN : atan2(y(), x());
603 }

◆ reverse()

Vector2D & reverse ( )
inline

Reverses the direction of the vector in place.

Definition at line 358 of file Vector2D.h.

359 {
360 scale(-1.0);
361 return *this;
362 }

◆ reversed()

Vector2D reversed ( ) const
inline

Returns a vector pointing in the opposite direction.

Definition at line 365 of file Vector2D.h.

366 {
367 return scaled(-1.0);
368 }

◆ sameSign()

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

Check if three values have the same sign.

Definition at line 545 of file Vector2D.h.

546 {
547 return ((n1 > 0 and n2 > 0 and n3 > 0) or (n1 < 0 and n2 < 0 and n3 < 0));
548 }

◆ scale()

Vector2D & scale ( const double factor)
inline

Scales the vector in place by the given factor.

Definition at line 243 of file Vector2D.h.

244 {
245 m_x *= factor;
246 m_y *= factor;
247 return *this;
248 }

◆ scaled()

Vector2D scaled ( const double factor) const
inline

Returns a scaled copy of the vector.

Definition at line 256 of file Vector2D.h.

257 {
258 return Vector2D(x() * factor, y() * factor);
259 }

◆ second()

double second ( ) const
inline

Getter for the second coordinate.

Definition at line 680 of file Vector2D.h.

681 {
682 return m_y;
683 }

◆ set() [1/2]

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

Setter for both coordinate.

Definition at line 691 of file Vector2D.h.

692 {
693 setX(first);
694 setY(second);
695 }

◆ set() [2/2]

void set ( const Vector2D & both)
inline

Setter for both coordinate by an other vector.

Definition at line 697 of file Vector2D.h.

698 {
699 m_x = both.x();
700 m_y = both.y();
701 }

◆ setCylindricalR()

void setCylindricalR ( const double cylindricalR)
inline

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

Definition at line 594 of file Vector2D.h.

595 {
596 scale(cylindricalR / norm());
597 }

◆ setFirst()

void setFirst ( const double first)
inline

Setter for the first coordinate.

Definition at line 675 of file Vector2D.h.

676 {
677 m_x = first;
678 }

◆ setSecond()

void setSecond ( const double second)
inline

Setter for the second coordinate.

Definition at line 685 of file Vector2D.h.

686 {
687 m_y = second;
688 }

◆ setX()

void setX ( const double x)
inline

Setter for the x coordinate.

Definition at line 636 of file Vector2D.h.

637 {
638 m_x = x;
639 }

◆ setXY() [1/2]

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

Setter for both coordinate.

Definition at line 657 of file Vector2D.h.

658 {
659 setX(x);
660 setY(y);
661 }

◆ setXY() [2/2]

void setXY ( const Vector2D & xy)
inline

Setter for both coordinate by an other vector.

Definition at line 663 of file Vector2D.h.

664 {
665 m_x = xy.x();
666 m_y = xy.y();
667 }

◆ setY()

void setY ( const double y)
inline

Setter for the y coordinate.

Definition at line 651 of file Vector2D.h.

652 {
653 m_y = y;
654 }

◆ sinWith()

double sinWith ( const Vector2D & rhs) const
inline

Sine of the angle between this and rhs.

Definition at line 223 of file Vector2D.h.

224 {
225 return cross(rhs) / (norm() * rhs.norm());
226 }

◆ subtract()

Vector2D & subtract ( const Vector2D & rhs)
inline

Subtracts a vector from this in place.

Definition at line 307 of file Vector2D.h.

308 {
309 m_x -= rhs.x();
310 m_y -= rhs.y();
311 return *this;
312 }

◆ swapCoordinates()

void swapCoordinates ( )
inline

Swaps the coordinates in place.

Definition at line 582 of file Vector2D.h.

583 {
584 std::swap(m_x, m_y);
585 }

◆ unit()

Vector2D unit ( ) const
inline

Returns a unit vector colaligned with this.

Definition at line 352 of file Vector2D.h.

353 {
354 return isNull() ? Vector2D(0.0, 0.0) : divided(norm());
355 }

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

478 {
479 return relativTo.cross(*this);
480 }

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

457 {
458 return relativTo.dot(*this);
459 }

◆ X()

double X ( ) const
inline

Getter for the x coordinate.

Definition at line 631 of file Vector2D.h.

632 {
633 return m_x;
634 }

◆ x()

double x ( ) const
inline

Getter for the x coordinate.

Definition at line 626 of file Vector2D.h.

627 {
628 return m_x;
629 }

◆ Y()

double Y ( ) const
inline

Getter for the y coordinate.

Definition at line 646 of file Vector2D.h.

647 {
648 return m_y;
649 }

◆ y()

double y ( ) const
inline

Getter for the y coordinate.

Definition at line 641 of file Vector2D.h.

642 {
643 return m_y;
644 }

Friends And Related Symbol Documentation

◆ operator*

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

Same as scaled()

Definition at line 262 of file Vector2D.h.

263 {
264 return vec2D.scaled(factor);
265 }

Member Data Documentation

◆ m_x

double m_x
private

Memory for the first coordinate.

Definition at line 705 of file Vector2D.h.

◆ m_y

double m_y
private

Memory for the second coordinate.

Definition at line 708 of file Vector2D.h.


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