コード例 #1
0
 public void mousePressed(MouseEvent me) {
   POINT = me.getPoint();
   double xa = POINT.x - w / 2 - (a - originX) * scale;
   F.addVariable("x", a);
   double ya = POINT.y - h / 2 + (F.getValue() - originY) * scale;
   if (xa * xa + ya * ya < rr) {
     newA = true;
   }
   requestFocus();
 }
コード例 #2
0
 public void drawEndpoints(Graphics2D g) {
   F.addVariable("x", a);
   drawPoint(g, a, F.getValue(), Color.red, overA);
   try {
     drawPoint(
         g,
         a,
         Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString()),
         Color.red,
         false);
   } catch (ParseException e) {
   } catch (Exception e) {
   }
 }
コード例 #3
0
  public DerivativeAltGraph(CalculusApplet applet, String f, String g, double a) {
    super();

    this.applet = applet;
    this.a = a;
    this.b = a;
    this.c = a;

    F.parseExpression(f);
    G.parseExpression(g);
  }
コード例 #4
0
  public void draw(Graphics2D g) {
    F.addVariable("x", a);
    double fa = F.getValue();

    // draw tangent line
    double m;
    double[] P = toCartesianPoint(0, 0);
    double[] Q = toCartesianPoint(w, 0);
    g.setStroke(new BasicStroke(3.0f));
    try {
      m = Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString());
      drawLine(g, P[0], fa + m * (P[0] - a), Q[0], fa + m * (Q[0] - a), Color.gray);
      applet.setStat("Slope \u2248 ", m, Color.red);
    } catch (ParseException e) {
    } catch (Exception e) {
    }

    // draw derivative from b to c
    try {
      double start = w / 2 + (b - originX) * scale;
      double stop = w / 2 + (c - originX) * scale;
      GeneralPath path = new GeneralPath();
      F.addVariable(variable, b);
      double y = Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString());
      path.moveTo(start, (float) (h / 2 - (y - originY) * scale));
      while (start < stop) {
        F.addVariable(variable, (start - w / 2) / scale + originX);
        y = Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString());
        path.lineTo(start, (float) (h / 2 - (y - originY) * scale));
        start++;
      }
      g.setColor(Color.red);
      g.setStroke(curve);
      g.draw(path);
    } catch (ParseException e) {
    } catch (Exception e) {
    }
  }