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();
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;
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;
181 if (
std::abs(cross) < kCarTolerance)
return false;
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)
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;
238 if (area < 0.)
std::reverse(result.begin(),result.end());
244 b = (a+1 < nv) ? a+1 : 0;
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;
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)
328 if (iprev < 0) iprev += nv;
329 if (polygon[iprev].
x() != removeIt)
break;
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;
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;
402 if (rmax <= rmin + kCarTolerance)
return false;
403 if (delPhi <= 0 + kCarTolerance)
return false;
407 pmin.
set(-rmax,-rmax);
408 pmax.
set( rmax, rmax);
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);
436 if (
std::abs(sinEnd-sinStart) < kCarTolerance &&
437 std::abs(cosEnd-cosStart) < kCarTolerance)
return;
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));
555 G4double e = std::sqrt((1. - b/a)*(1. + b/a)) / std::hypot(1.,b/h);
575 G4double b = std::sqrt((1. - e)*(1. + e));
577 if (b == 0.)
return 1.;
583 while (x - y > eps*y)
589 S += M * (x -
y)*(x - y);
602 return ((B-A).
cross(C-A))*0.5;
614 return ((C-A).
cross(D-B))*0.5;
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;
803 if (rmax <= rmin + kCarTolerance)
return false;
804 if (delTheta <= 0 + kCarTolerance)
return false;
805 if (delPhi <= 0 + kCarTolerance)
return false;
809 if (stheta < 0 && stheta >
CLHEP::pi)
return false;
810 if (stheta + dtheta > CLHEP::pi) dtheta = CLHEP::pi - stheta;
811 if (dtheta <= 0 + kCarTolerance)
return false;
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);
832 std::sin(startPhi),std::cos(startPhi),
833 std::sin(startPhi+delPhi),std::cos(startPhi+delPhi),
838 pmin.
set(xymin.
x(),xymin.
y(),zmin);
839 pmax.
set(xymax.
x(),xymax.
y(),zmax);