Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Member Functions | Package Attributes | Static Package Attributes
rene.zirkel.expression.FunctionExpression Class Reference

function = sin(parameter) etc. More...

Inheritance diagram for rene.zirkel.expression.FunctionExpression:
Inheritance graph
[legend]
Collaboration diagram for rene.zirkel.expression.FunctionExpression:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FunctionExpression (int f, BasicExpression e)
 FunctionExpression (int f, BasicExpression e, BasicExpression ee)
 FunctionExpression (int f, BasicExpression e, BasicExpression ee, BasicExpression eee)
double getValue () throws ConstructionException
PointObject getPoint (int n) throws ConstructionException
void translate ()
void reset ()
String toString ()
boolean isNumber ()
boolean isLogical ()

Static Public Member Functions

static BasicExpression scan (ExpressionText t, String name) throws ConstructionException
static BasicExpression scan (ExpressionText t) throws ConstructionException
static BasicExpression scan (ExpressionText t, int sign) throws ConstructionException
static BasicExpression scanBracket (ExpressionText t) throws ConstructionException

Package Attributes

int F
BasicExpression E []
int NParams

Static Package Attributes

static final String Functions []
static final int NX = 10
static final int NY = 11
static final int ND = 14
static final int NA = 15
static final int NS = 19
static final int NSUM = 22
static final int NIF = 23
static final int NINT = 26
static final int NZERO = 27
static final int NDIFF = 28
static final int NMIN = 29
static final int NMAX = 30
static final int NLENGTH = 31
static final int NZ = 40
static final int NSIM = 41
static final int NINSIDE = 42
static final int MINUS = -1
static final int PLUS = 1

Detailed Description

function = sin(parameter) etc.

function = x(point) function = y(point)

Definition at line 534 of file Expression.java.


Constructor & Destructor Documentation

Definition at line 539 of file Expression.java.

       {      F=f; 
              E=new BasicExpression[1]; 
              E[0]=e; NParams=1;
       }

Here is the caller graph for this function:

Definition at line 545 of file Expression.java.

       {      F=f; 
              E=new BasicExpression[2]; 
              E[0]=e; E[1]=ee; 
              NParams=2;
       }

Definition at line 552 of file Expression.java.

       {      F=f; 
              E=new BasicExpression[3]; 
              E[0]=e; E[1]=ee; E[2]=eee; 
              NParams=3;
       }

Member Function Documentation

Definition at line 966 of file Expression.java.

       {      PointObject p;
              try
              {      p=(PointObject)((ObjectExpression)E[n]).getObject();
              }
              catch (Exception e)
              {      throw new ConstructionException("exception.notfound");
              }
              if (!p.valid()) throw new ConstructionException("exception.invalid");
              return p;
       }

Here is the caller graph for this function:

Reimplemented from rene.zirkel.expression.BasicExpression.

Reimplemented in rene.zirkel.expression.IfExpression, rene.zirkel.expression.CumSumExpression, and rene.zirkel.expression.DExpression.

Definition at line 819 of file Expression.java.

       {      PointObject P,PP,PPP;
              switch (F)
              {      case NX : 
                            P=getPoint(0);
                            if (!P.valid())
                                   throw new InvalidException(Zirkel.name("exception.invalid"));
                            return ((PointObject)P).getX();
                     case NY :
                            P=getPoint(0);
                            if (!P.valid())
                                   throw new InvalidException(Zirkel.name("exception.invalid"));
                            return P.getY();
                     case NZ :
                            P=getPoint(0);
                            if (!P.valid())
                                   throw new InvalidException(Zirkel.name("exception.invalid"));
                            return P.getZ();
                     case ND :
                            P=getPoint(0); PP=getPoint(1);
                            if (!P.valid() || !PP.valid())
                                   throw new InvalidException(Zirkel.name("exception.invalid"));
                            double dx=P.getX()-PP.getX();
                            double dy=P.getY()-PP.getY();
                            return Math.sqrt(dx*dx+dy*dy);
                     case NA :
                            P=getPoint(0); PP=getPoint(1); PPP=getPoint(2);
                            if (!P.valid() || !PP.valid() || !PPP.valid())
                                   throw new InvalidException(Zirkel.name("exception.invalid"));
                            dx=P.getX()-PP.getX();
                            dy=P.getY()-PP.getY();
                            double dx1=PPP.getX()-PP.getX();
                            double dy1=PPP.getY()-PP.getY();
                            double a=Math.atan2(dx,dy)-Math.atan2(dx1,dy1);
                            a=a/Math.PI*180;
                            if (a<0) a+=360;
                            if (a>360) a-=360;
                            return a;
                     case NS :
                            double x=E[0].getValue(),xa=E[1].getValue(),xb=E[2].getValue();
                            if (x<xa || x>=xb || xb<=xa)
                                   throw new InvalidException(Zirkel.name("exception.invalid"));
                            return (x-xa)/(xb-xa);
                     case NINT :
                            if (((ObjectExpression)E[0]).getObject() instanceof FunctionObject)
                            {      FunctionObject F=(FunctionObject)(((ObjectExpression)E[0]).getObject());
                                   if (E.length>1)
                                   {      double aa=E[1].getValue(),bb=E[2].getValue();
                                          return Romberg.compute(F,aa,bb,10,1e-10,10);
                                   }
                                   else
                                   {      return F.getIntegral();
                                   }
                            }
                            else
                            {      TrackObject TO=(TrackObject)(((ObjectExpression)E[0]).getObject());
                                   if (E.length>1)
                                   {      double aa=E[1].getValue(),bb=E[2].getValue();
                                          return TO.getSum(aa,bb);
                                   }
                                   else return TO.getSum();
                            }                                  
                     case NLENGTH :
                            if (((ObjectExpression)E[0]).getObject() instanceof FunctionObject)
                            {      FunctionObject F=(FunctionObject)(((ObjectExpression)E[0]).getObject());
                                   return F.getLength();
                            }
                            else
                            {      TrackObject TO=(TrackObject)(((ObjectExpression)E[0]).getObject());
                                   return TO.getLength();
                            }      
                     case NZERO :
                            FunctionObject F=(FunctionObject)(((ObjectExpression)E[0]).getObject());
                            double aa=E[1].getValue(),bb=E[2].getValue();
                            return Secant.compute(F,aa,bb,1e-10);
                     case NDIFF :
                            F=(FunctionObject)(((ObjectExpression)E[0]).getObject());
                            aa=E[1].getValue();
                            return 
                                   (F.evaluateF(aa+1e-3)-F.evaluateF(aa-1e-3))/2e-3;       
                     case NMIN :
                            if (NParams==2)
                            {      return Math.min(E[0].getValue(),E[1].getValue());
                            }
                            else
                            {      F=(FunctionObject)(((ObjectExpression)E[0]).getObject());
                                   aa=E[1].getValue(); bb=E[2].getValue();
                                   return ConvexMin.computeMin(F,aa,bb,1e-10);
                            }
                     case NMAX :
                            if (NParams==2)
                            {      return Math.max(E[0].getValue(),E[1].getValue());
                            }
                            else
                            {      F=(FunctionObject)(((ObjectExpression)E[0]).getObject());
                                   aa=E[1].getValue(); bb=E[2].getValue();
                                   return ConvexMin.computeMax(F,aa,bb,1e-10);
                            }
                     case NINSIDE :
                            P=getPoint(0);
                            InsideObject IO=(InsideObject)(((ObjectExpression)E[1]).getObject());
                            return IO.containsInside(P);
              }
              double x=E[0].getValue();
              switch (F)
              {      case 0 : return Math.sin(x/180*Math.PI);
                     case 1 : return Math.cos(x/180*Math.PI);
                     case 2 : return Math.tan(x/180*Math.PI);
                     case 3 : return Math.asin(x)/Math.PI*180;
                     case 4 : return Math.acos(x)/Math.PI*180;
                     case 5 : return Math.atan(x)/Math.PI*180;
                     case 6 : return Math.sqrt(x);
                     case 7 : return Math.exp(x);
                     case 8 : return Math.log(x);
                     case 9 : return Math.round(x);
                     case 12 : return Math.floor(x);
                     case 13 : return Math.ceil(x);
                     case 16 :
                            x=x/360;
                            x-=Math.floor(x);
                            x=x*360;
                            if (x<180) return x;
                            else return (x-360);
                     case 17 :
                            x/=360;
                            x-=Math.floor(x);
                            return x*360;
                     case 18 :
                            return Math.abs(x);
                     case 20 :
                            if (x>0) return 1;
                            else if (x==0) return 0;
                            else return -1;
                     case 24 : return (x/Math.PI*180);
                     case 25 : return (x/180*Math.PI);
                     case 32 : return Math.sin(x);
                     case 33 : return Math.cos(x);
                     case 34 : return Math.tan(x);
                     case 35 : return Math.asin(x);
                     case 36 : return Math.acos(x);
                     case 37 : return Math.atan(x);
                     case 38 : return (Math.exp(x)-Math.exp(-x))/2;
                     case 39 : return (Math.exp(x)+Math.exp(-x))/2;
              }
              throw new ConstructionException("");
       }

Here is the call graph for this function:

Reimplemented in rene.zirkel.expression.OrExpression, rene.zirkel.expression.AndExpression, rene.zirkel.expression.NotExpression, and rene.zirkel.expression.CompareExpression.

Definition at line 143 of file Expression.java.

       {      return false;
       }

Here is the caller graph for this function:

Reimplemented in rene.zirkel.expression.MinusExpression, rene.zirkel.expression.ElementaryExpression, rene.zirkel.expression.BracketExpression, and rene.zirkel.expression.DoubleExpression.

Definition at line 135 of file Expression.java.

       {      return false;
       }

Here is the caller graph for this function:

Reimplemented from rene.zirkel.expression.BasicExpression.

Reimplemented in rene.zirkel.expression.CumSumExpression, and rene.zirkel.expression.DExpression.

Definition at line 984 of file Expression.java.

       {      for (int i=0; i<NParams; i++)
                     E[i].reset();
       }
static BasicExpression rene.zirkel.expression.BasicExpression.scan ( ExpressionText  t,
int  sign 
) throws ConstructionException [inline, static, inherited]

Definition at line 107 of file Expression.java.

       {      if (sign==MINUS)
              {      if (t.next()=='(') return new MinusExpression(scanBracket(t));
                     return new MinusExpression(ElementaryExpression.scan(t));
              }
              if (t.next()=='(') return scanBracket(t);
              return ElementaryExpression.scan(t);
       }

Here is the call graph for this function:

Definition at line 572 of file Expression.java.

       {      int f=-1;
              for (int i=0; i<Functions.length; i++)
              {      if (name.equals(Functions[i])) { f=i; break; }
              }
              if (f<0)
              {      boolean forward=false;
                     ConstructionObject o=t.getConstruction().find(name,t.getObject());
                     if (o==null)
                     {      o=t.getConstruction().find(name);
                            forward=true;
                     }
                     if (o!=null && (o instanceof FunctionObject || o instanceof UserFunctionObject) && !(o==t.getObject())
                                   && !t.getConstruction().dependsOn(o,t.getObject()))
                     {      if (t.next()!='(')
                                   throw new ConstructionException(Zirkel.name("exception.parameter"));
                            t.advance();
                            MyVector ex=new MyVector();
                            while (true)
                            {      BasicExpression e=TopExpression.scan(t);
                                   ex.addElement(e);
                                   if (t.next()==')') break;
                                   if (t.next()!=',')
                                          throw new ConstructionException(Zirkel.name("exception.parameter"));
                                   t.advance();
                            }
                            t.advance();
                            t.getDepList().add(o);
                            if (forward) t.getConstruction().needsOrdering();
                            BasicExpression exp[]=new BasicExpression[ex.size()];
                            ex.copyInto(exp);
                            return new UserFunctionExpression(o,exp);
                     }
                     throw new ConstructionException(Zirkel.name("exception.function")
                            +" ("+name+")");
              }
              if (t.next()!='(')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
              t.advance();
              BasicExpression e=TopExpression.scan(t);
              if (f==NX || f==NY || f==NZ)
              {      if (e instanceof FindObjectExpression)
                            e=new FunctionExpression(f,e);
                     else if (e instanceof ObjectExpression &&
                            ((ObjectExpression)e).getObject() instanceof PointObject)
                            e=new FunctionExpression(f,e);
                     else
                            throw new ConstructionException(Zirkel.name("exception.parameter")
                                   +" ("+Functions[f]+")");           
              }
              else if (f==ND)
              {      if (t.next()!=',')
                     {      e=new DExpression(e);
                     }
                     else
                     {      t.advance();
                            BasicExpression ee=TopExpression.scan(t);
                            if (
                                   ((e instanceof ObjectExpression &&
                                          ((ObjectExpression)e).getObject() instanceof PointObject)
                                   || e instanceof FindObjectExpression)
                                    && 
                                    ((ee instanceof ObjectExpression &&
                                          ((ObjectExpression)ee).getObject() instanceof PointObject)
                                   || ee instanceof FindObjectExpression)
                                   )
                                   e=new FunctionExpression(f,e,ee);
                            else
                                   throw new ConstructionException(Zirkel.name("exception.parameter")
                                          +" ("+Functions[f]+")");
                     }
              }
              else if (f==NA)
              {      if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression ee=TopExpression.scan(t);
                     if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression eee=TopExpression.scan(t);
                     if (
                            ((e instanceof ObjectExpression &&
                                   ((ObjectExpression)e).getObject() instanceof PointObject)
                            || e instanceof FindObjectExpression)
                             && 
                             ((ee instanceof ObjectExpression &&
                                   ((ObjectExpression)ee).getObject() instanceof PointObject)
                            || ee instanceof FindObjectExpression)
                             && 
                            ((eee instanceof ObjectExpression &&
                                   ((ObjectExpression)eee).getObject() instanceof PointObject)
                            || eee instanceof FindObjectExpression)
                            )
                                   e=new FunctionExpression(f,e,ee,eee);
                     else
                            throw new ConstructionException(Zirkel.name("exception.parameter")
                                   +" ("+Functions[f]+")");           
                     
              }
              else if (f==NS)
              {      if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression ee=TopExpression.scan(t);
                     if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression eee=TopExpression.scan(t);
                     e=new FunctionExpression(f,e,ee,eee);                   
              }
              else if (f==NSUM)
              {      if (t.next()!=',')
                     {      e=new CumSumExpression(e);
                     }
                     else
                     {      t.advance();
                            BasicExpression ee=TopExpression.scan(t);
                            e=new CumSumExpression(e,ee);
                     }
              }
              else if (f==NIF)
              {      if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression ee=TopExpression.scan(t);
                     if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression eee=TopExpression.scan(t);
                     e=new IfExpression(e,ee,eee);
              }
              else if (f==NINT || f==NZERO || f==NMIN || f==NMAX || f==NLENGTH)
              {      if (!(e instanceof ObjectExpression))
                     {      if (f==NMAX || f==NMIN)
                            {      if (t.next()!=',')
                                          throw new ConstructionException(Zirkel.name("exception.parameter"));
                                   t.advance();
                                   BasicExpression ee=TopExpression.scan(t);
                                   e=new FunctionExpression(f,e,ee);
                            }
                            else
                                   throw new ConstructionException(Zirkel.name("exception.parameter")
                                                 +" ("+Functions[f]+")");                         
                     }
                     else
                     {      boolean function=((ObjectExpression)e).getObject() instanceof FunctionObject
                                   || ((ObjectExpression)e).getObject() instanceof TrackObject;
                            if ((f==NINT || f==NLENGTH) && t.next()==')')
                            {      if (!function)
                                                 throw new ConstructionException(Zirkel.name("exception.parameter")
                                                               +" ("+Functions[f]+")");                         
                                   e=new FunctionExpression(f,e);
                            }
                            else if (f==NLENGTH)
                            {      throw new ConstructionException(Zirkel.name("exception.parameter"));
                            }
                            else
                            {      if (t.next()!=',')
                                          throw new ConstructionException(Zirkel.name("exception.parameter"));
                                   t.advance();
                                   BasicExpression ee=TopExpression.scan(t);
                                   if (function)
                                   {      if (t.next()!=',')
                                                 throw new ConstructionException(Zirkel.name("exception.parameter"));
                                          t.advance();
                                          BasicExpression eee=TopExpression.scan(t);
                                          e=new FunctionExpression(f,e,ee,eee);
                                   }
                                   else if (f==NMIN || f==NMAX)
                                   {      e=new FunctionExpression(f,e,ee);
                                   }
                                   else
                                          throw new ConstructionException(Zirkel.name("exception.parameter")
                                                        +" ("+Functions[f]+")");                                
                            }
                     }
              }
              else if (f==NDIFF)
              {      if (!(e instanceof ObjectExpression) ||
                            !(((ObjectExpression)e).getObject() instanceof FunctionObject))
                                   throw new ConstructionException(Zirkel.name("exception.parameter")
                                                 +" ("+Functions[f]+")");
                     if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression ee=TopExpression.scan(t);
                     e=new FunctionExpression(f,e,ee);
              }
              else if (f==NSIM)
              {      if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression ee=TopExpression.scan(t);
                     if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression eee=TopExpression.scan(t);
                     if (
                            (e instanceof ObjectExpression &&
                                   ((ObjectExpression)e).getObject() instanceof SimulationObject)
                            ||
                            !(eee instanceof ObjectExpression)
                            )
                     {      ConstructionObject SO=((ObjectExpression)e).getObject();
                            if (t.getConstruction().dependsOn(SO,t.getObject()))
                                   throw new ConstructionException(Zirkel.name("exception.parameter")
                                                 +" ("+Functions[f]+")");           
                            e=new SimulationExpression(
                                   ((ObjectExpression)e).getObject(),t.getObject(),ee,
                                   ((ObjectExpression)eee).getObject());
                     }
                     else 
                            throw new ConstructionException(Zirkel.name("exception.parameter")
                                          +" ("+Functions[f]+")");           
                     
              }
              else if (f==NINSIDE)
              {      if (t.next()!=',')
                            throw new ConstructionException(Zirkel.name("exception.parameter"));
                     t.advance();
                     BasicExpression ee=TopExpression.scan(t);
                     if (
                            ((e instanceof ObjectExpression &&
                                   ((ObjectExpression)e).getObject() instanceof PointObject)
                            || e instanceof FindObjectExpression)
                             && 
                             ((ee instanceof ObjectExpression &&
                                   ((ObjectExpression)ee).getObject() instanceof InsideObject)
                            || ee instanceof FindObjectExpression)
                            )
                            e=new FunctionExpression(f,e,ee);
                     else
                            throw new ConstructionException(Zirkel.name("exception.parameter")
                                   +" ("+Functions[f]+")");
              }
              else
              {      e=new FunctionExpression(f,e);
              }
              if (t.next()!=')')
                     throw new ConstructionException(Zirkel.name("exception.parameter"));
              t.advance();
              return e;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 118 of file Expression.java.

       {      t.advance();
              BasicExpression E=TopExpression.scan(t);
              if (t.next()==')') t.advance();
              else
                     throw new ConstructionException(Zirkel.name("exception.bracket"));
              return E;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 989 of file Expression.java.

       {      String s=Functions[F]+"(";
              for (int i=0; i<NParams; i++)
              {      if (i>0) s=s+",";
                     s=s+E[i];
              }
              return s+")";
       }

Reimplemented from rene.zirkel.expression.BasicExpression.

Definition at line 979 of file Expression.java.

       {      for (int i=0; i<NParams; i++)
                     E[i].translate();
       }

Member Data Documentation

Reimplemented from rene.zirkel.expression.BasicExpression.

Definition at line 536 of file Expression.java.

Definition at line 535 of file Expression.java.

final String rene.zirkel.expression.FunctionExpression.Functions[] [static, package]
Initial value:
              {      "sin","cos","tan","arcsin","arccos","arctan",
                     "sqrt","exp","log","round","x","y","floor","ceil",
                     "d","a","angle180","angle360","abs","scale","sign","d","sum",
                     "if","deg","rad","integrate","zero","diff","min","max","length",
                     "rsin","rcos","rtan","rarcsin","rarccos","rarctan",
                     "sinhyp","coshyp","z","simulate","inside"
              }

Definition at line 560 of file Expression.java.

final int rene.zirkel.expression.BasicExpression.MINUS = -1 [static, package, inherited]

Definition at line 91 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NA = 15 [static, package]

Definition at line 568 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.ND = 14 [static, package]

Definition at line 568 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NDIFF = 28 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NIF = 23 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NINSIDE = 42 [static, package]

Definition at line 570 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NINT = 26 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NLENGTH = 31 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NMAX = 30 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NMIN = 29 [static, package]

Definition at line 569 of file Expression.java.

Definition at line 537 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NS = 19 [static, package]

Definition at line 568 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NSIM = 41 [static, package]

Definition at line 570 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NSUM = 22 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NX = 10 [static, package]

Definition at line 568 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NY = 11 [static, package]

Definition at line 568 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NZ = 40 [static, package]

Definition at line 570 of file Expression.java.

final int rene.zirkel.expression.FunctionExpression.NZERO = 27 [static, package]

Definition at line 569 of file Expression.java.

final int rene.zirkel.expression.BasicExpression.PLUS = 1 [static, package, inherited]

Definition at line 91 of file Expression.java.


The documentation for this class was generated from the following file: