4 float FindSlope(
const std::pair<float,float> &p1,
5 const std::pair<float,float> &p2 )
7 float slope = (p2.second-p1.second)/(p2.first-p1.first);
12 bool Clockwise(
double Ax,
double Ay,
double Bx,
double By,
double Cx,
double Cy)
14 return (Cy-Ay)*(Bx-Ax) > (By-Ay)*(Cx-Ax);
19 double Cx,
double Cy,
double Dx,
double Dy)
22 bool overlap = ( (
Clockwise(Ax,Ay,Cx,Cy,Dx,Dy) !=
Clockwise(Bx,By,Cx,Cy,Dx,Dy))
23 and (
Clockwise(Ax,Ay,Bx,By,Cx,Cy) !=
Clockwise(Ax,Ay,Bx,By,Dx,Dy)) );
28 std::pair<float, float>
GetIntersection(
double Ax,
double Ay,
double Bx,
double By,
29 double Cx,
double Cy,
double Dx,
double Dy)
35 double s1 = (By-Ay)/(Bx-Ax);
36 double s2 = (Dy-Cy)/(Dx-Cx);
40 double Xintersection = (c2-
c1)/(s2-s1);
41 double Yintersection = s1 * Xintersection +
c1;
42 std::pair<float,float> intersection;
43 intersection = std::make_pair(Xintersection, Yintersection);
54 std::vector< std::pair<float,float> > nullpoint;
66 std::vector<std::pair<float,float> > IntersectionPoints;
68 for (
unsigned int p1=0; p1 < poly1.
Size(); p1++){
72 for (
unsigned int p2=0; p2 < poly2.
Size(); p2++){
77 for (
unsigned int i=0; i < poly1.
Size(); i++){
78 for (
unsigned int j=0; j < poly2.
Size(); j++){
80 poly1.
Point(i+1).first, poly1.
Point(i+1).second,
82 poly2.
Point(j+1).first, poly2.
Point(j+1).second) )
85 poly1.
Point(i+1).first, poly1.
Point(i+1).second,
87 poly2.
Point(j+1).first, poly2.
Point(j+1).second) );
101 for (
unsigned int i=0; i<
vertices.size(); i++){
116 float perimeter = 0.;
118 for (
unsigned int i=0; i<
vertices.size(); i++){
131 return sqrt(perimeter);
146 std::cout <<
"Out of bounds of Polygon!" <<std::endl;
157 std::pair<float,float> range(10000,0);
158 std::pair<float,float> ptmp;
160 for (
unsigned int i=0; i<
vertices.size(); i++){
163 ptmp = std::make_pair( (
vertices.at(i)).first - p.first , (
vertices.at(i)).second - p.second );
169 float xnew = (ptmp.first)*cos(theta) + (ptmp.second)*sin(theta);
171 if ( xnew < range.first )
173 if ( xnew > range.second )
182 const std::pair<float,float> &
origin)
const 185 float theta = tan(slope);
187 std::pair<float,float> range1 = this->
Project(origin,theta);
188 std::pair<float,float> range2 = poly2.
Project(origin,theta);
192 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 )) ) )
205 for (
unsigned int i=0; i<this->
Size(); i++){
217 for (
unsigned int i=0; i<poly2.
Size(); i++){
235 for (
unsigned int i=0; i<this->
Size(); i++){
236 for (
unsigned int j=0; j<poly2.
Size(); j++){
238 this->
Point(i+1).first, this->
Point(i+1).second,
240 poly2.
Point(j+1).first, poly2.
Point(j+1).second) ){
255 int intersections = 0;
256 for (
unsigned int i=0; i<this->
Size(); i++){
258 this->
Point(i+1).first, this->
Point(i+1).second,
260 point.first, point.second) )
263 if ( (intersections%2) == 0 )
276 for (
unsigned int i=0; i<poly2.
Size(); i++){
290 for (
unsigned int i=0; i <
vertices.size()-1; i++){
294 double By =
vertices.at(i+1).second;
296 for (
unsigned int j=i+2; j <
vertices.size()-1; j++){
304 double Dy =
vertices.at(j+1).second;
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)
bool PointInside(const std::pair< float, float > &point) const
bool PolyOverlap(const Polygon2D &poly2) const
void UntanglePolygon()
check if poly2 is inside poly1
constexpr Point origin()
Returns a origin position with a point of the specified type.