Belle II Software development
ParameterLine2D.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingCDC/geometry/GeneralizedCircle.h>
11#include <tracking/trackFindingCDC/geometry/Line2D.h>
12#include <tracking/trackFindingCDC/geometry/Vector2D.h>
13
14#include <tracking/trackFindingCDC/numerics/Quadratic.h>
15#include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
16#include <tracking/trackFindingCDC/numerics/ERightLeft.h>
17#include <tracking/trackFindingCDC/numerics/ERotation.h>
18#include <tracking/trackFindingCDC/numerics/ESign.h>
19
20#include <utility>
21#include <cmath>
22#include <iosfwd>
23
24namespace Belle2 {
29 namespace TrackFindingCDC {
30
32
39
40 public:
43 : m_support(0.0, 0.0)
44 , m_tangential(0.0, 0.0)
45 {
46 }
47
52 {
53 }
54
56
59 static ParameterLine2D fromSlopeIntercept(const double slope, const double intercept)
60 {
61 return ParameterLine2D(Vector2D(0.0, intercept), Vector2D(1.0, slope));
62 }
63
66
70 const double intercept,
71 const EForwardBackward orientation)
72 {
74 Vector2D(orientation, static_cast<double>(orientation) * slope));
75 }
76
78
82 static ParameterLine2D throughPoints(const Vector2D& start, const Vector2D& end)
83 {
84 return ParameterLine2D(start, end - start);
85 }
86
88
93 explicit ParameterLine2D(const Line2D& line)
94 : m_support(line.support())
95 , m_tangential(line.tangential())
96 {
97 }
98
100
108 static ParameterLine2D touchingCircles(const Vector2D& fromCenter,
109 double fromSignedRadius,
110 const Vector2D& toCenter,
111 double toSignedRadius);
112
114
118 operator Line2D()
119 {
120 return Line2D(distanceToOrigin(), normal().unit());
121 } // not optimal yet. tangential.norm() is getting calculated two times.
122
123 public:
125 const Vector2D& tangential() const
126 {
127 return m_tangential;
128 }
131 {
132 return tangential().orthogonal(ERotation::c_Clockwise);
133 }
134
136 const Vector2D& support() const
137 {
138 return m_support;
139 }
140
142 Vector2D at(const double parameter) const
143 {
144 return tangential() * parameter += support();
145 }
146
150 {
151 return static_cast<EForwardBackward>(sign(tangential().first()));
152 }
153
157 {
158 return static_cast<EForwardBackward>(sign(tangential().second()));
159 }
160
162
168 {
170 }
171
174 {
175 m_support.set(0, 0);
176 m_tangential.set(0, 0);
177 }
178
180 bool isInvalid() const
181 {
182 return m_tangential.isNull();
183 }
184
186 void reverse()
187 {
189 }
190
193 {
194 return ParameterLine2D(support(), -tangential());
195 }
196
197 public:
199
201 double distance(const Vector2D& point) const
202 {
203 return distanceToOrigin() - point.orthogonalComp(tangential());
204 }
205
207
209 double distance(const double first, const double second) const
210 {
211 return distance(Vector2D(first, second));
212 }
213
215 double distanceToOrigin() const
216 {
218 }
219
221 double absoluteDistance(const Vector2D& point) const
222 {
223 return fabs(distance(point));
224 }
225
228 {
229 return static_cast<ERightLeft>(sign(distance(point)));
230 }
231
233 bool isLeft(const Vector2D& rhs) const
234 {
235 return isRightOrLeft(rhs) == ERightLeft::c_Left;
236 }
237
239 bool isRight(const Vector2D& rhs) const
240 {
241 return isRightOrLeft(rhs) == ERightLeft::c_Right;
242 }
243
245 Vector2D closest(const Vector2D& point) const
246 {
247 double norm_squared = tangential().normSquared();
248 return Vector2D(tangential(),
249 tangential().dot(point) / norm_squared,
250 tangential().cross(support()) / norm_squared);
251 }
252
254 double closestAt(const Vector2D& point) const
255 {
256 return (tangential().dot(point) - tangential().dot(support())) / tangential().normSquared();
257 }
258
261 {
262 return tangential().orthogonal() *=
264 }
265
267 double closestToOriginAt() const
268 {
269 return -tangential().dot(support()) / tangential().normSquared();
270 }
271
273 double lengthOnCurve(const Vector2D& from, const Vector2D& to) const
274 {
275 return (to.dot(tangential()) - from.dot(tangential())) / tangential().norm();
276 }
277
279 double intersectionAt(const Line2D& line) const
280 {
281 return -(line.n0() + support().dot(line.normal())) / tangential().dot(line.normal());
282 }
283
285 double intersectionAt(const ParameterLine2D& line) const
286 {
287 return (line.tangential().cross(support()) - line.tangential().cross(line.support())) /
288 tangential().cross(line.tangential());
289 }
290
292
296 std::pair<double, double> intersectionsAt(const GeneralizedCircle& genCircle) const
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 }
304
306 Vector2D intersection(const Line2D& line) const
307 {
308 return at(intersectionAt(line));
309 }
310
313 {
314 return at(intersectionAt(line));
315 }
316
320
323 void passiveMoveAtBy(const double delta)
324 {
325 m_support += tangential() * delta;
326 }
327
329 void moveBy(const Vector2D& by)
330 {
331 m_support += by;
332 }
333
336 void moveAlongFirst(const double first)
337 {
339 }
340
343 void moveAlongSecond(const double second)
344 {
346 }
347
350 void passiveMoveBy(const Vector2D& by)
351 {
352 m_support -= by;
353 }
354
357 void passiveMoveAlongFirst(const double first)
358 {
360 }
361
364 void passiveMoveAlongSecond(const double second)
365 {
367 }
376 double slope() const
377 {
378 return tangential().second() / tangential().first();
379 }
380
382 double inverseSlope() const
383 {
384 return tangential().first() / tangential().second();
385 }
386
388 double intercept() const
389 {
390 return support().second() - slope() * support().first();
391 }
392
394 double zero() const
395 {
396 return support().first() - inverseSlope() * support().second();
397 }
398
400 double map(const double first) const
401 {
402 return support().second() + slope() * (first - support().first());
403 }
404
406 double operator()(const double first) const
407 {
408 return map(first);
409 }
410
412 double inverseMap(const double second) const
413 {
414 return support().first() + inverseSlope() * (second - support().second());
415 }
416
418 void invert()
419 {
422 }
423
426 {
427 return ParameterLine2D(Vector2D(support().second(), support().first()),
428 Vector2D(tangential().second(), tangential().first()));
429 }
431
432 private:
435
438 };
439
441 std::ostream& operator<<(std::ostream& output, const ParameterLine2D& line);
442 }
444}
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 n3() const
Getter for the fourth circle parameter.
A two dimensional normal line.
Definition: Line2D.h:37
A line with a support point and tangential vector.
ParameterLine2D()
Default constructor for ROOT compatibility.
const Vector2D & support() const
Gives the support vector of the line.
Vector2D m_support
Support vector of the line.
Vector2D m_tangential
Tangential vector of the line.
EForwardBackward alignedWithFirst() const
Indicates if the tangential vector point in a commmon direction with the first coordinate axes.
static ParameterLine2D fromSlopeIntercept(const double slope, const double intercept)
Constructs a line with slope and intercept.
double absoluteDistance(const Vector2D &point) const
Gives the unsigned distance of a point to the line.
double zero() const
First coordinate for second being zero.
static ParameterLine2D fromSlopeIntercept(const double slope, const double intercept, const EForwardBackward orientation)
Constructs a line with slope and intercept.
bool isInvalid() const
Check it the line is in an invalid state.
ParameterLine2D(const Vector2D &support, const Vector2D &tangential)
Standard constructor taking the support point and the tangential vector.
void reverse()
Reverses the tangential vector inplace.
double slope() const
The line slope.
double map(const double first) const
Method mapping the first coordinate to the second according to the line.
double distance(const Vector2D &point) const
Gives the signed distance of a point to the line.
ParameterLine2D(const Line2D &line)
Upcast the normal representation to a parameter line.
Vector2D at(const double parameter) const
Evaluates the line formula at the parameter given.
Vector2D closestToOrigin() const
Gives the position of closest approach to the origin.
std::pair< double, double > intersectionsAt(const GeneralizedCircle &genCircle) const
Gives the line parameters of this line, where it intersects with the generalized circle.
double distanceToOrigin() const
Gives the signed distance of the origin.
void passiveMoveBy(const Vector2D &by)
Moves the coordinate system in the given direction in place.
double intercept() const
Second coordinate for first being zero.
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.
void moveAlongFirst(const double first)
Moves the line along the first coordinate axes in place.
double intersectionAt(const Line2D &line) const
Gives the line parameter where the two lines meet. Infinity for parallels.
void passiveMoveAtBy(const double delta)
Moves the support point by the given amount of the parameter in the forward direction.
double inverseSlope() const
The inveres line slope.
double inverseMap(const double second) const
Method for the inverse mapping the second coordinate to the first according to the line.
double operator()(const double first) const
Operator mapping the first coordinate to the second according to the line.
void invert()
Turns the line into its inverse function in place. Orientation will be flipped as well.
void passiveMoveAlongFirst(const double first)
Moves the coordinate system along the first coordinate axes in place.
void invalidate()
Clear all information from the line.
ParameterLine2D reversed() const
Makes a copy line which has the opposite tangential vector but same support point.
EForwardBackward alignedWithSecond() const
Indicates if the tangential vector point in a commmon direction with the second coordinate axes.
Vector2D intersection(const Line2D &line) const
Gives the point where the two lines meet. Infinities for parallels.
void moveBy(const Vector2D &by)
Moves the line in the given direction in place. Corresponds to an active transformation.
ERightLeft isRightOrLeft(const Vector2D &point) const
Return if the point given is right or left of the line.
double intersectionAt(const ParameterLine2D &line) const
Gives the line parameter of this line where the two lines meet. Infinity for parallels.
Vector2D normal() const
Gives the normal vector of the line.
ParameterLine2D inverted() const
Gives the line assoziated with the inverse function as a copy.
static ParameterLine2D touchingCircles(const Vector2D &fromCenter, double fromSignedRadius, const Vector2D &toCenter, double toSignedRadius)
Constructs a line touching two circles in one point each.
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 closestAt(const Vector2D &point) const
Gives the line parameter at the closest approach to point.
Vector2D closest(const Vector2D &point) const
Gives the position at the closest approach on the line to point.
const Vector2D & tangential() const
Gives the tangential vector of the line.
void normalize()
Normalizes the tangential vector inplace.
void passiveMoveAlongSecond(const double second)
Moves the coordinate system along the second coordinate axes in place.
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.
void moveAlongSecond(const double second)
Moves the line along the second coordinate axes in place.
static ParameterLine2D throughPoints(const Vector2D &start, const Vector2D &end)
Static constructor for a line between to points.
Vector2D intersection(const ParameterLine2D &line) const
Gives the point where the two lines meet. Infinities for parallels.
A two dimensional vector which is equipped with functions for correct handeling of orientation relat...
Definition: Vector2D.h:32
void setSecond(const double second)
Setter for the second coordinate.
Definition: Vector2D.h:644
double normalize()
Normalizes the vector to unit length.
Definition: Vector2D.h:303
void swapCoordinates()
Swaps the coordinates in place.
Definition: Vector2D.h:551
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
Definition: Vector2D.h:158
void set(const double first, const double second)
Setter for both coordinate.
Definition: Vector2D.h:650
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
Definition: Vector2D.h:163
Vector2D & reverse()
Reverses the direction of the vector in place.
Definition: Vector2D.h:327
double orthogonalComp(const Vector2D &relativTo) const
Calculates the component orthogonal to the given vector.
Definition: Vector2D.h:432
double second() const
Getter for the second coordinate.
Definition: Vector2D.h:639
double normSquared() const
Calculates .
Definition: Vector2D.h:169
bool isNull() const
Checks if the vector is the null vector.
Definition: Vector2D.h:143
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
Definition: Vector2D.h:289
double first() const
Getter for the first coordinate.
Definition: Vector2D.h:629
double norm() const
Calculates the length of the vector.
Definition: Vector2D.h:175
void setFirst(const double first)
Setter for the first coordinate.
Definition: Vector2D.h:634
T dot(GeneralVector< T > a, GeneralVector< T > b)
dot product of two general vectors
Definition: beamHelpers.h:163
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
Definition: ERightLeft.h:25
Abstract base class for different kinds of events.