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

A two dimensional normal line. More...

#include <Line2D.h>

Collaboration diagram for Line2D:

Public Member Functions

 Line2D ()
 Default constructor for ROOT compatibility.
 
 Line2D (const double n0, const double n1, const double n2)
 Constructs taking all three line parameters.
 
 Line2D (const double n0, const Vector2D &n12)
 Constructs taking the distance to the origin ( n0 ) and the normal vector.
 
double n0 () const
 Getter for the first line parameter.
 
double n1 () const
 Getter for the second line parameter.
 
double n2 () const
 Getter for the third line parameter.
 
const Vector2Dn12 () const
 Getter for the unit normal vector to the line.
 
void setN0 (const double n0)
 Setter for first line parameter This sets the signed distance of the line to the origin. More...
 
void setN (const double n0, const double n1, const double n2)
 Setter the for the line parameters which takes care of the correct normalization of the normal vector.
 
void invalidate ()
 Sets all line parameters to zero.
 
void setSlopeIntercept (const double slope, const double intercept)
 Sets the new intercept and slope of the line the direction is set to be forward with the increasing x axes.
 
void setSlopeIntercept (const double slope, const double intercept, const EForwardBackward orientation)
 Sets the new intercept and slope of the line the direction is set to be forward with the increasing x axes.
 
void normalize ()
 Updates the parameters to obey the normalization condition.
 
void reverse ()
 Flips orientation the line in place.
 
Line2D reversed () const
 Returns a copy of the line with the reversed orientation.
 
double distance (const Vector2D &point) const
 Calculates the signed distance of the point to the line. More...
 
double distance (const double first, const double second) const
 Calculates the signed distance of the point given by its to coordinates to the line. More...
 
double distanceToOrigin () const
 Returns the distance to the origin The distance to the origin is equivalent to the first line parameter.
 
double absoluteDistance (const Vector2D &point) const
 Returns the absolute value of distance(point)
 
ERightLeft isRightOrLeft (const Vector2D &point) const
 Return if the point given is right or left of the line.
 
bool isLeft (const Vector2D &rhs) const
 Return if the point given is left of the line.
 
bool isRight (const Vector2D &rhs) const
 Return if the point given is right of the line.
 
Vector2D closest (const Vector2D &point) const
 Calculates the point of closest approach on the line to the point.
 
Vector2D closestToOrigin () const
 Returns the point closest to the origin.
 
double lengthOnCurve (const Vector2D &from, const Vector2D &to) const
 Calculates the length on the curve between two points. More...
 
bool isInvalid () const
 Indicates if all circle parameters are zero.
 
Vector2D tangential () const
 Gives the tangential vector in the direction of positiv advance on the line.
 
const Vector2Dnormal () const
 Getter for the unit normal vector of the line.
 
const Vector2Dgradient () const
 Getter for the gradient of the distance field.
 
Vector2D support () const
 Getter for the support point of the line being the point closest to the origin.
 
EForwardBackward alignedWithFirst () const
 Returns if the direction of positiv advance has a common component aligned or anti aligned with the first coordinate.
 
EForwardBackward alignedWithSecond () const
 Returns if the direction of positiv advance has a common component aligned or anti aligned with the second coordinate.
 
Vector2D intersection (const Line2D &line) const
 Calculates the intersection point of two line. Infinity for parallels.
 
Transformations of the line
void moveBy (const Vector2D &by)
 Activelly moves the line in the direction given in place by the vector given.
 
void moveAlongFirst (const double first)
 Activelly moves the line in the direction given in place along the first coordinate.
 
void moveAlongSecond (const double second)
 Activelly moves the line in the direction given in place along the second coordinate.
 
Line2D movedAlongFirst (const double first) const
 Return a copy of the line activally moved long the first coordinate.
 
Line2D movedAlongSecond (const double second) const
 Return a copy of the line activally moved long the first coordinate.
 
void passiveMoveBy (const Vector2D &by)
 Passivelly move the coordinate system in place by the given vector.
 
void passiveMoveAlongFirst (const double first)
 Passively move the coordinate system in place along the first coordinate.
 
void passiveMoveAlongSecond (const double second)
 Passively move the coordinate system in place along the second coordinate.
 
Line2D passiveMovedAlongFirst (const double first) const
 Return a copy of the line passively moved long the first coordinate.
 
Line2D passiveMovedAlongSecond (const double second) const
 Return a copy of the line passively moved long the first coordinate.
 
void flipFirst ()
 Flips the first coordinate inplace (no difference between active and pasive)
 
void flipSecond ()
 Flips the first coordinate inplace (no difference between active and pasive)
 
Line2D flippedFirst () const
 Makes a copy of the line with the first coordinate flipped (no difference between active and pasive)
 
Line2D flippedSecond () const
 Makes a copy of the line with the second coordinate flipped (no difference between active and pasive)
 
Line as a function of the first coordinate
double slope () const
 Returns the slope over the first coordinate.
 
double inverseSlope () const
 Returns the slope over the second coordinate.
 
double intercept () const
 Returns the intercept over the first coordinate.
 
double zero () const
 Returns the root of the line.
 
double map (const double first) const
 Maps the first coordinate to the second.
 
double operator() (const double first) const
 Maps the first coordinate to the second.
 
double inverseMap (const double second) const
 Maps the second coordinate to the first.
 
void invert ()
 Turns the line function into its inverse function in place.
 
Line2D inverted () const
 Returns the inverse function line as a copy.
 

Static Public Member Functions

static Line2D fromSlopeIntercept (const double slope, const double intercept)
 Constructs a line from its slope and intercept over the first coordinate (default forward orientation). More...
 
static Line2D fromSlopeIntercept (const double slope, const double intercept, const EForwardBackward orientation)
 Constructs a line from its slope and intercept over the first coordinate with the given orientation. More...
 
static Line2D throughPoints (const Vector2D &start, const Vector2D &end)
 Constructs a line through the two given points.
 

Private Member Functions

void setN1 (const double n1)
 Setter for the second line parameter. May violate the normlization.
 
void setN2 (const double n2)
 Setter for the third line parameter. May violate the normlization.
 
void setN12 (const double n1, const double n2)
 Setter for the normal vector by its coordinates.
 
void setN12 (const Vector2D &n12)
 Setter for the normal vector.
 
void scaleN (const double factor)
 Scales all parameters. Helper for normalize.
 
double normalizationSquared () const
 Calculates the squared normalization. Helper for normalize.
 
double normalization () const
 Calculates the normalization. Helper for normalize.
 

Private Attributes

double m_n0
 Memory for the first line parameter.
 
Vector2D m_n12
 Memory for the second line parameter.
 

Detailed Description

A two dimensional normal line.

This class represents a line in two dimensional space by its normal definition n0 + n1*x + n2*y = 0 subjected to n1*n1 + n2*n2 = 1. The vector (n1, n2) is called unit normal vector. It has an orientation. It is defining a right half plane with all points having n0 + n1*x + n2*y > 0 and a left half plane for point having n0 + n1*x + n2*y < 0 This naturally corresponds to a direction of positiv advance being the tangential to the line (-n2, n1). This line is best suited for linear least square fits.

Definition at line 37 of file Line2D.h.

Member Function Documentation

◆ distance() [1/2]

double distance ( const double  first,
const double  second 
) const
inline

Calculates the signed distance of the point given by its to coordinates to the line.

Returns the signed distance of the point to the line. The sign is positiv
for the right side of the line and negativ for the left side.

Definition at line 253 of file Line2D.h.

254  {
255  return n0() + first * n1() + second * n2();
256  }
double n1() const
Getter for the second line parameter.
Definition: Line2D.h:105
double n2() const
Getter for the third line parameter.
Definition: Line2D.h:111
double n0() const
Getter for the first line parameter.
Definition: Line2D.h:99

◆ distance() [2/2]

double distance ( const Vector2D point) const
inline

Calculates the signed distance of the point to the line.

Returns the signed distance of the point to the line. The sign is positiv
for the right side of the line and negativ for the left side.

Definition at line 243 of file Line2D.h.

◆ fromSlopeIntercept() [1/2]

static Line2D fromSlopeIntercept ( const double  slope,
const double  intercept 
)
inlinestatic

Constructs a line from its slope and intercept over the first coordinate (default forward orientation).

Constucts a line of the points fullfilling y = slope *x + intercept. The Line2D has an additional orientation in contrast to y = slope *x + intercept. The default orientation for the line is forward with the positiv x axes.

Definition at line 70 of file Line2D.h.

◆ fromSlopeIntercept() [2/2]

static Line2D fromSlopeIntercept ( const double  slope,
const double  intercept,
const EForwardBackward  orientation 
)
inlinestatic

Constructs a line from its slope and intercept over the first coordinate with the given orientation.

Constucts a line of the points fullfilling y = slope *x + intercept. The Line2D has an additional orientation in contrast to y = slope *x + intercept. The forward backward info sets if the constructed line shall have the direction with increasing or
decreasing x respectivly.

Definition at line 84 of file Line2D.h.

◆ lengthOnCurve()

double lengthOnCurve ( const Vector2D from,
const Vector2D to 
) const
inline

Calculates the length on the curve between two points.

Takes to two point to their closest approach to the origin and calculates the distance between them. The length is signed take relativ to the direction of positiv advance.

Definition at line 312 of file Line2D.h.

◆ setN0()

void setN0 ( const double  n0)
inline

Setter for first line parameter This sets the signed distance of the line to the origin.

Its not involved in the normalization hence it can be exported as a public function.

Definition at line 129 of file Line2D.h.


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