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, distOut2, dist2;
426 dist2 = distFrom * distFrom + distOut2;
429 *bestDistance = std::sqrt(dist2);
434 if ((std::fabs(edgeRZnorm) < atolerance)
435 && (distOut2 < atolerance * atolerance))
437 else if (edgeRZnorm < 0)
448 double* bestDistance)
459 *bestDistance = std::sqrt(dFrom * dFrom + dOut2);
461 double rds = p.
Perp();
488 double phi =
GetPhi(axis);
505 double ad = axis.
Dot(a),
510 if (bd > ad) ad = bd;
511 if (
cd > ad) ad =
cd;
512 if (dd > ad) ad = dd;
521 double aPerp = axis.
Perp();
523 double a = aPerp *
r[0] + axis.
z() *
z[0];
524 double b = aPerp *
r[1] + axis.
z() *
z[1];
889 double& distOutside2,
895 double rx = p.
Perp(), zx = p.
z();
900 if (opposite) rx = -rx;
905 double deltaR = rx -
r[0], deltaZ = zx -
z[0];
906 double answer = deltaR *
rNorm + deltaZ *
zNorm;
911 double q = deltaR *
rS + deltaZ *
zS;
914 distOutside2 = q * q;
930 if (edgeRZnorm) *edgeRZnorm = answer;
950 if (d2 < d1) d1 =
d2;
955 double dist = d1 * rx;
957 distOutside2 += dist * dist;
960 *edgeRZnorm =
std::max(std::fabs(*edgeRZnorm), std::fabs(dist));
976 double& distOutside2,
982 double rx = p.
Perp(), zx = p.
z();
988 if (rx < 0) part = -1;
993 double deltaR = rx -
r[0]*part, deltaZ = zx -
z[0];
994 double answer = deltaR *
rNorm*part + deltaZ *
zNorm;
999 double q = deltaR *
rS *part+ deltaZ *
zS;
1002 distOutside2 = q * q;
1013 deltaR = rx -
r[1]*part;
1021 if (edgeRZnorm) *edgeRZnorm = answer;
1041 if (d2 < d1) d1 =
d2;
1046 double dist = d1 * rx*part;
1048 distOutside2 += dist * dist;
1051 *edgeRZnorm =
std::max(std::fabs(*edgeRZnorm), std::fabs(dist));
1071 double rx = hit.
Perp();
1085 double phi =
GetPhi(hit);
1097 qb = qx - corners[3];
1100 if (normSign * qacb.
Dot(v) < 0)
return false;
1102 else if (phi < phiTolerant)
1106 qb = qx - corners[0];
1109 if (normSign * qacb.
Dot(v) < 0)
return false;
1135 double tx1,
double ty1,
1136 double x2,
double y2,
1137 double tx2,
double ty2,
1138 double& x,
double& y)
1143 double deter = tx1 * ty2 - tx2 * ty1;
1145 double s1 = ((x2 - x1) * ty2 - tx2 * (y2 - y1)) / deter;
1146 double s2 = ((x2 - x1) * ty1 - tx1 * (y2 - y1)) / deter;
1152 x = 0.5 * (x1 + s1 * tx1 + x2 + s2 * tx2);
1153 y = 0.5 * (y1 + s1 * ty1 + y2 + s2 * ty2);
1175 double rr, phi, dz, dr;
1181 x = rr * std::cos(phi);
1182 y = rr * std::sin(phi);
1198 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)