Belle II Software  release-08-01-10
Vector2D Class Reference

A two dimensional vector which is equipped with functions for correct handeling
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 TVector2 &tVector2)
 Constructor translating from a TVector2 instance.
 
 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. More...
 
Vector2Doperator= (const TVector2 &tvector)
 Assignment translating from a TVector2 instance.
 
 operator const TVector2 ()
 Casting the back to TVector2 seamlessly.
 
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. More...
 
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. More...
 
double normalizeTo (const double toLength)
 Normalizes the vector to the given length. More...
 
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. More...
 
Vector2D conformalTransformed () const
 Returns a copy of the vector transformed in conformal space. More...
 
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. More...
 
double orthogonalComp (const Vector2D &relativTo) const
 Calculates the component orthogonal to the given vector. More...
 
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. More...
 
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. More...
 
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 positve counterclockwise direction.

So a positiv 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)
 Constucts 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. More...
 
static Vector2D average (const Vector2D &one, const Vector2D &two)
 Constructs the average of two vectors. More...
 
static Vector2D average (const Vector2D &one, const Vector2D &two, const Vector2D &three)
 Constructs the average of three vectors. More...
 
static Vector2D getLowest ()
 Getter for the lowest possible vector. More...
 

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 handeling
of orientation related issues in addition to the expected vector methods.


Also this vector can be passed to functions where a TVector2 is expected syntactically.

Definition at line 35 of file Vector2D.h.

Constructor & Destructor Documentation

◆ Vector2D()

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

62  : m_x(coordinateVec.x() * parallelCoor - coordinateVec.y() * orthoCoor)
63  , m_y(coordinateVec.y() * parallelCoor + coordinateVec.x() * orthoCoor)
64  {
65  }
double m_x
Memory for the first coordinate.
Definition: Vector2D.h:676
double m_y
Memory for the second coordinate.
Definition: Vector2D.h:679

Member Function Documentation

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

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

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

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

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

◆ cosWith()

double cosWith ( const Vector2D rhs) const
inline

Cosine of the angle between this and rhs

Definition at line 199 of file Vector2D.h.

◆ getLowest()

static Vector2D getLowest ( )
inlinestatic

Getter for the lowest possible vector.

The lowest possilbe vector according to the comparision is the null vector

Definition at line 149 of file Vector2D.h.

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

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

◆ operator<()

bool operator< ( const Vector2D rhs) const
inline

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

Total order achiving a absolute lower bound Vector2D(0.0, 0.0). By first taking the cylindrical radius
for comparision 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 141 of file Vector2D.h.

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

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

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

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


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