Ringinator/5 Cursor-Calibration/geometry.py

27 lines
696 B
Python
Raw Normal View History

2024-08-16 20:30:44 +00:00
import math
def perpendicular(l, c, r):
# l stands for left, c for centre, r for right angles
# the inputs are floats representing angles
# returns the angle which is perpendicular to the screen
float theta1
dT1 = c - l
dT2 = r - c
# convert to radians
dT1 = dT1 * math.pi / 180
dT2 = dT2 * math.pi / 180
# This is really only a theoretic case
#if |dT2| < 0.001:
#theta1 = math.pi/2
# apply the formula to obtain theta1
up = math.cos(dT1) * math.sin(dT1) * math.sin(dT2) - 1
down = (math.sin(dT1) * math.sin(dT1)) * math.sin(dT2)
theta1 = math.arctan(up / down)
theta1 = theta1 * 180 / math.pi
return (l - theta1)