Exemplo n.º 1
0
 //    int x1, x2, y;
 private void drawLine(int currentY, int index) {
   // добавление рассматриваемых плоскостей
   for (; index < setBorders.size() && setBorders.get(index) >= currentY; index++) {
     changeDrawnSurfacesList(currentY, true);
   }
   // поиск всех точек, пересекающих эту плоскость, и составление из них отрезков
   // поиск точек пересечения между этими отрезками
   findAllIntersections(currentY);
   // сортировка
   pointsList =
       (ArrayList<Point>)
           pointsList
               .stream()
               .sorted((a, b) -> Double.compare(a.getX(), b.getX()))
               .collect(Collectors.toList());
   // отрисовка
   Point last = new Point(0, currentY, 0);
   for (Point p : pointsList) {
     ArrayList<PointEvent> events = listPointsEvent.getEvent((int) p.getX());
     for (PointEvent event : events) {
       if (event.event == PointEventsList.START) {
         drawnSegments.add(event.point.getParent());
       }
     }
     if (drawnSegments.size() > 0) {
       double maxZ = -Double.MAX_VALUE;
       Segment chosen = null;
       for (Segment seg : drawnSegments) {
         double z = seg.getZOnX(p.getX());
         if (z > maxZ) {
           maxZ = z;
           chosen = seg;
         }
       }
       if (chosen != null && maxZ > -Double.MAX_VALUE) {
         context.setStroke(chosen.getSurfaceColor());
         double x1 = canvas.getWidth() / 4 + last.getX() * 2,
             x2 = canvas.getWidth() / 4 + p.getX() * 2,
             y = canvas.getHeight() / 2 + currentY;
         context.strokeLine(x1, y, x2, y);
       }
     }
     // актуализация отрезков
     for (PointEvent event : events) {
       if (event.event == PointEventsList.FINISH) {
         drawnSegments.remove(event.point.getParent());
       }
     }
     last = p;
   }
 }
Exemplo n.º 2
0
  public void initTimer(int currentY, int index) {

    for (; index < setBorders.size() && setBorders.get(index) >= currentY; index++) {
      changeDrawnSurfacesList(currentY, true);
    }
    findAllIntersections(currentY);
    pointsList =
        (ArrayList<Point>)
            pointsList
                .stream()
                .sorted((a, b) -> Double.compare(a.getX(), b.getX()))
                .collect(Collectors.toList());
    Point last = new Point(0, currentY, 0);
    for (Point p : pointsList) {
      ArrayList<PointEvent> events = listPointsEvent.getEvent((int) p.getX());
      for (PointEvent event : events) {
        if (event.event == PointEventsList.START) {
          drawnSegments.add(event.point.getParent());
        }
      }
      if (drawnSegments.size() > 0) {
        double maxZ = -Double.MAX_VALUE;
        Segment chosen = null;
        for (Segment seg : drawnSegments) {
          double z = seg.getZOnX(p.getX());
          if (z > maxZ) {
            maxZ = z;
            chosen = seg;
          }
        }
        if (chosen != null && maxZ > -Double.MAX_VALUE) {
          //                    context.setStroke(chosen.getSurfaceColor());
          double x1 = canvas.getWidth() / 4 + last.getX() * 2,
              x2 = canvas.getWidth() / 4 + p.getX() * 2,
              y = canvas.getHeight() / 2 + currentY;
          Segment segment =
              new Segment(new Point(x1, y, 0), new Point(x2, y, 0), chosen.getSurfaceColor());
          result.add(segment);
          //                    context.strokeLine(x1, y, x2, y);
        }
      }
      // актуализация отрезков
      for (PointEvent event : events) {
        if (event.event == PointEventsList.FINISH) {
          drawnSegments.remove(event.point.getParent());
        }
      }
      last = p;
    }

    AnimationTimer timer =
        new AnimationTimer() {
          @Override
          public void handle(long now) {
            if (indexResult == result.size() - 1) {
              stop();
              return;
            }
            segmentResult = result.get(indexResult++);
            context.setStroke(segmentResult.getSurfaceColor());
            context.strokeLine(
                segmentResult.getStart().getX(),
                segmentResult.getStart().getY(),
                segmentResult.getFinish().getX(),
                segmentResult.getFinish().getY());
          }
        };
    timer.start();
  }
Exemplo n.º 3
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());
       }
     }
   }
 }