Esempio n. 1
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;
 }
Esempio n. 2
0
  // метод вычисляет точки пересечения фигур по контексту строки s.
  static void figureIntersection(String s) {
    if (s.equals("ll")) {
      Object[] ob = line1.intersection(line2);
      toScreen(ob);
    }
    if (s.equals("lc") | s.equals("cl")) {
      Object[] ob = circle1.intersection_with_line(line1);
      toScreen(ob);
    }
    if (s.equals("lt") | s.equals("tl")) {
      Object[][] ob = triangle1.trianle_intersection_with_line(line1);
      toScreen(ob);
    }
    if (s.equals("lr") | s.equals("rl")) {
      Object[] ob = rectangle1.intrsc_Line(line1);
      toScreen(ob);
    }

    if (s.equals("cc")) {
      Object[] ob = circle1.circles_intersection(circle2);
      toScreen(ob);
    }
    if (s.equals("ct") | s.equals("tc")) {
      Object[][] ob = triangle1.trianle_intersection_with_circle(circle1);
      toScreen(ob);
    }
    if (s.equals("cr") | s.equals("rc")) {
      Object[][] ob = rectangle1.intrsc_Rect_Circle(circle1);
      toScreen(ob);
    }

    if (s.equals("tt")) {
      Object[][] ob = triangle1.trianles_intersection(triangle2);
      toScreen(ob);
    }
    if (s.equals("tr") | s.equals("rt")) {
      Object[][][] ob = rectangle1.intrsc_Rect_Triangle(triangle1);
      toScreen(ob);
    }

    if (s.equals("rr")) {
      Object[][] ob = rectangle1.intrsc_Rect_Rect(rectangle2);
      toScreen(ob);
    }
  }
Esempio n. 3
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};
 }