Advanced RMS: Part 7 – Math Functions

By Matei of Woad Creations
created 9/10/03

In the same way that the RMS system doesn’t support arrays, it doesn’t support trigonometry functions such as sin, cos, tan,\046nbsp;and other math functions like log. Sometimes you want to be able to use these – for example, you might like to use trigonometry to place players in some sort of circle or ellipse, place things to the left of each player, etc. Luckily, you can use a function with hardcoded values to create a pretty good approximation function for any math function, as long as it’s defined on a finite interval. The way you do this is by evaluating the function at, say, 20 numbers, and interpolating in between those. For example, if sin 50 = 0.76 and sin 60 = 0.87, a good approximation for sin 58 = (2/10)*0.76 + (8/10)*0.87, or 0.848 (and in fact, sin 58 is within 0.01 of that). It’s not perfect, but when you get 30 or 40 points on a small interval to interpolate between and you have no weird breaks in your function it works quite well. Here’s a form I created that lets you type in a function name (in only one variable, which we’ll call x) and an expression (any valid JavaScript style\046nbsp;expression, such as sin(x), x*x – ln(x), etc will work – just type a function name, and it will probably be fine; note that trig functions are in radians, where PI radians = 180 degrees; if you know JavaScript, note that you don’t have to write Math.sin, Math.cos, etc – just write sin, cos, etc):

Create a function called(x) with domain to and value equal to, using
points on the interval.

Just copy and paste the code generated to the top of your script, and you’ll be ready to go :).

Back to the RMS Section