protected void rotatePoints(int n, double alpha) {
   // now we have the center point of the polygon and
   // the center angle alpha between two neighbouring points
   // let's create the points by rotating A around the center point
   for (int k = 0; k < n - 2; k++) {
     // rotate point around center point
     outputPoints.getElement(k).set((GeoElement) A);
     rotAngle.set((k + 2) * alpha);
     rotate((GeoPointND) outputPoints.getElement(k));
   }
 }
Ejemplo n.º 2
0
  /**
   * update bottom face for new length
   *
   * @param newBottomPointsLength new bottom points length
   */
  protected void updateBottom(int newBottomPointsLength) {

    GeoPolygon polygon = outputPolygonsBottom.getElement(0);
    GeoPoint3D[] points = new GeoPoint3D[newBottomPointsLength];
    GeoSegment3D[] segments = new GeoSegment3D[newBottomPointsLength];
    for (int i = 0; i < newBottomPointsLength; i++) {
      points[i] = outputPointsBottom.getElement(i);
      segments[i] = outputSegmentsBottom.getElement(i);
    }
    polygon.modifyInputPoints(points);
    polygon.setSegments(segments);
    polygon.calcArea();
  }
  /** @param nd number of vertices */
  public final void compute(int nd) {

    GeoPolygon poly = getPoly();

    // get integer number of vertices n
    this.n = Math.max(2, nd);

    // if number of points changed, we need to update the
    // points array and the output array
    updateOutput(n);

    // check if regular polygon is defined
    if (checkUnDefined(n)) {
      return;
    }

    this.alpha = Kernel.PI_2 / n; // center angle ACB
    double beta = (Math.PI - alpha) / 2; // base angle CBA = BAC

    setCenterPoint(n, beta);
    rotatePoints(n, alpha);

    GeoPointND[] points = new GeoPointND[n];
    points[0] = A;
    points[1] = B;
    for (int i = 2; i < n; i++) points[i] = (GeoPointND) outputPoints.getElement(i - 2);

    // update new segments
    for (int i = numOld - 1; i < n; i++) {
      // App.debug(i+": "+points[i]+" , "+points[(i+1)%n]);
      ((GeoSegmentND) outputSegments.getElement(i))
          .modifyInputPoints(points[i], points[(i + 1) % n]);
    }

    // update polygon
    poly.setPoints(points, null, false); // don't create segments
    GeoSegmentND[] segments = new GeoSegmentND[n];
    for (int i = 0; i < n; i++) {
      segments[i] = (GeoSegmentND) outputSegments.getElement(i);
    }
    poly.setSegments(segments);

    // compute area of poly
    calcArea();

    // update region coordinate system
    poly.updateRegionCSWithFirstPoints();

    numOld = n;
  }
Ejemplo n.º 4
0
  @Override
  public void compute() {

    if (!p.isDefined()) {
      setUndefined();
      return;
    }

    double f = v.getDouble();

    if (Kernel.isGreater(f, 1) || Kernel.isGreater(0, f)) {
      setUndefined();
      return;
    }

    // update bottom points
    GeoPolygon bottomFace = p.getBottomFace();
    if (bottomFace.isConvex()) {
      getNet().setDefined();
      Coords[] points = getPointsCoords(bottomFace);
      adjustOutputSize(points.length);
      outputPointsBottom.setLabels(null);
      for (int i = 0; i < points.length; i++) {
        outputPointsBottom.getElement(i).setCoords(points[i]);
      }
      compute(f, bottomFace, points);
    } else {
      setUndefined();
    }
  }
  /**
   * Ensures that the pointList holds n points.
   *
   * @param n
   */
  private void updateOutput(int n) {

    int nOld = outputPoints.size() + 2;

    // App.error("nOld="+nOld+", n="+n);

    if (nOld == n) return;

    // update points and segments
    if (n > nOld) {
      showNewPointsLabels =
          labelPointsAndSegments
              && (A.isEuclidianVisible() && A.isLabelVisible()
                  || B.isEuclidianVisible() && B.isLabelVisible());
      outputPoints.augmentOutputSize(n - nOld, false);
      if (labelPointsAndSegments && !labelsNeedIniting) outputPoints.updateLabels();

      showNewSegmentsLabels = false;
      for (int i = 0; i < outputSegments.size(); i++)
        showNewSegmentsLabels =
            showNewSegmentsLabels || outputSegments.getElement(i).isLabelVisible();
      outputSegments.augmentOutputSize(n - nOld, false);
      if (labelPointsAndSegments && !labelsNeedIniting) outputSegments.updateLabels();
    } else {
      for (int i = n; i < nOld; i++) {
        outputPoints.getElement(i - 2).setUndefined();
        outputSegments.getElement(i).setUndefined();
      }
      // update last segment
      if (n > 2)
        ((GeoSegmentND) outputSegments.getElement(n - 1))
            .modifyInputPoints((GeoPointND) outputPoints.getElement(n - 3), A);
      else ((GeoSegmentND) outputSegments.getElement(n - 1)).modifyInputPoints(B, A);
    }
  }
Ejemplo n.º 6
0
  @Override
  public final void compute() {
    if (index != null) {
      if (!p.isDefined()) {
        oneVertex.setUndefined();
      } else {
        int i = (int) Math.floor(index.getDouble()) - 1;
        if (i >= p.getPoints().length || i < 0) {
          oneVertex.setUndefined();
        } else {
          setPoint(oneVertex, i);
        }
      }
      oneVertex.update();
      return;
    }

    if (!p.isDefined()) {
      for (int i = 0; i < outputPoints.size(); i++) {
        outputPoints.getElement(i).setUndefined();
      }
      return;
    }

    int length = p.getPoints().length;
    // Log.debug(length);
    if (length > outputPoints.size()) {
      outputPoints.adjustOutputSize(length);
      refreshOutput();
    }

    for (int i = 0; i < length; i++) {
      GeoPointND point = (GeoPointND) outputPoints.getElement(i);
      setPoint(point, i);
    }
    // other points are undefined
    for (int i = length; i < outputPoints.size(); i++) {
      outputPoints.getElement(i).setUndefined();
    }
  }
Ejemplo n.º 7
0
  private void setLabels(String[] labels) {
    // if only one label (e.g. "A") for more than one output, new labels
    // will be A_1, A_2, ...
    if (labels != null
        && labels.length == 1
        &&
        // outputPoints.size() > 1 &&
        labels[0] != null
        && !labels[0].equals("")) {
      outputPoints.setIndexLabels(labels[0]);
    } else {

      outputPoints.setLabels(labels);
      outputPoints.setIndexLabels(
          outputPoints.getElement(0).getLabel(StringTemplate.defaultTemplate));
    }
  }
  /**
   * Creates a new regular polygon algorithm
   *
   * @param c construction
   * @param labels labels[0] for polygon, then labels for segments and then for points
   * @param A1 first input point
   * @param B1 second input point
   * @param num number of vertices
   */
  public AlgoPolygonRegularND(
      Construction c,
      String[] labels,
      GeoPointND A1,
      GeoPointND B1,
      NumberValue num,
      GeoDirectionND direction) {
    super(c);

    labelsNeedIniting = true;

    this.A = A1;
    this.B = B1;
    this.num = num;
    setDirection(direction);

    // labels given by user or loaded from file
    int labelsLength = labels == null ? 0 : labels.length;

    // set labels for segments only when points have labels
    labelPointsAndSegments = A.isLabelSet() || B.isLabelSet() || labelsLength > 1;
    showNewSegmentsLabels = false;
    showNewPointsLabels = false;

    // temp center point of regular polygon
    centerPoint = (GeoPointND) newGeoPoint(c);
    rotAngle = new MyDouble(kernel);

    outputPolygon =
        new OutputHandler<GeoPolygon>(
            new elementFactory<GeoPolygon>() {
              public GeoPolygon newElement() {
                GeoPolygon p = newGeoPolygon(cons);
                p.setParentAlgorithm(AlgoPolygonRegularND.this);
                return p;
              }
            });

    outputSegments =
        new OutputHandler<GeoElement>(
            new elementFactory<GeoElement>() {
              public GeoElement newElement() {
                GeoElement segment =
                    (GeoElement) outputPolygon.getElement(0).createSegment(A, B, true);
                segment.setAuxiliaryObject(true);
                boolean segmentsVisible = false;
                int size = outputSegments.size();
                if (size > 0) { // check if at least one segment is
                  // visible
                  for (int i = 0; i < size && !segmentsVisible; i++) {
                    segmentsVisible =
                        segmentsVisible || outputSegments.getElement(i).isEuclidianVisible();
                  }
                } else { // no segment yet
                  segmentsVisible = true;
                }
                segment.setEuclidianVisible(segmentsVisible);
                segment.setLabelVisible(showNewSegmentsLabels);
                segment.setViewFlags(((GeoElement) A).getViewSet());
                segment.setVisibleInView3D((GeoElement) A);
                segment.setVisibleInViewForPlane((GeoElement) A);
                return segment;
              }
            });

    if (!labelPointsAndSegments) outputSegments.removeFromHandler(); // no segments has output

    outputPoints =
        new OutputHandler<GeoElement>(
            new elementFactory<GeoElement>() {
              public GeoElement newElement() {
                GeoElement newPoint = newGeoPoint(cons);
                newPoint.setParentAlgorithm(AlgoPolygonRegularND.this);
                newPoint.setAuxiliaryObject(true);
                ((GeoPointND) newPoint).setPointSize(A.getPointSize());
                newPoint.setEuclidianVisible(A.isEuclidianVisible() || B.isEuclidianVisible());
                newPoint.setAuxiliaryObject(true);
                newPoint.setLabelVisible(showNewPointsLabels);
                newPoint.setViewFlags(((GeoElement) A).getViewSet());
                newPoint.setVisibleInView3D((GeoElement) A);
                newPoint.setVisibleInViewForPlane((GeoElement) A);
                GeoBoolean conditionToShow = ((GeoElement) A).getShowObjectCondition();
                if (conditionToShow == null)
                  conditionToShow = ((GeoElement) B).getShowObjectCondition();
                if (conditionToShow != null) {
                  try {
                    newPoint.setShowObjectCondition(conditionToShow);
                  } catch (Exception e) {
                    // circular exception -- do nothing
                  }
                }
                return newPoint;
              }
            });

    if (!labelPointsAndSegments) outputPoints.removeFromHandler(); // no segments has output

    // create polygon
    outputPolygon.adjustOutputSize(1);

    // create 2 first segments
    outputSegments.augmentOutputSize(2, false);
    outputSegments.getElement(0).setAuxiliaryObject(false);
    ((GeoSegmentND) outputSegments.getElement(1)).modifyInputPoints(B, A);

    // for AlgoElement
    setInputOutput();

    GeoPolygon poly = getPoly();

    // set that the poly output can have different points length
    poly.setNotFixedPointsLength(true);

    // compute poly
    if (labelsLength > 1) {
      compute((labelsLength + 1) / 2); // create maybe undefined outputs
      poly.setLabel(labels[0]);
      int d = 1;
      for (int i = 0; i < outputSegments.size(); i++)
        outputSegments.getElement(i).setLabel(labels[d + i]);
      d += outputSegments.size();
      for (int i = 0; i < outputPoints.size(); i++)
        outputPoints.getElement(i).setLabel(labels[d + i]);
    } else if (labelsLength == 1) {
      poly.setLabel(labels[0]);
    } else {
      poly.setLabel(null);
    }

    labelsNeedIniting = false;

    update();

    /*
     * if (labelPointsAndSegments) { //poly.initLabels(labels); } else if
     * (labelsLength == 1) { poly.setLabel(labels[0]); } else {
     * poly.setLabel(null); }
     *
     *
     * labelsNeedIniting = false;
     */
    // make sure that we set all point and segment labels when needed
    // updateSegmentsAndPointsLabels(points.length);
  }
 /** @return resulting polygon */
 public final GeoPolygon getPoly() {
   return outputPolygon.getElement(0);
 }
Ejemplo n.º 10
0
 /** @return the polyhedron */
 public GeoPolyhedronNet getNet() {
   return outputNet.getElement(0);
 }
Ejemplo n.º 11
0
 @Override
 public GeoElement getOutput(int i) {
   if (index != null) return (GeoElement) oneVertex;
   return outputPoints.getElement(i);
 }