39 : ncorners(0), corners(0)
118 zNormEdge[0] /= lAdj;
130 zNormEdge[1] /= lAdj;
138 : startPhi(0.), deltaPhi(0.), phiIsOpen(false), allBehind(false),
139 cone(0), rNorm(0.), zNorm(0.), rS(0.), zS(0.), length(0.),
140 prevRS(0.), prevZS(0.), nextRS(0.), nextZS(0.), ncorners(0), corners(0),
249 double surfTolerance,
251 double& distFromSurface,
256 double normSign = outgoing ? +1 : -1;
264 if (nside == 0)
return false;
276 if (normSign * v.Dot(normal) > 0)
290 double pr = p.
Perp();
293 if (normSign * v.Dot(pNormal) > 0)
299 distFromSurface = -normSign *
DistanceAway(p,
false, distOutside2);
300 if (distOutside2 < surfTolerance * surfTolerance)
302 if (distFromSurface > -surfTolerance)
314 distFromSurface = s1;
327 if (nside == 1)
return false;
339 if (normSign * v.Dot(normal) > 0)
341 double pr = p.
Perp();
344 if (normSign * v.Dot(pNormal) > 0)
347 distFromSurface = -normSign *
DistanceAway(p,
false, distOutside2);
348 if (distOutside2 < surfTolerance * surfTolerance)
350 if (distFromSurface > -surfTolerance)
358 distFromSurface = s2;
377 double normSign = outgoing ? -1 : +1;
378 double distFrom, distOut2;
390 return std::sqrt(distFrom * distFrom + distOut2);
392 return std::fabs(distFrom);
403 return std::sqrt(distFrom * distFrom + distOut2);
405 return std::fabs(distFrom);
417 double* bestDistance)
422 double distFrom[2], distOut2[2], dist2[2];
423 double edgeRZnorm[2];
425 distFrom[0] =
DistanceAway(p,
false, distOut2[0], edgeRZnorm);
426 distFrom[1] =
DistanceAway(p,
true, distOut2[1], edgeRZnorm + 1);
428 dist2[0] = distFrom[0] * distFrom[0] + distOut2[0];
429 dist2[1] = distFrom[1] * distFrom[1] + distOut2[1];
434 int i = std::fabs(dist2[0]) < std::fabs(dist2[1]) ? 0 : 1;
436 *bestDistance = std::sqrt(dist2[i]);
441 if ((std::fabs(edgeRZnorm[i]) < atolerance)
442 && (distOut2[i] < atolerance * atolerance))
444 else if (edgeRZnorm[i] < 0)
455 double* bestDistance)
466 *bestDistance = std::sqrt(dFrom * dFrom + dOut2);
468 double rds = p.
Perp();
495 double phi =
GetPhi(axis);
512 double ad = axis.
Dot(a),
517 if (bd > ad) ad = bd;
518 if (
cd > ad) ad =
cd;
519 if (dd > ad) ad = dd;
528 double aPerp = axis.
Perp();
530 double a = aPerp *
r[0] + axis.
z *
z[0];
531 double b = aPerp *
r[1] + axis.
z *
z[1];
896 double& distOutside2,
902 double rx = p.
Perp(), zx = p.
z;
907 if (opposite) rx = -rx;
912 double deltaR = rx -
r[0], deltaZ = zx -
z[0];
913 double answer = deltaR *
rNorm + deltaZ *
zNorm;
918 double q = deltaR *
rS + deltaZ *
zS;
921 distOutside2 = q * q;
937 if (edgeRZnorm) *edgeRZnorm = answer;
957 if (d2 < d1) d1 =
d2;
962 double dist = d1 * rx;
964 distOutside2 += dist * dist;
967 *edgeRZnorm =
std::max(std::fabs(*edgeRZnorm), std::fabs(dist));
987 double rx = hit.
Perp();
1001 double phi =
GetPhi(hit);
1013 qb = qx - corners[3];
1016 if (normSign * qacb.
Dot(v) < 0)
return false;
1018 else if (phi < phiTolerant)
1022 qb = qx - corners[0];
1025 if (normSign * qacb.
Dot(v) < 0)
return false;
1051 double tx1,
double ty1,
1052 double x2,
double y2,
1053 double tx2,
double ty2,
1054 double& x,
double& y)
1059 double deter = tx1 * ty2 - tx2 * ty1;
1061 double s1 = ((x2 - x1) * ty2 - tx2 * (y2 - y1)) / deter;
1062 double s2 = ((x2 - x1) * ty1 - tx1 * (y2 - y1)) / deter;
1068 x = 0.5 * (x1 + s1 * tx1 + x2 + s2 * tx2);
1069 y = 0.5 * (y1 + s1 * ty1 + y2 + s2 * ty2);
1091 double rr, phi, dz, dr;
1097 x = rr * std::cos(phi);
1098 y = rr * std::sin(phi);
1114 zz = z[0] + (rr - r[0]) * dz / dr;
UVector3 GetPointOnFace()
void CopyStuff(const UPolyconeSide &source)
double DistanceAway(const UVector3 &p, bool opposite, double &distOutside2, double *rzNorm=0)
UVector3 Cross(const UVector3 &) const
double Extent(const UVector3 axis)
UPolyconeSide & operator=(const UPolyconeSide &source)
VUSolid::EnumInside Inside(const UVector3 &p, double tolerance, double *bestDistance)
static const G4double tolerance
double GetPhi(const UVector3 &p)
static double Tolerance()
bool HitOn(const double r, const double z)
static double normal(HepRandomEngine *eptr)
static const double kInfinity
UVector3 Normal(const UVector3 &p, double *bestDistance)
double Dot(const UVector3 &) const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
double Safety(const UVector3 &p, bool outgoing)
UPolyconeSide(const UPolyconeSideRZ *prevRZ, const UPolyconeSideRZ *tail, const UPolyconeSideRZ *head, const UPolyconeSideRZ *nextRZ, double phiStart, double deltaPhi, bool phiIsOpen, bool isAllBehind=false)
bool Distance(const UVector3 &p, const UVector3 &v, bool outgoing, double surfTolerance, double &distance, double &distFromSurface, UVector3 &normal, bool &isAllBehind)
static void FindLineIntersect(double x1, double y1, double tx1, double ty1, double x2, double y2, double tx2, double ty2, double &x, double &y)
double Random(double min=0.0, double max=1.0)
int LineHitsCone(const UVector3 &p, const UVector3 &v, double &s1, double &s2)
bool PointOnCone(const UVector3 &hit, double normSign, const UVector3 &p, const UVector3 &v, UVector3 &normal)