Belle II Software development
GeneralizedCircle Class Reference

A generalized circle. More...

#include <GeneralizedCircle.h>

Public Member Functions

 GeneralizedCircle ()
 Default constructor for ROOT compatibility.
 
 GeneralizedCircle (double n0, double n1, double n2, double n3=0)
 Constructor with the four parameters of the generalized circle.
 
 GeneralizedCircle (double n0, const Vector2D &n12, double n3=0)
 Constructor with the four parameters of the generalized circle.
 
 GeneralizedCircle (const Line2D &n012)
 Constructor from a two dimensional line.
 
 GeneralizedCircle (const Circle2D &circle)
 Constructor from a two dimensional circle.
 
void setCenterAndRadius (const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
 Setter for the circle center and radius.
 
void setPerigeeParameters (double curvature, const Vector2D &tangential, double impact)
 Setter for the perigee parameters.
 
void setPerigeeParameters (const double curvature, const double tangentialPhi, const double impact)
 Setter for the perigee parameters.
 
void setN (const double n0, const double n1, const double n2, const double n3=0.0)
 Setter for all four circle parameters.
 
void setN (const double n0, const Vector2D &n12, const double n3=0.0)
 Setter for all four circle parameters.
 
void setN (const Line2D &n012)
 Setter for all four circle parameters from another circle.
 
void setN (const GeneralizedCircle &n0123)
 Setter for all four circle parameters from another circle.
 
void invalidate ()
 Sets all circle parameters to zero.
 
void reverse ()
 Flips the orientation of the circle in place.
 
void conformalTransform ()
 Transforms the generalized circle to conformal space inplace Applies the conformal map in the self-inverse form X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) inplace It works most easily by the exchange of the circle parameters n0 <-> n3.
 
void passiveMoveBy (const Vector2D &by)
 Moves the coordinate system by the given vector.
 
double n0 () const
 Getter for the first circle parameter.
 
double n1 () const
 Getter for the second circle parameter.
 
double n2 () const
 Getter for the third circle parameter.
 
const Vector2Dn12 () const
 Getter for the second and third circle parameter which natuarally from a vector.
 
double n3 () const
 Getter for the fourth circle parameter.
 
bool isInvalid () const
 Indicates if all circle parameters are zero.
 
bool isValid () const
 Indicates if the combination of the circle parameters makes up a valid circle.
 
double normalizationSquared () const
 Calculates the generalized circle specific squared norm.
 
GeneralizedCircle reversed () const
 Returns a copy of the circle with opposite orientation.
 
GeneralizedCircle conformalTransformed () const
 Returns a copy of the circle in conformal space.
 
Vector2D gradient (const Vector2D &point) const
 Gradient of the distance field Gives the gradient of the approximated distance field for the given point.
 
Vector2D normal (const Vector2D &point) const
 Normal vector to the circle near the given position.
 
Vector2D tangential (const Vector2D &point) const
 Tangential vector to the circle near the given position.
 
Vector2D closest (const Vector2D &point) const
 Closest approach on the circle to the point.
 
Vector2D perigee () const
 Calculates the closest approach to the two dimensional origin.
 
Vector2D apogee () const
 Calculates the point on the circle that is furthest away from the origin.
 
EForwardBackward isForwardOrBackwardOf (const Vector2D &from, const Vector2D &to) const
 Calculates if the to vector is closer to the from vector following the along orientation of the circle or against.
 
Vector2D chooseNextForwardOf (const Vector2D &start, const Vector2D &end1, const Vector2D &end2) const
 Returns the end point which is first reached if one follows the forward direction of the circle starting from the start point.
 
std::pair< Belle2::TrackFindingCDC::Vector2D, Belle2::TrackFindingCDC::Vector2DatCylindricalR (double cylindricalR) const
 Calculates the two points with the given cylindrical radius on the generalised circle.
 
Vector2D atCylindricalRForwardOf (const Vector2D &startPoint, double cylindricalR) const
 Approach on the circle with the given cylindrical radius that lies in the forward direction of a start point.
 
double fastDistance (const Vector2D &point) const
 Approximate distance.
 
double fastImpact () const
 Approximate distance to the origin.
 
double distance (const Vector2D &point) const
 Gives the proper distance of the point to the circle line retaining the sign of the fast distance.
 
double distance (double fastDistance) const
 Helper function to translate the fast linearized distance measure of the generalized circle to the proper distance from the circle retaining the sign of the distance.
 
double fastDistance (const double distance) const
 Helper function to translate the proper distance to the linearized distance measure of the generalized circle retaining the sign of the distance.
 
double impact () const
 Gives the signed distance of the origin to the circle.
 
double d0 () const
 Getter for the absolute distance to the z axes at the support point.
 
Vector2D tangential () const
 Gives the tangential vector at the closest approach to the origin / at the perigee.
 
double tangentialPhi () const
 Gives to azimuth angle phi of the direction of flight at the perigee.
 
double minimalCylindricalR () const
 Gives the minimal cylindrical radius the circle reaches (unsigned)
 
double maximalCylindricalR () const
 Gives the maximal cylindrical radius the circle reaches.
 
double absDistance (const Vector2D &point) const
 Gives the proper absolute distance of the point to the circle line.
 
ERightLeft isRightOrLeft (const Vector2D &point) const
 Indicates if the point is on the right or left side of the circle.
 
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.
 
bool isLine () const
 Indicates if the generalized circle is actually a line.
 
bool isCircle () const
 Indicates if the generalized circle is actually a circle.
 
double radius () const
 Gives the signed radius of the circle. If it was a line this will be infinity.
 
double absRadius () const
 Gives the signed radius of the circle. If it was a line this will be infinity.
 
double curvature () const
 Gives the signed curvature of the generalized circle.
 
double omega () const
 Gives the omega parameter as used by the framework helix.
 
Vector2D center () const
 Gives the center of the circle. If it was a line both components will be infinity.
 
double perimeter () const
 Gives the perimeter of the circle.
 
ERotation orientation () const
 Gives the orientation of the circle.
 
double arcLengthPeriod () const
 Getter for the arc length for a full round of the circle.
 
double arcLengthBetween (const Vector2D &from, const Vector2D &to) const
 Calculates the arc length between two points of closest approach on the circle.
 
double arcLengthTo (const Vector2D &to) const
 Calculates the arc length between the perigee and the given point.
 
double arcLengthToCylindricalR (double cylindricalR) const
 Calculates the two dimensional arc length till the cylindrical radius is reached If the radius can not be reached return NAN.
 
double arcLengthFactor (const double directDistance) const
 Helper function the calculate the factor between the length of a secant line and the length on the arc.
 
std::pair< Vector2D, Vector2Dintersections (const GeneralizedCircle &generalizedCircle) const
 Calculates the two points common to both circles.
 
Vector2D atArcLength (double arcLength) const
 Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
 

Static Public Member Functions

static GeneralizedCircle fromCenterAndRadius (const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
 Constructor from center, radius and a optional orientation.
 
static GeneralizedCircle fromPerigeeParameters (double curvature, const Vector2D &tangential, double impact)
 Constructor of a generalized circle from perigee parameters.
 
static GeneralizedCircle fromPerigeeParameters (double curvature, double tangentialPhi, double impact)
 Constructor of a generalized circle from perigee parameters.
 
static double arcLengthFactor (double directDistance, double curvature)
 Helper function the calculate the factor between the length of a secant line and the length on the arc.
 

Protected Member Functions

void setN0 (const double n0)
 Setter for first circle parameter.
 
void setN1 (const double n1)
 Setter for second circle parameter.
 
void setN2 (const double n2)
 Setter for third circle parameter.
 
void setN12 (const double n1, const double n2)
 Setter for second and third circle parameter.
 
void setN12 (const Vector2D &n12)
 Setter for second and third circle parameter.
 
void setN3 (const double n3)
 Setter for fourth circle parameter.
 
void normalize ()
 Normalizes the circle parameters.
 

Private Member Functions

void scaleN (const double factor)
 Scales the circle parameters by a common factor.
 

Private Attributes

double m_n3
 Memory for the fourth parameter.
 
Vector2D m_n12
 Memory for the second and third parameter.
 
double m_n0
 Memory for the first parameter.
 

Detailed Description

A generalized circle.

Makes a smooth generalization from a two dimensional normal line ( like Line2D ) to a circle.

The parameterisation is best suited for low curvature circle. The representation takes four parameters. They correspond to the normal circle parameters like
n0 = (m_x*m_x + m_y*m_y - r*r)/2r
n1 = -m_x/r
n2 = -m_y/r
n3 = 1/2r
where the normalization condtion is n1*n1 + n2*n2 - 4 * n0 * n3 = 1. The overall sign is fixed in the following way: If the last parameter is positiv the circle is assummed to be orientated counterclockwise else the circle is assummed to be orientated clockwise. The parameters n1 and n2 are indeed a vector in two dimensions and we keep them stored as Vector2D. Additionally we can represent a line with same parameters by setting n3 = 0. Compare Line2D.

Definition at line 51 of file GeneralizedCircle.h.

Constructor & Destructor Documentation

◆ GeneralizedCircle() [1/5]

Default constructor for ROOT compatibility.

Definition at line 26 of file GeneralizedCircle.cc.

27 : m_n3(0.0)
28 , m_n12(0.0, 0.0)
29 , m_n0(0.0)
30{
31}
double m_n3
Memory for the fourth parameter.
double m_n0
Memory for the first parameter.
Vector2D m_n12
Memory for the second and third parameter.

◆ GeneralizedCircle() [2/5]

GeneralizedCircle ( double  n0,
double  n1,
double  n2,
double  n3 = 0 
)

Constructor with the four parameters of the generalized circle.

Definition at line 33 of file GeneralizedCircle.cc.

37 : m_n3(n3)
38 , m_n12(n1, n2)
39 , m_n0(n0)
40{
41 normalize();
42}
double n1() const
Getter for the second circle parameter.
double n3() const
Getter for the fourth circle parameter.
double n2() const
Getter for the third circle parameter.
void normalize()
Normalizes the circle parameters.
double n0() const
Getter for the first circle parameter.

◆ GeneralizedCircle() [3/5]

GeneralizedCircle ( double  n0,
const Vector2D n12,
double  n3 = 0 
)

Constructor with the four parameters of the generalized circle.

Definition at line 44 of file GeneralizedCircle.cc.

45 : m_n3(n3)
46 , m_n12(n12)
47 , m_n0(n0)
48{
49 normalize();
50}
const Vector2D & n12() const
Getter for the second and third circle parameter which natuarally from a vector.

◆ GeneralizedCircle() [4/5]

GeneralizedCircle ( const Line2D n012)
explicit

Constructor from a two dimensional line.

Definition at line 52 of file GeneralizedCircle.cc.

53 : m_n3(0.0)
54 , m_n12(n012.n12())
55 , m_n0(n012.n0())
56{
57 normalize();
58}
const Vector2D & n12() const
Getter for the unit normal vector to the line.
Definition: Line2D.h:117
double n0() const
Getter for the first line parameter.
Definition: Line2D.h:99

◆ GeneralizedCircle() [5/5]

GeneralizedCircle ( const Circle2D circle)
explicit

Constructor from a two dimensional circle.

Definition at line 60 of file GeneralizedCircle.cc.

61 : m_n3(1.0 / 2.0 / circle.radius())
62 , m_n12(-circle.center().x() * (m_n3 * 2.0), -circle.center().y() * (m_n3 * 2.0))
63 , m_n0((circle.center().normSquared() - circle.radiusSquared()) * m_n3)
64{
65}
double radius() const
Getter for the signed radius.
Definition: Circle2D.h:197
Vector2D center() const
Getter for the central point of the circle.
Definition: Circle2D.h:221
double radiusSquared() const
Getter for the squared radius.
Definition: Circle2D.h:203
double x() const
Getter for the x coordinate.
Definition: Vector2D.h:595
double normSquared() const
Calculates .
Definition: Vector2D.h:169
double y() const
Getter for the y coordinate.
Definition: Vector2D.h:605

Member Function Documentation

◆ absDistance()

double absDistance ( const Vector2D point) const
inline

Gives the proper absolute distance of the point to the circle line.

Definition at line 529 of file GeneralizedCircle.h.

530 {
531 return fabs(distance(point));
532 }
double distance(const Vector2D &point) const
Gives the proper distance of the point to the circle line retaining the sign of the fast distance.

◆ absRadius()

double absRadius ( ) const
inline

Gives the signed radius of the circle. If it was a line this will be infinity.

Definition at line 574 of file GeneralizedCircle.h.

575 {
576 return fabs(radius());
577 }
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.

◆ apogee()

Vector2D apogee ( ) const

Calculates the point on the circle that is furthest away from the origin.

This results in Vector2D(NAN, NAN) in the straight line case.

Definition at line 168 of file GeneralizedCircle.cc.

169{
170 Vector2D result(n12());
171 result.setCylindricalR(-impact() - 2 * radius());
172 return result;
173}
double impact() const
Gives the signed distance of the origin to the circle.
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:32

◆ arcLengthBetween()

double arcLengthBetween ( const Vector2D from,
const Vector2D to 
) const

Calculates the arc length between two points of closest approach on the circle.

The arc length is signed positiv for travel in orientation direction. In the circle case the arc length is between -pi*radius and pi*radius, hence the discontinuity is on the far side of the circle relative to the given from point. The points are essentially first taken to their closest approach before we take the length on the curve. For the line case the length is the distance component parallel to the line.

Definition at line 244 of file GeneralizedCircle.cc.

245{
246 EForwardBackward lengthSign = isForwardOrBackwardOf(from, to);
247 if (not NForwardBackward::isValid(lengthSign)) return NAN;
248
249 // Handling the rare case that from and to correspond to opposing points on the circle
250 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
251
252 Vector2D closestAtFrom = closest(from);
253 Vector2D closestAtTo = closest(to);
254 double directDistance = closestAtFrom.distance(closestAtTo);
255
256 return static_cast<double>(lengthSign) * arcLengthFactor(directDistance) * directDistance;
257}
EForwardBackward isForwardOrBackwardOf(const Vector2D &from, const Vector2D &to) const
Calculates if the to vector is closer to the from vector following the along orientation of the circl...
Vector2D closest(const Vector2D &point) const
Closest approach on the circle to the point.
double arcLengthFactor(const double directDistance) const
Helper function the calculate the factor between the length of a secant line and the length on the ar...
double distance(const Vector2D &rhs=Vector2D(0.0, 0.0)) const
Calculates the distance of this point to the rhs.
Definition: Vector2D.h:204
bool isValid(EForwardBackward eForwardBackward)
Check whether the given enum instance is one of the valid values.
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.

◆ arcLengthFactor() [1/2]

double arcLengthFactor ( const double  directDistance) const
inline

Helper function the calculate the factor between the length of a secant line and the length on the arc.

Smooth function expressing the relation between arc length and direct length only using the curvature of the circle as additional information. It enables better handling of the line limit compared to the former implementaiton which used the opening angle of the arc.

Definition at line 653 of file GeneralizedCircle.h.

654 {
655 return arcLengthFactor(directDistance, curvature());
656 }
double curvature() const
Gives the signed curvature of the generalized circle.

◆ arcLengthFactor() [2/2]

double arcLengthFactor ( double  directDistance,
double  curvature 
)
static

Helper function the calculate the factor between the length of a secant line and the length on the arc.

Smooth function expressing the relation between arc length and direct length only using the curvature of the circle as additional information. It enables better handling of the line limit compared to the former implementaiton which used the opening angle of the arc.

Definition at line 290 of file GeneralizedCircle.cc.

291{
292 double x = directDistance * curvature / 2.0;
293 return asinc(x);
294}

◆ arcLengthPeriod()

double arcLengthPeriod ( ) const
inline

Getter for the arc length for a full round of the circle.

Definition at line 618 of file GeneralizedCircle.h.

619 {
620 return std::fabs(perimeter());
621 }
double perimeter() const
Gives the perimeter of the circle.

◆ arcLengthTo()

double arcLengthTo ( const Vector2D to) const

Calculates the arc length between the perigee and the given point.

Definition at line 259 of file GeneralizedCircle.cc.

260{
261 const Vector2D from = perigee();
262
263 EForwardBackward lengthSign = isForwardOrBackwardOf(from, to);
264 if (not NForwardBackward::isValid(lengthSign)) return NAN;
265
266 // Handling the rare case that from and to correspond to opposing points on the circle
267 if (lengthSign == EForwardBackward::c_Unknown) lengthSign = EForwardBackward::c_Forward;
268
269 const Vector2D& closestAtFrom = from;
270 Vector2D closestAtTo = closest(to);
271 double directDistance = closestAtFrom.distance(closestAtTo);
272
273 return static_cast<double>(lengthSign) * arcLengthFactor(directDistance) * directDistance;
274}
Vector2D perigee() const
Calculates the closest approach to the two dimensional origin.

◆ arcLengthToCylindricalR()

double arcLengthToCylindricalR ( double  cylindricalR) const

Calculates the two dimensional arc length till the cylindrical radius is reached If the radius can not be reached return NAN.

Note that there are two solutions which have equivalent arc lengths with different sign Always return the positive solution.

Definition at line 276 of file GeneralizedCircle.cc.

277{
278 // Slight trick here
279 // Since the sought point is on the helix we treat it as the perigee
280 // and the origin as the point to extrapolate to.
281 // We know the distance of the origin to the circle, which is just d0
282 // The direct distance from the origin to the imaginary perigee is just the given cylindricalR.
283 const double dr = d0();
284 const double directDistance =
285 sqrt((cylindricalR + dr) * (cylindricalR - dr) / (1 + dr * omega()));
286 const double arcLength = arcLengthFactor(directDistance) * directDistance;
287 return arcLength;
288}
double omega() const
Gives the omega parameter as used by the framework helix.
double d0() const
Getter for the absolute distance to the z axes at the support point.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ atArcLength()

Vector2D atArcLength ( double  arcLength) const

Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)

Definition at line 352 of file GeneralizedCircle.cc.

353{
354 double chi = arcLength * curvature();
355 double chiHalf = chi / 2.0;
356
357 double atX = arcLength * sinc(chiHalf) * sin(chiHalf) + impact();
358 double atY = -arcLength * sinc(chi);
359 return Vector2D::compose(-n12().unit(), atX, atY);
360}
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.
Definition: Vector2D.h:74

◆ atCylindricalR()

std::pair< Vector2D, Vector2D > atCylindricalR ( double  cylindricalR) const

Calculates the two points with the given cylindrical radius on the generalised circle.

Two versions in this case

Definition at line 209 of file GeneralizedCircle.cc.

210{
211 // extraploted to r
212 // solve
213 // n0 + n1*x + n2*y + n3*r*r == 0
214 // and r = cylindricalR
215 // search for x and y
216
217 // solve the equation in a coordinate system parallel and orthogonal to the reduced circle center
218 const Vector2D nUnit = n12().unit();
219
220 // parallel component
221 const double sameCylindricalRParallel = -(n0() + n3() * square(cylindricalR)) / n12().norm();
222
223 // orthogonal component
224 const double sameCylindricalROrthogonal = sqrt(square(cylindricalR) - square(sameCylindricalRParallel));
225
227 Vector2D sameCylindricalR1 =
228 Vector2D::compose(nUnit, sameCylindricalRParallel, -sameCylindricalROrthogonal);
229
230 Vector2D sameCylindricalR2 =
231 Vector2D::compose(nUnit, sameCylindricalRParallel, sameCylindricalROrthogonal);
232
233 std::pair<Vector2D, Vector2D> result(sameCylindricalR1, sameCylindricalR2);
234 return result;
235}
Vector2D unit() const
Returns a unit vector colaligned with this.
Definition: Vector2D.h:321
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:175

◆ atCylindricalRForwardOf()

Vector2D atCylindricalRForwardOf ( const Vector2D startPoint,
double  cylindricalR 
) const

Approach on the circle with the given cylindrical radius that lies in the forward direction of a start point.

Calculates the point on the circle with cylindrical radius cylindricalR, which is closest following the circle in the direction of positive forward orientation This is particularly useful to extraplotate into a certain layer. In case no intersection with this cylindrical radius exists the function returns Vector2D(NAN,NAN)

Parameters
startPointStart point from which to follow in the circle in the forward direction
cylindricalRCylindrical radius of interest
Returns
Close point in forward direction with same cylindrical radius on the circle.

Definition at line 237 of file GeneralizedCircle.cc.

239{
240 std::pair<Vector2D, Vector2D> candidatePoints = atCylindricalR(cylindricalR);
241 return chooseNextForwardOf(startPoint, candidatePoints.first, candidatePoints.second);
242}
Vector2D chooseNextForwardOf(const Vector2D &start, const Vector2D &end1, const Vector2D &end2) const
Returns the end point which is first reached if one follows the forward direction of the circle start...
std::pair< Belle2::TrackFindingCDC::Vector2D, Belle2::TrackFindingCDC::Vector2D > atCylindricalR(double cylindricalR) const
Calculates the two points with the given cylindrical radius on the generalised circle.

◆ center()

Vector2D center ( ) const
inline

Gives the center of the circle. If it was a line both components will be infinity.

Definition at line 595 of file GeneralizedCircle.h.

596 {
597 return n12().divided(-2 * n3());
598 }
Vector2D divided(const double denominator) const
Returns a copy where all coordinates got divided by a common denominator.
Definition: Vector2D.h:251

◆ chooseNextForwardOf()

Vector2D chooseNextForwardOf ( const Vector2D start,
const Vector2D end1,
const Vector2D end2 
) const

Returns the end point which is first reached if one follows the forward direction of the circle starting from the start point.

Evaluates which of the given end points end1 and end2 is closer to start This espicially treats the discontinuity on the far side of the circle correctly. If the generalized circle is truely a line none of the points might lie in the forward direction and Vector2D(NAN,NAN) is returned.

Parameters
startPoint to start the traversal
end1One possible end point
end2Other possible end point
Returns
end1 or end2 depending, which lies closer to start in the forward direction or Vector2D(NAN,NAN) if neither end1 nor end2 are reachable in the forward direction (line case only)

Definition at line 175 of file GeneralizedCircle.cc.

178{
179 double lengthOnCurve1 = arcLengthBetween(start, end1);
180 double lengthOnCurve2 = arcLengthBetween(start, end2);
181
182 if (lengthOnCurve1 >= 0.0) {
183
184 if (lengthOnCurve2 >= 0.0) {
185 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
186 } else {
187 return end1;
188 }
189 } else {
190
191 if (lengthOnCurve2 >= 0.0) {
192 return end2;
193 } else {
194
195 // both lengths on curve have a negative sign
196 // the candidate with the lesser length on curve wins because of the discontinuaty
197 // unless the generalized circle is a line
198 // in this case their is no forward intersection with the same cylindrical radius
199 if (isLine()) {
200 return Vector2D(NAN, NAN);
201 } else {
202 return lengthOnCurve1 < lengthOnCurve2 ? end1 : end2;
203 }
204 }
205 }
206 return Vector2D(NAN, NAN); // just avoid a compiler warning
207}
bool isLine() const
Indicates if the generalized circle is actually a line.
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.

◆ closest()

Vector2D closest ( const Vector2D point) const

Closest approach on the circle to the point.

Calculates the closest point on the circle relative to the given point.

Parameters
pointPoint in the plane to calculate the closest approach to
Returns
Point of closest approach on the circle.

Definition at line 116 of file GeneralizedCircle.cc.

117{
118 if (fastDistance(point) == 0) return point;
119
120 // solve the minization | point - pointOnCirlce | ^2 subjected to the on circle constraint
121 // 1.0 * m_n0 +
122 // point.x() * m_n1 +
123 // point.y() * m_n2 +
124 // point.cylindricalRSquared() * m_n3 == 0
125 // solved with a lagrangian muliplicator for the constraint
126
127 Vector2D gradientAtPoint = gradient(point);
128 Vector2D coordinateSystem = gradientAtPoint.unit();
129
130 // component of closest approach orthogonal to coordinateSystem
131 double closestOrthogonal = n12().cross(point) / gradientAtPoint.norm();
132
133 // component of closest approach parallel to coordinateSystem - two solutions expected
134 double nOrthogonal = n12().unnormalizedOrthogonalComp(coordinateSystem);
135 double nParallel = n12().unnormalizedParallelComp(coordinateSystem);
136
137 double closestParallel = 0.0;
138 if (isLine()) {
139 closestParallel = -(nOrthogonal * closestOrthogonal + n0()) / nParallel;
140
141 } else {
142 const double a = n3();
143 const double b = nParallel;
144 const double c = n0() + (nOrthogonal + n3() * closestOrthogonal) * closestOrthogonal;
145
146 const std::pair<double, double> closestParallel12 = solveQuadraticABC(a, b, c);
147
148 // take the solution with smaller distance to point
149 const double pointParallel = point.unnormalizedParallelComp(coordinateSystem);
150
151 const double criterion1 =
152 closestParallel12.first * (closestParallel12.first - 2 * pointParallel);
153 const double criterion2 =
154 closestParallel12.second * (closestParallel12.second - 2 * pointParallel);
155
156 closestParallel = criterion1 < criterion2 ? closestParallel12.first : closestParallel12.second;
157 }
158 return Vector2D::compose(coordinateSystem, closestParallel, closestOrthogonal);
159}
double fastDistance(const Vector2D &point) const
Approximate distance.
Vector2D gradient(const Vector2D &point) const
Gradient of the distance field Gives the gradient of the approximated distance field for the given po...
double unnormalizedParallelComp(const Vector2D &relativTo) const
Same as parallelComp() but assumes the given vector to be of unit length.
Definition: Vector2D.h:425
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
Definition: Vector2D.h:163
double unnormalizedOrthogonalComp(const Vector2D &relativTo) const
Same as orthogonalComp() but assumes the given vector to be of unit length.
Definition: Vector2D.h:446

◆ conformalTransform()

void conformalTransform ( )
inline

Transforms the generalized circle to conformal space inplace Applies the conformal map in the self-inverse form X = x / (x^2 + y^2) and Y = y / (x^2 +y^2) inplace It works most easily by the exchange of the circle parameters n0 <-> n3.

Definition at line 229 of file GeneralizedCircle.h.

230 {
231 std::swap(m_n0, m_n3);
232 reverse(); // Correct orientation
233 }
void reverse()
Flips the orientation of the circle in place.

◆ conformalTransformed()

GeneralizedCircle conformalTransformed ( ) const
inline

Returns a copy of the circle 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 GeneralizedCircle. It works most easily by the exchange of the circle parameters n0 <-> n3

Definition at line 335 of file GeneralizedCircle.h.

336 {
337 return GeneralizedCircle(-n3(), -n12(), -n0());
338 }
GeneralizedCircle()
Default constructor for ROOT compatibility.

◆ curvature()

double curvature ( ) const
inline

Gives the signed curvature of the generalized circle.

Definition at line 580 of file GeneralizedCircle.h.

581 {
582 return 2 * n3();
583 }

◆ d0()

double d0 ( ) const
inline

Getter for the absolute distance to the z axes at the support point.

Definition at line 499 of file GeneralizedCircle.h.

500 {
501 return -impact();
502 }

◆ distance() [1/2]

double distance ( const Vector2D point) const

Gives the proper distance of the point to the circle line retaining the sign of the fast distance.

Definition at line 296 of file GeneralizedCircle.cc.

297{
298 const double fastD = fastDistance(point);
299 return distance(fastD);
300}

◆ distance() [2/2]

double distance ( double  fastDistance) const

Helper function to translate the fast linearized distance measure of the generalized circle to the proper distance from the circle retaining the sign of the distance.

Definition at line 302 of file GeneralizedCircle.cc.

303{
304 if (fastDistance == 0.0 or isLine()) {
305 // special case for unfitted state
306 // and line
307 return fastDistance;
308 } else {
309
310 const double a = n3();
311 const double b = 1;
312 const double c = -fastDistance;
313
314 std::pair<double, double> distance12 = solveQuadraticABC(a, b, c);
315
316 // take the small solution which has always the same sign of the fastDistance
317 return distance12.second;
318 }
319}

◆ fastDistance() [1/2]

double fastDistance ( const double  distance) const
inline

Helper function to translate the proper distance to the linearized distance measure of the generalized circle retaining the sign of the distance.

Definition at line 487 of file GeneralizedCircle.h.

488 {
489 return (distance * n3() + 1.0) * distance;
490 }

◆ fastDistance() [2/2]

double fastDistance ( const Vector2D point) const
inline

Approximate distance.

Gives a fast signed approximation of the distance to the circle. The absolute value of the fast distance is accurate up to first order of distance/circle radius, hence best used with big circles and small distances. The sign of the fast distance indicates if the point is to the right or to the left of the circle.

Definition at line 459 of file GeneralizedCircle.h.

460 {
461 return n0() + point.dot(n12()) + point.normSquared() * n3();
462 }

◆ fastImpact()

double fastImpact ( ) const
inline

Approximate distance to the origin.

Definition at line 465 of file GeneralizedCircle.h.

466 {
467 return n0();
468 }

◆ fromCenterAndRadius()

GeneralizedCircle fromCenterAndRadius ( const Vector2D center,
double  absRadius,
ERotation  orientation = ERotation::c_CounterClockwise 
)
static

Constructor from center, radius and a optional orientation.

The center and radius alone do not carry any orientation. However the generalized circle does. This constructor makes an orientated representation from them. If not given the orientation defaults to mathematical positiv counterclockwise.

Definition at line 67 of file GeneralizedCircle.cc.

70{
71 GeneralizedCircle generalizedCircle;
73 return generalizedCircle;
74}
void setCenterAndRadius(const Vector2D &center, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Setter for the circle center and radius.
Vector2D center() const
Gives the center of the circle. If it was a line both components will be infinity.
double absRadius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
ERotation orientation() const
Gives the orientation of the circle.

◆ fromPerigeeParameters() [1/2]

GeneralizedCircle fromPerigeeParameters ( double  curvature,
const Vector2D tangential,
double  impact 
)
static

Constructor of a generalized circle from perigee parameters.

Tangential at perigee given as two dimensional vector.

Definition at line 76 of file GeneralizedCircle.cc.

79{
80 GeneralizedCircle generalizedCircle;
82 return generalizedCircle;
83}
Vector2D tangential() const
Gives the tangential vector at the closest approach to the origin / at the perigee.
void setPerigeeParameters(double curvature, const Vector2D &tangential, double impact)
Setter for the perigee parameters.

◆ fromPerigeeParameters() [2/2]

GeneralizedCircle fromPerigeeParameters ( double  curvature,
double  tangentialPhi,
double  impact 
)
static

Constructor of a generalized circle from perigee parameters.

Tangential at perigee given as azimuth angle.

Definition at line 85 of file GeneralizedCircle.cc.

88{
89 GeneralizedCircle generalizedCircle;
91 return generalizedCircle;
92}
double tangentialPhi() const
Gives to azimuth angle phi of the direction of flight at the perigee.

◆ gradient()

Vector2D gradient ( const Vector2D point) const
inline

Gradient of the distance field Gives the gradient of the approximated distance field for the given point.

Parameters
pointPoint in the plane to calculate the gradient
Returns
Gradient of the distance field

Definition at line 347 of file GeneralizedCircle.h.

348 {
349 return point * (2.0 * n3()) + n12();
350 }

◆ impact()

double impact ( ) const
inline

Gives the signed distance of the origin to the circle.

Definition at line 493 of file GeneralizedCircle.h.

494 {
495 return distance(fastImpact());
496 }
double fastImpact() const
Approximate distance to the origin.

◆ intersections()

std::pair< Vector2D, Vector2D > intersections ( const GeneralizedCircle generalizedCircle) const

Calculates the two points common to both circles.

If the two points coincide both returned points are the same. If there is no common point both returned points will be made of NAN.

Definition at line 322 of file GeneralizedCircle.cc.

323{
324 const double m0 = generalizedCircle.n0();
325 const Vector2D& m12 = generalizedCircle.n12();
326 const double m3 = generalizedCircle.n3();
327
328 const double n0 = this->n0();
329 const Vector2D& n12 = this->n12();
330 const double n3 = this->n3();
331
332 Vector2D unitC = n12 * m3 - m12 * n3;
333 double absC = unitC.normalize();
334
335 double xParallel = (m0 * n3 - m3 * n0) / absC;
336
337 // Use symmetric solution and use all input parameters
338 Vector2D mn12 = n12 + m12;
339 double mn12Parallel = unitC.unnormalizedParallelComp(mn12);
340 double mn12Orthogonal = unitC.unnormalizedOrthogonalComp(mn12);
341
342 double a = m3 + n3;
343 double b = mn12Orthogonal;
344 double c = (a * xParallel + mn12Parallel) * xParallel + m0 + n0;
345
346 std::pair<double, double> xOrthogonal = solveQuadraticABC(a, b, c);
347
348 return std::make_pair(Vector2D::compose(unitC, xParallel, xOrthogonal.first),
349 Vector2D::compose(unitC, xParallel, xOrthogonal.second));
350}
double normalize()
Normalizes the vector to unit length.
Definition: Vector2D.h:303

◆ invalidate()

void invalidate ( )
inline

Sets all circle parameters to zero.

Definition at line 212 of file GeneralizedCircle.h.

213 {
214 setN(0.0, 0.0, 0.0, 0.0);
215 }
void setN(const double n0, const double n1, const double n2, const double n3=0.0)
Setter for all four circle parameters.

◆ isCircle()

bool isCircle ( ) const
inline

Indicates if the generalized circle is actually a circle.

Definition at line 562 of file GeneralizedCircle.h.

563 {
564 return n3() != 0.0;
565 }

◆ isForwardOrBackwardOf()

EForwardBackward isForwardOrBackwardOf ( const Vector2D from,
const Vector2D to 
) const
inline

Calculates if the to vector is closer to the from vector following the along orientation of the circle or against.

Returns
  • EForwardBackward::c_Forward in case the to vector is closer following the along the orientation
  • EForwardBackward::c_Backward in case the to vector is closer against the orientation.
  • EForwardBackward::c_Unknown if neither can be determined.

Definition at line 408 of file GeneralizedCircle.h.

409 {
410 Vector2D difference = to - from;
411 Vector2D tangentialAtFrom = tangential(from);
412 return tangentialAtFrom.isForwardOrBackwardOf(difference);
413 }

◆ isInvalid()

bool isInvalid ( ) const
inline

Indicates if all circle parameters are zero.

Definition at line 300 of file GeneralizedCircle.h.

301 {
302 return n0() == 0 and n12().isNull() and n3() == 0;
303 }
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 544 of file GeneralizedCircle.h.

545 {
546 return isRightOrLeft(rhs) == ERightLeft::c_Left;
547 }
ERightLeft isRightOrLeft(const Vector2D &point) const
Indicates if the point is on the right or left side of the circle.

◆ isLine()

bool isLine ( ) const
inline

Indicates if the generalized circle is actually a line.

Definition at line 556 of file GeneralizedCircle.h.

557 {
558 return n3() == 0.0;
559 }

◆ isRight()

bool isRight ( const Vector2D rhs) const
inline

Return if the point given is right of the line.

Definition at line 550 of file GeneralizedCircle.h.

551 {
552 return isRightOrLeft(rhs) == ERightLeft::c_Right;
553 }

◆ isRightOrLeft()

ERightLeft isRightOrLeft ( const Vector2D point) const
inline

Indicates if the point is on the right or left side of the circle.

This is also refered to as alpha.

Definition at line 538 of file GeneralizedCircle.h.

539 {
540 return static_cast<ERightLeft>(sign(fastDistance(point)));
541 }
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25

◆ isValid()

bool isValid ( ) const
inline

Indicates if the combination of the circle parameters makes up a valid circle.

Definition at line 306 of file GeneralizedCircle.h.

307 {
308 return not isInvalid();
309 }
bool isInvalid() const
Indicates if all circle parameters are zero.

◆ maximalCylindricalR()

double maximalCylindricalR ( ) const
inline

Gives the maximal cylindrical radius the circle reaches.

Definition at line 523 of file GeneralizedCircle.h.

524 {
525 return std::fabs(impact() + 2 * radius());
526 }

◆ minimalCylindricalR()

double minimalCylindricalR ( ) const
inline

Gives the minimal cylindrical radius the circle reaches (unsigned)

Definition at line 517 of file GeneralizedCircle.h.

518 {
519 return std::fabs(impact());
520 }

◆ n0()

double n0 ( ) const
inline

Getter for the first circle parameter.

Definition at line 269 of file GeneralizedCircle.h.

270 {
271 return m_n0;
272 }

◆ n1()

double n1 ( ) const
inline

Getter for the second circle parameter.

Definition at line 275 of file GeneralizedCircle.h.

276 {
277 return m_n12.x();
278 }

◆ n12()

const Vector2D & n12 ( ) const
inline

Getter for the second and third circle parameter which natuarally from a vector.

Definition at line 287 of file GeneralizedCircle.h.

288 {
289 return m_n12;
290 }

◆ n2()

double n2 ( ) const
inline

Getter for the third circle parameter.

Definition at line 281 of file GeneralizedCircle.h.

282 {
283 return m_n12.y();
284 }

◆ n3()

double n3 ( ) const
inline

Getter for the fourth circle parameter.

Definition at line 293 of file GeneralizedCircle.h.

294 {
295 return m_n3;
296 }

◆ normal()

Vector2D normal ( const Vector2D point) const
inline

Normal vector to the circle near the given position.

Gives the unit normal vector to the circle line. It points to the outside of the circle for counterclockwise orientation, and inwards for the clockwise orientation. It is essentially the gradient normalized to unit length

Parameters
pointPoint in the plane to calculate the tangential
Returns
Unit normal vector to the circle line

Definition at line 361 of file GeneralizedCircle.h.

362 {
363 return gradient(point).unit();
364 }

◆ normalizationSquared()

double normalizationSquared ( ) const
inline

Calculates the generalized circle specific squared norm.

Correctly normalized this should give one.

Definition at line 315 of file GeneralizedCircle.h.

316 {
317 return n12().normSquared() - 4 * n0() * n3();
318 }

◆ normalize()

void normalize ( )
inlineprotected

Normalizes the circle parameters.

The normalization is only made if the circle parameters have a valid positiv norm. If the normalization of the cirlce is negativ or zero all circle parameters are not changed.

Definition at line 252 of file GeneralizedCircle.h.

253 {
254 double normalization_squared = normalizationSquared();
255 if (normalization_squared > 0) scaleN(1.0 / std::sqrt(normalization_squared));
256 }
double normalizationSquared() const
Calculates the generalized circle specific squared norm.
void scaleN(const double factor)
Scales the circle parameters by a common factor.

◆ omega()

double omega ( ) const
inline

Gives the omega parameter as used by the framework helix.

It is the signed curvature of the generalized circle with the opposite sign.

Definition at line 589 of file GeneralizedCircle.h.

590 {
591 return -curvature();
592 }

◆ orientation()

ERotation orientation ( ) const
inline

Gives the orientation of the circle.

The circle can be either orientated counterclockwise or clockwise.

Returns
ERotation::c_CounterClockwise for counterclockwise travel, ERotation::c_Clockwise for clockwise.

Definition at line 612 of file GeneralizedCircle.h.

613 {
614 return static_cast<ERotation>(sign(n3()));
615 }
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Definition: ERotation.h:25

◆ passiveMoveBy()

void passiveMoveBy ( const Vector2D by)
inline

Moves the coordinate system by the given vector.

Updates the circle parameters inplace.

Definition at line 239 of file GeneralizedCircle.h.

240 {
241 setN(fastDistance(by), gradient(by), n3());
242 }

◆ perigee()

Vector2D perigee ( ) const

Calculates the closest approach to the two dimensional origin.

Definition at line 161 of file GeneralizedCircle.cc.

162{
163 Vector2D result(n12());
164 result.setCylindricalR(-impact());
165 return result;
166}

◆ perimeter()

double perimeter ( ) const
inline

Gives the perimeter of the circle.

Definition at line 601 of file GeneralizedCircle.h.

602 {
603 return 2 * M_PI * radius();
604 }

◆ radius()

double radius ( ) const
inline

Gives the signed radius of the circle. If it was a line this will be infinity.

Definition at line 568 of file GeneralizedCircle.h.

569 {
570 return 1 / curvature();
571 }

◆ reverse()

void reverse ( )
inline

Flips the orientation of the circle in place.

Definition at line 218 of file GeneralizedCircle.h.

219 {
220 scaleN(-1);
221 }

◆ reversed()

GeneralizedCircle reversed ( ) const
inline

Returns a copy of the circle with opposite orientation.

Definition at line 322 of file GeneralizedCircle.h.

323 {
324 return GeneralizedCircle(-n0(), -n12(), -n3());
325 }

◆ scaleN()

void scaleN ( const double  factor)
inlineprivate

Scales the circle parameters by a common factor.

Definition at line 260 of file GeneralizedCircle.h.

261 {
262 m_n0 *= factor;
263 m_n12 *= factor;
264 m_n3 *= factor;
265 }

◆ setCenterAndRadius()

void setCenterAndRadius ( const Vector2D center,
double  absRadius,
ERotation  orientation = ERotation::c_CounterClockwise 
)

Setter for the circle center and radius.

Definition at line 94 of file GeneralizedCircle.cc.

97{
98 double curvature = static_cast<double>(orientation) / fabs(absRadius);
100 setN1(-center.x() * curvature);
101 setN2(-center.y() * curvature);
102 setN3(curvature / 2.0);
103 normalize(); // the call to normalize should be superfluous
104}
void setN0(const double n0)
Setter for first circle parameter.
void setN2(const double n2)
Setter for third circle parameter.
void setN3(const double n3)
Setter for fourth circle parameter.
void setN1(const double n1)
Setter for second circle parameter.

◆ setN() [1/4]

void setN ( const double  n0,
const double  n1,
const double  n2,
const double  n3 = 0.0 
)
inline

Setter for all four circle parameters.

Makes a normalization after setting. The normal representation of a line leave out the last parameter.

Definition at line 178 of file GeneralizedCircle.h.

179 {
180 setN0(n0);
181 setN12(n1, n2);
182 setN3(n3);
183 normalize();
184 }
void setN12(const double n1, const double n2)
Setter for second and third circle parameter.

◆ setN() [2/4]

void setN ( const double  n0,
const Vector2D n12,
const double  n3 = 0.0 
)
inline

Setter for all four circle parameters.

Makes a normalization after setting. The normal representation of a line leave out the last parameter.

Definition at line 191 of file GeneralizedCircle.h.

192 {
193 setN0(n0);
194 setN12(n12);
195 setN3(n3);
196 normalize();
197 }

◆ setN() [3/4]

void setN ( const GeneralizedCircle n0123)
inline

Setter for all four circle parameters from another circle.

Definition at line 206 of file GeneralizedCircle.h.

207 {
208 setN(n0123.n0(), n0123.n12(), n0123.n3());
209 }

◆ setN() [4/4]

void setN ( const Line2D n012)
inline

Setter for all four circle parameters from another circle.

Definition at line 200 of file GeneralizedCircle.h.

201 {
202 setN(n012.n0(), n012.n12());
203 }

◆ setN0()

void setN0 ( const double  n0)
inlineprotected

Setter for first circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 102 of file GeneralizedCircle.h.

103 {
104 m_n0 = n0;
105 }

◆ setN1()

void setN1 ( const double  n1)
inlineprotected

Setter for second circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 112 of file GeneralizedCircle.h.

113 {
114 m_n12.setX(n1);
115 }
void setX(const double x)
Setter for the x coordinate.
Definition: Vector2D.h:600

◆ setN12() [1/2]

void setN12 ( const double  n1,
const double  n2 
)
inlineprotected

Setter for second and third circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 132 of file GeneralizedCircle.h.

133 {
134 m_n12.setXY(n1, n2);
135 }
void setXY(const double x, const double y)
Setter for both coordinate.
Definition: Vector2D.h:616

◆ setN12() [2/2]

void setN12 ( const Vector2D n12)
inlineprotected

Setter for second and third circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 142 of file GeneralizedCircle.h.

143 {
144 m_n12.setXY(n12);
145 }

◆ setN2()

void setN2 ( const double  n2)
inlineprotected

Setter for third circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 122 of file GeneralizedCircle.h.

123 {
124 m_n12.setY(n2);
125 }
void setY(const double y)
Setter for the y coordinate.
Definition: Vector2D.h:610

◆ setN3()

void setN3 ( const double  n3)
inlineprotected

Setter for fourth circle parameter.

Makes no normalization after setting. Use is discouraged.

Definition at line 152 of file GeneralizedCircle.h.

153 {
154 m_n3 = n3;
155 }

◆ setPerigeeParameters() [1/2]

void setPerigeeParameters ( const double  curvature,
const double  tangentialPhi,
const double  impact 
)
inline

Setter for the perigee parameters.

Definition at line 168 of file GeneralizedCircle.h.

169 {
171 }
static Vector2D Phi(const double phi)
Constucts a unit vector with azimuth angle equal to phi.
Definition: Vector2D.h:62

◆ setPerigeeParameters() [2/2]

void setPerigeeParameters ( double  curvature,
const Vector2D tangential,
double  impact 
)

Setter for the perigee parameters.

Definition at line 106 of file GeneralizedCircle.cc.

109{
110 double n0 = impact * (impact * curvature / 2.0 + 1.0);
112 double n3 = curvature / 2.0;
113 setN(n0, n12, n3);
114}
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:289

◆ tangential() [1/2]

Vector2D tangential ( ) const
inline

Gives the tangential vector at the closest approach to the origin / at the perigee.

Definition at line 505 of file GeneralizedCircle.h.

506 {
507 return tangential(Vector2D(0.0, 0.0)).unit();
508 }

◆ tangential() [2/2]

Vector2D tangential ( const Vector2D point) const
inline

Tangential vector to the circle near the given position.

Gives the unit tangential vector to the circle line. It always points in the direction of positiv advance at the point of closest approach from the given point.

Parameters
pointPoint in the plane to calculate the tangential
Returns
Unit tangential vector to the circle line

Definition at line 374 of file GeneralizedCircle.h.

375 {
376 return normal(point).orthogonal();
377 }
Vector2D normal(const Vector2D &point) const
Normal vector to the circle near the given position.

◆ tangentialPhi()

double tangentialPhi ( ) const
inline

Gives to azimuth angle phi of the direction of flight at the perigee.

Definition at line 511 of file GeneralizedCircle.h.

512 {
513 return tangential().phi();
514 }
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
Definition: Vector2D.h:569

Member Data Documentation

◆ m_n0

double m_n0
private

Memory for the first parameter.

Definition at line 691 of file GeneralizedCircle.h.

◆ m_n12

Vector2D m_n12
private

Memory for the second and third parameter.

Definition at line 688 of file GeneralizedCircle.h.

◆ m_n3

double m_n3
private

Memory for the fourth parameter.

Definition at line 685 of file GeneralizedCircle.h.


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