v2End = updatedIndices[3]; getClosestPointsFromRemainingEdgesAndVertices(polygon1, polygon2, v1Start, v1End, v2Start, v2End, point1ToPack, point2ToPack);
/** * Finds the minimum distance between two convex polygons * Taken from http://cygnus-x1.cs.duke.edu/~edels/Papers/1985-J-02-ComputingExtremeDistances.pdf * @return Two points, one from each polygon, between which is the minimum distance between the two polygons */ public static Point2d[] computeMinimumDistancePoints(ConvexPolygon2d polygon1, ConvexPolygon2d polygon2, double epsilon) { // TODO Do something more clever than actually computing the intersection there! if (computeIntersectionOfPolygons(polygon1, polygon2, new ConvexPolygon2d())) { throw new RuntimeException("Cannot compute minimum distance between intersecting polygons."); } if ((polygon1.getNumberOfVertices() < 3) || (polygon2.getNumberOfVertices() < 3)) { throw new RuntimeException("Polygon inputs are degenerate."); } int[] v1Tangents = findStartAndEndTangents(polygon2.getVertex(0), polygon1, epsilon); int[] v2Tangents = findStartAndEndTangents(polygon1.getVertex(0), polygon2, epsilon); int v1Start = v1Tangents[0]; int v1End = v1Tangents[1]; int v2Start = v2Tangents[0]; int v2End = v2Tangents[1]; int[] updatedIndices = binaryElimination(polygon1, polygon2, v1Start, v1End, v2Start, v2End, epsilon); v1Start = updatedIndices[0]; v1End = updatedIndices[1]; v2Start = updatedIndices[2]; v2End = updatedIndices[3]; return getClosestPointsFromRemainingEdgesAndVertices(polygon1, polygon2, v1Start, v1End, v2Start, v2End); }