Beispiel #1
0
 public static boolean onBoundary(ArrayList<Point> pol, Point p) {
   int n = pol.size();
   for (int i = 0; i < n; i++) {
     int j = (i + 1) % n;
     if (Points.onSegment(pol.get(i), pol.get(j), p)) return true;
   }
   return false;
 }
Beispiel #2
0
 public static boolean onBoundary(Point[] pol, Point p) {
   int n = pol.length;
   for (int i = 0; i < n; i++) {
     int j = (i + 1) % n;
     if (Points.onSegment(pol[i], pol[j], p)) return true;
   }
   return false;
 }
Beispiel #3
0
 public static ArrayList<Point> cut(ArrayList<Point> pol, Point p, Point q, Point x) {
   ArrayList<Point> res = new ArrayList<>();
   int orient = Points.orient(p, q, x);
   Line L = new Line(p, q);
   for (int i = 0; i < pol.size(); i++) {
     int j = (i + 1) % pol.size();
     if (Points.orient(p, q, pol.get(i)) == orient) {
       res.add(pol.get(i));
     }
     Point inter = L.intersection(new Line(pol.get(i), pol.get(j)));
     if (inter != null && Points.onSegment(pol.get(i), pol.get(j), inter)) {
       res.add(inter);
     }
   }
   return res;
 }
Beispiel #4
0
 /*
  * Cut a polygon by the line pq
  */
 @SuppressWarnings("rawtypes")
 public static ArrayList[] cut(ArrayList<Point> pol, Point p, Point q) {
   ArrayList<Point> polWithInter = new ArrayList<>();
   Line L = new Line(p, q);
   for (int i = 0; i < pol.size(); i++) {
     polWithInter.add(pol.get(i));
     int j = (i + 1) % pol.size();
     Point inter = L.intersection(new Line(pol.get(i), pol.get(j)));
     if (inter != null
         && Points.onSegment(pol.get(i), pol.get(j), inter)
         && !Points.eq(pol.get(i), inter)
         && !Points.eq(pol.get(j), inter)) {
       polWithInter.add(inter);
     }
   }
   ArrayList<Point> pol1 = new ArrayList<Point>();
   ArrayList<Point> pol2 = new ArrayList<Point>();
   for (Point x : polWithInter) {
     int orient = Points.orient(x, p, q);
     if (orient <= 0) pol1.add(x);
     if (orient >= 0) pol2.add(x);
   }
   return new ArrayList[] {pol1, pol2};
 }