Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I calculate tangent with degrees instead of radians?

I am trying to make a basic tool to make my everyday easier, solving some assignments for me. Unfortunately, I can't figure out how to make it calculate in degrees when tangent is being used.

My code:

import math


class Astro():
    def start(self):
        velocity = input("What is the galaxy's velocity? (m/s) \n")
        peculiar = (float(velocity) - 938600) ** 2
        mass = (3 * float(peculiar) * (10 ** 11) * 50 * (10 ** 6) * (8 * (180 / math.pi))
                * 9.46 * (10 ** 15)) / (2 * 6.67 * (10 ** -11))
        print("The galaxy's mass is " + str(mass) + " kg. \n")


if __name__ == '__main__':
    sup = Astro()
    sup.start()

EDIT: Sorry for the lack of context; this is about calculating the masses of galaxies using 2 functions, the first one, line 7 to get the peculiar velocity, and the second one in lines 8-9 to get the actual mass of the considered galaxy.

SOLVED: math.tan(8 * pi / 180)

Thank you for all your help!

like image 219
foot enjoyer Avatar asked Aug 31 '25 04:08

foot enjoyer


1 Answers

Computers work in radians. Try

answer = tan(angle * pi / 180)

to use your angle in degrees into a trig function. Or try

answer = atan(number) * 180 / pi  

to get answer in degrees.

like image 91
Dan Sp. Avatar answered Sep 02 '25 17:09

Dan Sp.