import math
import matplotlib.pyplot as plt
import seaborn as sns
def plotXiddler(theta):
a = math.radians(theta)
c = math.cos(a)
s = math.sin(a)
R = 100*c / (1 - c)
X = R * c
Y = R * s
Xt = 100 * c
Yt = 100 * s
Yr = 12*s/c
fig = plt.figure(figsize = (12, 2*Yr))
ax = fig.add_subplot(111, xlim = (-0.5*Xt, R+3.5*Xt), ylim = (-Y-2*Yt, Y+2*Yt))
#Remove axes and ticks.
for side in ['bottom', 'left', 'top', 'right']:
ax.spines[side].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
#Planet.
xiddler = plt.Circle((0,0), R, color = "#EEEEEE")
ax.add_patch(xiddler)
#Top Tower.
ax.scatter((X + Xt), (Y+Yt),
c = 'k',
s = 80)
ax.plot((X, X + Xt), (Y, Y+Yt),
c = 'k',
ls = '-',
lw = 3)
#Bottom Tower.
ax.scatter((X + Xt), (-Y-Yt),
c = 'k',
s = 80)
ax.plot((X, X + Xt), (-1*Y, -1*Y-Yt),
c = 'k',
ls = '-',
lw = 3)
#View path.
ax.plot((X + Xt, X + Xt), (Y+Yt, -1*Y-Yt),
c = 'k',
ls = ':',
lw = 3)
#Top Radius.
ax.plot((0, X), (0, Y),
c = '#287D8E',
ls = ':',
lw = 3)
#Center Radius.
ax.plot((0, R), (0, 0),
c = '#287D8E',
ls = ':',
lw = 3)
#Bottom Radius.
ax.plot((0, X), (0, -1*Y),
c = '#287D8E',
ls = ':',
lw = 3)
#Annotations
variables = [("R", (X/2, Y/2), '#287D8E', 'center', 'bottom'),
("R", (R/2, 0), '#287D8E', 'center', 'bottom'),
("R", (X/2, -1*Y/2), '#287D8E', 'center', 'bottom'),
("θ", (X/6, Y/12), '#287D8E', 'center', 'center'),
("θ", (X/6, -1*Y/12), '#287D8E', 'center', 'center')]
for v in variables:
plt.annotate(v[0], v[1], c = v[2],
fontsize = 20,
fontweight = "bold",
ha = v[3],
va = v[4])
fig.savefig("2022.07.01 Classic1.png")
plotXiddler(16)
def plotXiddler2(theta):
a = math.radians(theta)
c = math.cos(a)
s = math.sin(a)
R = 100*c / (1 - c)
X = R * s
Y = R * c
Xt = 100 * s
Yt = 100 * c
T = (R * (R+100)**2) / (2*R*R - (R+100)**2) - R
XT = T * s
YT = T * c
Ylow = Y+YT+Yt - 7*(2*X+XT+2*Xt)/12
Xlow = X*Ylow / Y
fig = plt.figure(figsize = (12, 7))
ax = fig.add_subplot(111, xlim = (-1*X-Xt, X+XT+Xt), ylim = (Ylow, Y+YT+Yt))
#Remove axes and ticks.
for side in ['bottom', 'left', 'top', 'right']:
ax.spines[side].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
#Planet.
xiddler = plt.Circle((0,0), R, color = "#EEEEEE")
ax.add_patch(xiddler)
#Left.
ax.scatter((-1*X), (Y),
c = 'k',
s = 80,
zorder = 2)
#Right Tower.
ax.scatter((X+XT), (Y+YT),
c = 'k',
s = 80)
ax.plot((X, X+XT), (Y, Y+YT),
c = 'k',
ls = '-',
lw = 3)
#View path.
ax.plot((-1*X, X+XT), (Y, Y+YT),
c = 'k',
ls = ':',
lw = 3)
#Left Radius.
ax.plot((-1*Xlow, -1*X), (Ylow, Y),
c = '#287D8E',
ls = ':',
lw = 3)
#Center Radius.
ax.plot((0, 0), (Ylow, R),
c = '#287D8E',
ls = ':',
lw = 3)
#Right Radius.
ax.plot((Xlow, X), (Ylow, Y),
c = '#287D8E',
ls = ':',
lw = 3)
#Annotations
variables = [("R", (7*X/8, Ylow*12/11), '#287D8E', 'center', 'bottom'),
("R", (0, Ylow*12/11), '#287D8E', 'center', 'bottom'),
("R", (-7*X/8, Ylow*12/11), '#287D8E', 'center', 'bottom'),
("Tower", (X, Y*14/13), 'k', 'center', 'bottom')]
for v in variables:
plt.annotate(v[0], v[1], c = v[2],
fontsize = 20,
fontweight = "bold",
ha = v[3],
va = v[4])
m = YT / (2*X+XT)
ax.plot((-1*X+80*m, -1*X+80*m+80, -1*X+80), (Y-80, Y-80+80*m, Y+80*m),
c = 'k',
lw = 2)
fig.savefig("2022.07.01 Classic2.png")
plotXiddler2(16)
#Plot.
def plotTower(var) :
if var == "angle" :
xs = [a/100 for a in range(1, 1500)]
tower_heights = []
for a in xs:
c = math.cos(math.radians(a))
R = 100*c / (1 - c)
T = (R * (R+100)**2) / (2*R*R - (R+100)**2) - R
tower_heights.append(T)
xlabel = "Angle Between Two Towers (°)"
xs = [2*x for x in xs]
save = "2022.07.01 Classic3.png"
else :
xs = [r for r in range(1000, 100000)]
tower_heights = []
for R in xs:
T = (R * (R+100)**2) / (2*R*R - (R+100)**2) - R
tower_heights.append(T)
xlabel = "Radius of Xiddler (km)"
xs = [x/1000 for x in xs]
save = "2022.07.01 Classic4.png"
#Plot.
sns.set()
fig = plt.figure(figsize = (14, 8))
ax = fig.add_subplot(111)
#Scatter.
ax.scatter(x = xs,
y = tower_heights,
s = 10,
c = "#287D8E")
#Title.
ax.set_title("Tower Height To See Friend", fontsize = 24)
#Axes.
ax.set_xlabel(xlabel, fontsize = 20)
ax.set_ylabel("Tower Height (m)", fontsize = 20)
ax.tick_params(axis = 'both', labelsize = 16)
fig.savefig(save)
plotTower("angle")
plotTower("radius")