/** * Efficiently combines two Disjoint Polygons. Returns null if not disjoint. * Note: Generates garbage! * * @param polygon1 ConvexPolygon2d * @param polygon2 ConvexPolygon2d * @return ConvexPolygon2dAndConnectingEdges */ public static ConvexPolygon2dAndConnectingEdges combineDisjointPolygons(ConvexPolygon2d polygon1, ConvexPolygon2d polygon2) { ConvexPolygon2d combinedPolygon = new ConvexPolygon2d(); LineSegment2d connectingEdge1 = new LineSegment2d(); LineSegment2d connectingEdge2 = new LineSegment2d(); boolean success = combineDisjointPolygons(polygon1, polygon2, combinedPolygon, connectingEdge1, connectingEdge2); if (!success) return null; return new ConvexPolygon2dAndConnectingEdges(combinedPolygon, connectingEdge1, connectingEdge2); }
public static boolean combineDisjointPolygons(FrameConvexPolygon2d polygon1, FrameConvexPolygon2d polygon2, FrameConvexPolygon2d combinedPolygonToPack, FrameLineSegment2d connectingEdge1ToPack, FrameLineSegment2d connectingEdge2ToPack) { combinedPolygonToPack.clear(polygon1.getReferenceFrame()); combinedPolygonToPack.checkReferenceFrameMatch(connectingEdge1ToPack); combinedPolygonToPack.checkReferenceFrameMatch(connectingEdge2ToPack); boolean success = combineDisjointPolygons(polygon1.convexPolygon, polygon2.convexPolygon, combinedPolygonToPack.convexPolygon, connectingEdge1ToPack.lineSegment, connectingEdge2ToPack.lineSegment); if (!success) return false; // combinedPolygonToPack.updateFramePoints(); combinedPolygonToPack.update(); return true; }
public boolean combineDisjointPolygons(FrameConvexPolygon2DReadOnly polygon1, FrameConvexPolygon2DReadOnly polygon2, FrameConvexPolygon2DBasics combinedPolygonToPack, FrameLineSegment2DBasics connectingEdge1ToPack, FrameLineSegment2DBasics connectingEdge2ToPack) { combinedPolygonToPack.clear(polygon1.getReferenceFrame()); combinedPolygonToPack.checkReferenceFrameMatch(connectingEdge1ToPack); combinedPolygonToPack.checkReferenceFrameMatch(connectingEdge2ToPack); boolean success = combineDisjointPolygons((ConvexPolygon2DReadOnly) polygon1, (ConvexPolygon2DReadOnly) polygon2, (ConvexPolygon2DBasics) combinedPolygonToPack, (LineSegment2DBasics) connectingEdge1ToPack, (LineSegment2DBasics) connectingEdge2ToPack); if (!success) return false; // combinedPolygonToPack.updateFramePoints(); combinedPolygonToPack.update(); return true; }
/** * generates garbage * @param polygon1 * @param polygon2 * @return */ //this should throw away points that are inside of the other polygon public static FrameConvexPolygon2dAndConnectingEdges combineDisjointPolygons(FrameConvexPolygon2d polygon1, FrameConvexPolygon2d polygon2) { ReferenceFrame referenceFrame = polygon1.getReferenceFrame(); polygon2.checkReferenceFrameMatch(referenceFrame); ConvexPolygon2dAndConnectingEdges polygonAndEdges = combineDisjointPolygons(polygon1.convexPolygon, polygon2.convexPolygon); if (polygonAndEdges == null) return null; // Return null if not disjoint FrameConvexPolygon2d frameConvexPolygon2d = new FrameConvexPolygon2d(referenceFrame, polygonAndEdges.getConvexPolygon2d()); FrameLineSegment2d connectingEdge1 = new FrameLineSegment2d(referenceFrame, polygonAndEdges.getConnectingEdge1()); FrameLineSegment2d connectingEdge2 = new FrameLineSegment2d(referenceFrame, polygonAndEdges.getConnectingEdge2()); FrameConvexPolygon2dAndConnectingEdges ret = new FrameConvexPolygon2dAndConnectingEdges(polygon1, polygon2, frameConvexPolygon2d, connectingEdge1, connectingEdge2); return ret; }
FrameLineSegment2D connectingEdge1 = new FrameLineSegment2D(); FrameLineSegment2D connectingEdge2 = new FrameLineSegment2D(); convexPolygonTools.combineDisjointPolygons(polygon1, polygon2, actualPolygon, connectingEdge1, connectingEdge2);
for (int i = 0; i < numTests; i++) convexPolygonTools.combineDisjointPolygons(polygon1, polygon2, combinedPolygon, connectingEdge1, connectingEdge2);
LineSegment2D connectingEdge1 = new LineSegment2D(); LineSegment2D connectingEdge2 = new LineSegment2D(); convexPolygonTools.combineDisjointPolygons(polygonWithOnePoint, anotherPolygonWithOnePoint, combinedPolygon, connectingEdge1, connectingEdge2); assertEquals(2, combinedPolygon.getNumberOfVertices()); point0 = combinedPolygon.getVertex(0);