61 fVertices =
new vector<G4ThreeVector>(3);
80 fArea = 0.5 * E1xE2.
mag();
81 for (
G4int i = 0; i < 3; ++i) fIndices[i] = -1;
91 if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
100 if (2.*fArea/std::max(std::max(leng1,leng2),leng3) <= delta)
110 ostringstream message;
111 message <<
"Facet is too small or too narrow." <<
G4endl
112 <<
"Triangle area = " << fArea <<
G4endl
116 <<
"Side1 length (P0->P1) = " << leng1 <<
G4endl
117 <<
"Side2 length (P1->P2) = " << leng2 <<
G4endl
118 <<
"Side3 length (P2->P0) = " << leng3;
119 G4Exception(
"G4TriangularFacet::G4TriangularFacet()",
121 fSurfaceNormal.
set(0,0,0);
124 fCircumcentre = vt0 + 0.5*fE1 + 0.5*fE2;
125 fArea = fRadius = 0.0;
129 fSurfaceNormal = E1xE2.
unit();
133 fDet = std::fabs(fA*fC - fB*fB);
136 vt0 + (E1xE2.
cross(fE1)*fC + fE2.
cross(E1xE2)*fA) / (2.*E1xE2.
mag2());
137 fRadius = (fCircumcentre - vt0).mag();
145 fVertices =
new vector<G4ThreeVector>(3);
150 for (
G4int i = 0; i < 3; ++i) fIndices[i] = -1;
152 fSurfaceNormal.
set(0,0,0);
157 fArea = fRadius = 0.0;
171 auto p = (
char *) &rhs;
172 copy(p, p +
sizeof(*
this), (
char *)
this);
174 if (fIndices[0] < 0 && fVertices ==
nullptr)
176 fVertices =
new vector<G4ThreeVector>(3);
177 for (
G4int i = 0; i < 3; ++i) (*fVertices)[i] = (*rhs.fVertices)[i];
185 fSurfaceNormal = std::move(rhs.fSurfaceNormal);
187 fCircumcentre = std::move(rhs.fCircumcentre);
188 fRadius = rhs.fRadius;
189 fIndices = rhs.fIndices;
190 fA = rhs.fA; fB = rhs.fB; fC = rhs.fC;
192 fSqrDist = rhs.fSqrDist;
193 fE1 = std::move(rhs.fE1); fE2 = std::move(rhs.fE2);
194 fIsDefined = rhs.fIsDefined;
195 fVertices = rhs.fVertices;
196 rhs.fVertices =
nullptr;
236 SetVertices(
nullptr);
310 if (-d >= fA) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
311 else {q = -d/fA; fSqrDist = d*q + f;}
316 if (e >= 0.0) {t = 0.0; fSqrDist = f;}
317 else if (-e >= fC) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
318 else {t = -e/fC; fSqrDist = e*t + f;}
327 if (e >= 0.0) {t = 0.0; fSqrDist = f;}
328 else if (-e >= fC) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
329 else {t = -e/fC; fSqrDist = e*t + f;}
338 if (d >= 0.0) {q = 0.0; fSqrDist = f;}
339 else if (-d >= fA) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
340 else {q = -d/fA; fSqrDist = d*q + f;}
348 fSqrDist = dist*dist;
349 return fSurfaceNormal*dist;
365 if (numer >= denom) {q = 1.0; t = 0.0; fSqrDist = fA + 2.0*d + f;}
370 fSqrDist = q*(fA*q + fB*t +2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
376 if (tmp1 <= 0.0) {t = 1.0; fSqrDist = fC + 2.0*e + f;}
377 else if (e >= 0.0) {t = 0.0; fSqrDist = f;}
378 else {t = -e/fC; fSqrDist = e*t + f;}
392 if (numer >= denom) {t = 1.0; q = 0.0; fSqrDist = fC + 2.0*e + f;}
397 fSqrDist = q*(fA*q + fB*t +2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
403 if (tmp1 <= 0.0) {q = 1.0; fSqrDist = fA + 2.0*d + f;}
404 else if (d >= 0.0) {q = 0.0; fSqrDist = f;}
405 else {q = -d/fA; fSqrDist = d*q + f;}
418 fSqrDist = fC + 2.0*e + f;
423 if (numer >= denom) {q = 1.0; t = 0.0; fSqrDist = fA + 2.0*d + f;}
428 fSqrDist = q*(fA*q + fB*t + 2.0*d) + t*(fB*q + fC*t + 2.0*e) + f;
450 if (fSqrDist < 0.0) fSqrDist = 0.;
457 if (fSqrDist > u2) fSqrDist = u2;
481 if ((p-fCircumcentre).mag()-fRadius < minDist)
517 if ((p-fCircumcentre).mag()-fRadius < minDist)
526 G4bool wrongSide = (dir > 0.0 && !outgoing) || (dir < 0.0 && outgoing);
533 if (wrongSide) dist = 0.0;
536 else if (!wrongSide) dist = dist1;
552 if (sp > ss) ss = sp;
554 if (sp > ss) ss = sp;
600 distance = kInfinity;
601 distFromSurface = kInfinity;
613 distFromSurface =
D.
dot(fSurfaceNormal);
619 distance = kInfinity;
620 distFromSurface = kInfinity;
625 wrongSide = (outgoing && distFromSurface < 0.0)
626 || (!outgoing && distFromSurface > 0.0);
642 normal = fSurfaceNormal;
652 distance = kInfinity;
653 distFromSurface = kInfinity;
682 vprime, P0prime, E0prime, E1prime, loc))
690 G4double s0 = (loc[0] - pprime).mag()/vprimemag;
691 G4double s1 = (loc[1] - pprime).mag()/vprimemag;
692 G4double normDist0 = fSurfaceNormal.
dot(s0*v) - distFromSurface;
693 G4double normDist1 = fSurfaceNormal.
dot(s1*v) - distFromSurface;
695 if ((normDist0 < 0.0 && normDist1 < 0.0)
696 || (normDist0 > 0.0 && normDist1 > 0.0)
697 || (normDist0 == 0.0 && normDist1 == 0.0) )
699 distance = kInfinity;
700 distFromSurface = kInfinity;
706 G4double dnormDist = normDist1 - normDist0;
710 normal = fSurfaceNormal;
711 if (!outgoing) distFromSurface = -distFromSurface;
716 distance = s0 - normDist0*(s1-s0)/dnormDist;
717 normal = fSurfaceNormal;
718 if (!outgoing) distFromSurface = -distFromSurface;
725 distance = kInfinity;
726 distFromSurface = kInfinity;
738 distance = distFromSurface / w;
751 if (ss < -sTolerance || t < -tTolerance || ( ss+t - fDet ) > detTolerance)
756 distance = distFromSurface = kInfinity;
765 normal = fSurfaceNormal;
766 if (!outgoing) distFromSurface = -distFromSurface;
781 if (u+v > 1.) { u = 1. - u; v = 1. - v; }
800 return "G4TriangularFacet";
807 return fSurfaceNormal;
814 fSurfaceNormal = normal;
G4double D(G4double temp)
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])
G4GeometryType GetEntityType() const override
G4double Extent(const G4ThreeVector axis) override
void SetVertex(G4int i, const G4ThreeVector &val) override
G4ThreeVector GetSurfaceNormal() const override
G4ThreeVector GetVertex(G4int i) const override
G4bool Intersect(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool outgoing, G4double &distance, G4double &distFromSurface, G4ThreeVector &normal) override
~G4TriangularFacet() override
G4TriangularFacet & operator=(const G4TriangularFacet &right)
void SetVertices(std::vector< G4ThreeVector > *v) override
G4ThreeVector GetPointOnFace() const override
G4TriangularFacet * GetFlippedFacet()
G4ThreeVector Distance(const G4ThreeVector &p)
G4VFacet * GetClone() override
void SetSurfaceNormal(const G4ThreeVector &normal)
G4double GetArea() const override
static const G4double dirTolerance