codexring-laser-closed-path.py
ring-laser-closed-path.py
"""Draw ring-laser-closed-path.png in CWD on opaque white.
Original idealized three-mirror ring; not a reconstruction of a cited apparatus.
Tested with Python 3.14.4, NumPy 2.3.5, Matplotlib 3.10.7.
"""
from pathlib import Path
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
def main():
plt.rcParams.update({'font.size': 11, 'figure.facecolor': 'white',
'axes.facecolor': 'white'})
fig, ax = plt.subplots(figsize=(7.4, 4.6), dpi=100)
fig.subplots_adjust(left=.06, right=.97, top=.82, bottom=.16)
vertices = np.array([[.08, .14], [.88, .14], [.48, .79]])
blue, orange = '#1768ac', '#bc5d17'
for i, v in enumerate(vertices):
nxt, prev = vertices[(i+1) % 3], vertices[(i-1) % 3]
ax.plot([v[0], nxt[0]], [v[1], nxt[1]], color='#70818c', lw=1.4)
incoming = (v-prev)/np.linalg.norm(v-prev)
outgoing = (nxt-v)/np.linalg.norm(nxt-v)
normal = (incoming-outgoing)/np.linalg.norm(incoming-outgoing)
tangent = np.array([-normal[1], normal[0]])
a, b = v-.065*tangent, v+.065*tangent
ax.plot([a[0], b[0]], [a[1], b[1]], color='#46545c', lw=5,
solid_capstyle='butt')
if i > 0:
d = nxt-v
side = np.array([-d[1], d[0]])/np.linalg.norm(d)
for start, end, offset, color in [(.25, .65, .025, blue),
(.70, .30, -.025, orange)]:
ax.annotate('', xy=v+end*d+offset*side,
xytext=v+start*d+offset*side,
arrowprops={'arrowstyle': '-|>', 'lw': 2, 'color': color})
ax.add_patch(Rectangle((.23, .095), .32, .09, facecolor='#dfefdf',
edgecolor='#388048', lw=1.5, zorder=4))
ax.text(.385, .14, 'Gain medium', ha='center', va='center', fontsize=10, zorder=5)
ax.annotate('', xy=(1.10, .14), xytext=(.89, .14),
arrowprops={'arrowstyle': '-|>', 'lw': 2, 'color': blue})
ax.text(1.02, .045, 'Output', ha='center', color=blue)
ax.annotate('Partly transmitting\noutput mirror', xy=(.88, .14), xytext=(.96, .36), ha='left', fontsize=10, arrowprops={'arrowstyle': '-', 'color': '#70818c', 'lw': .8})
ax.text(.48, .91, 'Mirror', ha='center')
ax.text(.04, .04, 'Mirror', ha='center')
ax.text(.48, .44, 'Ring path', ha='center', fontsize=11)
ax.set(xlim=(-.06, 1.15), ylim=(-.02, 1.0), aspect='equal')
ax.axis('off')
fig.suptitle('Ring laser: light circulates through the gain medium', y=.97, fontsize=14)
fig.text(.5, .87, 'Idealized three-mirror geometry; simultaneous lasing is not guaranteed.',
ha='center', fontsize=10)
fig.text(.5, .075, r'Round-trip phase $2\pi m$; vacuum spacing $\Delta\nu=c/P$',
ha='center', fontsize=11)
fig.text(.5, .025, 'P is the full circuit length. Reflection phase is idealized as constant.',
ha='center', fontsize=9, color='#46545c')
fig.savefig(Path.cwd() / 'ring-laser-closed-path.png', facecolor='white', transparent=False)
plt.close(fig)
if __name__ == '__main__':
main()