Commit
·
adc8d2e
1
Parent(s):
64b00ed
Add clutter removal option
Browse files- app.py +10 -8
- backend/nonreflecting_ray_tracing.py +4 -3
- backend/reflecting_ray_tracing.py +5 -3
app.py
CHANGED
|
@@ -10,10 +10,11 @@ description1 = (
|
|
| 10 |
iface1 = gr.Interface(
|
| 11 |
fn = nonreflecting_plotter,
|
| 12 |
inputs=[
|
| 13 |
-
gr.Number(label="Circle Center X (a)", value=20),
|
| 14 |
-
gr.Number(label="Circle Center Y (b)", value=20),
|
| 15 |
-
gr.Number(label="Radius (r)", value=15),
|
| 16 |
-
gr.Slider(minimum=3, maximum=1000, step=1, label="Number of Rays", value=50)
|
|
|
|
| 17 |
],
|
| 18 |
outputs="image",
|
| 19 |
live=True,
|
|
@@ -27,10 +28,11 @@ description2 = ("A source of **light** placed at the **origin**. A spherical **R
|
|
| 27 |
iface2 = gr.Interface(
|
| 28 |
fn = reflecting_plotter,
|
| 29 |
inputs=[
|
| 30 |
-
gr.Number(label="Circle Center X (a)", value=20),
|
| 31 |
-
gr.Number(label="Circle Center Y (b)", value=20),
|
| 32 |
-
gr.Number(label="Radius (r)", value=15),
|
| 33 |
-
gr.Slider(minimum=3, maximum=1000, step=1, label="Number of Rays", value=50)
|
|
|
|
| 34 |
],
|
| 35 |
outputs="image",
|
| 36 |
live=True,
|
|
|
|
| 10 |
iface1 = gr.Interface(
|
| 11 |
fn = nonreflecting_plotter,
|
| 12 |
inputs=[
|
| 13 |
+
gr.Number(label="Circle Center X (a)", value=20, info="X coordinate of Circle center"),
|
| 14 |
+
gr.Number(label="Circle Center Y (b)", value=20, info="Y coordinate of Circle center"),
|
| 15 |
+
gr.Number(label="Radius (r)", value=15, info="Radius of the circle"),
|
| 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="image",
|
| 20 |
live=True,
|
|
|
|
| 28 |
iface2 = gr.Interface(
|
| 29 |
fn = reflecting_plotter,
|
| 30 |
inputs=[
|
| 31 |
+
gr.Number(label="Circle Center X (a)", value=20, info="X coordinate of Circle center"),
|
| 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 by the surface."),
|
| 36 |
],
|
| 37 |
outputs="image",
|
| 38 |
live=True,
|
backend/nonreflecting_ray_tracing.py
CHANGED
|
@@ -25,7 +25,7 @@ def is_angle_between(angle, start, end):
|
|
| 25 |
return angle >= start or angle <= end
|
| 26 |
|
| 27 |
|
| 28 |
-
def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50):
|
| 29 |
|
| 30 |
max_dim = max(abs(a), abs(b), r) * 3
|
| 31 |
fig, ax = plt.subplots()
|
|
@@ -99,8 +99,7 @@ def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50):
|
|
| 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 |
-
# continue
|
| 104 |
A = dx**2 + dy**2
|
| 105 |
B = -2 * (a * dx + b * dy)
|
| 106 |
C = a**2 + b**2 - r**2
|
|
@@ -120,6 +119,8 @@ def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50):
|
|
| 120 |
except ValueError:
|
| 121 |
continue
|
| 122 |
else:
|
|
|
|
|
|
|
| 123 |
x, y = draw_line(angle)
|
| 124 |
ax.plot(x, y, color='red', lw=1)
|
| 125 |
|
|
|
|
| 25 |
return angle >= start or angle <= end
|
| 26 |
|
| 27 |
|
| 28 |
+
def nonreflecting_plotter(a = 20, b = 20, r = 15, ray_count = 50, clutter = "No"):
|
| 29 |
|
| 30 |
max_dim = max(abs(a), abs(b), r) * 3
|
| 31 |
fig, ax = plt.subplots()
|
|
|
|
| 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
|
|
|
|
| 119 |
except ValueError:
|
| 120 |
continue
|
| 121 |
else:
|
| 122 |
+
if clutter == "Yes":
|
| 123 |
+
continue
|
| 124 |
x, y = draw_line(angle)
|
| 125 |
ax.plot(x, y, color='red', lw=1)
|
| 126 |
|
backend/reflecting_ray_tracing.py
CHANGED
|
@@ -55,7 +55,7 @@ def plot_reflection_on_circle(ax, angle, center, radius, ray_length=50, color='b
|
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
-
def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15):
|
| 59 |
max_dim = max(abs(a), abs(b), r) * 3
|
| 60 |
fig, ax = plt.subplots()
|
| 61 |
ax.set_xlim(-max_dim, max_dim)
|
|
@@ -66,6 +66,7 @@ def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15):
|
|
| 66 |
|
| 67 |
circle = plt.Circle((a, b), r, color='black', fill=False)
|
| 68 |
ax.add_artist(circle)
|
|
|
|
| 69 |
|
| 70 |
def inside_circle_plotter():
|
| 71 |
"""Function to plot the rays inside the circle"""
|
|
@@ -143,8 +144,9 @@ def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15):
|
|
| 143 |
plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
| 144 |
|
| 145 |
else:
|
| 146 |
-
|
| 147 |
-
|
|
|
|
| 148 |
# plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
| 149 |
ax.set_title(f'Rays with shadow from a perfectly reflective circle,\nCenter - ({a},{b}), Radius {r}')
|
| 150 |
plt.grid(True)
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
+
def reflecting_plotter(a = 20, b = 20, r = 15, ray_count = 15, clutter = "No"):
|
| 59 |
max_dim = max(abs(a), abs(b), r) * 3
|
| 60 |
fig, ax = plt.subplots()
|
| 61 |
ax.set_xlim(-max_dim, max_dim)
|
|
|
|
| 66 |
|
| 67 |
circle = plt.Circle((a, b), r, color='black', fill=False)
|
| 68 |
ax.add_artist(circle)
|
| 69 |
+
ax.plot(a, b, 'ro', markersize=5)
|
| 70 |
|
| 71 |
def inside_circle_plotter():
|
| 72 |
"""Function to plot the rays inside the circle"""
|
|
|
|
| 144 |
plot_reflection_on_circle(ax, angle, center=(a, b), radius=r)
|
| 145 |
|
| 146 |
else:
|
| 147 |
+
if 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 - ({a},{b}), Radius {r}')
|
| 152 |
plt.grid(True)
|