32 static const double halfCarTolerance
38 type1 = (std::fabs(z[1] - z[0]) > std::fabs(r[1] - r[0]));
42 B = (r[1] - r[0]) / (z[1] - z[0]);
43 A = 0.5 * (r[1] + r[0] -
B * (z[1] + z[0]));
47 B = (z[1] - z[0]) / (r[1] - r[0]);
48 A = 0.5 * (z[1] + z[0] -
B * (r[1] + r[0]));
55 rLo = r[0] - halfCarTolerance;
56 rHi = r[1] + halfCarTolerance;
60 rLo = r[1] - halfCarTolerance;
61 rHi = r[0] + halfCarTolerance;
66 zLo = z[0] - halfCarTolerance;
67 zHi = z[1] + halfCarTolerance;
71 zLo = z[1] - halfCarTolerance;
72 zHi = z[0] + halfCarTolerance;
112 if (z < zLo || z >
zHi)
return false;
116 if (r < rLo || r >
rHi)
return false;
211 double x0 = p.
x, y0 = p.
y,
z0 = p.
z;
212 double tx = v.
x, ty = v.
y, tz = v.
z;
215 double b = 2 * (x0 * tx + y0 * ty - (
A *
B +
B *
B *
z0) * tz);
218 double radical = b * b - 4 * a * c;
221 double minRadical = 1E-6 * std::fabs(b);
223 if (radical < -minRadical)
228 if (radical < minRadical)
239 if (std::fabs(x0 * ty - y0 * tx) < std::fabs(1E-6 /
B))
246 radicalSqrt = radical;
250 radicalSqrt = std::sqrt(radical);
255 double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
268 if (
A +
B * (z0 + (s1)*tz) < 0)
277 double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
280 s1 = (tz *
B > 0) ^ (sa > sb) ? sb : sa;
290 if (
A +
B * (z0 + (s1)*tz) < 0)
303 double x0 = p.
x, y0 = p.
y,
z0 = p.
z;
304 double tx = v.
x, ty = v.
y, tz = v.
z;
307 double b = 2 * (x0 * tx + y0 * ty - (
A *
B +
B *
B *
z0) * tz);
310 double radical = b * b - 4 * a * c;
312 double minRadical = 1E-6 * std::fabs(b);
314 if (radical < -minRadical)
321 if (radical < minRadical)
331 if (std::fabs(x0 * ty - y0 * tx) < std::fabs(1E-6 /
B))
340 double radicalSqrt = std::sqrt(radical);
344 double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
357 if (
A +
B * (z0 + (s1)*tz) < 0)
366 double sa, sb, q = -0.5 * (b + (b < 0 ? -radicalSqrt : +radicalSqrt));
369 s1 = (tz *
B > 0) ^ (sa > sb) ? sb : sa;
383 if (
A +
B * (z0 + (s1)*tz) < 0)
418 double& s1,
double& s2)
420 double x0 = p.
x, y0 = p.
y,
z0 = p.
z;
421 double tx = v.
x, ty = v.
y, tz = v.
z;
438 double a = tz * tz - B2 * (tx * tx + ty * ty);
439 double b = 2 * ((
z0 -
A) * tz - B2 * (x0 * tx + y0 * ty));
442 double radical = b * b - 4 * a * c;
444 if (radical < -1E-6 * std::fabs(b))
449 if (radical < 1E-6 * std::fabs(b))
456 if (std::fabs(x0 * ty - y0 * tx) < std::fabs(1E-6 / B))
466 radical = std::sqrt(radical);
471 double sa, sb, q = -0.5 * (b + (b < 0 ? -radical : +radical));
484 if ((
z0 + (s1)*tz -
A) / B < 0)
492 double sa, sb, q = -0.5 * (b + (b < 0 ? -radical : +radical));
495 s1 = (tz * B > 0) ^ (sa > sb) ? sb : sa;
505 if ((
z0 + (s1)*tz -
A) / B < 0)
int LineHitsCone1(const UVector3 &p, const UVector3 &v, double &s1, double &s2)
int LineHitsCone1Optimized(const UVector3 &p, const UVector3 &v, double &s1, double &s2)
int LineHitsCone2(const UVector3 &p, const UVector3 &v, double &s1, double &s2)
virtual ~UIntersectingCone()
static double Tolerance()
bool HitOn(const double r, const double z)
static const double EpsilonQuad
UIntersectingCone(const double r[2], const double z[2])
int LineHitsCone(const UVector3 &p, const UVector3 &v, double &s1, double &s2)