Arc Tangent

#!/usr/bin/python3 # ==================================================================== # test arc tangent # # In trigonometry, arctan is the inverse of the tangent function and # is used to compute the angle measure from the tangent ratio # (tan = opposite/adjacent) of a right triangle. Arctan can be # calculated in terms of degrees and as well as radians. # # The Python math.atan() function in Python returns the arctangent # of a number, expressed in radians. It is part of the math module # and is used to calculate the inverse tangent of a value. The # function takes a single argument, which represents the tangent # of the angle, and returns the corresponding angle in radians, # within the range of -π/2 to π/2. # # 1 radian = 57.2958 degrees # 1 pi radians = 180 degrees # 2 pi radians = 360 degrees # 3 pi radians = 540 degrees # # -------------------------------------------------------------------- # angle x # # + sin(x) = a/h # /| cos(x) = b/h # / | # h / | a h = math.sqrt(a**2 + b**2) # / | # / | x = atan(a/b) x = atan2(x,y) # / x | x = asin(a/h) # +------+ x = acos(b/h) # b # # ==================================================================== import math import user_interface as ui # -------------------------------------------------------------------- # ---- main # -------------------------------------------------------------------- while True: print() s = ui.get_user_input('Enter angle (degrees): ') if not s: break tf,deg = ui.is_float(s) # angle in degrees? if not tf: print() print('bad input - try again') continue rad = math.radians(deg) # angle in radians angle_tan = math.tan(rad) # angle tangent print() print(f'input: deg={deg:.6f} rad={rad:.6f} tan={angle_tan:.6f}') angle_rad = math.atan(angle_tan) angle_deg = math.degrees(angle_rad) print(f'angle: deg={angle_deg:.6f} rad={angle_rad:.6f}')