Beispiel #1
0
  /**
   * General constructor.
   *
   * @param element {@link GeoElement}
   * @param scope {@link EquationScope}
   */
  public EquationPolygon(final GeoElement element, final EquationScope scope) {
    super(element, scope);

    GeoPolygon polygon = (GeoPolygon) element;

    this.setSegments(polygon.getSegments());
  }
  private void updateTop(int n) {

    GeoPolygon polygon = getTopFace();
    GeoPointND[] p = new GeoPointND[n];
    p[0] = getTopPoint();
    for (int i = 0; i < n - 1; i++) p[1 + i] = getTopPoint(i + 1);
    // polygon.setPoints(p,null,false); //don't create segments
    polygon.modifyInputPoints(p);
    polygon.setSegments(outputSegmentsTop.getOutput(new GeoSegment3D[n]));
    polygon.calcArea();
  }
Beispiel #3
0
 /**
  * Return the edges of a polygon
  *
  * @param poly the polygon
  * @return and array with all the edges of the polygon
  */
 public static GeoSegment[] getPolygonEdges(GeoPolygon poly) {
   GeoSegmentND[] nd_edges = poly.getSegments();
   GeoSegment[] edges = new GeoSegment[nd_edges.length];
   for (int i = 0; i < nd_edges.length; i++) {
     edges[i] = (GeoSegment) nd_edges[i];
   }
   return edges;
 }
 private void updateSide(int index, GeoPointND[] bottomPoints) {
   outputSegmentsTop
       .getElement(index - 1)
       .modifyInputPoints(getTopPoint(index - 1), getTopPoint(index));
   GeoPolygon polygon = outputPolygonsSide.getElement(index - 1);
   GeoPointND[] p = new GeoPointND[4];
   p[0] = bottomPoints[index - 1];
   p[1] = bottomPoints[index];
   p[2] = getTopPoint(index);
   p[3] = getTopPoint(index - 1);
   polygon.setPoints(p, null, false); // don't create segments
   GeoSegmentND[] s = new GeoSegmentND[4];
   s[0] = getBottom().getSegments()[index];
   s[1] = outputSegmentsSide.getElement(index);
   s[2] = outputSegmentsTop.getElement(index);
   s[3] = outputSegmentsSide.getElement(index - 1);
   polygon.setSegments(s);
   polygon.calcArea();
 }
  @Override
  protected void updateOutput() {
    if (isOldFileVersion()) {
      // add polyhedron's segments and polygons, without setting this algo as algoparent
      int index = 0;
      if (!bottomAsInput) { // check bottom
        outputPolygonsBottom.addOutput(polyhedron.getFace(index), false);
        index++;
        for (int i = 0; i < bottomPointsLength; i++)
          outputSegmentsBottom.addOutput(
              (GeoSegment3D) polyhedron.getSegment(points[i], points[(i + 1) % bottomPointsLength]),
              false);
      }

      // sides
      for (int i = 0; i < bottomPointsLength; i++) {
        outputPolygonsSide.addOutput(polyhedron.getFace(index), false);
        index++;
        outputSegmentsSide.addOutput(
            (GeoSegment3D) polyhedron.getSegment(points[i], points[i + bottomPointsLength]), false);
      }

      // top
      outputPolygonsTop.addOutput(polyhedron.getFace(index), false);
      for (int i = 0; i < bottomPointsLength; i++)
        outputSegmentsTop.addOutput(
            (GeoSegment3D)
                polyhedron.getSegment(
                    points[bottomPointsLength + i],
                    points[bottomPointsLength + ((i + 1) % bottomPointsLength)]),
            false);
    } else {
      // Application.debug("ici");
      Collection<GeoPolygon3D> faces = polyhedron.getFacesCollection();
      int top = faces.size();
      int step = 1;
      for (GeoPolygon polygon : faces) {

        GeoSegmentND[] segments = polygon.getSegments();
        if (step == 1 && !bottomAsInput) { // bottom
          outputPolygonsBottom.addOutput((GeoPolygon3D) polygon, false);
          for (int i = 0; i < segments.length; i++)
            outputSegmentsBottom.addOutput((GeoSegment3D) segments[i], false);
          step++;
          continue;
        } else if (step == top) { // top
          outputPolygonsTop.addOutput((GeoPolygon3D) polygon, false);
          for (int i = 0; i < segments.length; i++)
            outputSegmentsTop.addOutput((GeoSegment3D) segments[i], false);
          step++;
          continue;
        }

        // sides
        outputPolygonsSide.addOutput((GeoPolygon3D) polygon, false);
        outputSegmentsSide.addOutput((GeoSegment3D) polygon.getSegments()[3], false);
        step++;
      }
    }

    refreshOutput();
  }
  @Override
  protected void updateOutput(int newBottomPointsLength, GeoPointND[] bottomPoints) {

    // current length of top points
    int nOld = outputPoints.size() + getShift();

    if (newBottomPointsLength > nOld) {

      int length = newBottomPointsLength - nOld;
      outputPoints.augmentOutputSize(length);
      outputPoints.setLabels(null);

      updateOutputPoints();

      // new sides of the prism
      int l = nOld + length;
      for (int i = nOld; i < l; i++) {
        polyhedron.startNewFace();
        polyhedron.addPointToCurrentFace(bottomPoints[i]);
        polyhedron.addPointToCurrentFace(bottomPoints[(i + 1) % l]);
        polyhedron.addPointToCurrentFace(getTopPoint((i + 1) % l));
        polyhedron.addPointToCurrentFace(getTopPoint(i));
        polyhedron.endCurrentFace();
        GeoPolygon3D polygon = polyhedron.createPolygon(i + 1); // i+1 due to top face
        outputPolygonsSide.addOutput(polygon, false);
        outputSegmentsSide.addOutput((GeoSegment3D) polygon.getSegments()[3], false);
        outputSegmentsTop.addOutput((GeoSegment3D) polygon.getSegments()[2], false);
      }
      outputSegmentsSide.setLabels(null);
      outputSegmentsTop.setLabels(null);

      refreshOutput();
    } else if (newBottomPointsLength < nOld) {

      for (int i = newBottomPointsLength; i < bottomPointsLength; i++) {
        outputPoints.getElement(i - getShift()).setUndefined();
      }

      updateOutputPoints();

      // update top side
      outputSegmentsTop
          .getElement(newBottomPointsLength - 1)
          .modifyInputPoints(getTopPoint(newBottomPointsLength - 1), getTopPoint());
      GeoPolygon polygon = getTopFace();
      GeoPointND[] p = new GeoPointND[newBottomPointsLength];
      p[0] = getTopPoint();
      for (int i = 0; i < newBottomPointsLength - 1; i++) p[1 + i] = getTopPoint(i + 1);
      // polygon.setPoints(p,null,false); //don't create segments
      polygon.modifyInputPoints(p);
      polygon.setSegments(outputSegmentsTop.getOutput(new GeoSegment3D[newBottomPointsLength]));
      polygon.calcArea();

      // update last side
      polygon = outputPolygonsSide.getElement(newBottomPointsLength - 1);
      p = new GeoPointND[4];
      p[0] = bottomPoints[newBottomPointsLength - 1];
      p[1] = bottomPoints[0];
      p[2] = getTopPoint();
      p[3] = getTopPoint(newBottomPointsLength - 1);
      polygon.setPoints(p, null, false); // don't create segments
      GeoSegmentND[] s = new GeoSegmentND[4];
      s[0] = getBottom().getSegments()[newBottomPointsLength];
      s[1] = outputSegmentsSide.getElement(newBottomPointsLength);
      s[2] = outputSegmentsTop.getElement(newBottomPointsLength);
      s[3] = outputSegmentsSide.getElement(newBottomPointsLength - 1);
      polygon.setSegments(s);
      polygon.calcArea();

    } else updateOutputPoints();

    if (bottomPointsLength < newBottomPointsLength) {

      // update top side
      updateTop(newBottomPointsLength);

      // update last sides
      for (int i = bottomPointsLength; i < newBottomPointsLength; i++) updateSide(i, bottomPoints);
    }

    bottomPointsLength = newBottomPointsLength;
  }
Beispiel #7
0
 /**
  * Return the directed area of a polygon
  *
  * @param poly the polygon
  * @return its directed area
  */
 public static double getPolygonDirectedArea(GeoPolygon poly) {
   return poly.getAreaWithSign();
 }
Beispiel #8
0
 /**
  * Return the number of points in a polygon
  *
  * @param poly the polygon
  * @return the polygon's number of points
  */
 public static int getPolygonSize(GeoPolygon poly) {
   return poly.getPointsLength();
 }