Belle II Software development
ParameterLine2D Class Reference

A line with a support point and tangential vector. More...

#include <ParameterLine2D.h>

Public Member Functions

 ParameterLine2D ()
 Default constructor for ROOT compatibility.
 
 ParameterLine2D (const Vector2D &support, const Vector2D &tangential)
 Standard constructor taking the support point and the tangential vector.
 
 ParameterLine2D (const Line2D &line)
 Upcast the normal representation to a parameter line.
 
 operator Line2D ()
 Downcast the line to the normal representation.
 
const Vector2Dtangential () const
 Gives the tangential vector of the line.
 
Vector2D normal () const
 Gives the normal vector of the line.
 
const Vector2Dsupport () const
 Gives the support vector of the line.
 
Vector2D at (const double parameter) const
 Evaluates the line formula at the parameter given.
 
EForwardBackward alignedWithFirst () const
 Indicates if the tangential vector point in a common direction with the first coordinate axes.
 
EForwardBackward alignedWithSecond () const
 Indicates if the tangential vector point in a common direction with the second coordinate axes.
 
void normalize ()
 Normalizes the tangential vector inplace.
 
void invalidate ()
 Clear all information from the line.
 
bool isInvalid () const
 Check it the line is in an invalid state.
 
void reverse ()
 Reverses the tangential vector inplace.
 
ParameterLine2D reversed () const
 Makes a copy line which has the opposite tangential vector but same support point.
 
double distance (const Vector2D &point) const
 Gives the signed distance of a point to the line.
 
double distance (const double first, const double second) const
 Calculates the signed distance of the point given by its to coordinates to the line.
 
double distanceToOrigin () const
 Gives the signed distance of the origin.
 
double absoluteDistance (const Vector2D &point) const
 Gives the unsigned distance of a point to the line.
 
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
 Gives the position at the closest approach on the line to point.
 
double closestAt (const Vector2D &point) const
 Gives the line parameter at the closest approach to point.
 
Vector2D closestToOrigin () const
 Gives the position of closest approach to the origin.
 
double closestToOriginAt () const
 Gives the line parameter at the closest approach to the origin.
 
double lengthOnCurve (const Vector2D &from, const Vector2D &to) const
 Denotes the length on the line between the two points.
 
double intersectionAt (const Line2D &line) const
 Gives the line parameter where the two lines meet. Infinity for parallels.
 
double intersectionAt (const ParameterLine2D &line) const
 Gives the line parameter of this line where the two lines meet. Infinity for parallels.
 
std::pair< double, double > intersectionsAt (const GeneralizedCircle &genCircle) const
 Gives the line parameters of this line, where it intersects with the generalized circle.
 
Vector2D intersection (const Line2D &line) const
 Gives the point where the two lines meet. Infinities for parallels.
 
Vector2D intersection (const ParameterLine2D &line) const
 Gives the point where the two lines meet. Infinities for parallels.
 
Transformations of the line
void passiveMoveAtBy (const double delta)
 Moves the support point by the given amount of the parameter in the forward direction.
 
void moveBy (const Vector2D &by)
 Moves the line in the given direction in place. Corresponds to an active transformation.
 
void moveAlongFirst (const double first)
 Moves the line along the first coordinate axes in place.
 
void moveAlongSecond (const double second)
 Moves the line along the second coordinate axes in place.
 
void passiveMoveBy (const Vector2D &by)
 Moves the coordinate system in the given direction in place.
 
void passiveMoveAlongFirst (const double first)
 Moves the coordinate system along the first coordinate axes in place.
 
void passiveMoveAlongSecond (const double second)
 Moves the coordinate system along the second coordinate axes in place.
 
Line as a function of the first coordinate

The next couple of methods are to interpret the line as a function mapping from first to second coordinate

double slope () const
 The line slope.
 
double inverseSlope () const
 The inverse line slope.
 
double intercept () const
 Second coordinate for first being zero.
 
double zero () const
 First coordinate for second being zero.
 
double map (const double first) const
 Method mapping the first coordinate to the second according to the line.
 
double operator() (const double first) const
 Operator mapping the first coordinate to the second according to the line.
 
double inverseMap (const double second) const
 Method for the inverse mapping the second coordinate to the first according to the line.
 
void invert ()
 Turns the line into its inverse function in place. Orientation will be flipped as well.
 
ParameterLine2D inverted () const
 Gives the line associated with the inverse function as a copy.
 

Static Public Member Functions

static ParameterLine2D fromSlopeIntercept (const double slope, const double intercept)
 Constructs a line with slope and intercept.
 
static ParameterLine2D fromSlopeIntercept (const double slope, const double intercept, const EForwardBackward orientation)
 Constructs a line with slope and intercept.
 
static ParameterLine2D throughPoints (const Vector2D &start, const Vector2D &end)
 Static constructor for a line between to points.
 
static ParameterLine2D touchingCircles (const Vector2D &fromCenter, double fromSignedRadius, const Vector2D &toCenter, double toSignedRadius)
 Constructs a line touching two circles in one point each.
 

Private Attributes

Vector2D m_support
 Support vector of the line.
 
Vector2D m_tangential
 Tangential vector of the line.
 

Detailed Description

A line with a support point and tangential vector.

Implements the representation $ x = s + \lambda \cdot t $ where
$ s $ is the support point and $ t $ is the tangential vector
$ \lambda $ is called the parameter of the line. In the same sense as the Line2D
this line defines a direction of positive advance ( the tangential vector ) as well as
a right and a left half plane.

Definition at line 38 of file ParameterLine2D.h.

Constructor & Destructor Documentation

◆ ParameterLine2D() [1/3]

ParameterLine2D ( )
inline

Default constructor for ROOT compatibility.

Definition at line 42 of file ParameterLine2D.h.

43 : m_support(0.0, 0.0)
44 , m_tangential(0.0, 0.0)
45 {
46 }
Vector2D m_support
Support vector of the line.
Vector2D m_tangential
Tangential vector of the line.

◆ ParameterLine2D() [2/3]

ParameterLine2D ( const Vector2D support,
const Vector2D tangential 
)
inline

Standard constructor taking the support point and the tangential vector.

Definition at line 49 of file ParameterLine2D.h.

52 {
53 }
const Vector2D & support() const
Gives the support vector of the line.
const Vector2D & tangential() const
Gives the tangential vector of the line.

◆ ParameterLine2D() [3/3]

ParameterLine2D ( const Line2D line)
inlineexplicit

Upcast the normal representation to a parameter line.

Upcasting requires some additional information to be set namely the support point and the scale of the tangential. The support is set the point closest to the origin. The tangential is of unit length. Note the orientation of the line remains the same.

Definition at line 93 of file ParameterLine2D.h.

94 : m_support(line.support())
95 , m_tangential(line.tangential())
96 {
97 }

Member Function Documentation

◆ absoluteDistance()

double absoluteDistance ( const Vector2D point) const
inline

Gives the unsigned distance of a point to the line.

Definition at line 221 of file ParameterLine2D.h.

222 {
223 return fabs(distance(point));
224 }
double distance(const Vector2D &point) const
Gives the signed distance of a point to the line.

◆ alignedWithFirst()

EForwardBackward alignedWithFirst ( ) const
inline

Indicates if the tangential vector point in a common direction with the first coordinate axes.

Definition at line 149 of file ParameterLine2D.h.

150 {
151 return static_cast<EForwardBackward>(sign(tangential().first()));
152 }
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.

◆ alignedWithSecond()

EForwardBackward alignedWithSecond ( ) const
inline

Indicates if the tangential vector point in a common direction with the second coordinate axes.

Definition at line 156 of file ParameterLine2D.h.

157 {
158 return static_cast<EForwardBackward>(sign(tangential().second()));
159 }

◆ at()

Vector2D at ( const double  parameter) const
inline

Evaluates the line formula at the parameter given.

Definition at line 142 of file ParameterLine2D.h.

143 {
144 return tangential() * parameter += support();
145 }

◆ closest()

Vector2D closest ( const Vector2D point) const
inline

Gives the position at the closest approach on the line to point.

Definition at line 245 of file ParameterLine2D.h.

246 {
247 double norm_squared = tangential().normSquared();
248 return Vector2D(tangential(),
249 tangential().dot(point) / norm_squared,
250 tangential().cross(support()) / norm_squared);
251 }
double normSquared() const
Calculates .
Definition: Vector2D.h:169
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
Definition: beamHelpers.h:163

◆ closestAt()

double closestAt ( const Vector2D point) const
inline

Gives the line parameter at the closest approach to point.

Definition at line 254 of file ParameterLine2D.h.

255 {
256 return (tangential().dot(point) - tangential().dot(support())) / tangential().normSquared();
257 }

◆ closestToOrigin()

Vector2D closestToOrigin ( ) const
inline

Gives the position of closest approach to the origin.

Definition at line 260 of file ParameterLine2D.h.

261 {
262 return tangential().orthogonal() *=
264 }
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
Definition: Vector2D.h:163
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:289

◆ closestToOriginAt()

double closestToOriginAt ( ) const
inline

Gives the line parameter at the closest approach to the origin.

Definition at line 267 of file ParameterLine2D.h.

268 {
269 return -tangential().dot(support()) / tangential().normSquared();
270 }
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
Definition: Vector2D.h:158

◆ 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 positive
for the right side of the line and negative for the left side.

Definition at line 209 of file ParameterLine2D.h.

210 {
211 return distance(Vector2D(first, second));
212 }

◆ distance() [2/2]

double distance ( const Vector2D point) const
inline

Gives the signed distance of a point to the line.

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

Definition at line 201 of file ParameterLine2D.h.

202 {
203 return distanceToOrigin() - point.orthogonalComp(tangential());
204 }
double distanceToOrigin() const
Gives the signed distance of the origin.

◆ distanceToOrigin()

double distanceToOrigin ( ) const
inline

Gives the signed distance of the origin.

Definition at line 215 of file ParameterLine2D.h.

216 {
218 }
double orthogonalComp(const Vector2D &relativTo) const
Calculates the component orthogonal to the given vector.
Definition: Vector2D.h:432

◆ fromSlopeIntercept() [1/2]

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

Constructs a line with slope and intercept.

Orientation will be coaligned with the first axes. Tangential vector is normalized to have a unit in the first coordinate.

Definition at line 59 of file ParameterLine2D.h.

60 {
61 return ParameterLine2D(Vector2D(0.0, intercept), Vector2D(1.0, slope));
62 }
ParameterLine2D()
Default constructor for ROOT compatibility.
double slope() const
The line slope.
double intercept() const
Second coordinate for first being zero.

◆ fromSlopeIntercept() [2/2]

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

Constructs a line with slope and intercept.

Orientation means the alignment with the first axes. Orientation will be coaligned or antialigned as given. Tangential vector is normalized to have a unit in the first coordinate.

Definition at line 69 of file ParameterLine2D.h.

72 {
73 return ParameterLine2D(Vector2D(0.0, intercept),
74 Vector2D(orientation, static_cast<double>(orientation) * slope));
75 }

◆ intercept()

double intercept ( ) const
inline

Second coordinate for first being zero.

Definition at line 388 of file ParameterLine2D.h.

389 {
390 return support().second() - slope() * support().first();
391 }
double second() const
Getter for the second coordinate.
Definition: Vector2D.h:639
double first() const
Getter for the first coordinate.
Definition: Vector2D.h:629

◆ intersection() [1/2]

Vector2D intersection ( const Line2D line) const
inline

Gives the point where the two lines meet. Infinities for parallels.

Definition at line 306 of file ParameterLine2D.h.

307 {
308 return at(intersectionAt(line));
309 }
Vector2D at(const double parameter) const
Evaluates the line formula at the parameter given.
double intersectionAt(const Line2D &line) const
Gives the line parameter where the two lines meet. Infinity for parallels.

◆ intersection() [2/2]

Vector2D intersection ( const ParameterLine2D line) const
inline

Gives the point where the two lines meet. Infinities for parallels.

Definition at line 312 of file ParameterLine2D.h.

313 {
314 return at(intersectionAt(line));
315 }

◆ intersectionAt() [1/2]

double intersectionAt ( const Line2D line) const
inline

Gives the line parameter where the two lines meet. Infinity for parallels.

Definition at line 279 of file ParameterLine2D.h.

280 {
281 return -(line.n0() + support().dot(line.normal())) / tangential().dot(line.normal());
282 }

◆ intersectionAt() [2/2]

double intersectionAt ( const ParameterLine2D line) const
inline

Gives the line parameter of this line where the two lines meet. Infinity for parallels.

Definition at line 285 of file ParameterLine2D.h.

286 {
287 return (line.tangential().cross(support()) - line.tangential().cross(line.support())) /
288 tangential().cross(line.tangential());
289 }

◆ intersectionsAt()

std::pair< double, double > intersectionsAt ( const GeneralizedCircle genCircle) const
inline

Gives the line parameters of this line, where it intersects with the generalized circle.

Calculates the two line parameters of the intersections with the circle as a pair. The second of the pair is always the small of the two solutions, which is closer to the support point.

Definition at line 296 of file ParameterLine2D.h.

297 {
298 double a = genCircle.n3() * tangential().normSquared();
299 double b = tangential().dot(genCircle.gradient(support()));
300 double c = genCircle.fastDistance(support());
301
302 return solveQuadraticABC(a, b, c);
303 }

◆ invalidate()

void invalidate ( )
inline

Clear all information from the line.

Definition at line 173 of file ParameterLine2D.h.

174 {
175 m_support.set(0, 0);
176 m_tangential.set(0, 0);
177 }
void set(const double first, const double second)
Setter for both coordinate.
Definition: Vector2D.h:650

◆ inverseMap()

double inverseMap ( const double  second) const
inline

Method for the inverse mapping the second coordinate to the first according to the line.

Definition at line 412 of file ParameterLine2D.h.

413 {
414 return support().first() + inverseSlope() * (second - support().second());
415 }
double inverseSlope() const
The inverse line slope.

◆ inverseSlope()

double inverseSlope ( ) const
inline

The inverse line slope.

Definition at line 382 of file ParameterLine2D.h.

383 {
384 return tangential().first() / tangential().second();
385 }

◆ invert()

void invert ( )
inline

Turns the line into its inverse function in place. Orientation will be flipped as well.

Definition at line 418 of file ParameterLine2D.h.

419 {
422 }
void swapCoordinates()
Swaps the coordinates in place.
Definition: Vector2D.h:551

◆ inverted()

ParameterLine2D inverted ( ) const
inline

Gives the line associated with the inverse function as a copy.

Definition at line 425 of file ParameterLine2D.h.

426 {
427 return ParameterLine2D(Vector2D(support().second(), support().first()),
428 Vector2D(tangential().second(), tangential().first()));
429 }

◆ isInvalid()

bool isInvalid ( ) const
inline

Check it the line is in an invalid state.

Definition at line 180 of file ParameterLine2D.h.

181 {
182 return m_tangential.isNull();
183 }
bool isNull() const
Checks if the vector is the null vector.
Definition: Vector2D.h:143

◆ isLeft()

bool isLeft ( const Vector2D rhs) const
inline

Return if the point given is left of the line.

Definition at line 233 of file ParameterLine2D.h.

234 {
235 return isRightOrLeft(rhs) == ERightLeft::c_Left;
236 }
ERightLeft isRightOrLeft(const Vector2D &point) const
Return if the point given is right or left of the line.

◆ isRight()

bool isRight ( const Vector2D rhs) const
inline

Return if the point given is right of the line.

Definition at line 239 of file ParameterLine2D.h.

240 {
241 return isRightOrLeft(rhs) == ERightLeft::c_Right;
242 }

◆ isRightOrLeft()

ERightLeft isRightOrLeft ( const Vector2D point) const
inline

Return if the point given is right or left of the line.

Definition at line 227 of file ParameterLine2D.h.

228 {
229 return static_cast<ERightLeft>(sign(distance(point)));
230 }
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25

◆ lengthOnCurve()

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

Denotes the length on the line between the two points.

Definition at line 273 of file ParameterLine2D.h.

274 {
275 return (to.dot(tangential()) - from.dot(tangential())) / tangential().norm();
276 }
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:175

◆ map()

double map ( const double  first) const
inline

Method mapping the first coordinate to the second according to the line.

Definition at line 400 of file ParameterLine2D.h.

401 {
402 return support().second() + slope() * (first - support().first());
403 }

◆ moveAlongFirst()

void moveAlongFirst ( const double  first)
inline

Moves the line along the first coordinate axes in place.

Corresponds to an active transformation.

Definition at line 336 of file ParameterLine2D.h.

337 {
339 }
void setFirst(const double first)
Setter for the first coordinate.
Definition: Vector2D.h:634

◆ moveAlongSecond()

void moveAlongSecond ( const double  second)
inline

Moves the line along the second coordinate axes in place.

Corresponds to an active transformation.

Definition at line 343 of file ParameterLine2D.h.

344 {
346 }
void setSecond(const double second)
Setter for the second coordinate.
Definition: Vector2D.h:644

◆ moveBy()

void moveBy ( const Vector2D by)
inline

Moves the line in the given direction in place. Corresponds to an active transformation.

Definition at line 329 of file ParameterLine2D.h.

330 {
331 m_support += by;
332 }

◆ normal()

Vector2D normal ( ) const
inline

Gives the normal vector of the line.

Definition at line 130 of file ParameterLine2D.h.

131 {
132 return tangential().orthogonal(ERotation::c_Clockwise);
133 }

◆ normalize()

void normalize ( )
inline

Normalizes the tangential vector inplace.

Normalizes the line representation such that the parameter is identical with the distance from the support point of a point on the line. This can be useful if you want to give the parameter a certain meaning where you have to get rid of the proportional factor associated with the length of the tangential.

Definition at line 167 of file ParameterLine2D.h.

168 {
170 }
double normalize()
Normalizes the vector to unit length.
Definition: Vector2D.h:303

◆ operator Line2D()

operator Line2D ( )
inline

Downcast the line to the normal representation.

Downcasting the parameter line to the line representation using the normal vector. You loose the information where the support point is and the scale of the parameter. However the same points lie on the line and distance to is remain the same

Definition at line 118 of file ParameterLine2D.h.

119 {
120 return Line2D(distanceToOrigin(), normal().unit());
121 } // not optimal yet. tangential.norm() is getting calculated two times.
Vector2D normal() const
Gives the normal vector of the line.

◆ operator()()

double operator() ( const double  first) const
inline

Operator mapping the first coordinate to the second according to the line.

Definition at line 406 of file ParameterLine2D.h.

407 {
408 return map(first);
409 }
double map(const double first) const
Method mapping the first coordinate to the second according to the line.

◆ passiveMoveAlongFirst()

void passiveMoveAlongFirst ( const double  first)
inline

Moves the coordinate system along the first coordinate axes in place.

Corresponds to a passive transformation.

Definition at line 357 of file ParameterLine2D.h.

358 {
360 }

◆ passiveMoveAlongSecond()

void passiveMoveAlongSecond ( const double  second)
inline

Moves the coordinate system along the second coordinate axes in place.

Corresponds to a passive transformation.

Definition at line 364 of file ParameterLine2D.h.

365 {
367 }

◆ passiveMoveAtBy()

void passiveMoveAtBy ( const double  delta)
inline

Moves the support point by the given amount of the parameter in the forward direction.

This moves the parameter by -delta and the following relation hold
old at(p) = new at(p - delta) hence the coordinate at is diminished
This corresponds to a passive movement of the coordinate system on the line

Definition at line 323 of file ParameterLine2D.h.

324 {
325 m_support += tangential() * delta;
326 }

◆ passiveMoveBy()

void passiveMoveBy ( const Vector2D by)
inline

Moves the coordinate system in the given direction in place.

Corresponds to a passive transformation.

Definition at line 350 of file ParameterLine2D.h.

351 {
352 m_support -= by;
353 }

◆ reverse()

void reverse ( )
inline

Reverses the tangential vector inplace.

Definition at line 186 of file ParameterLine2D.h.

187 {
189 }
Vector2D & reverse()
Reverses the direction of the vector in place.
Definition: Vector2D.h:327

◆ reversed()

ParameterLine2D reversed ( ) const
inline

Makes a copy line which has the opposite tangential vector but same support point.

Definition at line 192 of file ParameterLine2D.h.

193 {
194 return ParameterLine2D(support(), -tangential());
195 }

◆ slope()

double slope ( ) const
inline

The line slope.

Definition at line 376 of file ParameterLine2D.h.

377 {
378 return tangential().second() / tangential().first();
379 }

◆ support()

const Vector2D & support ( ) const
inline

Gives the support vector of the line.

Definition at line 136 of file ParameterLine2D.h.

137 {
138 return m_support;
139 }

◆ tangential()

const Vector2D & tangential ( ) const
inline

Gives the tangential vector of the line.

Definition at line 125 of file ParameterLine2D.h.

126 {
127 return m_tangential;
128 }

◆ throughPoints()

static ParameterLine2D throughPoints ( const Vector2D start,
const Vector2D end 
)
inlinestatic

Static constructor for a line between to points.

The resulting line will have start as support. Tangential vector is the difference between end and start. Hence at(0) == start and at(1) == end for the constructed line.

Definition at line 82 of file ParameterLine2D.h.

83 {
84 return ParameterLine2D(start, end - start);
85 }

◆ touchingCircles()

ParameterLine2D touchingCircles ( const Vector2D fromCenter,
double  fromSignedRadius,
const Vector2D toCenter,
double  toSignedRadius 
)
static

Constructs a line touching two circles in one point each.

Parameters
[in]fromCenterfirst circle center
[in]fromSignedRadiusradius of the first circle multiplied with the right left passage information
[in]toCentersecond circle center
[in]toSignedRadiusradius of the first circle multiplied with the right left passage information.
Returns
the line being tangential to both circles. Note : the touch points reside at(0) for the first and at(1) for the second

Definition at line 17 of file ParameterLine2D.cc.

21{
22 Vector2D connecting = toCenter - fromCenter;
23
24 // Normalize to the coordinate system vector, but keep the original norm
25 const double norm = connecting.normalize();
26
27 double kappa = (fromSignedRadius - toSignedRadius) / norm;
28 double cokappa = sqrt(1 - kappa * kappa);
29
30 Vector2D fromPos = Vector2D(connecting, kappa * fromSignedRadius, cokappa * fromSignedRadius);
31 fromPos += fromCenter;
32
33 Vector2D toPos = Vector2D(connecting, kappa * toSignedRadius, cokappa * toSignedRadius);
34 toPos += toCenter;
35
36 return ParameterLine2D::throughPoints(fromPos, toPos);
37}
static ParameterLine2D throughPoints(const Vector2D &start, const Vector2D &end)
Static constructor for a line between to points.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
Definition: Vector2D.h:32
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ zero()

double zero ( ) const
inline

First coordinate for second being zero.

Definition at line 394 of file ParameterLine2D.h.

395 {
396 return support().first() - inverseSlope() * support().second();
397 }

Member Data Documentation

◆ m_support

Vector2D m_support
private

Support vector of the line.

Definition at line 434 of file ParameterLine2D.h.

◆ m_tangential

Vector2D m_tangential
private

Tangential vector of the line.

Definition at line 437 of file ParameterLine2D.h.


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