Commit
·
8949a25
1
Parent(s):
46251b7
Add edge case when sphere blocks all the light
Browse files
backend/nonreflecting_ray_tracing.py
CHANGED
@@ -48,14 +48,47 @@ def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50):
|
|
48 |
y_1 = length * mt.sin(angle) + y_0
|
49 |
return [x_0, x_1], [y_0, y_1]
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
theta_center = mt.atan2(b, a)
|
53 |
d = mt.hypot(a, b)
|
54 |
|
55 |
try:
|
56 |
delta = mt.asin(r / d)
|
57 |
except:
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
lower_angle = theta_center - delta
|
61 |
upper_angle = theta_center + delta
|
|
|
48 |
y_1 = length * mt.sin(angle) + y_0
|
49 |
return [x_0, x_1], [y_0, y_1]
|
50 |
|
51 |
+
def inside_circle_plotter():
|
52 |
+
"""Function to plot the rays inside the circle"""
|
53 |
+
increment = 2 * mt.pi / ray_count
|
54 |
+
|
55 |
+
for angle in np.arange(0, 2 * mt.pi, increment):
|
56 |
+
dx = mt.cos(angle)
|
57 |
+
dy = mt.sin(angle)
|
58 |
+
|
59 |
+
A = dx**2 + dy**2
|
60 |
+
B = -2 * (a * dx + b * dy)
|
61 |
+
C = a**2 + b**2 - r**2
|
62 |
+
|
63 |
+
try:
|
64 |
+
t1, t2 = quad_solver(A, B, C)
|
65 |
+
|
66 |
+
valid_ts = [t for t in (t1, t2) if t > 0]
|
67 |
+
if not valid_ts:
|
68 |
+
continue
|
69 |
+
t_hit = min(valid_ts)
|
70 |
+
|
71 |
+
x = [0, t_hit * dx]
|
72 |
+
y = [0, t_hit * dy]
|
73 |
+
ax.plot(x, y, color='orange', lw=1)
|
74 |
+
except ValueError:
|
75 |
+
continue
|
76 |
theta_center = mt.atan2(b, a)
|
77 |
d = mt.hypot(a, b)
|
78 |
|
79 |
try:
|
80 |
delta = mt.asin(r / d)
|
81 |
except:
|
82 |
+
inside_circle_plotter()
|
83 |
+
ax.set_title(f'Rays origin - (0,0). From inside a perfectly absorbing circle\nCenter - ({a},{b}), Radius {r}')
|
84 |
+
plt.grid(True)
|
85 |
+
plt.show()
|
86 |
+
|
87 |
+
fig.canvas.draw()
|
88 |
+
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
89 |
+
plt.close(fig)
|
90 |
+
return image_array
|
91 |
+
# raise ValueError("Circle radius is too large for the given center coordinates.")
|
92 |
|
93 |
lower_angle = theta_center - delta
|
94 |
upper_angle = theta_center + delta
|