87 if (j >= 0 && j < np-1) {
104 for (
int j=0; j<np-1; j++) {
106 EGS_Float lam = uj[j]*v;
107 if (lam >= 0 && lam <= uj[j].length2()) {
109 EGS_Float t = fabs(d[j] - x*a[j]);
114 else if (lam < 0 && do_it) {
115 EGS_Float t = v.length();
127 EGS_Float lam = uj[0]*v;
130 if (lam <= uj[0].length2()) {
132 tperp = fabs(d[0] - x*a[0]);
141 EGS_Float t = fabs(d[1] - x*a[1]);
147 EGS_Float t = v.length();
162 int nn = open ? np-2 : np-1;
163 for (
int j=0; j<nn; j++)
169 if (!cpol->isInside(x)) {
172 for (
int j=0; j<ncut; j++)
if (cut[j]->isInside(x)) {
193 int nn = open ? np-2 : np-1;
196 for (
int j=0; j<nn; j++) {
197 if ((up = u*a[j]) < 0 && (xp = x*a[j])+
epsilon > d[j]) {
198 EGS_Float tt = d[j] - xp;
201 bool ok = is_convex || pc[j];
203 EGS_Float lam = uj[j]*(x-p[j]+u*tt);
204 if (lam >= 0 && lam < uj[j].length2()) {
224 if ((up = u*a[0]) > 0 && (xp = x*a[0]) < d[0]+
epsilon) {
225 EGS_Float tt = (d[0] - xp)/up;
227 EGS_Float lam = uj[0]*(x-p[0]+u*tt);
228 if (lam < uj[0].length2()) {
235 if ((up = u*a[1]) > 0 && (xp = x*a[1]) < d[1]+
epsilon) {
236 EGS_Float tt = (d[1] - xp)/up;
238 EGS_Float lam = uj[1]*(x-p[1]+u*tt);
248 for (
int j=0; j<nn; j++) {
249 if ((up = u*a[j]) > 0 && (xp = x*a[j]) < d[j]+
epsilon) {
250 EGS_Float tt = (d[j] - xp)/up;
252 EGS_Float lam = uj[j]*(x-p[j]+u*tt);
253 if (lam >= 0 && lam < uj[j].length2()) {
269 *normal = a[jhit]*(-1);
277 if (j >= 0 && j < np) {
294 EGS_Float xmin, xmax, ymin, ymax;
307 static bool checkCCW(
const vector<EGS_2DVector> &points);
346 bool Open=
false) : p(new
EGS_2DPolygon(points,Open)), a(projector) {};
355 return p->isConvex();
365 return a.getPoint(p->getPoint(j));
380 return a.normal(p->getNormal(j));
385 return a.getProjection(x);
390 return a.distance(x);
395 return p->isInside(xp);
401 return p->isInside(a.getProjection(x));
407 return (a.distance(x) >= 0);
413 return p->hownear(in,a.getProjection(x));
420 EGS_Float t1 = fabs(a.distance(x));
421 if (p->isInside(pos)) {
424 EGS_Float t2 = p->hownear(
true,pos);
425 return sqrt(t1*t1+t2*t2);
439 return p->howfar(in,a.getProjection(x),dir,t,normal);
449 EGS_Float &t)
const {
451 if ((in && up >= 0) || (!in && up <= 0)) {
454 EGS_Float tt = -a.distance(x)/up;
457 if (p->isInside(a.getProjection(xp))) {
#define EGS_EXPORT
Export symbols from the egspp library.
bool isConvex() const
Is the polygon convex ?
EGS_Float hownear(bool in, const EGS_Vector &x) const
Get the nearest distance between x and any point inside the polygon.
EGS_Vector getPoint(int j) const
Get the j'th point.
EGS_PolygonT(vector< EGS_2DVector > &points, const T &projector, bool Open=false)
Construct a 3D polygon defined by the 2D points points in the plane defined by the projector projecto...
A class representing 2D vectors.
bool howfar(bool in, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t) const
Will the line defined by position x and direction u intersect the polygon plane at a position inside ...
EGS_Vector getNormal(const EGS_2DVector &x) const
bool isConvex() const
Is this polygon convex ?
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
A class representing 3D vectors.
const string & getType() const
Get the polygon type.
Global egspp functions header file.
const EGS_Float veryFar
A very large float.
EGS_EXPORT EGS_Polygon * makePolygon(const vector< EGS_Vector > &points)
Make a polygon from the 3D points points.
EGS_Float hownear2D(bool in, const EGS_Vector &x) const
Get the nearest distance between the projection of x and the polygon outline.
EGS_Float hownear(bool in, const EGS_2DVector &x) const
Get the nearest distance from x to the polygon.
EGS_Vector getNormal() const
Get the normal to the polygon plane.
EGS_PolygonT< EGS_XProjector > EGS_PolygonYZ
A 3D polygon in the x-plane.
bool isInside2D(const EGS_2DVector &xp) const
Is the 2D point xp inside the polygon ?
int getN() const
Get the number of polygon points.
EGS_PolygonT< EGS_Projector > EGS_Polygon
A 3D polygon in any plane.
int getN() const
Get the number of points (vertices) in this polygon object.
EGS_2DVector getPoint(int j) const
Get the j'th point of this polygon.
bool howfar2D(bool in, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, EGS_2DVector *normal=0) const
Does the projection on the polygon plane of the trajectory defined by position x and direction u inte...
Attempts to fix broken math header files.
EGS_2DVector getProjection(const EGS_Vector &x) const
Get the projection of x on the polygon plane.
bool isInside2D(const EGS_Vector &x) const
Is the projection of the 3D point x on the polygon plane inside the polygon ?
A template class for 3D polygons.
bool howfar(bool in, const EGS_2DVector &x, const EGS_2DVector &u, EGS_Float &t, EGS_2DVector *normal=0)
Will the line defined by position x and direction u intersect the polygon ?
EGS_PolygonT< EGS_ZProjector > EGS_PolygonXY
A 3D polygon in the z-plane.
~EGS_PolygonT()
Destructor.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
bool isInside(const EGS_Vector &x) const
Is the 3D point inside the polygon plane ? (i.e. on than side of the plane to which the plane normal ...
bool isInside(const EGS_2DVector &x) const
Is the 2D point x inside the polygon ?
A class to represent a polygon in a plane (a 2D polygon).
EGS_Projector and EGS_2DVector class header file.
EGS_Float distance(const EGS_Vector &x) const
Get the distance between x and the polygon plane.
EGS_PolygonT< EGS_YProjector > EGS_PolygonXZ
A 3D polygon in the y-plane.
EGS_2DVector getNormal(int j) const
Get a line normal to the j'th polygon edge.
EGS_Vector getNormal(int j) const
Get the normal to the j'th polygon edge.