Ejemplo n.º 1
0
 protected GeoElement[] processImplicitPoly(Equation equ) {
   GeoElement[] ret = new GeoElement[1];
   String label = equ.getLabel();
   Polynomial lhs = equ.getNormalForm();
   boolean isIndependent = !equ.isFunctionDependent() && lhs.isConstant();
   GeoImplicitPoly poly;
   GeoElement geo = null;
   if (isIndependent) {
     poly = kernel.ImplicitPoly(label, lhs);
     poly.setUserInput(equ);
     geo = poly;
   } else {
     geo = kernel.DependentImplicitPoly(label, equ); // might also return Line or Conic
     if (geo instanceof GeoUserInputElement) {
       ((GeoUserInputElement) geo).setUserInput(equ);
     }
   }
   ret[0] = geo;
   //		Application.debug("User Input: "+equ);
   ret[0].updateRepaint();
   return ret;
 }
Ejemplo n.º 2
0
  public GeoElement[] processEquation(Equation equ) throws MyError {
    //		Application.debug("EQUATION: " + equ);
    //		Application.debug("NORMALFORM POLYNOMIAL: " + equ.getNormalForm());

    try {
      equ.initEquation();
      // Application.debug("EQUATION: " + equ.getNormalForm());
      // check no terms in z
      checkNoTermsInZ(equ);

      if (equ.isFunctionDependent()) {
        return processImplicitPoly(equ);
      }

      // consider algebraic degree of equation
      // check not equation of eg plane
      switch (equ.degree()) {
          // linear equation -> LINE
        case 1:
          return processLine(equ, false);

          // quadratic equation -> CONIC
        case 2:
          return processConic(equ);

        default:
          // test for "y= <rhs>" here as well
          if (equ.getLHS().toString().trim().equals("y")) {
            Function fun = new Function(equ.getRHS());
            // try to use label of equation
            fun.setLabel(equ.getLabel());
            return processFunction(null, fun);
          }
          return processImplicitPoly(equ);
      }
    } catch (MyError eqnError) {
      eqnError.printStackTrace();

      // invalid equation: maybe a function of form "y = <rhs>"?
      String lhsStr = equ.getLHS().toString().trim();
      if (lhsStr.equals("y")) {
        try {
          // try to create function from right hand side
          Function fun = new Function(equ.getRHS());

          // try to use label of equation
          fun.setLabel(equ.getLabel());
          return processFunction(null, fun);
        } catch (MyError funError) {
          funError.printStackTrace();
        }
      }

      // throw invalid equation error if we get here
      if (eqnError.getMessage() == "InvalidEquation") throw eqnError;
      else {
        String[] errors = {"InvalidEquation", eqnError.getLocalizedMessage()};
        throw new MyError(app, errors);
      }
    }
  }