/** * Returns true only if removing the vertex would generate a kink in the concave polygon. * Meaning, it would cause several edges to cross each other. */ public boolean isVertexPreventingKink(int vertexIndex) { return ConcaveHullTools.isVertexPreventingKink(vertexIndex, hullVertices); }
boolean isAngleWithinThresholds = angle < peakAngleThreshold || angle > shallowAngleThreshold; if (isAngleWithinThresholds && !isVertexPreventingKink(currentIndex, concaveHullVerticesToFilter))
if (isConvex && EuclidGeometryTools.triangleArea(a, b, c) < areaThreshold && !isVertexPreventingKink(nextIndex, concaveHullVerticesToFilter))
public static int filterOutShallowVertices(double percentageThreshold, List<Point2D> concaveHullVerticesToFilter) { int numberOfVerticesRemoved = 0; // abc represent a triangle formed by three successive vertices. // At each step of the iteration, b is tested to see if it can be removed. Point2D a = concaveHullVerticesToFilter.get(0); Point2D b = concaveHullVerticesToFilter.get(1); Point2D c = concaveHullVerticesToFilter.get(2); for (int currentIndex = 0; currentIndex < concaveHullVerticesToFilter.size();) { // If convex at b, then b should be on the outside of ac => on the left of the vector ac. boolean isConvex = EuclidGeometryTools.isPoint2DOnLeftSideOfLine2D(b, a, c); int nextIndex = next(currentIndex, concaveHullVerticesToFilter); if (isConvex && a.distance(c) / (a.distance(b) + b.distance(c)) > percentageThreshold && !isVertexPreventingKink(nextIndex, concaveHullVerticesToFilter)) { concaveHullVerticesToFilter.remove(nextIndex); b = c; numberOfVerticesRemoved++; } else { a = b; b = c; currentIndex++; } c = getNext(nextIndex, concaveHullVerticesToFilter); } return numberOfVerticesRemoved; }
if (isVertexPreventingKink(firstEdgeVertexIndex, concaveHullVerticesToFilter)) if (isVertexPreventingKink(secondEdgeVertexIndex, concaveHullVerticesToFilter)) if (!isVertexPreventingKink(firstEdgeVertexIndex, concaveHullVerticesToFilter)) if (!isVertexPreventingKink(secondEdgeVertexIndex, concaveHullVerticesToFilter)) if (!isVertexPreventingKink(secondEdgeVertexIndex, concaveHullVerticesToFilter)) if (!isVertexPreventingKink(firstEdgeVertexIndex, concaveHullVerticesToFilter))