[Tutor] Angles

Terry Carroll carroll at tjc.com
Wed Nov 29 02:53:45 CET 2006


On Tue, 28 Nov 2006, Carlos wrote:

> I was never very good at trigonometry, but looks like my translation of 
> the equation is ok and the problem is some kind of python behavior, 
> because whenever the results exceed 100° (deg) Python returns the 
> complementary angle, it is possible to avoid this? Or I'm overlooking 
> somethig?

Carlos, I'm not so good at trigonometry myself, but I suspect that the 
trouble is that for some trig functions, both an angle and that angle's 
complement map to the same value.  For example:

>>> angle1 = radians(45)  # 45 degrees
>>> angle2 = pi-angle1    # 135 degrees
>>> print degrees(angle1), degrees(angle2)
45.0 135.0
>>> sin(angle1), sin(angle2)
(0.70710678118654746, 0.70710678118654757)
>>> angle1 = radians(30)
>>> angle2 = pi-angle1
>>> print degrees(angle1), degrees(angle2)
30.0 150.0
>>> sin(angle1), sin(angle2)
(0.49999999999999994, 0.49999999999999994)

So basically, once you take a sine in your early steps, you're getting the 
same sine result regardless of whether it's in the first quadrant (0-90 
degrees) or second quadrant (90-180 degrees).  When you subsequently use 
that sine and try to eventually get an angle out of it, it's going to give 
you a first-quadrant result.

I think you'll need to track the range of your input angle and adjust your 
output angle accordingly.  The algorithm you got may only be valid for 
0-90 degrees.



More information about the Tutor mailing list