Python: math Module, atan2(), degrees()

Use Arctangent to Calculate Angle (Theta)

nick3499
1 min readOct 3, 2017

After executing calc_angle(AB, BC) in the CLI, input two numbers which represent lengths of opposite side AB and adjacent side BC for the calculation of ϴ° or ∠MBC (see below). atan2() returns a value in radians, which is converted to ϴ° by thedegrees() function.

$ python calc_angle.py
10
10
45°
image by DOSHI

The workings of calc_angle(AB, BC) are demonstrated below:

>>> from math import atan2, degrees
>>> atan2(10, 10)
0.7853981633974483
>>> degrees(atan2(10, 10))
45.0
>>> round(degrees(atan2(10, 10)))
45
>>> str(round(degrees(atan2(10, 10)))) + '°'
'45°'
>>> print(str(round(degrees(atan2(10, 10)))) + '°')
45°

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet