A92: Trig Lib


[Prev][Next][Index][Thread]

A92: Trig Lib




A full blown, fast and compact trig library can be developed on the basis of an
algorithm that I devised, requring a table of values in the range of only [0, pi/2]

Let sin(x) be the operation of "looking up" in a table of values
Assume positive angles
if theta > 2pi a=theta mod 2pi
if theta < 2pi a = theta
if 0 =< a =< pi/2  return sin(a)
if pi/2 < a =< pi  return sin(pi-a)
if pi < a =< 3pi/2 return -sin(a-pi)
if 3pi/2 < a =< 2pi return -sin(3pi/2-a)

Thus only the interval [0, pi/2] is really needed.
At an increment of .01, that is less than 160 entries.
If every entry is one byte, and it is agreed that sin(pi/2)=.999, then the eight
bits guarantee three-digit (decimal) accuracy (11100111 would correspond to .999).
This precision is entirely adequate for any application that I can concieve of,
especially given the resolution of LCD.  The sign can be represented with a bit in
the system register, or anywhere else.
The following identities can then be taken advantage of:
cos(x) = sin(pi/2 -x)
sin(-x) = -sin(x)

So, would anyone be intrested in writing such a lib? It's size can probably be kept
under 300 bytes, and, if properly coded, it should be rather fast.




Follow-Ups: References: