7 float FindSlope(
const std::pair<float, float>& p1,
const std::pair<float, float>& p2)
9 float slope = (p2.second - p1.second) / (p2.first - p1.first);
14 bool Clockwise(
double Ax,
double Ay,
double Bx,
double By,
double Cx,
double Cy)
16 return (Cy - Ay) * (Bx - Ax) > (By - Ay) * (Cx - Ax);
30 bool overlap = ((
Clockwise(Ax, Ay, Cx, Cy, Dx, Dy) !=
Clockwise(Bx, By, Cx, Cy, Dx, Dy)) and
31 (
Clockwise(Ax, Ay, Bx, By, Cx, Cy) !=
Clockwise(Ax, Ay, Bx, By, Dx, Dy)));
49 double s1 = (By - Ay) / (Bx - Ax);
50 double s2 = (Dy - Cy) / (Dx - Cx);
51 double c1 = By - s1 * Bx;
52 double c2 = Dy - s2 * Dx;
54 double Xintersection = (c2 -
c1) / (s2 - s1);
55 double Yintersection = s1 * Xintersection +
c1;
56 std::pair<float, float> intersection;
57 intersection = std::make_pair(Xintersection, Yintersection);
68 std::vector<std::pair<float, float>> nullpoint;
80 std::vector<std::pair<float, float>> IntersectionPoints;
82 for (
unsigned int p1 = 0; p1 < poly1.
Size(); p1++) {
86 for (
unsigned int p2 = 0; p2 < poly2.
Size(); p2++) {
91 for (
unsigned int i = 0; i < poly1.
Size(); i++) {
92 for (
unsigned int j = 0; j < poly2.
Size(); j++) {
94 poly1.
Point(i).second,
95 poly1.
Point(i + 1).first,
96 poly1.
Point(i + 1).second,
98 poly2.
Point(j).second,
99 poly2.
Point(j + 1).first,
100 poly2.
Point(j + 1).second))
103 poly1.
Point(i).second,
104 poly1.
Point(i + 1).first,
105 poly1.
Point(i + 1).second,
106 poly2.
Point(j).first,
107 poly2.
Point(j).second,
108 poly2.
Point(j + 1).first,
109 poly2.
Point(j + 1).second));
123 for (
unsigned int i = 0; i <
vertices.size(); i++) {
131 if (area < 0.0) area = -area;
139 float perimeter = 0.;
141 for (
unsigned int i = 0; i <
vertices.size(); i++) {
154 return sqrt(perimeter);
169 std::cout <<
"Out of bounds of Polygon!" << std::endl;
178 std::pair<float, float> range(10000, 0);
179 std::pair<float, float> ptmp;
181 for (
unsigned int i = 0; i <
vertices.size(); i++) {
190 float xnew = (ptmp.first) * cos(theta) + (ptmp.second) * sin(theta);
192 if (xnew < range.first) range.first = xnew;
193 if (xnew > range.second) range.second = xnew;
201 const std::pair<float, float>&
origin)
const 204 float theta = tan(slope);
206 std::pair<float, float> range1 = this->
Project(origin, theta);
207 std::pair<float, float> range2 = poly2.
Project(origin, theta);
211 if ((((range1.first <= range2.second) and (range1.first >= range2.first)) or
212 ((range1.second <= range2.second) and (range1.second >= range2.first))) or
213 (((range2.first <= range1.second) and (range2.first >= range1.first)) or
214 ((range2.second <= range1.second) and (range2.second >= range1.first))))
227 for (
unsigned int i = 0; i < this->
Size(); i++) {
234 if (!(this->
Overlap(slope, poly2, this->
Point(i))))
return false;
238 for (
unsigned int i = 0; i < poly2.
Size(); i++) {
241 if (!(poly2.
Overlap(slope, *
this, poly2.
Point(i))))
return false;
253 for (
unsigned int i = 0; i < this->
Size(); i++) {
254 for (
unsigned int j = 0; j < poly2.
Size(); j++) {
257 this->
Point(i + 1).first,
258 this->
Point(i + 1).second,
259 poly2.
Point(j).first,
260 poly2.
Point(j).second,
261 poly2.
Point(j + 1).first,
262 poly2.
Point(j + 1).second)) {
277 int intersections = 0;
278 for (
unsigned int i = 0; i < this->
Size(); i++) {
281 this->
Point(i + 1).first,
282 this->
Point(i + 1).second,
289 if ((intersections % 2) == 0)
301 for (
unsigned int i = 0; i < poly2.
Size(); i++) {
313 for (
unsigned int i = 0; i <
vertices.size() - 1; i++) {
316 double Bx =
vertices.at(i + 1).first;
317 double By =
vertices.at(i + 1).second;
319 for (
unsigned int j = i + 2; j <
vertices.size() - 1; j++) {
326 double Dx =
vertices.at(j + 1).first;
327 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.
std::vector< std::pair< float, float > > vertices
bool Clockwise(double Ax, double Ay, double Bx, double By, double Cx, double Cy)
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
second_as<> second
Type of time stored in seconds, in double precision.
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.