private boolean setQuadric() {
    // check end points
    if (!((GeoElement) origin).isDefined()
        || origin.isInfinite()
        || !((GeoElement) secondPoint).isDefined()
        || secondPoint.isInfinite()
        || !radius.isDefined()) {
      getQuadric().setUndefined();
      return false;
    }

    Coords o = origin.getInhomCoordsInD3();
    Coords o2 = secondPoint.getInhomCoordsInD3();
    Coords d = o2.sub(o);

    if (d.equalsForKernel(0, Kernel.STANDARD_PRECISION)) {
      getQuadric().setUndefined();
      return false;
    }

    double r = radius.getDouble();

    d.calcNorm();
    double altitude = d.getNorm();

    quadric.setDefined();

    setQuadric(o, o2, d.mul(1 / altitude), r, 0, altitude);

    return true;
  }
Example #2
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();
    }
  }
  public void rotate(NumberValue r) {

    if (tmpMatrix4x4 == null) {
      tmpMatrix4x4 = new CoordMatrix4x4();
    }
    CoordMatrix4x4.Rotation4x4(r.getDouble(), tmpMatrix4x4);
    transform(tmpMatrix4x4);
  }
  public void rotate(NumberValue r, GeoPointND S) {

    if (tmpMatrix4x4 == null) {
      tmpMatrix4x4 = new CoordMatrix4x4();
    }
    CoordMatrix4x4.Rotation4x4(r.getDouble(), S.getInhomCoordsInD3(), tmpMatrix4x4);
    transform(tmpMatrix4x4);
  }
  private ExpressionNode randomCoef(boolean acceptZero) {

    double minD = min.getDouble();
    double maxD = max.getDouble();

    if (acceptZero
        // either both positive, both negative
        // or both zero (which shouldn't happen)
        // eg RandomPolynomial[3,0,0] returns undefined
        || Math.signum(maxD) == Math.signum(minD)) {
      return new ExpressionNode(
          kernel, kernel.getApplication().getRandomIntegerBetween(minD, maxD));
    }

    // logic doen't work unless minD < 0 < maxD
    int rnd = kernel.getApplication().getRandomIntegerBetween(minD, maxD - 1);
    return new ExpressionNode(kernel, rnd >= 0 ? rnd + 1 : rnd);
  }
  /** Computes points of regular polygon */
  @Override
  public final void compute() {

    // check points and number
    double nd = num.getDouble();

    if (Double.isNaN(nd)) nd = 2;

    compute((int) Math.round(nd));
  }
  public void rotate(NumberValue r, GeoPointND S, GeoDirectionND orientation) {

    if (tmpMatrix4x4 == null) {
      tmpMatrix4x4 = new CoordMatrix4x4();
    }
    CoordMatrix4x4.Rotation4x4(
        orientation.getDirectionInD3().normalized(),
        r.getDouble(),
        S.getInhomCoordsInD3(),
        tmpMatrix4x4);
    transform(tmpMatrix4x4);
  }
  public void rotate(NumberValue r, GeoLineND line) {

    if (tmpMatrix4x4 == null) {
      tmpMatrix4x4 = new CoordMatrix4x4();
    }

    CoordMatrix4x4.Rotation4x4(
        line.getDirectionInD3().normalized(),
        r.getDouble(),
        line.getStartInhomCoords(),
        tmpMatrix4x4);
    transform(tmpMatrix4x4);
  }
Example #9
0
  private void doTextFieldActionPerformed(JTextField source) {
    if (isUpdating) return;
    try {
      String inputText = source.getText().trim();
      NumberValue nv;
      nv = app.getKernel().getAlgebraProcessor().evaluateToNumeric(inputText, false);
      double value = nv.getDouble();

      // TODO better validation

      if (source == fldXMin) {
        settings.xMin = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldXMax) {
        settings.xMax = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldYMax) {
        settings.yMax = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldYMin) {
        settings.yMin = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldXInterval && value >= 0) {
        settings.xAxesInterval = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldYInterval && value >= 0) {
        settings.yAxesInterval = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldBarWidth && value >= 0) {
        settings.setBarWidth(value);
        firePropertyChange("settings", true, false);
      }
      updateGUI();

    } catch (NumberFormatException e) {
      e.printStackTrace();
    }
  }
  // calc tangent at x=a
  @Override
  public final void compute() {
    double a = n.getDouble();
    if (!f.isDefined() || !deriv.isDefined() || Double.isInfinite(a) || Double.isNaN(a)) {
      tangent.setUndefined();
      return;
    }

    // calc the tangent;
    double fa = f.evaluate(a);
    double slope = deriv.evaluate(a);
    tangent.setCoords(-slope, 1.0, a * slope - fa);
    T.setCoords(a, fa, 1.0);
  }
Example #11
0
  private void doTextFieldActionPerformed(JTextField source) {
    if (isIniting) return;

    if (source == fldInputX) {
      try {
        String inputText = source.getText().trim();
        if (inputText == null || inputText.length() == 0) return;

        NumberValue nv;
        nv = app.getKernel().getAlgebraProcessor().evaluateToNumeric(inputText, true);
        double value = nv.getDouble();
        double output =
            ((GeoFunctionable) statDialog.getRegressionModel()).getGeoFunction().evaluate(value);

        fldOutputY.setText(statDialog.format(output));

      } catch (NumberFormatException e) {
        e.printStackTrace();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
  /**
   * @param cons construction
   * @param label label for output
   * @param n function parameter
   * @param f function
   */
  public AlgoTangentFunctionNumber(Construction cons, String label, NumberValue n, GeoFunction f) {
    super(cons);
    this.n = n;
    ngeo = n.toGeoElement();
    this.f = f;

    tangent = new GeoLine(cons);
    T = new GeoPoint(cons);
    tangent.setStartPoint(T);

    // derivative of f
    // now uses special non-CAS version of algo
    algo = new AlgoDerivative(cons, f, true);
    deriv = (GeoFunction) algo.getResult();
    cons.removeFromConstructionList(algo);

    setInputOutput(); // for AlgoElement
    compute();
    tangent.setLabel(label);
  }
 @Override
 public void compute() {
   // cover undefined cases
   if (!degree.isDefined() || !min.isDefined() || !max.isDefined() || degree.getDouble() < 0) {
     polynomial.setUndefined();
     return;
   }
   int lower = (int) Math.ceil(min.getDouble());
   int upper = (int) Math.floor(max.getDouble());
   if (lower > upper || (lower == 0 && upper == 0)) {
     polynomial.setUndefined();
     return;
   }
   // input is sane, we can do the computation
   int deg = (int) Math.floor(degree.getDouble());
   ExpressionNode varExpr = new ExpressionNode(kernel, fv);
   ExpressionNode newExpr = randomCoef(deg != 0);
   for (int i = 1; i <= deg; i++) {
     newExpr = varExpr.power(new MyDouble(kernel, i)).multiply(randomCoef(i != deg)).plus(newExpr);
   }
   f.setExpression(newExpr, fv);
   polynomial.setFunction(f);
 }
 @Override
 protected void setInputOutput() {
   setOnlyOutput(polynomial);
   input = new GeoElement[] {degree.toGeoElement(), min.toGeoElement(), max.toGeoElement()};
   setDependencies();
 }