Commit
·
cc6e945
1
Parent(s):
adc8d2e
Add ratio of rays that are incident for both
Browse files- app.py +9 -3
- backend/nonreflecting_ray_tracing.py +6 -4
- backend/reflecting_ray_tracing.py +8 -4
app.py
CHANGED
@@ -16,7 +16,10 @@ iface1 = gr.Interface(
|
|
16 |
gr.Slider(minimum=3, maximum=1000, step=1, label="Number of Rays", value=50, info="Number of rays to be plotted in total"),
|
17 |
gr.Radio(label="Remove Clutter", choices=["Yes", "No"], value="No", info="Only keep rays that are INCIDENT by the surface."),
|
18 |
],
|
19 |
-
outputs=
|
|
|
|
|
|
|
20 |
live=True,
|
21 |
title="Non-Reflective Ray Tracing",
|
22 |
description=description1,
|
@@ -32,9 +35,12 @@ iface2 = gr.Interface(
|
|
32 |
gr.Number(label="Circle Center Y (b)", value=20, info="Y coordinate of Circle center"),
|
33 |
gr.Number(label="Radius (r)", value=15, info="Radius of the circle"),
|
34 |
gr.Slider(minimum=3, maximum=1000, step=1, label="Number of Rays", value=50, info="Number of rays to be plotted in total"),
|
35 |
-
gr.Radio(label="Remove Clutter", choices=["Yes", "No"], value="No", info="Only keep rays that are REFLECTED
|
|
|
|
|
|
|
|
|
36 |
],
|
37 |
-
outputs="image",
|
38 |
live=True,
|
39 |
title="Reflective Ray Tracing",
|
40 |
description=description2,
|
|
|
16 |
gr.Slider(minimum=3, maximum=1000, step=1, label="Number of Rays", value=50, info="Number of rays to be plotted in total"),
|
17 |
gr.Radio(label="Remove Clutter", choices=["Yes", "No"], value="No", info="Only keep rays that are INCIDENT by the surface."),
|
18 |
],
|
19 |
+
outputs=[
|
20 |
+
gr.Image(label="Ray Tracing Output"),
|
21 |
+
gr.Number(label="Fraction of Incident Rays", info="Out of 100 rays, how many are incident on the surface"),
|
22 |
+
],
|
23 |
live=True,
|
24 |
title="Non-Reflective Ray Tracing",
|
25 |
description=description1,
|
|
|
35 |
gr.Number(label="Circle Center Y (b)", value=20, info="Y coordinate of Circle center"),
|
36 |
gr.Number(label="Radius (r)", value=15, info="Radius of the circle"),
|
37 |
gr.Slider(minimum=3, maximum=1000, step=1, label="Number of Rays", value=50, info="Number of rays to be plotted in total"),
|
38 |
+
gr.Radio(label="Remove Clutter", choices=["Yes", "No"], value="No", info="Only keep rays that are REFLECTED to the surface."),
|
39 |
+
],
|
40 |
+
outputs=[
|
41 |
+
gr.Image(label="Ray Tracing Output"),
|
42 |
+
gr.Number(label="Fraction of Reflected Rays", info="Out of 100 rays, how many get reflected by the surface"),
|
43 |
],
|
|
|
44 |
live=True,
|
45 |
title="Reflective Ray Tracing",
|
46 |
description=description2,
|
backend/nonreflecting_ray_tracing.py
CHANGED
@@ -78,7 +78,7 @@ def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50, clutter = "No"
|
|
78 |
delta = mt.asin(r / d)
|
79 |
except:
|
80 |
inside_circle_plotter()
|
81 |
-
ax.set_title(f'Rays origin - (0,0). From inside a perfectly absorbing circle\nCenter
|
82 |
plt.grid(True)
|
83 |
plt.show()
|
84 |
|
@@ -95,11 +95,12 @@ def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50, clutter = "No"
|
|
95 |
upper_angle = normalize(upper_angle)
|
96 |
|
97 |
increment = 2*mt.pi/ray_count
|
98 |
-
|
99 |
for angle in np.arange(0, 2 * mt.pi, increment): # 1° steps
|
100 |
dx = mt.cos(angle)
|
101 |
dy = mt.sin(angle)
|
102 |
if is_angle_between(angle, lower_angle, upper_angle):
|
|
|
103 |
A = dx**2 + dy**2
|
104 |
B = -2 * (a * dx + b * dy)
|
105 |
C = a**2 + b**2 - r**2
|
@@ -130,11 +131,12 @@ def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50, clutter = "No"
|
|
130 |
ax.plot(x1, y1, color='green', lw=2, linestyle='--')
|
131 |
ax.plot(x2, y2, color='green', lw=2, linestyle='--')
|
132 |
|
133 |
-
ax.set_title(f'Rays with shadow from a perfectly absorbing circle\nCenter
|
134 |
plt.grid(True)
|
135 |
plt.show()
|
136 |
|
137 |
fig.canvas.draw()
|
138 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
139 |
plt.close(fig)
|
140 |
-
|
|
|
|
78 |
delta = mt.asin(r / d)
|
79 |
except:
|
80 |
inside_circle_plotter()
|
81 |
+
ax.set_title(f'Rays origin - (0,0). From inside a perfectly absorbing circle\nCenter-({a},{b}), Radius-{r}')
|
82 |
plt.grid(True)
|
83 |
plt.show()
|
84 |
|
|
|
95 |
upper_angle = normalize(upper_angle)
|
96 |
|
97 |
increment = 2*mt.pi/ray_count
|
98 |
+
total_hits = 0
|
99 |
for angle in np.arange(0, 2 * mt.pi, increment): # 1° steps
|
100 |
dx = mt.cos(angle)
|
101 |
dy = mt.sin(angle)
|
102 |
if is_angle_between(angle, lower_angle, upper_angle):
|
103 |
+
total_hits += 1
|
104 |
A = dx**2 + dy**2
|
105 |
B = -2 * (a * dx + b * dy)
|
106 |
C = a**2 + b**2 - r**2
|
|
|
131 |
ax.plot(x1, y1, color='green', lw=2, linestyle='--')
|
132 |
ax.plot(x2, y2, color='green', lw=2, linestyle='--')
|
133 |
|
134 |
+
ax.set_title(f'Rays with shadow from a perfectly absorbing circle\nCenter-({a},{b}), Radius-{r}')
|
135 |
plt.grid(True)
|
136 |
plt.show()
|
137 |
|
138 |
fig.canvas.draw()
|
139 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
140 |
plt.close(fig)
|
141 |
+
hit_ratio = (total_hits / ray_count) * 100
|
142 |
+
return image_array, f"{hit_ratio:.2f}"
|
backend/reflecting_ray_tracing.py
CHANGED
@@ -101,14 +101,14 @@ def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15, clutter = "No"):
|
|
101 |
delta = mt.asin(r / d)
|
102 |
except:
|
103 |
inside_circle_plotter()
|
104 |
-
ax.set_title(f'Rays origin - (0,0). From inside a perfectly reflective circle\nCenter
|
105 |
plt.grid(True)
|
106 |
plt.show()
|
107 |
|
108 |
fig.canvas.draw()
|
109 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
110 |
plt.close(fig)
|
111 |
-
return image_array
|
112 |
|
113 |
# raise ValueError("Circle radius is too large for the given center coordinates.")
|
114 |
|
@@ -137,10 +137,12 @@ def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15, clutter = "No"):
|
|
137 |
return [x_0, x_1], [y_0, y_1]
|
138 |
|
139 |
increment = 2*mt.pi/ray_count
|
|
|
140 |
for angle in np.arange(0, 2 * np.pi, increment):
|
141 |
# dx = mt.cos(angle)
|
142 |
# dy = mt.sin(angle)
|
143 |
if is_angle_between(angle, lower_angle, upper_angle):
|
|
|
144 |
plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
145 |
|
146 |
else:
|
@@ -148,10 +150,12 @@ def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15, clutter = "No"):
|
|
148 |
x, y = draw_line(angle)
|
149 |
ax.plot(x, y, color='red', lw=1, zorder=5)
|
150 |
# plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
151 |
-
ax.set_title(f'Rays with shadow from a perfectly reflective circle,\nCenter
|
152 |
plt.grid(True)
|
153 |
plt.show()
|
154 |
fig.canvas.draw()
|
155 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
156 |
plt.close(fig)
|
157 |
-
|
|
|
|
|
|
101 |
delta = mt.asin(r / d)
|
102 |
except:
|
103 |
inside_circle_plotter()
|
104 |
+
ax.set_title(f'Rays origin - (0,0). From inside a perfectly reflective circle\nCenter-({a},{b}), Radius-{r}')
|
105 |
plt.grid(True)
|
106 |
plt.show()
|
107 |
|
108 |
fig.canvas.draw()
|
109 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
110 |
plt.close(fig)
|
111 |
+
return image_array, 100
|
112 |
|
113 |
# raise ValueError("Circle radius is too large for the given center coordinates.")
|
114 |
|
|
|
137 |
return [x_0, x_1], [y_0, y_1]
|
138 |
|
139 |
increment = 2*mt.pi/ray_count
|
140 |
+
total_hits = 0
|
141 |
for angle in np.arange(0, 2 * np.pi, increment):
|
142 |
# dx = mt.cos(angle)
|
143 |
# dy = mt.sin(angle)
|
144 |
if is_angle_between(angle, lower_angle, upper_angle):
|
145 |
+
total_hits += 1
|
146 |
plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
147 |
|
148 |
else:
|
|
|
150 |
x, y = draw_line(angle)
|
151 |
ax.plot(x, y, color='red', lw=1, zorder=5)
|
152 |
# plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
153 |
+
ax.set_title(f'Rays with shadow from a perfectly reflective circle,\nCenter-({a},{b}), Radius-{r}')
|
154 |
plt.grid(True)
|
155 |
plt.show()
|
156 |
fig.canvas.draw()
|
157 |
image_array = np.array(fig.canvas.renderer.buffer_rgba())
|
158 |
plt.close(fig)
|
159 |
+
|
160 |
+
hit_ratio = 100*total_hits / ray_count
|
161 |
+
return image_array, f"{hit_ratio:.1f}"
|