85 fVertices =
new vector<G4ThreeVector>(3);
104 fArea = 0.5 * E1xE2.
mag();
105 for (
G4int i = 0; i < 3; ++i) fIndices[i] = -1;
115 if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
134 ostringstream message;
135 message <<
"Facet is too small or too narrow." <<
G4endl
136 <<
"Triangle area = " << fArea <<
G4endl
140 <<
"Side1 length (P0->P1) = " << leng1 <<
G4endl
141 <<
"Side2 length (P1->P2) = " << leng2 <<
G4endl
142 <<
"Side3 length (P2->P0) = " << leng3;
143 G4Exception(
"G4TriangularFacet::G4TriangularFacet()",
145 fSurfaceNormal.
set(0,0,0);
148 fCircumcentre = vt0 + 0.5*fE1 + 0.5*fE2;
149 fArea = fRadius = 0.0;
153 fSurfaceNormal = E1xE2.
unit();
157 fDet = std::fabs(fA*fC - fB*fB);
160 vt0 + (E1xE2.
cross(fE1)*fC + fE2.
cross(E1xE2)*fA) / (2.*E1xE2.
mag2());
161 fRadius = (fCircumcentre - vt0).mag();
170 fVertices =
new vector<G4ThreeVector>(3);
175 for (
G4int i = 0; i < 3; ++i) fIndices[i] = -1;
177 fSurfaceNormal.
set(0,0,0);
182 fArea = fRadius = 0.0;
196 char *
p = (
char *) &rhs;
197 copy(p, p +
sizeof(*
this), (
char *)
this);
199 if (fIndices[0] < 0 && fVertices)
201 fVertices =
new vector<G4ThreeVector>(3);
202 for (
G4int i = 0; i < 3; ++i) (*fVertices)[i] = (*rhs.fVertices)[i];
290 if (-d >= fA) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
291 else {q = -d/fA; fSqrDist = d*q + f;}
296 if (e >= 0.0) {t = 0.0; fSqrDist = f;}
297 else if (-e >= fC) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
298 else {t = -e/fC; fSqrDist = e*t + f;}
307 if (e >= 0.0) {t = 0.0; fSqrDist = f;}
308 else if (-e >= fC) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
309 else {t = -e/fC; fSqrDist = e*t + f;}
318 if (d >= 0.0) {q = 0.0; fSqrDist = f;}
319 else if (-d >= fA) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
320 else {q = -d/fA; fSqrDist = d*q + f;}
329 fSqrDist = q*(fA*q + fB*t + 2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
345 if (numer >= denom) {q = 1.0; t = 0.0; fSqrDist = fA + 2.0*d + f;}
350 fSqrDist = q*(fA*q + fB*t +2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
356 if (tmp1 <= 0.0) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
357 else if (e >= 0.0) {t = 0.0; fSqrDist = f;}
358 else {t = -e/fC; fSqrDist = e*t + f;}
372 if (numer >= denom) {t = 1.0; q = 0.0; fSqrDist = fC + 2.0*e + f;}
377 fSqrDist = q*(fA*q + fB*t +2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
383 if (tmp1 <= 0.0) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
384 else if (d >= 0.0) {q = 0.0; fSqrDist = f;}
385 else {q = -d/fA; fSqrDist = d*q + f;}
398 fSqrDist = fC + 2.0*e + f;
403 if (numer >= denom) {q = 1.0; t = 0.0; fSqrDist = fA + 2.0*d + f;}
408 fSqrDist = q*(fA*q + fB*t + 2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
430 if (fSqrDist < 0.0) fSqrDist = 0.;
437 if (fSqrDist > u2) fSqrDist = u2;
461 if ((p-fCircumcentre).mag()-fRadius < minDist)
497 if ((p-fCircumcentre).mag()-fRadius < minDist)
506 G4bool wrongSide = (dir > 0.0 && !outgoing) || (dir < 0.0 && outgoing);
513 if (wrongSide) dist = 0.0;
516 else if (!wrongSide) dist = dist1;
532 if (sp > ss) ss =
sp;
534 if (sp > ss) ss =
sp;
593 distFromSurface = D.
dot(fSurfaceNormal);
605 wrongSide = (outgoing && distFromSurface < 0.0)
606 || (!outgoing && distFromSurface > 0.0);
622 normal = fSurfaceNormal;
662 vprime, P0prime, E0prime, E1prime, loc))
670 G4double s0 = (loc[0] - pprime).mag()/vprimemag;
671 G4double s1 = (loc[1] - pprime).mag()/vprimemag;
672 G4double normDist0 = fSurfaceNormal.
dot(s0*v) - distFromSurface;
673 G4double normDist1 = fSurfaceNormal.
dot(s1*v) - distFromSurface;
675 if ((normDist0 < 0.0 && normDist1 < 0.0)
676 || (normDist0 > 0.0 && normDist1 > 0.0)
677 || (normDist0 == 0.0 && normDist1 == 0.0) )
686 G4double dnormDist = normDist1 - normDist0;
690 normal = fSurfaceNormal;
691 if (!outgoing) distFromSurface = -distFromSurface;
696 distance = s0 - normDist0*(s1-
s0)/dnormDist;
697 normal = fSurfaceNormal;
698 if (!outgoing) distFromSurface = -distFromSurface;
718 distance = distFromSurface / w;
731 if (ss < -sTolerance || t < -tTolerance || ( ss+t - fDet ) > detTolerance)
745 normal = fSurfaceNormal;
746 if (!outgoing) distFromSurface = -distFromSurface;
761 if (u+v > 1.) { u = 1. - u; v = 1. - v; }
780 return "G4TriangularFacet";
787 return fSurfaceNormal;
void set(double x, double y, double z)
G4TriangularFacet & operator=(const G4TriangularFacet &right)
G4bool Intersect(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool outgoing, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal)
static const G4double kInfinity
static const G4double kCarTolerance
double dot(const Hep3Vector &) const
void SetVertices(std::vector< G4ThreeVector > *v)
void SetVertex(G4int i, const G4ThreeVector &val)
static double normal(HepRandomEngine *eptr)
G4GeometryType GetEntityType() const
static const G4double dirTolerance
void SetSurfaceNormal(G4ThreeVector normal)
G4double Extent(const G4ThreeVector axis)
static G4bool IntersectLineAndTriangle2D(const G4TwoVector &p, const G4TwoVector &v, const G4TwoVector &p0, const G4TwoVector &e0, const G4TwoVector &e1, G4TwoVector location[2])
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
T max(const T t1, const T t2)
brief Return the largest of the two arguments
G4TriangularFacet * GetFlippedFacet()
G4ThreeVector GetVertex(G4int i) const
Hep3Vector cross(const Hep3Vector &) const
G4ThreeVector GetPointOnFace() const
G4ThreeVector GetSurfaceNormal() const
G4ThreeVector Distance(const G4ThreeVector &p)