8 const std::pair<float,float> &p2 )
10 float slope = (p2.second-p1.second)/(p2.first-p1.first);
15 bool Clockwise(
double Ax,
double Ay,
double Bx,
double By,
double Cx,
double Cy)
17 return (Cy-Ay)*(Bx-Ax) > (By-Ay)*(Cx-Ax);
22 double Cx,
double Cy,
double Dx,
double Dy)
25 bool overlap = ( (
Clockwise(Ax,Ay,Cx,Cy,Dx,Dy) !=
Clockwise(Bx,By,Cx,Cy,Dx,Dy))
26 and (
Clockwise(Ax,Ay,Bx,By,Cx,Cy) !=
Clockwise(Ax,Ay,Bx,By,Dx,Dy)) );
31 std::pair<float, float>
GetIntersection(
double Ax,
double Ay,
double Bx,
double By,
32 double Cx,
double Cy,
double Dx,
double Dy)
38 double s1 = (By-Ay)/(Bx-Ax);
39 double s2 = (Dy-Cy)/(Dx-Cx);
43 double Xintersection = (c2-c1)/(s2-s1);
44 double Yintersection = s1 * Xintersection + c1;
45 std::pair<float,float> intersection;
46 intersection = std::make_pair(Xintersection, Yintersection);
57 std::vector< std::pair<float,float> > nullpoint;
69 std::vector<std::pair<float,float> > IntersectionPoints;
71 for (
unsigned int p1=0;
p1 < poly1.
Size();
p1++){
75 for (
unsigned int p2=0; p2 < poly2.
Size(); p2++){
80 for (
unsigned int i=0; i < poly1.
Size(); i++){
81 for (
unsigned int j=0; j < poly2.
Size(); j++){
83 poly1.
Point(i+1).first, poly1.
Point(i+1).second,
85 poly2.
Point(j+1).first, poly2.
Point(j+1).second) )
88 poly1.
Point(i+1).first, poly1.
Point(i+1).second,
90 poly2.
Point(j+1).first, poly2.
Point(j+1).second) );
104 for (
unsigned int i=0; i<
vertices.size(); i++){
119 float perimeter = 0.;
121 for (
unsigned int i=0; i<
vertices.size(); i++){
134 return sqrt(perimeter);
149 std::cout <<
"Out of bounds of Polygon!" <<std::endl;
160 std::pair<float,float> range(10000,0);
161 std::pair<float,float> ptmp;
163 for (
unsigned int i=0; i<
vertices.size(); i++){
172 float xnew = (ptmp.first)*cos(theta) + (ptmp.second)*sin(theta);
174 if ( xnew < range.first )
176 if ( xnew > range.second )
185 const std::pair<float,float> &
origin)
const
188 float theta = tan(slope);
190 std::pair<float,float> range1 = this->
Project(origin,theta);
191 std::pair<float,float> range2 = poly2.
Project(origin,theta);
195 if ( ( ((range1.first <= range2.second)
and ( range1.first >= range2.first )) or ((range1.second <= range2.second)
and ( range1.second >= range2.first )) ) or ( ((range2.first <= range1.second)
and ( range2.first >= range1.first )) or ((range2.second <= range1.second)
and ( range2.second >= range1.first )) ) )
208 for (
unsigned int i=0; i<this->
Size(); i++){
220 for (
unsigned int i=0; i<poly2.
Size(); i++){
238 for (
unsigned int i=0; i<this->
Size(); i++){
239 for (
unsigned int j=0; j<poly2.
Size(); j++){
241 this->
Point(i+1).first, this->
Point(i+1).second,
243 poly2.
Point(j+1).first, poly2.
Point(j+1).second) ){
258 int intersections = 0;
259 for (
unsigned int i=0; i<this->
Size(); i++){
261 this->
Point(i+1).first, this->
Point(i+1).second,
263 point.first, point.second) )
266 if ( (intersections%2) == 0 )
279 for (
unsigned int i=0; i<poly2.
Size(); i++){
293 for (
unsigned int i=0; i <
vertices.size()-1; i++){
297 double By =
vertices.at(i+1).second;
299 for (
unsigned int j=i+2; j <
vertices.size()-1; j++){
307 double Dy =
vertices.at(j+1).second;
310 std::pair<float, float> tmp =
vertices.at(i+1);
std::pair< float, float > Project(const std::pair< float, float > &, float) const
bool Contained(const Polygon2D &poly2) const
const std::pair< float, float > & Point(unsigned int p) const
unsigned int Size() const
Create Intersection Polygon.
bool Clockwise(double Ax, double Ay, double Bx, double By, double Cx, double Cy)
std::vector< std::pair< float, float > > vertices
std::pair< float, float > GetIntersection(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
bool PolyOverlapSegments(const Polygon2D &poly2) const
bool SegmentOverlap(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Dx, double Dy)
bool Overlap(float slope, const Polygon2D &poly2, const std::pair< float, float > &origin) const
float FindSlope(const std::pair< float, float > &p1, const std::pair< float, float > &p2)
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
bool PointInside(const std::pair< float, float > &point) const
bool PolyOverlap(const Polygon2D &poly2) const
physics associatedGroupsWithLeft p1
void UntanglePolygon()
check if poly2 is inside poly1
BEGIN_PROLOG could also be cout
constexpr Point origin()
Returns a origin position with a point of the specified type.