Search code examples
pythontriangulation

get adjacent and opposite of an triangle with hypotenuse and an angle


I'm trying to create a program that calculates the adjacent and opposite of a triangle using the hypotenuse and the angle between the hypotenuse and the adjacent with python


Solution

  • Just remember SohCahToa. We have the hypotenuse (h) so for the opposite, we set up the equation sin(angle) = opposite/hypotenuse. To find the opposite we multiply both sides by the hypotenuse to get hypotenuse * sin(angle) = opposite. The do a similar thing with cos(angle) = adjacent / hypotenuse. Then you have your opposite and adjacent sides. In terms of code it would look something like this:

    import math # we need this specifically to use trig functions
    angle = (some angle here)
    hypotenuse = (some number here)
    opposite = hypotenuse * math.sin(math.radians(angle))
    # we have to multiply the angle by PI/180 because the python sin function uses radians and we do this by using math.radians() is how to convert from degrees to radians.
    adjacent = hypotenuse * math.cos(angle * (math.pi/180))