Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,58 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
with gr.Blocks() as demo:
|
4 |
-
gr.Markdown("""
|
5 |
-
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
where $x$ is the horizontal displacement, $x_0$ is the initial horizontal position, $v_0$ is the initial velocity, $\theta$ is the angle at which the projectile is launched, and $t$ is the time.
|
10 |
|
11 |
To find the range of the projectile, we need to find the time at which it hits the ground (i.e., when its vertical displacement becomes zero). The vertical displacement of a projectile at any time can be calculated using the following kinematic equation:
|
12 |
|
13 |
-
|
14 |
|
15 |
where $y$ is the vertical displacement, $y_0$ is the initial vertical position, $v_0$ is the initial velocity, $\theta$ is the angle at which the projectile is launched, $t$ is the time, $g$ is the acceleration due to gravity, and $t$ is the time.
|
16 |
|
17 |
To find the time at which the projectile hits the ground, we can set the vertical displacement to zero and solve for $t$. This gives us the following equation:
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
Solving for $t$, we get:
|
22 |
-
|
23 |
-
$$t = \frac{v_0 \sin \theta \pm \sqrt{v_0^2 \sin^2 \theta + 2gy_0}}{g}$$
|
24 |
|
25 |
-
|
26 |
|
|
|
27 |
""")
|
28 |
|
29 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
def plot(v, a):
|
6 |
+
g = 9.81
|
7 |
+
theta = a / 180 * 3.14
|
8 |
+
tmax = ((2 * v) * np.sin(theta)) / g
|
9 |
+
timemat = tmax * np.linspace(0, 1, 40)[:, None]
|
10 |
+
|
11 |
+
x = (v * timemat) * np.cos(theta)
|
12 |
+
y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
|
13 |
+
|
14 |
+
trajectory = pd.DataFrame({'x': x.flatten(), 'y': y.flatten()})
|
15 |
+
return trajectory
|
16 |
+
|
17 |
|
18 |
with gr.Blocks() as demo:
|
19 |
+
gr.Markdown(r"""
|
20 |
+
# Range of a Projectile
|
21 |
|
22 |
+
The range of a projectile is the horizontal distance it travels during its motion. You can see how the range changes as you adjust the initial speed and angle of the projectile:
|
23 |
+
|
24 |
+
""")
|
25 |
+
|
26 |
+
with gr.Row():
|
27 |
+
speed = gr.Slider(1, 30, 25, label="Speed")
|
28 |
+
angle = gr.Slider(0, 90, 45, label="Angle")
|
29 |
+
|
30 |
+
output = gr.ScatterPlot(None, 'x', 'y')
|
31 |
+
speed.change(plot, [speed, angle], output)
|
32 |
+
angle.change(plot, [speed, angle], output)
|
33 |
+
demo.load(plot, [speed, angle], output)
|
34 |
+
|
35 |
+
gr.Markdown(r"""
|
36 |
+
|
37 |
+
The horizontal displacement of a projectile at any time can be calculated using the following kinematic equation:
|
38 |
+
|
39 |
+
$x = x_0 + v_0 \cos \theta \cdot t$
|
40 |
|
41 |
where $x$ is the horizontal displacement, $x_0$ is the initial horizontal position, $v_0$ is the initial velocity, $\theta$ is the angle at which the projectile is launched, and $t$ is the time.
|
42 |
|
43 |
To find the range of the projectile, we need to find the time at which it hits the ground (i.e., when its vertical displacement becomes zero). The vertical displacement of a projectile at any time can be calculated using the following kinematic equation:
|
44 |
|
45 |
+
$y = y_0 + v_0 \sin \theta \cdot t - \frac{1}{2}gt^2$
|
46 |
|
47 |
where $y$ is the vertical displacement, $y_0$ is the initial vertical position, $v_0$ is the initial velocity, $\theta$ is the angle at which the projectile is launched, $t$ is the time, $g$ is the acceleration due to gravity, and $t$ is the time.
|
48 |
|
49 |
To find the time at which the projectile hits the ground, we can set the vertical displacement to zero and solve for $t$. This gives us the following equation:
|
50 |
|
51 |
+
$0 = y_0 + v_0 \sin \theta \cdot t - \frac{1}{2}gt^2$
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
Solving for $t$, we get two possible solutions, but since the projectile will hit the ground at a later time, we need to take the positive value of $t$. Substituting this value into the equation for horizontal displacement and using a trigonometric identity, we get the following equation for the range of the projectile:
|
54 |
|
55 |
+
$R = v_0^2 \cdot \frac{\sin(2\theta)}{g}$
|
56 |
""")
|
57 |
|
58 |
demo.launch()
|