Пример #1
0
 private void addSurface(Color color, Point[] points) {
   Surface added = new Surface(color);
   for (int i = 0, n = points.length; i < n; i++) {
     added.addEdge(points[i % n], points[(i + 1) % n]);
   }
   surfaces.add(added);
 }
Пример #2
0
 /**
  * Поиск всех точек пересечения поверхностей с плоскостью У, а также поиск пересечений между
  * отрезками получающимися.
  *
  * @param currentY
  */
 private void findAllIntersections(double currentY) {
   drawnSegments.clear();
   pointsList.clear();
   listPointsEvent.map.clear();
   for (Surface surface : drawnSurfaces) {
     Segment segment = surface.getIntersectionWithY(currentY);
     if (segment == null) {
       continue;
     }
     if (segment.getFinish().getX() < segment.getStart().getX()) {
       segment = new Segment(segment.getFinish(), segment.getStart(), surface.getSurfaceColor());
     }
     segments.add(segment);
     pointsList.add(segment.getStart());
     pointsList.add(segment.getFinish());
     listPointsEvent.addEvent(
         new PointEvent(PointEventsList.START, segment.getStart()),
         (int) segment.getStart().getX());
     listPointsEvent.addEvent(
         new PointEvent(PointEventsList.FINISH, segment.getFinish()),
         (int) segment.getFinish().getX());
   }
   for (int i = 0, number = drawnSegments.size(); i < number; i++) {
     for (int j = i + 1; j < number; j++) {
       Point intersection = drawnSegments.get(i).getIntersectionWithSegment(drawnSegments.get(j));
       if (intersection != null) {
         pointsList.add(intersection);
         listPointsEvent.addEvent(
             new PointEvent(PointEventsList.INTERSECTION, intersection),
             (int) intersection.getX());
       }
     }
   }
 }
Пример #3
0
  public Executer(Canvas canvas) {
    this.canvas = canvas;
    context = canvas.getGraphicsContext2D();

    //          Point[] points = new Point[]{
    //            new Point(0, 0, 0),
    //            new Point(50, 50, 0),
    //            new Point(100, 0, 0)
    //        };
    //        addSurface(Color.RED, points);
    //
    //        points = new Point[]{
    //            new Point(0, 40, -70),
    //            new Point(10, 50, -50),
    //            new Point(65, -5, 100),
    //            new Point(55, -10, 100)
    //        };
    //        addSurface(Color.BLUE, points);
    //
    //        points = new Point[]{
    //            new Point(25, 0, -70),
    //            new Point(50, 0, -50),
    //            new Point(50, 70, 100),
    //            new Point(25, 50, 100)
    //        };
    //        addSurface(Color.YELLOW, points);
    Point[] points =
        new Point[] {
          new Point(10, 30, 0), new Point(10, 70, 0), new Point(50, 100, 0), new Point(100, 70, 0)
        };
    addSurface(Color.RED, points);

    points =
        new Point[] {
          new Point(-70, -70, 0),
          new Point(-100, 30, 0),
          new Point(-30, 100, 0),
          new Point(50, 50, 0),
          new Point(70, -70, 0)
        };
    addSurface(Color.BLUE, points);

    points = new Point[] {new Point(10, -60, 0), new Point(-20, 20, 0), new Point(40, 20, 0)};
    addSurface(Color.GREEN, points);

    points =
        new Point[] {
          new Point(10, 30, 0), new Point(10, 70, 0), new Point(50, 100, 0), new Point(100, 70, 0)
        };
    addSurface(Color.BROWN, points);

    points = new Point[] {new Point(10, -60, 0), new Point(-20, 20, 0), new Point(40, 20, 0)};
    addSurface(Color.BLACK, points);

    Random random = new Random();
    for (Surface s : surfaces) {
      s.XRotate(random.nextInt(60));
      s.YRotate(1 + random.nextInt(170));
      s.ZRotate(random.nextInt(180));
    }
  }