10#include <tracking/trackingUtilities/geometry/VectorUtil.h>
12#include <tracking/trackingUtilities/numerics/EForwardBackward.h>
13#include <tracking/trackingUtilities/numerics/ERightLeft.h>
14#include <tracking/trackingUtilities/numerics/ESign.h>
16#include <Math/Vector2D.h>
25 namespace TrackingUtilities {
88 const EForwardBackward orientation)
90 return Line2D(
intercept *
static_cast<double>(orientation),
slope *
static_cast<double>(orientation), -orientation);
96 return Line2D(VectorUtil::Cross(end, start), VectorUtil::Orthogonal(start - end));
119 const ROOT::Math::XYVector&
n12()
const
191 const EForwardBackward orientation)
194 setN1(
slope *
static_cast<double>(orientation));
245 double distance(
const ROOT::Math::XYVector& point)
const
247 return n0() + point.Dot(
n12());
255 double distance(
const double first,
const double second)
const
257 return n0() + first *
n1() + second *
n2();
278 return static_cast<ERightLeft
>(sign(
distance(point)));
282 bool isLeft(
const ROOT::Math::XYVector& rhs)
const
288 bool isRight(
const ROOT::Math::XYVector& rhs)
const
294 ROOT::Math::XYVector
closest(
const ROOT::Math::XYVector& point)
const
296 const double closestParallel = -
n0();
297 const double closestOrthgonal = VectorUtil::unnormalizedOrthogonalComp(point,
n12());
298 return VectorUtil::compose(
n12(), closestParallel, closestOrthgonal);
304 return n12() * (-
n0());
314 double lengthOnCurve(
const ROOT::Math::XYVector& from,
const ROOT::Math::XYVector& to)
const
316 return VectorUtil::unnormalizedOrthogonalComp(to,
n12()) - VectorUtil::unnormalizedOrthogonalComp(from,
n12());
322 return n0() == 0.0 and VectorUtil::isNull(
n12());
328 return VectorUtil::Orthogonal(
normal());
332 const ROOT::Math::XYVector&
normal()
const
353 return static_cast<EForwardBackward
>(-sign(
n2()));
360 return static_cast<EForwardBackward
>(sign(
n1()));
369 void moveBy(
const ROOT::Math::XYVector& by)
371 m_n0 -= VectorUtil::unnormalizedParallelComp(by,
n12());
401 m_n0 += VectorUtil::unnormalizedParallelComp(by,
n12());
483 double map(
const double first)
const
485 return -(
n0() +
n1() * first) /
n2();
496 return -(
n0() +
n2() * second) /
n1();
A two dimensional normal line.
Line2D passiveMovedAlongFirst(const double first) const
Return a copy of the line passively moved long the first coordinate.
void flipSecond()
Flips the first coordinate inplace (no difference between active and passive)
Line2D movedAlongFirst(const double first) const
Return a copy of the line actively moved long the first coordinate.
Line2D()
Default constructor for ROOT compatibility.
double n1() const
Getter for the second line parameter.
EForwardBackward alignedWithFirst() const
Returns if the direction of positive advance has a common component aligned or anti aligned with the ...
Line2D flippedSecond() const
Makes a copy of the line with the second coordinate flipped (no difference between active and passive...
bool isRight(const ROOT::Math::XYVector &rhs) const
Return if the point given is right of the line.
double normalization() const
Calculates the normalization. Helper for normalize.
double zero() const
Returns the root of the line.
bool isInvalid() const
Indicates if all circle parameters are zero.
void reverse()
Flips orientation the line in place.
ROOT::Math::XYVector intersection(const Line2D &line) const
Calculates the intersection point of two line. Infinity for parallels.
Line2D inverted() const
Returns the inverse function line as a copy.
void setN0(const double n0)
Setter for first line parameter This sets the signed distance of the line to the origin.
double slope() const
Returns the slope over the first coordinate.
void setSlopeIntercept(const double slope, const double intercept)
Sets the new intercept and slope of the line the direction is set to be forward with the increasing x...
double map(const double first) const
Maps the first coordinate to the second.
const ROOT::Math::XYVector & n12() const
Getter for the unit normal vector to the line.
const ROOT::Math::XYVector & normal() const
Getter for the unit normal vector of the line.
void setN2(const double n2)
Setter for the third line parameter. May violate the normalization.
void moveBy(const ROOT::Math::XYVector &by)
Actively moves the line in the direction given in place by the vector given.
bool isLeft(const ROOT::Math::XYVector &rhs) const
Return if the point given is left of the line.
ROOT::Math::XYVector closest(const ROOT::Math::XYVector &point) const
Calculates the point of closest approach on the line to the point.
ROOT::Math::XYVector closestToOrigin() const
Returns the point closest to the origin.
void flipFirst()
Flips the first coordinate inplace (no difference between active and passive)
void setN1(const double n1)
Setter for the second line parameter. May violate the normalization.
double m_n0
Memory for the first line parameter.
double distanceToOrigin() const
Returns the distance to the origin The distance to the origin is equivalent to the first line paramet...
double intercept() const
Returns the intercept over the first coordinate.
void moveAlongFirst(const double first)
Actively moves the line in the direction given in place along the first coordinate.
void setN12(const double n1, const double n2)
Setter for the normal vector by its coordinates.
double inverseSlope() const
Returns the slope over the second coordinate.
double normalizationSquared() const
Calculates the squared normalization. Helper for normalize.
double inverseMap(const double second) const
Maps the second coordinate to the first.
double operator()(const double first) const
Maps the first coordinate to the second.
double distance(const ROOT::Math::XYVector &point) const
Calculates the signed distance of the point to the line.
void invert()
Turns the line function into its inverse function in place.
static Line2D fromSlopeIntercept(const double slope, const double intercept, const EForwardBackward orientation)
Constructs a line from its slope and intercept over the first coordinate with the given orientation.
void passiveMoveAlongFirst(const double first)
Passively move the coordinate system in place along the first coordinate.
void invalidate()
Sets all line parameters to zero.
ERightLeft isRightOrLeft(const ROOT::Math::XYVector &point) const
Return if the point given is right or left of the line.
void passiveMoveBy(const ROOT::Math::XYVector &by)
Passively move the coordinate system in place by the given vector.
ROOT::Math::XYVector tangential() const
Gives the tangential vector in the direction of positive advance on the line.
EForwardBackward alignedWithSecond() const
Returns if the direction of positive advance has a common component aligned or anti aligned with the ...
Line2D flippedFirst() const
Makes a copy of the line with the first coordinate flipped (no difference between active and passive)
void scaleN(const double factor)
Scales all parameters. Helper for normalize.
Line2D reversed() const
Returns a copy of the line with the reversed orientation.
double n2() const
Getter for the third line parameter.
Line2D movedAlongSecond(const double second) const
Return a copy of the line actively moved long the first coordinate.
double distance(const double first, const double second) const
Calculates the signed distance of the point given by its to coordinates to the line.
void setSlopeIntercept(const double slope, const double intercept, const EForwardBackward orientation)
Sets the new intercept and slope of the line the direction is set to be forward with the increasing x...
double absoluteDistance(const ROOT::Math::XYVector &point) const
Returns the absolute value of distance(point)
void setN(const double n0, const double n1, const double n2)
Setter the for the line parameters which takes care of the correct normalization of the normal vector...
ROOT::Math::XYVector support() const
Getter for the support point of the line being the point closest to the origin.
void normalize()
Updates the parameters to obey the normalization condition.
Line2D(const double n0, const double n1, const double n2)
Constructs taking all three line parameters.
void setN12(const ROOT::Math::XYVector &n12)
Setter for the normal vector.
void passiveMoveAlongSecond(const double second)
Passively move the coordinate system in place along the second coordinate.
double n0() const
Getter for the first line parameter.
double lengthOnCurve(const ROOT::Math::XYVector &from, const ROOT::Math::XYVector &to) const
Calculates the length on the curve between two points.
static Line2D throughPoints(const ROOT::Math::XYVector &start, const ROOT::Math::XYVector &end)
Constructs a line through the two given points.
static Line2D fromSlopeIntercept(const double slope, const double intercept)
Constructs a line from its slope and intercept over the first coordinate (default forward orientation...
const ROOT::Math::XYVector & gradient() const
Getter for the gradient of the distance field.
Line2D(const double n0, const ROOT::Math::XYVector &n12)
Constructs taking the distance to the origin ( n0 ) and the normal vector.
void moveAlongSecond(const double second)
Actively moves the line in the direction given in place along the second coordinate.
Line2D passiveMovedAlongSecond(const double second) const
Return a copy of the line passively moved long the first coordinate.
ROOT::Math::XYVector m_n12
Memory for the second line parameter.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.