Skip to content

Instantly share code, notes, and snippets.

@mailtodanish
Last active May 4, 2022 12:33
Show Gist options
  • Save mailtodanish/b48aa88ef1915a45b5f3d4c6d7f34cb8 to your computer and use it in GitHub Desktop.
Save mailtodanish/b48aa88ef1915a45b5f3d4c6d7f34cb8 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
p1 = [1, 1]
p2 = [5, 3]
p3 = [2, 3]
x_values = [p1[0], p2[0]]
y_values = [p1[1], p2[1]]
plt.plot(x_values, y_values, 'bo', linestyle="--")
plt.xlim(0, 6), plt.ylim(0, 6)
plt.text(p1[0]-0.015, p1[1]+0.25, "Point1")
plt.text(p2[0]-0.050, p2[1]-0.25, "Point2")
plt.text(p3[0]-.050, p3[1]-.25, "Point3")
plt.plot(x_values, y_values, marker='o')
plt.plot(p3[0], p3[1], marker="o", markersize=10,
markeredgecolor="red", markerfacecolor="green")
def orientation():
# m1 = round(((p2[1]-p1[1])/(p2[0]-p1[0])),2)
# m2 = round(((p3[1]-p1[1])/(p3[0]-p1[0])),2)
# cross multiply to avoid 0 in Divisor
result =((p3[1]-p1[1])*(p2[0]-p1[0])) - ((p2[1]-p1[1])*(p3[0]-p1[0]))
if result == 0:
return 0
return 1 if result > 0 else 2
response = ["TOUCH", "LEFT", "RIGHT"]
print(orientation())
plt.text(5, 5, response[orientation()],fontsize=22)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment