Search code examples
pythoncomputational-geometry

is there a way to examine if an angle is a right angle programmatically?


i plot an angle in python

i

here is the code

x = [0,0.5,1]
y = [0,0.5,0]
plt.scatter(x,y)
plt.plot(x,y)
plt.show()

is there a way to examine if the angle is a right angle programmatically?


Solution

  • Yes, there is.

    x = [0,0.5,1]
    y = [0,0.5,0]
    points = [np.array(point) for point in zip(x,y)]
    a, b, c = points
    ba = a - b
    bc = c - b
    cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
    angle_rad = np.arccos(cosine_angle)
    angle_deg = np.rad2deg(angle_rad)
    print(angle_deg) # 90.0