import math
from matplotlib.patches import Polygon as poly
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#Points!
def xy(d):
x = math.cos(math.radians(d))
y = math.sin(math.radians(d))
return([x, y])
A = [0, 0]
B = [1, 0]
C = xy(15)
Bp = xy(30)
Cp = xy(45)
#Triangles!
def triangle(points):
t = poly(np.array(points),
ec = "k",
lw = 3,
fc = "cornflowerblue")
return(t)
#Plot!
fig = plt.figure(figsize = (10, 7.5))
ax = fig.add_subplot(111, xlim = (-.04, 1.04), ylim = (-.03, .78))
#Remove axes and ticks.
for side in ['bottom', 'left', 'top', 'right']:
ax.spines[side].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
#Stack 3 triangles.
t1 = triangle([A, B, C, A])
t2 = triangle([A, C, Bp, A])
t3 = triangle([A, Bp, Cp, A])
plt.gca().add_patch(t1)
plt.gca().add_patch(t2)
plt.gca().add_patch(t3)
#Right Angle
plt.plot((0.48, 0.5, 0.52), (0.48, 0.46, 0.48), c = 'k', lw = 3)
#Amare!
F = [0.5, 0.5]
plt.plot((1, 0.5), (0, 0.5), c = 'r', lw = 3)
#Variables.
variables = [("A", (A[0]-.04, A[1]-.02)),
("B", (B[0]+.01, B[1]-.02)),
("C", (C[0]+.01, C[1]-.02)),
("B'", (Bp[0]+.01, Bp[1]-.01)),
("C'", (Cp[0]+.01, Cp[1]-.01)),
("F", (F[0]-.03, F[1]))]
for variable in variables :
plt.annotate(variable[0], variable[1], fontsize = 24)
plt.savefig("2022.01.07 Classic1.png");
#Get intersection point of two lines given two sets of points.
def linInt(line_1_pts, line_2_pts):
x00 = line_1_pts[0][0]
y00 = line_1_pts[0][1]
x01 = line_1_pts[1][0]
y01 = line_1_pts[1][1]
x10 = line_2_pts[0][0]
y10 = line_2_pts[0][1]
x11 = line_2_pts[1][0]
y11 = line_2_pts[1][1]
m0 = (y01-y00) / (x01-x00)
m1 = (y11-y10) / (x11-x10)
b0 = y00 - m0*x00
b1 = y10 - m1*x10
x = (b1-b0) / (m0-m1)
y = (b1*m0 - b0*m1) / (m0-m1)
return((x,y))
D = linInt((B, F), (A, C))
E = linInt((B, F), (A, Bp))
AE = math.dist(A, E)
E = (AE, 0)
AF = math.dist(A, F)
F = (C[0]*AF, C[1]*AF)
#Plot!
fig = plt.figure(figsize = (15, 5))
ax = fig.add_subplot(111, xlim = (-.03, 1.02), ylim = (-.01, .34))
#Remove axes and ticks.
for side in ['bottom', 'left', 'top', 'right']:
ax.spines[side].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
plt.gca().add_patch(triangle([A, B, C, A]))
#Right Angle
plt.plot((B[0], D[0], E[0], F[0]), (B[1], D[1], E[1], F[1]), c = 'r', lw = 3)
#Variables.
variables = [("A", (A[0]-.02, A[1]-.01)),
("B", (B[0]+.01, B[1]-.01)),
("C", (C[0]+.01, C[1])),
("D", (D[0]-.01, D[1]+.01)),
("E", (E[0]-.03, E[1]+.01)),
("F", (F[0]-.01, F[1]+.01)),]
for variable in variables :
plt.annotate(variable[0], variable[1], fontsize = 24)
plt.savefig("2022.01.07 Classic2.png");
for pair in [B, D, E, F]:
print((round(pair[0], 5), round(pair[1], 5)))
(1, 0) (0.78868, 0.21132) (0.73205, 0) (0.68301, 0.18301)
ABD = math.atan((D[1]-B[1]) / (D[0]-B[0]))
math.degrees(ABD)
-44.99999999999999
ADE = math.atan((E[1]-D[1]) / (E[0]-D[0]))
math.degrees(ADE)-15
60.0
AEF = math.atan((F[1]-E[1]) / (F[0]-E[0]))
math.degrees(AEF)
-75.00000000000001