#!/usr/bin/python3 # ==================================================================== # sine and cosine test # (play with + and - angles, and angles greater than 360) # ==================================================================== import numpy as np import user_interface as ui diagram = ''' +-----------------------------------------------------+ | + +y | | ..| | | | .. | | | | .. | -x,+y | +x,+y | | .. | sin | | | .. | (y) -x ---------+--------- +x | | .. | | | | .. | -x,-y | +x,-y | | +..............+ | | | cos | | | (x) -y | +-----------------------------------------------------+''' # -------------------------------------------------------------------- # ---- display sine and cosine # -------------------------------------------------------------------- def sin_cos(deg): asin = np.sin(np.deg2rad(deg)) acos = np.cos(np.deg2rad(deg)) return (asin,acos) # -------------------------------------------------------------------- # ---- main # -------------------------------------------------------------------- print(diagram) while True: print() sdeg = ui.get_user_input('Enter angle (degrees): ') if not sdeg: break if sdeg[0] == '*' or sdeg[0].lower() == 'd': print(diagram) continue ##if sdeg[0].lower() == 'c': # may not work ## ui.clear_screen() # depends on the terminal ## continue tf,deg = ui.is_float(sdeg) if not tf: print() print(f'bad angle {sdeg}') continue # ---- display degrees, sine, cosine asin,acos = sin_cos(deg) print() print(f'{deg:>+7.2f} sin = {asin:.4f}') print(f'{deg:>+7.2f} cos = {acos:.4f}')