Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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++.

share|cite|improve this question
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
up vote 4 down vote accepted

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.

share|cite|improve this answer
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: – 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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.