# Mirror-optics-geometry.ipynb

In [2]:
import matplotlib.pyplot as plt
import numpy as np

In [37]:
def get_reflection_points(p1, radius, reflection_type, center = None, mirror_center = None, ray_length = 8):
length = p1[1]
if reflection_type == 'parallel':
A = np.array([x1, y1])

theta2 = np.pi + 2*theta1
x2 = ray_length*np.cos(theta2)
y2 = ray_length*np.sin(theta2)
B = np.array([x2, y2])
return A, B
elif reflection_type == 'center':
d = np.linalg.norm((mirror_center[0] - p1[0], mirror_center[1] - p1[1]))
theta1 = np.arcsin(length/(d))
x1 = p1[0] + d*np.cos(-theta1)
y1 = p1[1] + d*np.sin(-theta1)
A = np.array([x1, y1])

theta2 = np.pi + theta1
x2 = ray_length*np.cos(theta2)
y2 = ray_length*np.sin(theta2)
B = np.array([x2, y2])

return A, B

In [41]:
c1 = np.array([5, 0])
r = 45
# f1 = (c1[0] + r/2, 0)
mirror_theta = np.pi/4
mirror_center = np.array([c1[0] + r, c1[1]])
length = 10
obj_x = 0
obj_y = 0
ray_length = 45

pu0 = np.array([obj_x, obj_y])
pu1 = np.array([obj_x, obj_y + length])

list_of_values = []

# A, B = get_reflection_points(p1 = pu1,
#                              center = c1,
#                              ray_length = ray_length,
#                              reflection_type = 'parallel')
# C, D = get_reflection_points(p1 = (pu1[0], (pu1[1] + pu0[1])/2), radius = r, center = c1, ray_length = ray_length, reflection_type = 'parallel')
# E, F = get_reflection_points(p1 = pu0, radius = r, center = c1, ray_length = ray_length, reflection_type = 'parallel')

no_of_rays = 10

for i in np.linspace(0, length, no_of_rays):
A, B = get_reflection_points(p1 = np.array([obj_x, obj_y + i]),
center = c1,
ray_length = ray_length,
reflection_type = 'parallel'
)
list_of_values.append([A, B])

A, B = get_reflection_points(p1 = pu1, radius = r, mirror_center = mirror_center, ray_length = ray_length, reflection_type = 'center')

In [42]:
fig = plt.figure(figsize = (9, 9))

plt.plot(*c1, color = 'b', marker = 'o')
# plt.plot(*c2, color = 'b', marker = 'o')

# plt.plot(*pu0, color = 'b', marker = 'o')
# plt.plot(pu0[0] + pu0[1]+length, color = 'r', marker = 'o')

angle_circle = np.linspace(-mirror_theta, mirror_theta, 50)
circle_x = r*np.cos(angle_circle) + c1[0]
circle_y = r*np.sin(angle_circle) + c1[1]
plt.plot(circle_x, circle_y, color = 'black')

plt.plot([pu1[0], A[0]], [pu1[1], A[1]], color = 'green')
plt.arrow(*A, *B, color = 'green', width = 0.1)

plt.arrow(*pu0, 0, length, width = 0.1, color = 'blue', length_includes_head = True)

for n, i in enumerate(np.linspace(0, length, no_of_rays)):
plt.plot([obj_x, list_of_values[n][0][0]], [obj_y + i, list_of_values[n][0][1]], color = 'r', alpha = 0.5)

plt.arrow(*list_of_values[n][0], *list_of_values[n][1], color = 'r', alpha = 0.5)

plt.gca().set_aspect('equal')

In [ ]: