public boolean intersectionWith(ConvexPolygon2d convexPolygon, ConvexPolygon2d intersectionToPack) { checkIfUpToDate(); return ConvexPolygonTools.computeIntersectionOfPolygons(this, convexPolygon, intersectionToPack); }
public double computeIntersectionAreaOfPolygons(ConvexPolygon2DReadOnly polygonP, ConvexPolygon2DReadOnly polygonQ) { if (computeIntersectionOfPolygons(polygonP, polygonQ, intersectionToThrowAway)) return intersectionToThrowAway.getArea(); else return 0.0; } }
public ArrayList<ConvexPolygon2D> findIntersectionPolygonList(ConvexPolygon2D targetPolygon) { ArrayList<ConvexPolygon2D> tentativeList = findTentativeListOfPolygonsIntersectingTargetPolygon(targetPolygon); if (tentativeList == null || tentativeList.isEmpty()) return null; ArrayList<ConvexPolygon2D> ret = new ArrayList<ConvexPolygon2D>(); for (ConvexPolygon2D tentativePolygon : tentativeList) { ConvexPolygon2D intersection = new ConvexPolygon2D(); boolean success = convexPolygonTools.computeIntersectionOfPolygons(targetPolygon, tentativePolygon, intersection); if (success) ret.add(intersection); } return ret; }
public ArrayList<ConvexPolygon2d> findIntersectionPolygonList(ConvexPolygon2d targetPolygon) { ArrayList<ConvexPolygon2d> tentativeList = findTentativeListOfPolygonsIntersectingTargetPolygon(targetPolygon); if (tentativeList == null || tentativeList.isEmpty()) return null; ArrayList<ConvexPolygon2d> ret = new ArrayList<ConvexPolygon2d>(); for (ConvexPolygon2d tentativePolygon : tentativeList) { ConvexPolygon2d intersection = new ConvexPolygon2d(); boolean success = ConvexPolygonTools.computeIntersectionOfPolygons(targetPolygon, tentativePolygon, intersection); if (success) ret.add(intersection); } return ret; }
@Override public ConvexPolygon2d intersectionWith(ConvexPolygon2d convexPolygon) { checkIfUpToDate(); ConvexPolygon2d ret = new ConvexPolygon2d(); boolean success = ConvexPolygonTools.computeIntersectionOfPolygons(this, convexPolygon, ret); if (!success) ret = null; return ret; }
/** * Returns all of the intersections when the convexPolygon is projected vertically onto this * PlanarRegion. * * @param convexPolygon2DBasics Polygon to project vertically. * @param intersectionsInPlaneFrameToPack ArrayList of ConvexPolygon2d to pack with the * intersections. */ public void getPolygonIntersectionsWhenProjectedVertically(ConvexPolygon2DBasics convexPolygon2DBasics, ArrayList<ConvexPolygon2D> intersectionsInPlaneFrameToPack) { // Instead of projecting all the polygons of this region onto the world XY-plane, // the given convex polygon is projected along the z-world axis to be snapped onto plane. ConvexPolygon2D projectedPolygon = projectPolygonVerticallyToRegion(convexPolygon2DBasics); // Now, just need to go through each polygon of this region and see there is at least one intersection for (int i = 0; i < getNumberOfConvexPolygons(); i++) { ConvexPolygon2D intersectingPolygon = new ConvexPolygon2D(); if (convexPolygonTools.computeIntersectionOfPolygons(convexPolygons.get(i), projectedPolygon, intersectingPolygon)) { intersectionsInPlaneFrameToPack.add(intersectingPolygon); } } }
@ContinuousIntegrationTest(estimatedDuration = 0.0) @Test(timeout = 30000) public void testIntersectionWhenFullyInsideWithRepeatedPoint() { ConvexPolygonTools convexPolygonTools = new ConvexPolygonTools(); ArrayList<Point2D> listOfPoints = new ArrayList<Point2D>(); listOfPoints.add(new Point2D(0.19, 0.0)); listOfPoints.add(new Point2D(0.192, 0.6)); listOfPoints.add(new Point2D(0.25, 0.5)); listOfPoints.add(new Point2D(0.19, 0.0)); ConvexPolygon2D convexPolygon2dA = new ConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(listOfPoints)); listOfPoints.clear(); listOfPoints.add(new Point2D(-1.0, -1.0)); listOfPoints.add(new Point2D(2.0, -1.0)); listOfPoints.add(new Point2D(-1.0, 2.0)); listOfPoints.add(new Point2D(2.0, 2.0)); ConvexPolygon2D convexPolygon2dB = new ConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(listOfPoints)); ConvexPolygon2D intersection = new ConvexPolygon2D(); convexPolygonTools.computeIntersectionOfPolygons(convexPolygon2dA, convexPolygon2dB, intersection); boolean epsilonEquals = intersection.epsilonEquals(convexPolygon2dA, 1e-14); assertTrue(epsilonEquals); convexPolygonTools.computeIntersectionOfPolygons(convexPolygon2dB, convexPolygon2dA, intersection); epsilonEquals = intersection.epsilonEquals(convexPolygon2dA, 1e-14); assertTrue(epsilonEquals); }
boolean success = new ConvexPolygonTools().computeIntersectionOfPolygons(convexPolygon2ds.get(i), captureRegionPolygon, intersection); if (success)
/** * Check if the given polygon intersects this region projected onto the XY-plane. * * @param convexPolygon2d * @return true if the polygon intersects this PlanarRegion. */ public boolean isPolygonIntersecting(ConvexPolygon2DReadOnly convexPolygon2d) { BoundingBox2DReadOnly polygonBoundingBox = convexPolygon2d.getBoundingBox(); if (!boundingBox3dInWorld.intersectsInclusiveInXYPlane(polygonBoundingBox)) return false; // Instead of projecting all the polygons of this region onto the world XY-plane, // the given convex polygon is projected along the z-world axis to be snapped onto plane. ConvexPolygon2D projectedPolygon = projectPolygonVerticallyToRegion(convexPolygon2d); ConvexPolygon2D dummyPolygon = new ConvexPolygon2D(); // Now, just need to go through each polygon of this region and see there is at least one intersection for (int i = 0; i < getNumberOfConvexPolygons(); i++) { ConvexPolygon2D polygonToCheck = convexPolygons.get(i); boolean hasIntersection = convexPolygonTools.computeIntersectionOfPolygons(polygonToCheck, projectedPolygon, dummyPolygon); if (hasIntersection) return true; } // Did not find any intersection return false; }
boolean success = new ConvexPolygonTools().computeIntersectionOfPolygons(convexPolygon2ds.get(i), captureRegionPolygon, intersection); if (success)
convexPolygonTools.computeIntersectionOfPolygons(convexPolygon2dA, convexPolygon2dB, intersection); boolean epsilonEquals = intersection.epsilonEquals(convexPolygon2dA, 1e-7); assertTrue(epsilonEquals); convexPolygonTools.computeIntersectionOfPolygons(convexPolygon2dB, convexPolygon2dA, intersection); epsilonEquals = intersection.epsilonEquals(convexPolygon2dA, 1e-7); assertTrue(epsilonEquals); convexPolygon2dB = new ConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(listOfPoints)); convexPolygonTools.computeIntersectionOfPolygons(convexPolygon2dB, convexPolygon2dA, intersection); epsilonEquals = intersection.epsilonEquals(convexPolygon2dA, 1e-14); assertTrue(epsilonEquals); convexPolygonTools.computeIntersectionOfPolygons(convexPolygon2dA, convexPolygon2dB, intersection); epsilonEquals = intersection.epsilonEquals(convexPolygon2dA, 1e-14); assertTrue(epsilonEquals);
if (computeIntersectionOfPolygons(polygon1, polygon2, intersectingPolygonToPack))
/** * 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); }
boolean success = convexPolygonTools.computeIntersectionOfPolygons(convexPolygon1, convexPolygon2, intersectingPolygon); if (!success) intersectingPolygon = null;
/** * Returns a transform that will move the given polygon into a planar region. Problematic if the planar region consists of * multiple sub convex polygons. The polygon to wiggle must have the same transform to world as the planar region. * * @param polygonToWiggleInRegionFrame * @param regionToWiggleInto * @param wiggleParameters * @return */ public static RigidBodyTransform wigglePolygonIntoRegion(ConvexPolygon2D polygonToWiggleInRegionFrame, PlanarRegion regionToWiggleInto, WiggleParameters parameters) { // find the part of the region that has the biggest intersection with the polygon ConvexPolygon2D bestMatch = null; double overlap = 0.0; ConvexPolygonTools convexPolygonTools = new ConvexPolygonTools(); for (int i = 0; i < regionToWiggleInto.getNumberOfConvexPolygons(); i++) { ConvexPolygon2D intersection = new ConvexPolygon2D(); convexPolygonTools.computeIntersectionOfPolygons(regionToWiggleInto.getConvexPolygon(i), polygonToWiggleInRegionFrame, intersection); if (intersection.getArea() > overlap) { overlap = intersection.getArea(); bestMatch = regionToWiggleInto.getConvexPolygon(i); } } if (bestMatch == null) return null; return findWiggleTransform(polygonToWiggleInRegionFrame, bestMatch, parameters); }
convexPolygonTools.computeIntersectionOfPolygons(convexPolygons.get(i), projectedPolygon, intersectingPolygon);
assertTrue(polygonWithOnePoint.getVertex(0).equals(pointThatDefinesThePolygon)); assertFalse(convexPolygonTools.computeIntersectionOfPolygons(polygonWithOnePoint, sparePolygon, intersectionPolygon)); assertTrue(polygonWithOnePoint.intersectionWith(arbitraryLine) == null); assertFalse(polygonWithOnePoint.isPointInside(arbitraryPoint0)); assertEqualsInEitherOrder(pointThatDefinesThePolygon, pointThatDefinesAnotherPolygon, point0, point1); assertTrue(convexPolygonTools.computeIntersectionOfPolygons(polygonWithOnePoint, anotherPolygonWithOnePoint, new ConvexPolygon2D()) == false); ConvexPolygon2D intersection = new ConvexPolygon2D(); convexPolygonTools.computeIntersectionOfPolygons(polygonWithOnePoint, polygonWithOnePoint, intersection); assertEquals(1, intersection.getNumberOfVertices()); convexPolygonTools.computeIntersectionOfPolygons(polygonWithOnePoint, polygonWithOnePoint, intersection); assertTrue(intersection.getVertex(0).equals(pointThatDefinesThePolygon)); assertTrue(polygonWithOnePoint.intersectionWith(arbitraryLineSegment) == null);
pointThatDefinesThePolygon1)); ConvexPolygon2D actualIntersectionWithSparePolygon = new ConvexPolygon2D(); boolean success = convexPolygonTools .computeIntersectionOfPolygons(sparePolygon, polygonWithTwoPoints, actualIntersectionWithSparePolygon); success = convexPolygonTools.computeIntersectionOfPolygons(polygonWithTwoPoints, sparePolygon, polygonIntersection);
footPolygonInRegion.set(footStepPolygon); footPolygonInRegion.applyTransform(soleToRegion, false); convexPolygonTools.computeIntersectionOfPolygons(regionToMoveTo.getConvexHull(), footPolygonInRegion, foothold); soleToRegion.invert(); foothold.applyTransform(soleToRegion, false);