18 boost::array<Vector2D,3> points;
39 double eps = 1e-7*
abs(p1 - p0)*
abs(q1 - q0);
42 double xi=((q0.x-q1.
x)*(p0.x*p1.
y-p1.
x*p0.y)-(p0.x-p1.
x)*
43 (q0.x*q1.
y-q1.
x*q0.y))/d;
44 double yi=((q0.y-q1.
y)*(p0.x*p1.
y-p1.
x*p0.y)-(p0.y-p1.
y)*
45 (q0.x*q1.
y-q1.
x*q0.y))/d;
46 Intersection.
Set(xi,yi);
47 eps=1e-7*sqrt(
abs(p1-p0)*
abs(q1-q0));
48 if((xi+eps)<
min(p0.x,p1.
x)||(xi-eps)>
max(p0.x,p1.
x))
50 if((xi+eps)<
min(q0.x,q1.
x)||(xi-eps)>
max(q0.x,q1.
x))
52 if((yi+eps)<
min(p0.y,p1.
y)||(yi-eps)>
max(p0.y,p1.
y))
54 if((yi+eps)<
min(q0.y,q1.
y)||(yi-eps)>
max(q0.y,q1.
y))
89 const int n=
static_cast<int>(poly0.size());
90 const int m=
static_cast<int>(poly1.size());
91 int p0index=0,p1index=0;
92 boost::array<Vector2D,3> AreaSignCheck;
93 int p0counter=0,p1counter=0;
96 AreaSignCheck[0]=poly0[
static_cast<size_t>((p0index+n-1)%n)];
97 AreaSignCheck[1]=poly0[
static_cast<size_t>(p0index)];
98 AreaSignCheck[2]=poly1[
static_cast<size_t>(p1index)];
101 (poly0[static_cast<size_t>((p0index+n-1)%n)],
102 poly0[static_cast<size_t>(p0index)],
103 poly1[static_cast<size_t>(p1index)]));
104 AreaSignCheck[0]=poly1[
static_cast<size_t>((p1index+m-1)%m)];
105 AreaSignCheck[1]=poly1[
static_cast<size_t>(p1index)];
106 AreaSignCheck[2]=poly0[
static_cast<size_t>(p0index)];
109 (poly1[static_cast<size_t>((p1index+m-1)%m)],
110 poly1[static_cast<size_t>(p1index)],
111 poly0[static_cast<size_t>(p0index)]));
115 poly0[static_cast<size_t>(p0index)],
116 poly1[static_cast<size_t>(p1index)],
117 poly1[static_cast<size_t>((p1index+m-1)%m)],intersect);
120 res.push_back(intersect);
134 AreaSignCheck[1]=poly0[
static_cast<size_t>(p0index)]-poly0[static_cast<size_t>((p0index+n-1)%n)];
135 AreaSignCheck[2]=poly1[
static_cast<size_t>(p1index)]-poly1[static_cast<size_t>((p1index+m-1)%m)];
139 poly0[static_cast<size_t>(p0index)]-poly0[static_cast<size_t>((p0index+n-1)%n)],
140 poly1[static_cast<size_t>(p1index)]-poly1[static_cast<size_t>((p1index+m-1)%m)]));
143 if(
ScalarProd(poly0[static_cast<size_t>(p0index)]-poly0[static_cast<size_t>((p0index+n-1)%n)],
144 poly1[static_cast<size_t>(p1index)]-poly1[static_cast<size_t>((p1index+m-1)%m)])<0)
149 return vector<Vector2D> ();
152 if((fabs(areasign)<1e-9)&&(aLeftOfb<0)&&(bLeftOfa<0))
153 return vector<Vector2D> ();
154 if((fabs(areasign)<1e-9)&&(fabs(aLeftOfb)<1e-9)&&(fabs(bLeftOfa)<1e-9))
159 p1index=(p1index+1)%m;
164 p0index=(p0index+1)%n;
172 res.push_back(poly0[static_cast<size_t>(p0index)]);
174 p0index=(p0index+1)%n;
179 res.push_back(poly1[static_cast<size_t>(p1index)]);
181 p1index=(p1index+1)%m;
189 res.push_back(poly1[static_cast<size_t>(p1index)]);
191 p1index=(p1index+1)%m;
196 res.push_back(poly0[static_cast<size_t>(p0index)]);
198 p0index=(p0index+1)%n;
202 while(((p0counter<n)||(p1counter<m))&&(p0counter<2*n)&&(p1counter<2*m));
bool SegmentIntersection(Edge const &edge1, Edge const &edge2, Vector2D &Intersection, double eps=1e-8)
Calculates the intersection of two edges.
InFlags
Flags for if the segment is inner or outer.
double max(vector< double > const &v)
returns the maximal term in a vector
double y
Component in the y direction.
A collection of three identical references.
vector< Vector2D > ConvexIntersect(vector< Vector2D > const &poly0, vector< Vector2D > const &poly1)
Calculates the intersection between two convex polygons.
Finds the intersection points between two polygons.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
double min(vector< double > const &v)
Returns the minimal term in a vector.
void Set(double ix, double iy)
Set vector components.
double abs(Vector3D const &v)
Norm of a vector.
IntersectFlags
Flags for there is an intersction or not or if the segments are parallel.
double orient2d(const TripleConstRef< Vector2D > &points)
Checks whether 3 given points are on a counterclockwise circle, clockwise circle or colinear...
double x
Component in the x direction.