82 if ((cornerA + cornerB) == 2) {
86 if ((cornerA + cornerB + cornerC) == 2) {
90 if ((cornerA + cornerB + cornerC + cornerD) == 2) {
94 for (
int i = 0; i < ((int)shape.size() - 1); i++) {
105 const auto squaredRadius = radius * radius;
130 std::vector<Triangle> triangles;
134 if (shape.size() >= 3) {
136 while (shape.size() > 3) {
137 int shapeSize = (int)shape.size();
140 for (
int i = 0; (i < shapeSize) && (earIndex == -1); i++) {
141 const auto& earA = shape[(i + shapeSize - 1) % shapeSize];
142 const auto& earB = shape[i];
143 const auto& earC = shape[(i + 1) % shapeSize];
144 if (
isEar(earA, earB, earC, shape)) {
148 if (earIndex != -1) {
150 shape[(earIndex + shapeSize - 1) % shapeSize],
152 shape[(earIndex + 1) % shapeSize])
154 shape.erase(shape.begin() + earIndex);
157 triangles.push_back(
Triangle(shape[0], shape[1], shape[2]));
158 shape.erase(shape.begin() + 1);
162 triangles.push_back(
Triangle(shape[0], shape[1], shape[2]));
176 return !(*
this == other);
187 return ((crossAB >= 0) && (crossBC >= 0) && (crossCA >= 0)) ||
188 ((crossAB <= 0) && (crossBC <= 0) && (crossCA <= 0));
199 for (
const auto& pos : shape) {
200 if ((pos != a) && (pos != b) && (pos != c) &&
isPositionWithin(a, b, c, pos)) {
210 return (b.
x() - a.
x()) * (c.
y() - a.
y()) - (b.
y() - a.
y()) * (c.
x() - a.
x());
216 const double val = (q.
y() - p.
y()) * (r.
x() - q.
x()) - (q.
x() - p.
x()) * (r.
y() - q.
y());
220 }
else if (val < 0) {
232 return (q.
x() >= std::min(p.
x(), r.
x()) && q.
x() <= std::max(p.
x(), r.
x()) &&
233 q.
y() >= std::min(p.
y(), r.
y()) && q.
y() <= std::max(p.
y(), r.
y()));
245 if ((o1 != o2) && (o3 != o4)) {
247 }
else if ((o1 == 0) &&
onSegment(p1, p2, q1)) {
249 }
else if ((o2 == 0) &&
onSegment(p1, q2, q1)) {
251 }
else if ((o3 == 0) &&
onSegment(p2, p1, q2)) {
253 }
else if ((o4 == 0) &&
onSegment(p2, q1, q2)) {
272 const double dx = posB.
x() - posA.
x();
273 const double dy = posB.
y() - posA.
y();
274 const double a = dx * dx + dy * dy;
275 const double b = 2 * (dx * (posA.
x() - center.
x()) + dy * (posA.
y() - center.
y()));
276 const double c = (posA.
x() - center.
x()) * (posA.
x() - center.
x()) + (posA.
y() - center.
y()) * (posA.
y() - center.
y()) - radius * radius;
278 const double discriminant = (b * b - 4 * a * c);
280 if (discriminant >= 0) {
282 const double sqrtDiscriminant = sqrt(discriminant);
283 const double t1 = (-b + sqrtDiscriminant) / (2 * a);
284 const double t2 = (-b - sqrtDiscriminant) / (2 * a);
286 return (t1 >= 0 && t1 <= 1) || (t2 >= 0 && t2 <= 1);
A class that stores a 2D geometrical boundary.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
A point in 2D or 3D with translation and scaling methods.
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
double x() const
Returns the x-position.
double y() const
Returns the y-position.
void openPolygon()
open polygon
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point.
A simple triangle defined in 3D.
const Boundary & getBoundary() const
get triangle boundary
int orientation(const Position &p, const Position &q, const Position &r) const
bool segmentsIntersect(const Position &p1, const Position &q1, const Position &p2, const Position &q2) const
check if two line segments (p1,q1) and (p2,q2) intersect
Boundary myBoundary
triangle boundary
bool operator!=(const Triangle &other) const
inequality operator
bool isPositionWithin(const Position &pos) const
check if the given position is within this triangle
const PositionVector getShape() const
get shape boundary
bool isBoundaryFullWithin(const Boundary &boundary) const
check if the given position is FULL within this triangle
static const Triangle INVALID
invalid triangle
static bool isEar(const Position &a, const Position &b, const Position &c, const PositionVector &shape)
Check if the triangle (A, B, C) is an ear.
bool lineIntersectsTriangle(const Position &p1, const Position &p2) const
check if a line segment (p1, p2) intersects this triangle
static std::vector< Triangle > triangulate(PositionVector shape)
bool intersectWithShape(const PositionVector &shape) const
check if the given shape is within or intersect with this triangle
Position myB
second triangle position
Triangle()
default constructor
bool onSegment(const Position &p, const Position &q, const Position &r) const
check if point q lies on segment pr
Position myA
first triangle position
bool operator==(const Triangle &other) const
equalityoperators
Position myC
third triangle position
bool lineIntersectCircle(const Position &posA, const Position &posB, const Position ¢er, const double radius) const
function to check if line between posA and posB intersect circle
bool intersectWithCircle(const Position ¢er, const double radius) const
check if the given circle intersect with this triangle
static double crossProduct(const Position &a, const Position &b, const Position &c)
calculate cross product of the given points