I have recently made some attempts for a simple 3D program and have come across a problem with converting degrees to radians and then giving the result to sin() MSVC++ function.
I understand that radians = degrees*pi/180. This works precisely with 30 degrees, e.g., sin(30*pi/180) gives 0.5. But I face a problem when I want the program to calculate the sine of 180 degrees. The result I get should be 0, but is actually a little different. The difference is in some 14th digit after decimal point, however the result is not precisely zero and this makes a mess later.
I think that the problem is caused by a not enough precise value of pi used. I use my own #define pi 3.141592653589793238 as I have not found any pi nor degrees-to-radians function in math.h. I think that probably this is why the input value for the sin() function is not exactly what it would expect it to be in order to return precise zero (i.e. "its pi" radians). But how should I solve this when expanding the decimal part of the pi constant does not help and I don't know any other way how to convert from degrees to radians?
Will welcome any help on this.
Marek in Czech Republic
Start Free Trial