public void addObstacle(PolygonObstacle obstacle) { ArrayList<Mat> vertices = new ArrayList<Mat>(); for (Point2D.Double vert : obstacle.getVertices()) { vertices.add(Mat.encodePoint(vert.x, vert.y)); } addObstacle(new Polygon(vertices)); }
// assumes that there will be no enclosed empty spaces in the result, and that the result will // be contiguous, and that everything is convex public static Polygon minkowskiSumSimple(Polygon poly1, Polygon poly2) { ArrayList<Mat> verts = new ArrayList<Mat>(); for (Mat v1 : poly1.vertices) { for (Mat v2 : poly2.vertices) { verts.add(Mat.add(v1, v2)); } } ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>(); for (Mat v : verts) { points.add(new Point2D.Double(v.data[0][0], v.data[1][0])); } PolygonObstacle po = GeomUtils.convexHull(points); verts = new ArrayList<Mat>(); for (Point2D.Double vert : po.getVertices()) { verts.add(Mat.encodePoint(vert.x, vert.y)); } return new Polygon(verts); }