logoLightwave3D Expression Pluginlogo

Arithmetic expression evaluator for plugins.

Equation.p is an arithmetic expression evaluator which converts a string containing a valid mathematical equation into its floating point value. It is based on Eval113, a command-line-based expression evaluator which is Copyright (C) 1993 Will Menninger and has been put into public distribution under the GNU public license agreement. This derivative software is also covered by this license, I have made minor modifications to the source, and added several small glue modules to make this code into a Lightwave3D plug-in. The source is available.

Equation.p is a global-class plug-in module. This means that its functions are only available to other plug-ins, not to end users. To call Equation.p from a plug-in file, you must first get access to its functions by calling the global function with the name for the plug-in service, in this case "ExpressEval". If the plug-in is loaded in LW, the global function will return the address of an Evaluator structure, which has pointers to all the available functions. The definitions for this and other necessary structures are in the file lweval.h, which must be #included in your source.

The Evaluator structure has the following elements:

int MaxInput
This number is the length of the largest equation string the functions bellow will accept.
double StringValue(char *eq)
This function evaluates the given equation and returns its value.
double ValueXYZT(char *eq, double X, double Y, double Z, double T)
This function returns the value for the given equation after setting the internal variables 'x', 'y', 'z', and 't' to the input values in X,Y,Z and T. The equation may contain references to none, any, or all of the variables 'x', 'y', 'z', and 't'.
double Value(char *eq, int argc, ev_arg *argv)
This function returns the value for the given equation after setting internal variables listed in the input array of ev_arg structures (argv). The number of args in the array is specified in argc. The ev_arg structure is just a variable name (1 lowercase character), and a value for that variable:
      typedef struct { 

                char    *symbol;

                double  value;

        } ev_arg;

The following built-in functions are supported by the evaluator:

abs(x)                  absolute value                                            

acos(x)                 arccosine, return value in radians                        

acosh(x)                inverse hyperbolic cosine                                 

asin(x)                 arcsine, return value in radians                          

asinh(x)                inverse hyperbolic sine                                   

atan(x)                 arctangent, return value in radians                       

atan2(y,x)              arctangent of y/x, return value in radians                

atanh(x)                inverse hyperbolic tangent                                

bessi(m,x)              bessel function Im(x)                                     

bessj(m,x)              bessel function Jm(x)                                     

bessk(m,x)              bessel function Km(x)                                     

ceil(x)                 round up                                                  

cos(x)                  cosine, x in radians                                      

cosh(x)                 hyperbolic cosine                                         

dbessi(m,x)             derivative of bessel function:  Im'(x)                    

dbessj(m,x)             derivative of bessel function:  Jm'(x)                    

dbessk(m,x)             derivative of bessel function:  Km'(x)                    

djroot(m,n)             nth non-zero root of Jm'(x)                               

exp(x)                  e (2.718..) raised to the power of x                      

fact(n)                 factorial (n!)                                            

floor(x)                round down                                                

jroot(m,n)              nth non-zero root of Jm(x)                                

ln(x)                   natural logarithm (base e)                                

log(x)                  logarithm to the base 10                                  

sgn(x)                  -1 if x<0, 0 if x=0, +1 if x>0                            

sin(x)                  sine, x in radians                                        

sinh(x)                 hyperbolic sine                                           

sqrt(x)                 squareroot                                                

tan(x)                  tangent, x in radians                                     

tanh(x)                 hyperbolic tangent                                        

rand(x)                 random value between 0.0 and 1.0, int part of x is seed   

noise(x,y,z)            fractal noise

ifeq(a,b,t,f)           if a=b then t else f

iflt(a,b,t,f)           if a<b then t else f

ifgt(a,b,t,f)           if a>b then t else f

iflte(a,b,t,f)          if a<=b then t else f

ifgte(a,b,t,f)          if a>=b then t else f 

Here are the constants available (and their values):

_acres_per_sq_km                                247.1

_air_density                                    1.293

_air_mol_mass                                   .02897

_atm_per_psi                                    .06804

_avagadro                                       6.0220e23

_boltzmann                                      1.3807e-23

_c                                              2.997925e8

_cm_per_in                                      2.54

_coulomb_const                                  8.98755e9

_deg_per_rad                                    57.2958

_earth_esc_spd                                  1.12e4

_earth_grav                                     9.80665

_earth_mass                                     5.98e24

_earth_radius                                   6.37e6

_earth_to_moon                                  3.844e8

_earth_to_sun                                   1.496e11

_eps0                                           8.85419e-12

_erg_per_joule                                  1e7

_eulers_const                                   .57721566490153286061

_ft_per_m                                       3.280839895

_g                                              6.672e-11

_gas_const                                      8.314

_gauss_per_tesla                                1e4

_gm_per_oz                                      28.34952313

_golden_ratio                                   1.6180339887498948482

_h                                              6.6262e-34

_hbar                                           1.05459e-34

_joule_per_btu                                  1054.35

_joule_per_cal                                  4.184

_joule_per_ftlb                                 1.356

_joule_per_kwh                                  3.6e6

_kg_per_slug                                    14.59

_km_per_mi                                      1.609344

_knots_per_mph                                  .86897624

_lbs_per_kg                                     2.204622622

_lit_per_gal                                    3.785411784

_me                                             9.1095e-31

_mn                                             1.67495e-27

_moon_grav                                      1.62

_moon_mass                                      7.35e22

_moon_period                                    2360448.

_moon_radius                                    1.738e6

_mp                                             1.67265e-27

_mu0                                            1.256637e-6

_oz_per_gal                                     128.

_pasc_per_atm                                   101325.

_pasc_per_psi                                   6895.

_pasc_per_torr                                  133.32

_pi                                             3.14159265358979323846

_qe                                             1.60219e-19

_solar_const                                    1350.

_speed_sound                                    331.

_sun_mass                                       1.99e30

_sun_radius                                     6.96e8

_watts_per_hp                                   745.712

_zero_deg_cels                                  273.15



Get the Expression Plugin for: