In Python I want to move an object away from a second object by calculating the length of the hypotenuse, adding to its length and then calculatin the x and y co-ordinates of the new position. To do this I’m using the Python math module.
From my school days I remember ‘soh car toa’ where a is the adjacent side of the angle, h is the hypotenuse and o is the opposite side to the angle.
As a test my code is:
import math
a = 30
o = 40
h = math.sqrt(o*o+a*a) # should = 50
ta = math.tan(o/a) * 180 / math.pi # toa
ca = math.cos(a/h) * 180 / math.pi # cah
sa = math.sin(o/h) * 180 / math.pi # soh
print(" : hypotenuse = ",h,"n : tan angle = ",int(ta),"n : cos angle = ",int(ca),"n : sine angle = ",int(sa))
I would have expected the answers to all come back with the same angle, but they don’t. These are the answers I get:
: hypotenuse = 50.0
: tan angle = 236
: cos angle = 47
: sine angle = 41
Why are the answers so different and/or what am I doing wrong?