# How can I solve trigonometric functions without a calculator?

I am basically looking for formulae that calculate trigonometric functions (both geometric and circular), because I want to write my own math functions for my game engine. I have found some that seem to use imaginary numbers, but I don't know how to represent those in c++.

-
std::complex<double>. Are you sure you don't want to use the standard library functions for computing trig functions? – Hurkyl Mar 6 '13 at 1:38
Yes, I want to learn more about math and I think adding my own math functions is a good way to do that. Also it seems like fun to be able to do that. – Friso1990 Mar 6 '13 at 1:40
It is fun and interesting, but library functions or a precomputed table are the way to go. – Ross Millikan Mar 6 '13 at 1:43
I think this an important exercise. You must look "inside out" as well as "outside in" of programming concepts. – ncmathsadist Mar 6 '13 at 2:23

## 2 Answers

If you can compute sin and cos, you will get the rest. If $x$ is a real number you can find a real number $y\in[0,\pi/4]$ so that $y = \pm(\hbox{sin or cos})(x)$. In this interval the Taylor series for sine or cosine converge very fast. Now compute that and use the remainder theorem.

-
Taylor series are usually not a very good approach. They are very accurate near one point, and get progressively worse as you move away. Chebyshev expansions are much better. To see how the professionals do this sort of thing, look at the Cordic library: en.wikipedia.org/wiki/CORDIC – bubba Mar 6 '13 at 2:49
You can do this but it's more complex. This simple method works quite nicely. – ncmathsadist Mar 6 '13 at 2:51

In addition to sin and cos, you also need the inverse tan - the inverse sin and cos can be gotten from this.

My recommendation is to initially write your program using the standard library functions. While doing this, you can, on the side and in parallel, look at how the functions are computed and try to write your own versions. Do not let this side project prevent you from finishing the main project on time (I have been hurt in the past when this happened.)

Once your program is working and you have your own functions written, substitute yours for the standard functions and see what happens. This may be instructive.

-