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();
104 auto cosPhi = 1.f - 2.f *
tmp *
tmp;
106 startingDir.
x() * sinPhi + startingDir.
y() * cosPhi,
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();
148 if (
d1.mag2() < d2.
mag2()) {
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);