Exemple #1
0
    public static boolean pointInPolygon(Polygon poly, Mat point) {
      ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>();
      for (Mat v : poly.vertices) {
        points.add(new Point2D.Double(v.data[0][0], v.data[1][0]));
      }
      PolygonObstacle po = GeomUtils.convexHull(points);
      return po.contains(point.data[0][0], point.data[1][0]);

      /*Mat farPoint = Mat.encodePoint(0, 0);
      double maxDist = -1;
      double dist;

      for (Mat vertex : poly.vertices) {
      	dist = Mat.dist(point, vertex);
      	if (maxDist < dist) {
      		maxDist = dist;
      	}
      }

      farPoint = Mat.add(point, Mat.mul(maxDist + 1, Mat.encodePoint(1, 0)));

      int size = poly.vertices.size();
      int intersections = 0;
      for (int i = 0; i < size; i++) {
      	if (lineSegIntersect(point, farPoint, poly.vertices.get(i), poly.vertices.get((i + 1) % size))) {
      		intersections++;
      	}
      }

      return ((intersections % 2) == 1);*/
    }
Exemple #2
0
  public PolygonObstacle getRobot() {
    Point2D.Double center = polymap.getRobotStart();
    PolygonObstacle robot = new PolygonObstacle();

    double x, y, angle;
    for (int i = 0; i < NUM_SIDES; i++) {
      angle = i * 2.0 * Math.PI / NUM_SIDES;
      x = RADIUS * Math.cos(angle);
      y = RADIUS * Math.sin(angle);
      robot.addVertex(x, y);
    }

    robot.close();

    return robot;
  }
Exemple #3
0
 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));
 }
Exemple #4
0
 // 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);
 }