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 ROOT::Math::XYVector &support, const ROOT::Math::XYVector &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 ROOT::Math::XYVector & tangential () const
 Gives the tangential vector of the line.
 
ROOT::Math::XYVector normal () const
 Gives the normal vector of the line.
 
const ROOT::Math::XYVector & support () const
 Gives the support vector of the line.
 
ROOT::Math::XYVector 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 ROOT::Math::XYVector &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 ROOT::Math::XYVector &point) const
 Gives the unsigned distance of a point to the line.
 
ERightLeft isRightOrLeft (const ROOT::Math::XYVector &point) const
 Return if the point given is right or left of the line.
 
bool isLeft (const ROOT::Math::XYVector &rhs) const
 Return if the point given is left of the line.
 
bool isRight (const ROOT::Math::XYVector &rhs) const
 Return if the point given is right of the line.
 
ROOT::Math::XYVector closest (const ROOT::Math::XYVector &point) const
 Gives the position at the closest approach on the line to point.
 
double closestAt (const ROOT::Math::XYVector &point) const
 Gives the line parameter at the closest approach to point.
 
ROOT::Math::XYVector 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 ROOT::Math::XYVector &from, const ROOT::Math::XYVector &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.
 
ROOT::Math::XYVector intersection (const Line2D &line) const
 Gives the point where the two lines meet. Infinities for parallels.
 
ROOT::Math::XYVector 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 ROOT::Math::XYVector &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 ROOT::Math::XYVector &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 ROOT::Math::XYVector &start, const ROOT::Math::XYVector &end)
 Static constructor for a line between to points.
 
static ParameterLine2D touchingCircles (const ROOT::Math::XYVector &fromCenter, double fromSignedRadius, const ROOT::Math::XYVector &toCenter, double toSignedRadius)
 Constructs a line touching two circles in one point each.
 

Private Attributes

ROOT::Math::XYVector m_support
 Support vector of the line.
 
ROOT::Math::XYVector 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 40 of file ParameterLine2D.h.

Constructor & Destructor Documentation

◆ ParameterLine2D() [1/3]

ParameterLine2D ( )
inline

Default constructor for ROOT compatibility.

Definition at line 44 of file ParameterLine2D.h.

45 : m_support(0.0, 0.0)
46 , m_tangential(0.0, 0.0)
47 {
48 }

◆ ParameterLine2D() [2/3]

ParameterLine2D ( const ROOT::Math::XYVector & support,
const ROOT::Math::XYVector & tangential )
inline

Standard constructor taking the support point and the tangential vector.

Definition at line 51 of file ParameterLine2D.h.

52 : m_support(support)
53 , m_tangential(tangential)
54 {
55 }

◆ 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 95 of file ParameterLine2D.h.

96 : m_support(line.support())
97 , m_tangential(line.tangential())
98 {
99 }

Member Function Documentation

◆ absoluteDistance()

double absoluteDistance ( const ROOT::Math::XYVector & point) const
inline

Gives the unsigned distance of a point to the line.

Definition at line 225 of file ParameterLine2D.h.

226 {
227 return fabs(distance(point));
228 }

◆ alignedWithFirst()

EForwardBackward alignedWithFirst ( ) const
inline

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

Definition at line 151 of file ParameterLine2D.h.

152 {
153 return static_cast<EForwardBackward>(sign(tangential().X()));
154 }
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 158 of file ParameterLine2D.h.

159 {
160 return static_cast<EForwardBackward>(sign(tangential().Y()));
161 }

◆ at()

ROOT::Math::XYVector at ( const double parameter) const
inline

Evaluates the line formula at the parameter given.

Definition at line 144 of file ParameterLine2D.h.

145 {
146 return tangential() * parameter += support();
147 }

◆ closest()

ROOT::Math::XYVector closest ( const ROOT::Math::XYVector & point) const
inline

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

Definition at line 249 of file ParameterLine2D.h.

250 {
251 double norm_squared = tangential().Mag2();
252 return VectorUtil::compose(tangential(),
253 tangential().Dot(point) / norm_squared,
254 VectorUtil::Cross(tangential(), support()) / norm_squared);
255 }

◆ closestAt()

double closestAt ( const ROOT::Math::XYVector & point) const
inline

Gives the line parameter at the closest approach to point.

Definition at line 258 of file ParameterLine2D.h.

259 {
260 return (tangential().Dot(point) - tangential().Dot(support())) / tangential().Mag2();
261 }

◆ closestToOrigin()

ROOT::Math::XYVector closestToOrigin ( ) const
inline

Gives the position of closest approach to the origin.

Definition at line 264 of file ParameterLine2D.h.

265 {
266 return VectorUtil::Orthogonal(tangential()) *
267 (VectorUtil::Cross(tangential(), support()) / tangential().Mag2());
268 }

◆ closestToOriginAt()

double closestToOriginAt ( ) const
inline

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

Definition at line 271 of file ParameterLine2D.h.

272 {
273 return -tangential().Dot(support()) / tangential().Mag2();
274 }

◆ 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 213 of file ParameterLine2D.h.

214 {
215 return distance(ROOT::Math::XYVector(first, second));
216 }

◆ distance() [2/2]

double distance ( const ROOT::Math::XYVector & 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 205 of file ParameterLine2D.h.

206 {
207 return distanceToOrigin() - VectorUtil::orthogonalComp(point, tangential());
208 }

◆ distanceToOrigin()

double distanceToOrigin ( ) const
inline

Gives the signed distance of the origin.

Definition at line 219 of file ParameterLine2D.h.

220 {
221 return VectorUtil::orthogonalComp(support(), tangential());
222 }

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

62 {
63 return ParameterLine2D(ROOT::Math::XYVector(0.0, intercept), ROOT::Math::XYVector(1.0, slope));
64 }

◆ 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 71 of file ParameterLine2D.h.

74 {
75 return ParameterLine2D(ROOT::Math::XYVector(0.0, intercept),
76 ROOT::Math::XYVector(orientation, static_cast<double>(orientation) * slope));
77 }

◆ intercept()

double intercept ( ) const
inline

Second coordinate for first being zero.

Definition at line 392 of file ParameterLine2D.h.

393 {
394 return support().Y() - slope() * support().X();
395 }

◆ intersection() [1/2]

ROOT::Math::XYVector intersection ( const Line2D & line) const
inline

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

Definition at line 310 of file ParameterLine2D.h.

311 {
312 return at(intersectionAt(line));
313 }

◆ intersection() [2/2]

ROOT::Math::XYVector intersection ( const ParameterLine2D & line) const
inline

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

Definition at line 316 of file ParameterLine2D.h.

317 {
318 return at(intersectionAt(line));
319 }

◆ 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 283 of file ParameterLine2D.h.

284 {
285 return -(line.n0() + support().Dot(line.normal())) / tangential().Dot(line.normal());
286 }

◆ 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 289 of file ParameterLine2D.h.

290 {
291 return (VectorUtil::Cross(line.tangential(), support()) - VectorUtil::Cross(line.tangential(), line.support())) /
292 VectorUtil::Cross(tangential(), line.tangential());
293 }

◆ 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 300 of file ParameterLine2D.h.

301 {
302 double a = genCircle.n3() * tangential().Mag2();
303 double b = tangential().Dot(genCircle.gradient(support()));
304 double c = genCircle.fastDistance(support());
305
306 return solveQuadraticABC(a, b, c);
307 }

◆ invalidate()

void invalidate ( )
inline

Clear all information from the line.

Definition at line 177 of file ParameterLine2D.h.

178 {
179 m_support.SetXY(0, 0);
180 m_tangential.SetXY(0, 0);
181 }

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

417 {
418 return support().X() + inverseSlope() * (second - support().Y());
419 }

◆ inverseSlope()

double inverseSlope ( ) const
inline

The inverse line slope.

Definition at line 386 of file ParameterLine2D.h.

387 {
388 return tangential().X() / tangential().Y();
389 }

◆ invert()

void invert ( )
inline

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

Definition at line 422 of file ParameterLine2D.h.

423 {
424 m_tangential.SetXY(m_tangential.Y(), m_tangential.X());
425 m_support.SetXY(m_support.Y(), m_support.X());
426 }

◆ inverted()

ParameterLine2D inverted ( ) const
inline

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

Definition at line 429 of file ParameterLine2D.h.

430 {
431 return ParameterLine2D(ROOT::Math::XYVector(support().Y(), support().X()),
432 ROOT::Math::XYVector(tangential().Y(), tangential().X()));
433 }

◆ isInvalid()

bool isInvalid ( ) const
inline

Check it the line is in an invalid state.

Definition at line 184 of file ParameterLine2D.h.

185 {
186 return VectorUtil::isNull(m_tangential);
187 }

◆ isLeft()

bool isLeft ( const ROOT::Math::XYVector & rhs) const
inline

Return if the point given is left of the line.

Definition at line 237 of file ParameterLine2D.h.

238 {
239 return isRightOrLeft(rhs) == ERightLeft::c_Left;
240 }

◆ isRight()

bool isRight ( const ROOT::Math::XYVector & rhs) const
inline

Return if the point given is right of the line.

Definition at line 243 of file ParameterLine2D.h.

244 {
245 return isRightOrLeft(rhs) == ERightLeft::c_Right;
246 }

◆ isRightOrLeft()

ERightLeft isRightOrLeft ( const ROOT::Math::XYVector & point) const
inline

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

Definition at line 231 of file ParameterLine2D.h.

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

◆ lengthOnCurve()

double lengthOnCurve ( const ROOT::Math::XYVector & from,
const ROOT::Math::XYVector & to ) const
inline

Denotes the length on the line between the two points.

Definition at line 277 of file ParameterLine2D.h.

278 {
279 return (to.Dot(tangential()) - from.Dot(tangential())) / tangential().R();
280 }

◆ map()

double map ( const double first) const
inline

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

Definition at line 404 of file ParameterLine2D.h.

405 {
406 return support().Y() + slope() * (first - support().X());
407 }

◆ 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 340 of file ParameterLine2D.h.

341 {
342 m_support.SetX(m_support.X() + first);
343 }

◆ 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 347 of file ParameterLine2D.h.

348 {
349 m_support.SetY(m_support.Y() + second);
350 }

◆ moveBy()

void moveBy ( const ROOT::Math::XYVector & by)
inline

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

Definition at line 333 of file ParameterLine2D.h.

334 {
335 m_support += by;
336 }

◆ normal()

ROOT::Math::XYVector normal ( ) const
inline

Gives the normal vector of the line.

Definition at line 132 of file ParameterLine2D.h.

133 {
134 return VectorUtil::Orthogonal(tangential(), ERotation::c_Clockwise);
135 }

◆ 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 169 of file ParameterLine2D.h.

170 {
171 if (m_tangential.R() != 0.0) {
172 m_tangential *= (1. / m_tangential.R());
173 }
174 }

◆ 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 120 of file ParameterLine2D.h.

121 {
122 return Line2D(distanceToOrigin(), VectorUtil::unit(normal()));
123 } // not optimal yet. tangential.R() is getting calculated two times.

◆ operator()()

double operator() ( const double first) const
inline

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

Definition at line 410 of file ParameterLine2D.h.

411 {
412 return map(first);
413 }

◆ 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 361 of file ParameterLine2D.h.

362 {
363 m_support.SetX(m_support.X() - first);
364 }

◆ 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 368 of file ParameterLine2D.h.

369 {
370 m_support.SetY(m_support.Y() - second);
371 }

◆ 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 327 of file ParameterLine2D.h.

328 {
329 m_support += tangential() * delta;
330 }

◆ passiveMoveBy()

void passiveMoveBy ( const ROOT::Math::XYVector & by)
inline

Moves the coordinate system in the given direction in place.

Corresponds to a passive transformation.

Definition at line 354 of file ParameterLine2D.h.

355 {
356 m_support -= by;
357 }

◆ reverse()

void reverse ( )
inline

Reverses the tangential vector inplace.

Definition at line 190 of file ParameterLine2D.h.

191 {
192 m_tangential = -m_tangential;
193 }

◆ reversed()

ParameterLine2D reversed ( ) const
inline

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

Definition at line 196 of file ParameterLine2D.h.

197 {
198 return ParameterLine2D(support(), -tangential());
199 }

◆ slope()

double slope ( ) const
inline

The line slope.

Definition at line 380 of file ParameterLine2D.h.

381 {
382 return tangential().Y() / tangential().X();
383 }

◆ support()

const ROOT::Math::XYVector & support ( ) const
inline

Gives the support vector of the line.

Definition at line 138 of file ParameterLine2D.h.

139 {
140 return m_support;
141 }

◆ tangential()

const ROOT::Math::XYVector & tangential ( ) const
inline

Gives the tangential vector of the line.

Definition at line 127 of file ParameterLine2D.h.

128 {
129 return m_tangential;
130 }

◆ throughPoints()

static ParameterLine2D throughPoints ( const ROOT::Math::XYVector & start,
const ROOT::Math::XYVector & 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 84 of file ParameterLine2D.h.

85 {
86 return ParameterLine2D(start, end - start);
87 }

◆ touchingCircles()

ParameterLine2D touchingCircles ( const ROOT::Math::XYVector & fromCenter,
double fromSignedRadius,
const ROOT::Math::XYVector & 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 ROOT::Math::XYVector connecting = toCenter - fromCenter;
23
24 // Normalize to the coordinate system vector, but keep the original norm
25 const double norm = connecting.R();
26 if (norm != 0.0) {
27 connecting *= (1. / norm);
28 }
29
30 double kappa = (fromSignedRadius - toSignedRadius) / norm;
31 double cokappa = sqrt(1 - kappa * kappa);
32
33 ROOT::Math::XYVector fromPos = VectorUtil::compose(connecting, kappa * fromSignedRadius, cokappa * fromSignedRadius);
34 fromPos += fromCenter;
35
36 ROOT::Math::XYVector toPos = VectorUtil::compose(connecting, kappa * toSignedRadius, cokappa * toSignedRadius);
37 toPos += toCenter;
38
39 return ParameterLine2D::throughPoints(fromPos, toPos);
40}
static ParameterLine2D throughPoints(const ROOT::Math::XYVector &start, const ROOT::Math::XYVector &end)
Static constructor for a line between to points.
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 398 of file ParameterLine2D.h.

399 {
400 return support().X() - inverseSlope() * support().Y();
401 }

Member Data Documentation

◆ m_support

ROOT::Math::XYVector m_support
private

Support vector of the line.

Definition at line 438 of file ParameterLine2D.h.

◆ m_tangential

ROOT::Math::XYVector m_tangential
private

Tangential vector of the line.

Definition at line 441 of file ParameterLine2D.h.


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