PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from tkinter import Tk, Canvas
window = Tk()
canvas = Canvas(window)
# Creating and drawing the triangle
P1, P2, P3 = (41, 145), (150, 150), (100, 48)
canvas.create_line(P1, P2); canvas.create_line(P2, P3); canvas.create_line(P3, P1)
#1: Sorting the points by Y-Coordinate, from highest to lowest
max_Point = lambda *P: (P[0] if P[0][1]>=P[1][1] else P[1]) if len(P)<=2 else max_Point(P[0], max_Point(*P[1:]))
min_Point = lambda *P: (P[0] if P[0][1]<=P[1][1] else P[1]) if len(P)<=2 else min_Point(P[0], min_Point(*P[1:]))
max_P = max_Point(P1, P2, P3)
min_P = min_Point(P1, P2, P3)
mid_P = P1 if P1!=max_P and P1!=min_P else P2 if P2!=max_P and P2!=min_P else P3
#2: Sorting the lines, to see which one has the longest projection on Y-Axis:
main_line = (max_P, min_P) # This is the line that contains all horizontal points
top_line = (max_P, mid_P)
bottom_line = (mid_P, min_P)
#3: Getting the linear equations:
slope_of = lambda P1, P2: (P2[1]-P1[1])/(P2[0]-P1[0]) if P2[0]-P1[0]!=0 else 0
main_slope = slope_of(*main_line)
main_y_intercept = main_line[0][1]-main_slope*main_line[0][0]
main_equation = lambda y: (y-main_y_intercept)/main_slope if main_slope!=0 else 0
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run