[Tutor] trigonometry in python
Fri Nov 1 07:23:01 2002
> when i import math module to count the value of for example sin(30), why
the value is not 0.5 ? i used this syntax :
> the result value is not 0.5, what happened ? anyone can help me ?
There are two reasons you get a different value than you expected.
The first is that there are two(*) ways to look at trig. You can count
angles in degrees and you can count them in radians.
The trig functions in math work in radians, not in degrees. So the correct
approach is to first convert your angle in degrees to radians.
>>> def toRadians(degrees):
>>> return degrees * ((2 * math.pi) / 360)
However, we're still not getting 0.5
This is where the second reason comes into play. As you might know, there is
an infinite amount of real numbers. However, due to computer constraints
there is only a limited amount of real numbers that can be represented on a
computer. Therefore, Python often gives you an /approximation/ of the
I hope this helps.