IntelliTriangulation.h
Go to the documentation of this file.
#ifndef INTELLITRIANGULATION_H
#define INTELLITRIANGULATION_H
//for unit testing
class UnitTest;
#include <QPoint>
#include <vector>
struct Triangle {
QPoint A,B,C;
};
namespace IntelliTriangulation {
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
return (p1.x() - p3.x()) * (p2.y() - p3.y()) - (p2.x() - p3.x()) * (p1.y() - p3.y());
}
inline bool isInTriangle(Triangle& tri, QPoint& P){
float val1, val2, val3;
bool neg, pos;
val1 = IntelliTriangulation::sign(P,tri.A,tri.B);
val2 = IntelliTriangulation::sign(P,tri.B,tri.C);
val3 = IntelliTriangulation::sign(P,tri.C,tri.A);
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
return !(neg && pos);
}
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
bool isInPolygon(const std::vector<Triangle> &triangles, QPoint &point);
}
#endif
IntelliTriangulation::isInTriangle
bool isInTriangle(Triangle &tri, QPoint &P)
A function to check if a given point is in a triangle.
Definition: IntelliTriangulation.h:36
IntelliTriangulation::sign
float sign(QPoint &p1, QPoint &p2, QPoint &p3)
A function to get the 2*area of a traingle, using its determinat.
Definition: IntelliTriangulation.h:26
IntelliTriangulation::calculateTriangles
std::vector< Triangle > calculateTriangles(std::vector< QPoint > polyPoints)
A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by ...
Definition: IntelliTriangulation.cpp:7
Triangle::B
QPoint B
Definition: IntelliTriangulation.h:14
Triangle::C
QPoint C
Definition: IntelliTriangulation.h:14
Triangle
The Triangle struct holds the 3 vertices of a triangle.
Definition: IntelliTriangulation.h:13
IntelliTriangulation
Definition: IntelliTriangulation.h:17
Triangle::A
QPoint A
Definition: IntelliTriangulation.h:14
UnitTest
Definition: mainUnitTest.cpp:8
IntelliTriangulation::isInPolygon
bool isInPolygon(const std::vector< Triangle > &triangles, QPoint &point)
A function to check if a point lies in a polygon by checking its spanning triangles.
Definition: IntelliTriangulation.cpp:116