27 const double sraightLineCutoff = 1.e-7;
28 if (fabs(rho) * R < sraightLineCutoff && fabs(rho) * startingPos.
perp() < sraightLineCutoff) {
31 std::pair<bool, double> pl = slc.
pathLength(cyl);
43 double pt = startingDir.
perp();
44 Point center(startingPos.
x() - startingDir.
y() / (pt *
rho), startingPos.
y() + startingDir.
x() / (pt *
rho));
45 double p2 = startingPos.
perp2();
48 if (fabs(center.
x()) > fabs(center.
y())) {
50 E = (R2cyl -
p2) / (2. * center.
x());
51 F = center.
y() / center.
x();
52 B = 2. * (startingPos.
y() - F * startingPos.
x() - E *
F);
53 C = 2. * E * startingPos.
x() + E * E + p2 - R2cyl;
56 E = (R2cyl -
p2) / (2. * center.
y());
57 F = center.
x() / center.
y();
58 B = 2. * (startingPos.
x() - F * startingPos.
y() - E *
F);
59 C = 2. * E * startingPos.
y() + E * E + p2 - R2cyl;
81 std::tie(theD, theActualDir) =
chooseSolution(d1, d2, startingPos, startingDir, propDir);
85 float ipabs = 1.f / startingDir.
mag();
86 float sinTheta = float(pt) * ipabs;
87 float cosTheta = startingDir.
z() * ipabs;
91 auto dMag = theD.
mag();
92 float tmp = 0.5f * float(dMag * rho);
94 tmp = std::copysign(1.
f, tmp);
95 theS = theActualDir * 2.f * std::asin(tmp) / (float(rho) * sinTheta);
119 auto dMag1 = d1.
mag();
120 auto tmp1 = 0.5f * dMag1 * float(rho);
122 tmp1 = std::copysign(1.
f, tmp1);
123 auto theS1 = theActualDir1 * 2.f * std::asin(tmp1) / (rho * sinTheta);
126 auto dMag2 = d2.
mag();
127 auto tmp2 = 0.5f * dMag2 * float(rho);
129 tmp2 = std::copysign(1.
f, tmp2);
130 auto theS2 = theActualDir2 * 2.f * std::asin(tmp2) / (float(rho) * sinTheta);
143 auto momProj1 = startingDir.
x() * d1.
x() + startingDir.
y() * d1.
y();
144 auto momProj2 = startingDir.
x() * d2.
x() + startingDir.
y() * d2.
y();
150 theActualDir = (momProj1 > 0) ? 1 : -1;
153 theActualDir = (momProj2 > 0) ? 1 : -1;
157 if (momProj1 * momProj2 < 0) {
160 theD = (momProj1 * propSign > 0) ? d1 : d2;
161 theActualDir = propSign;
162 }
else if (momProj1 * propSign > 0) {
165 theD = (d1.
mag2() < d2.
mag2()) ? d1 : d2;
166 theActualDir = propSign;
171 return std::pair<Vector, int>(theD, theActualDir);
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
HelixBarrelCylinderCrossing(const GlobalPoint &startingPos, const GlobalVector &startingDir, double rho, PropagationDirection propDir, const Cylinder &cyl, Solution sol=bothSol)
GlobalVector DirectionType
std::pair< bool, double > pathLength(const Cylinder &cyl) const
Global3DPoint GlobalPoint
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::pair< Vector, int > chooseSolution(const Point &p1, const Point &p2, const PositionType &startingPos, const DirectionType &startingDir, PropagationDirection propDir)
Scalar radius() const
Radius of the cylinder.
Basic2DVector< TmpType > Point
LocalPoint toLocal(const GlobalPoint &gp) const
Abs< T >::type abs(const T &t)
static const std::string B
T y() const
Cartesian y coordinate.
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
static constexpr float d1
T x() const
Cartesian x coordinate.