62 fVertices =
new vector<G4ThreeVector>(3);
81 fArea = 0.5 * E1xE2.
mag();
82 for (
G4int i = 0; i < 3; ++i) fIndices[i] = -1;
92 if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
101 if (2.*fArea/std::max(std::max(leng1,leng2),leng3) <= delta)
111 ostringstream message;
112 message <<
"Facet is too small or too narrow." <<
G4endl
113 <<
"Triangle area = " << fArea <<
G4endl
117 <<
"Side1 length (P0->P1) = " << leng1 <<
G4endl
118 <<
"Side2 length (P1->P2) = " << leng2 <<
G4endl
119 <<
"Side3 length (P2->P0) = " << leng3;
120 G4Exception(
"G4TriangularFacet::G4TriangularFacet()",
122 fSurfaceNormal.
set(0,0,0);
125 fCircumcentre = vt0 + 0.5*fE1 + 0.5*fE2;
126 fArea = fRadius = 0.0;
130 fSurfaceNormal = E1xE2.
unit();
134 fDet = std::fabs(fA*fC - fB*fB);
137 vt0 + (E1xE2.
cross(fE1)*fC + fE2.
cross(E1xE2)*fA) / (2.*E1xE2.
mag2());
138 fRadius = (fCircumcentre - vt0).mag();
147 fVertices =
new vector<G4ThreeVector>(3);
152 for (
G4int i = 0; i < 3; ++i) fIndices[i] = -1;
154 fSurfaceNormal.
set(0,0,0);
159 fArea = fRadius = 0.0;
173 char *p = (
char *) &rhs;
174 copy(p, p +
sizeof(*
this), (
char *)
this);
176 if (fIndices[0] < 0 && fVertices ==
nullptr)
178 fVertices =
new vector<G4ThreeVector>(3);
179 for (
G4int i = 0; i < 3; ++i) (*fVertices)[i] = (*rhs.fVertices)[i];
187 fSurfaceNormal = move(rhs.fSurfaceNormal);
188 fArea = move(rhs.fArea);
189 fCircumcentre = move(rhs.fCircumcentre);
190 fRadius = move(rhs.fRadius);
191 fIndices = move(rhs.fIndices);
192 fA = move(rhs.fA); fB = move(rhs.fB); fC = move(rhs.fC);
193 fDet = move(rhs.fDet);
194 fSqrDist = move(rhs.fSqrDist);
195 fE1 = move(rhs.fE1); fE2 = move(rhs.fE2);
196 fIsDefined = move(rhs.fIsDefined);
197 fVertices = move(rhs.fVertices);
198 rhs.fVertices =
nullptr;
312 if (-d >= fA) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
313 else {q = -d/fA; fSqrDist = d*q + f;}
318 if (e >= 0.0) {t = 0.0; fSqrDist = f;}
319 else if (-e >= fC) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
320 else {t = -e/fC; fSqrDist = e*t + f;}
329 if (e >= 0.0) {t = 0.0; fSqrDist = f;}
330 else if (-e >= fC) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
331 else {t = -e/fC; fSqrDist = e*t + f;}
340 if (d >= 0.0) {q = 0.0; fSqrDist = f;}
341 else if (-d >= fA) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
342 else {q = -d/fA; fSqrDist = d*q + f;}
351 fSqrDist = q*(fA*q + fB*t + 2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
367 if (numer >= denom) {q = 1.0; t = 0.0; fSqrDist = fA + 2.0*d + f;}
372 fSqrDist = q*(fA*q + fB*t +2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
378 if (tmp1 <= 0.0) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
379 else if (e >= 0.0) {t = 0.0; fSqrDist = f;}
380 else {t = -e/fC; fSqrDist = e*t + f;}
394 if (numer >= denom) {t = 1.0; q = 0.0; fSqrDist = fC + 2.0*e + f;}
399 fSqrDist = q*(fA*q + fB*t +2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
405 if (tmp1 <= 0.0) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
406 else if (d >= 0.0) {q = 0.0; fSqrDist = f;}
407 else {q = -d/fA; fSqrDist = d*q + f;}
420 fSqrDist = fC + 2.0*e + f;
425 if (numer >= denom) {q = 1.0; t = 0.0; fSqrDist = fA + 2.0*d + f;}
430 fSqrDist = q*(fA*q + fB*t + 2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
452 if (fSqrDist < 0.0) fSqrDist = 0.;
459 if (fSqrDist > u2) fSqrDist = u2;
483 if ((p-fCircumcentre).mag()-fRadius < minDist)
519 if ((p-fCircumcentre).mag()-fRadius < minDist)
528 G4bool wrongSide = (dir > 0.0 && !outgoing) || (dir < 0.0 && outgoing);
535 if (wrongSide) dist = 0.0;
538 else if (!wrongSide) dist = dist1;
554 if (sp > ss) ss = sp;
556 if (sp > ss) ss = sp;
602 distance = kInfinity;
603 distFromSurface = kInfinity;
615 distFromSurface =
D.dot(fSurfaceNormal);
621 distance = kInfinity;
622 distFromSurface = kInfinity;
627 wrongSide = (outgoing && distFromSurface < 0.0)
628 || (!outgoing && distFromSurface > 0.0);
644 normal = fSurfaceNormal;
654 distance = kInfinity;
655 distFromSurface = kInfinity;
684 vprime, P0prime, E0prime, E1prime, loc))
692 G4double s0 = (loc[0] - pprime).mag()/vprimemag;
693 G4double s1 = (loc[1] - pprime).mag()/vprimemag;
694 G4double normDist0 = fSurfaceNormal.
dot(s0*v) - distFromSurface;
695 G4double normDist1 = fSurfaceNormal.
dot(s1*v) - distFromSurface;
697 if ((normDist0 < 0.0 && normDist1 < 0.0)
698 || (normDist0 > 0.0 && normDist1 > 0.0)
699 || (normDist0 == 0.0 && normDist1 == 0.0) )
701 distance = kInfinity;
702 distFromSurface = kInfinity;
708 G4double dnormDist = normDist1 - normDist0;
712 normal = fSurfaceNormal;
713 if (!outgoing) distFromSurface = -distFromSurface;
718 distance = s0 - normDist0*(s1-s0)/dnormDist;
719 normal = fSurfaceNormal;
720 if (!outgoing) distFromSurface = -distFromSurface;
727 distance = kInfinity;
728 distFromSurface = kInfinity;
740 distance = distFromSurface / w;
753 if (ss < -sTolerance || t < -tTolerance || ( ss+t - fDet ) > detTolerance)
758 distance = distFromSurface = kInfinity;
767 normal = fSurfaceNormal;
768 if (!outgoing) distFromSurface = -distFromSurface;
783 if (u+v > 1.) { u = 1. - u; v = 1. - v; }
802 return "G4TriangularFacet";
809 return fSurfaceNormal;
816 fSurfaceNormal = normal;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Hep3Vector cross(const Hep3Vector &) const
double dot(const Hep3Vector &) const
void set(double x, double y, double z)
static G4bool IntersectLineAndTriangle2D(const G4TwoVector &p, const G4TwoVector &v, const G4TwoVector &p0, const G4TwoVector &e0, const G4TwoVector &e1, G4TwoVector location[2])
void SetSurfaceNormal(G4ThreeVector normal)
void SetVertex(G4int i, const G4ThreeVector &val)
G4ThreeVector GetPointOnFace() const
void SetVertices(std::vector< G4ThreeVector > *v)
G4bool Intersect(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool outgoing, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal)
G4TriangularFacet & operator=(const G4TriangularFacet &right)
G4TriangularFacet * GetFlippedFacet()
G4GeometryType GetEntityType() const
G4ThreeVector Distance(const G4ThreeVector &p)
G4ThreeVector GetVertex(G4int i) const
G4ThreeVector GetSurfaceNormal() const
G4double Extent(const G4ThreeVector axis)
static const G4double dirTolerance