Advertisement

Sine and Cosine

Started by February 14, 2000 12:10 PM
4 comments, last by Ranok 25 years ago
Does anybody know how a computer calculates sine and cosine. I beleive that it could use an infinite series which could then be approximated using a Taylor Polynomial. If this is the method used, would it not be possible to write your own sine and cosine function that could sacrifice accuracy for speed (or vice versa)?
---Ranok---
It depends what you need them for. If you are only using, say 16 angles out of 360, you could use a lookup table and avoid calculations all together.

I believe you are correct in assuming it uses the taylor series for calculations of sine and cosine. And yes, you could sacrifice accuracy.

Six
Advertisement
What might be even faster is implement look up tables for a good range of angles for sine and cosine and interpolate values in between the known values. You can trade off granularity of the table and the complexity of interpolation for space and time taken vs. accuracy.
As for the LUT, do you prefer to use two tables, one for sine and one for cosine, or do you prefer to just use one LUT and then equate them using the identity cosine = sine(theta + pi/2). I am just asking because it seems as if everyone prefers to use two tables, but I believe that the second way is a better option, use save memory and the simple addition operation is nothing to worry about on todays machines. Does anybody else have an opinion on this.
---Ranok---
The last time I implemented lookup tables for sin and cos, I used one array, but indexed into it in different positions for the sin and cos. It was calculated by iterating cos from 0 to 449. The cos pointer pointed at the 0 index, the sin pointer pointed at the 90 index. This way I didn''t have to do any additions to handle the indexing into the same table for sins and cosines and it was only 25% larger.
In case your interested, thats the way I do it as well.

--== Rapier ==--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Save the whales, feed the hungry, free the mallocs!
--== Rapier ==--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Save the whales, feed the hungry, free the mallocs!

This topic is closed to new replies.

Advertisement