Test arccos

#!/usr/bin/python3
# ===================================================================
# test arccos
# The inverse of cos so that, if y = cos(x), then x = arccos(y).
#
# Python's input to sin and cos is radians
# ===================================================================

import numpy as np

$ -------------------------------------------------------------------
# ---- know triangle 3,4,5 for testing
# ---- angles are 90 degrees, 36.87 degrees and 53.13 degrees
#
#         +
#        /|
#       / |
#    5 /  | 4
#     /   |
#    /    |
#   +-----+
#      3
# -------------------------------------------------------------------

# ---- angle 1 is in lower left corner of the triangle

ang1 = 53.13                    # degrees
rad1 = np.deg2rad(ang1)         # radians
ang2 = 36.87                    # degrees
rad2 = np.deg2rad(ang2)         # radians

print(f'ang1 = {ang1:.3f}  rad1 = {rad1:.3f}')
print(f'ang2 = {ang2:.3f}  rad2 = {rad2:.3f}')

# ---- cos = adjacent over hypotenuse

print(f'3/5         = {3/5:10.3f}  (adjacent over hypotenuse)')
 
cos = np.cos(rad1)

print(f'cos(rad1)   = {cos:10.3f}  (adjacent over hypotenuse)')

a = np.arccos(cos)

print(f'arccos(cos) = {a:10.3f}  (angle in radians)')

aa = np.rad2deg(a)

print(f'arccos(cos) = {aa:10.3f}  (angle in degrees)')