45 return ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax))*0.5;
57 return ((
B.x()-Ax)*(
C.y()-Ay) - (
B.y()-Ay)*(
C.x()-Ax))*0.5;
69 return ((
C.x()-
A.x())*(
D.y()-
B.y()) - (
C.y()-
A.y())*(
D.x()-
B.x()))*0.5;
79 if (n < 3)
return 0.0;
80 G4double area = p[n-1].x()*p[0].y() - p[0].x()*p[n-1].y();
81 for(
G4int i=1; i<n; ++i)
83 area += p[i-1].x()*p[i].y() - p[i].x()*p[i-1].y();
98 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
100 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.)
return false;
101 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.)
return false;
102 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.)
return false;
106 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.)
return false;
107 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.)
return false;
108 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.)
return false;
126 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) > 0.)
128 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) < 0.)
return false;
129 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) < 0.)
return false;
130 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) < 0.)
return false;
134 if ((Ax-Cx)*(Py-Cy) - (Ay-Cy)*(Px-Cx) > 0.)
return false;
135 if ((Bx-Ax)*(Py-Ay) - (By-Ay)*(Px-Ax) > 0.)
return false;
136 if ((Cx-Bx)*(Py-By) - (Cy-By)*(Px-Bx) > 0.)
return false;
150 for (
G4int i = 0, k = Nv - 1; i < Nv; k = i++)
152 if ((v[i].y() > p.
y()) != (v[k].y() > p.
y()))
154 G4double ctg = (v[k].x()-v[i].x())/(v[k].y()-v[i].y());
155 in ^= (p.
x() < (p.
y()-v[i].y())*ctg + v[i].x());
170 G4bool gotNegative =
false;
171 G4bool gotPositive =
false;
172 G4int n = polygon.size();
173 if (n <= 0)
return false;
174 for (
G4int icur=0; icur<n; ++icur)
176 G4int iprev = (icur == 0) ? n-1 : icur-1;
177 G4int inext = (icur == n-1) ? 0 : icur+1;
182 if (cross < 0) gotNegative =
true;
183 if (cross > 0) gotPositive =
true;
184 if (gotNegative && gotPositive)
return false;
197 std::vector<G4int> triangles;
200 G4int n = triangles.size();
201 for (
G4int i=0; i<n; ++i) result.push_back(polygon[triangles[i]]);
210 std::vector<G4int>& result)
216 G4int n = polygon.size();
217 if (n < 3)
return false;
224 for (
G4int i=0; i<n; ++i) V[i] = i;
226 for (
G4int i=0; i<n; ++i) V[i] = (n-1)-i;
232 for(
G4int b=nv-1; nv>2; )
238 if (area < 0.) std::reverse(result.begin(),result.end());
243 G4int a = (b < nv) ? b : 0;
244 b = (a+1 < nv) ? a+1 : 0;
245 G4int c = (b+1 < nv) ? b+1 : 0;
247 if (CheckSnip(polygon, a,b,c, nv,V))
250 result.push_back(V[a]);
251 result.push_back(V[b]);
252 result.push_back(V[c]);
256 for(
G4int i=b; i<nv; ++i) V[i] = V[i+1];
262 if (area < 0.) std::reverse(result.begin(),result.end());
279 G4double Ax = contour[V[a]].x(), Ay = contour[V[a]].y();
280 G4double Bx = contour[V[b]].x(), By = contour[V[b]].y();
281 G4double Cx = contour[V[c]].x(), Cy = contour[V[c]].y();
282 if ((Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax) <
kCarTolerance)
return false;
285 G4double xmin = std::min(std::min(Ax,Bx),Cx);
286 G4double xmax = std::max(std::max(Ax,Bx),Cx);
287 G4double ymin = std::min(std::min(Ay,By),Cy);
288 G4double ymax = std::max(std::max(Ay,By),Cy);
289 for (
G4int i=0; i<n; ++i)
291 if((i == a) || (i == b) || (i == c))
continue;
293 if (Px < xmin || Px > xmax)
continue;
295 if (Py < ymin || Py > ymax)
continue;
306 std::vector<G4int>& iout,
315 G4int nv = polygon.size();
320 G4int icur = 0, iprev = 0, inext = 0, nout = 0;
321 for (
G4int i=0; i<nv; ++i)
325 for (
G4int k=1; k<nv+1; ++k)
328 if (iprev < 0) iprev += nv;
329 if (polygon[iprev].x() != removeIt)
break;
332 for (
G4int k=1; k<nv+1; ++k)
335 if (inext >= nv) inext -= nv;
336 if (polygon[inext].x() != removeIt)
break;
339 if (iprev == inext)
break;
351 if (leng1 <= delta || leng2 <= delta || leng3 <= delta)
353 polygon[icur].setX(removeIt); ++nout;
357 G4double lmax = std::max(std::max(leng1,leng2),leng3);
358 G4double area = std::abs(e1.
x()*e2.
y()-e1.
y()*e2.
x())*0.5;
359 if (area/std::sqrt(lmax) <= std::abs(tolerance))
361 polygon[icur].setX(removeIt); ++nout;
371 for (
G4int i=0; i<nv; ++i) iout.push_back(i);
375 for (
G4int i=0; i<nv; ++i)
377 if (polygon[i].x() != removeIt)
378 polygon[icur++] = polygon[i];
382 if (icur < nv) polygon.resize(icur);
401 if (rmin < 0)
return false;
407 pmin.
set(-rmax,-rmax);
408 pmax.
set( rmax, rmax);
409 if (delPhi >= CLHEP::twopi)
return true;
412 std::sin(startPhi),std::cos(startPhi),
413 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
433 pmin.
set(-rmax,-rmax);
434 pmax.
set( rmax, rmax);
445 G4int icase = (cosEnd < 0) ? 1 : 0;
446 if (sinEnd < 0) icase += 2;
447 if (cosStart < 0) icase += 4;
448 if (sinStart < 0) icase += 8;
454 if (sinEnd < sinStart)
break;
455 pmin.
set(rmin*cosEnd,rmin*sinStart);
456 pmax.
set(rmax*cosStart,rmax*sinEnd );
459 pmin.
set(rmax*cosEnd,std::min(rmin*sinStart,rmin*sinEnd));
460 pmax.
set(rmax*cosStart,rmax );
463 pmin.
set(-rmax,-rmax);
464 pmax.
set(std::max(rmax*cosStart,rmax*cosEnd),rmax);
467 pmin.
set(-rmax,rmax*sinEnd);
468 pmax.
set(rmax*cosStart,rmax);
472 pmin.
set(-rmax,-rmax);
473 pmax.
set(rmax,std::max(rmax*sinStart,rmax*sinEnd));
476 if (sinEnd > sinStart)
break;
477 pmin.
set(rmax*cosEnd,rmin*sinEnd );
478 pmax.
set(rmin*cosStart,rmax*sinStart);
481 pmin.
set(-rmax,-rmax);
482 pmax.
set(rmax*cosEnd,rmax*sinStart);
485 pmin.
set(-rmax,rmax*sinEnd);
486 pmax.
set(std::max(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
490 pmin.
set(std::min(rmin*cosStart,rmin*cosEnd),rmax*sinStart);
491 pmax.
set(rmax,rmax*sinEnd);
494 pmin.
set(rmax*cosEnd,rmax*sinStart);
498 if (sinEnd < sinStart)
break;
499 pmin.
set(rmin*cosStart,rmax*sinStart);
500 pmax.
set(rmax*cosEnd,rmin*sinEnd );
503 pmin.
set(-rmax,std::min(rmax*sinStart,rmax*sinEnd));
508 pmin.
set(rmax*cosStart,-rmax);
509 pmax.
set(rmax,rmax*sinEnd);
512 pmin.
set(std::min(rmax*cosStart,rmax*cosEnd),-rmax);
516 pmin.
set(rmax*cosStart,-rmax);
517 pmax.
set(rmax*cosEnd,std::max(rmin*sinStart,rmin*sinEnd));
520 if (sinEnd > sinStart)
break;
521 pmin.
set(rmax*cosStart,rmax*sinEnd);
522 pmax.
set(rmin*cosEnd,rmin*sinStart);
538 G4double e = std::sqrt((1. - b/a)*(1. + b/a));
539 return 4. * a * comp_ellint_2(e);
555 G4double e = std::sqrt((1. - b/a)*(1. + b/a)) / std::hypot(1.,b/h);
556 return 2. * a * std::hypot(b,h) * comp_ellint_2(e);
572 const G4double eps = 1. / 134217728.;
575 G4double b = std::sqrt((1. - e)*(1. + e));
576 if (b == 1.)
return CLHEP::halfpi;
577 if (b == 0.)
return 1.;
583 while (x - y > eps*y)
589 S += M * (x - y)*(x - y);
591 return 0.5 * CLHEP::halfpi * ((a + b)*(a + b) -
S) / (x + y);
602 return ((
B-
A).cross(
C-
A))*0.5;
614 return ((
C-
A).cross(
D-
B))*0.5;
626 for(
G4int i=1; i<n; ++i)
628 normal += p[i-1].
cross(p[i]);
645 if (u <= 0)
return AP.
mag();
648 if (u >= len2)
return (
B-P).mag();
650 return ((u/len2)*AB - AP).mag();
666 if (u <= 0)
return A;
669 if (u >= len2)
return B;
726 region = (t0 < 0) ? ((t1 < 0) ? 4 : 3) : ((t1 < 0) ? 5 : 0);
728 region = (t0 < 0) ? 2 : ((t1 < 0) ? 6 : 1);
735 return A + (t0*invDet)*edge0 + (t1*invDet)*edge1;
740 if (numer <= 0)
return C;
742 return (numer >= denom) ?
B :
C + (numer/denom)*(edge0-edge1);
752 return (numer >= denom) ?
B :
C + (numer/denom)*(edge0-edge1);
755 return (tmp1 <= 0) ?
C : (( e >= 0) ?
A :
A + (-e/c)*edge1);
758 return (e >= 0) ?
A : ((-e >= c) ?
C :
A + (-e/c)*edge1);
761 if (d < 0)
return (-d >= a) ?
B :
A + (-d/a)*edge0;
762 return (e >= 0) ?
A : ((-e >= c) ?
C :
A + (-e/c)*edge1);
765 return (d >= 0) ?
A : ((-d >= a) ?
B :
A + (-d/a)*edge0);
775 return (numer >= denom) ?
C :
B + (numer/denom)*(edge1-edge0);
778 return (tmp1 <= 0) ?
B : (( d >= 0) ?
A :
A + (-d/a)*edge0);
802 if (rmin < 0)
return false;
809 if (stheta < 0 && stheta > CLHEP::pi)
return false;
810 if (stheta + dtheta > CLHEP::pi) dtheta = CLHEP::pi - stheta;
815 pmin.
set(-rmax,-rmax,-rmax);
816 pmax.
set( rmax, rmax, rmax);
817 if (dtheta >= CLHEP::pi && delPhi >= CLHEP::twopi)
return true;
820 G4double sinStart = std::sin(stheta);
821 G4double cosStart = std::cos(stheta);
825 G4double rhomin = rmin*std::min(sinStart,sinEnd);
827 if (stheta > CLHEP::halfpi) rhomax = rmax*sinStart;
828 if (etheta < CLHEP::halfpi) rhomax = rmax*sinEnd;
832 std::sin(startPhi),std::cos(startPhi),
833 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
836 G4double zmin = std::min(rmin*cosEnd,rmax*cosEnd);
837 G4double zmax = std::max(rmin*cosStart,rmax*cosStart);
838 pmin.
set(xymin.
x(),xymin.
y(),zmin);
839 pmax.
set(xymax.
x(),xymax.
y(),zmax);
const G4double kCarTolerance
double B(double temperature)
double A(double temperature)
CLHEP::Hep3Vector G4ThreeVector
void set(double x, double y)
Hep3Vector cross(const Hep3Vector &) const
double dot(const Hep3Vector &) const
void set(double x, double y, double z)
G4double GetSurfaceTolerance() const
static G4GeometryTolerance * GetInstance()