Example #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);*/
    }