I would like to modify FB^3's trig functions to work with degrees
automatically, rather than radian measurements for angles. I think
OVERRIDE is the way to go but have not found a workable routine yet.
Any help with this small sample for the sine function would be
appreciated. It's a start, to be compiled in CONSOLE mode and for
cpuPPC. I need help with the OVERRIDE section which doesn't seem to
have any effect.
OVERRIDE RUNTIME SIN( degrees AS DOUBLE )
DIM AS DOUBLE radians, result
LET radians = degrees / 180.0 * PI
LET result = SIN( radians )
END FN = result
DIM AS DOUBLE sineValue, angle
DIM h,v ' horz & vert position of plotted points
PLOT 400,400 ' force size of graphics window
PLOT 0,200 TO 400,200 ' draw horz. axis
PEN 2,2
COLOR _zRed
FOR angle = 0 TO 360 STEP 15
LET sineValue = SIN( angle )
PRINT USING "### "; angle ;
PRINT USING "##.### ###"; sineValue
LET h = angle
LET v = 200 - sineValue * 100
CIRCLE h,v, 2 ' show a small point (or PLOT h,v )
NEXT angle
Ideally, this would print a table of every 15 degrees and their sine
values as well as plot a set of red points for the function.
Unfortunately, the result is the same as without my attempt to
override the SIN routine.
I did not find a definition for function SIN( x AS DOUBLE ) in the
headers, just for RUNTIME "_SIN" which had assembler code in it.
BTW - I'd like to do this for use by students in high school that are
learning some programming ideas and investigating
geometry/trigonometry but without any knowledge of radians - just
degrees. Once I learn how to override the routines, the new versions
can be placed in an INCLUDE file so the students don't see the inner
workings. Plan B would be to create an alternate set of functions
with similar names, for example FN SINE( x ) but then the 'FN' syntax
and names would not be the same as that used in their texts.
Ideally, I'd really like to see a global variable or constant in FB
that would indicate whether trig uses degrees or radians, like many
calculators do. (ex. gFBtrigOption = _fbUseDegrees or gFBtrigOption
= _fbUseRadians) But that's another story for the future.
Thanks in advance for any help.
- Stu Cram
Regina, Sask. CANADA