Advertisement

cos() , sin() functions not returning corect value

Started by May 29, 2001 09:53 AM
2 comments, last by Zerosignull 23 years, 8 months ago
the cos() and sin() functions are not returning the corect value! when i put in a value it gives me some wacky answer like cos(180) = -0.59846006905786 when it is actually equal to -1 acording to my £6 calculator and the coalculator program on widows. HELP this is very anoying!!! ~prevail by daring to fail~
Well here is the problem summed up for you. Sin & Cos on your calculator work in Degrees. The sin and cos functions in most programming languages such as C or C++ work in Radians. Here is a link to a site which will explain the degrees to radians conversion and how it''s done: http://math.usask.ca/readin/rmoa.html</html>
Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
Advertisement
Radians are used because it''s easier for the hardware to calculate sines and cosines using radians.

When x is in radians,
sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! ...
cos(x) = 1 - x^2/2! - x^4/4! + x^6/6! - x^8/8! ...

There is no formula for sin and cos in degrees, so to do those calculations would require converting degrees to radians and then using the formula.

To convert degrees to radians, divide by 180 and multiply by pi. There are 2*pi radians in a circle.

So what are radians?
In a unit circle, if you have an angle at the center, that angle, in radians, is equal to the length of the curved line along the circumference of the circle which is contained by the angle. You can imagine that defining angles in terms of a length would have made it possible to make formulas for sin and cos in the first place.
Just do this, if you want cos(60) where 60 is a 60 degree angle or what have you, then you actually need to call cos like this

cos(60 * 0.017453292f);

0.017453292f is PI divided by 180, i.e. 3.14159 / 180, which is how to convert degrees to radians as the other posts said.

This topic is closed to new replies.

Advertisement