Kinematics

Adapted from Gradio Playground.

Code
import pandas as pd
import numpy as np
import gradio as gr


def plot(v, a):
    g = 9.81
    theta = a / 180 * 3.14
    tmax = ((2 * v) * np.sin(theta)) / g
    timemat = tmax * np.linspace(0, 1, 40)

    x = (v * timemat) * np.cos(theta)
    y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2))
    df = pd.DataFrame({"x": x, "y": y})
    return df


with gr.Blocks() as demo:
    gr.Markdown(
        r"""
        Let's do some kinematics! Choose the speed and angle to see the trajectory. 
        Remember that the range $R = v_0^2 \cdot \frac{\sin(2\theta)}{g}$
        """,
        latex_delimiters=[{"left": "$", "right": "$", "display": False}]
    )
    
    with gr.Row():
        speed = gr.Slider(1, 30, value=25, label="Speed")
        angle = gr.Slider(0, 90, value=45, label="Angle")
        
    plot_output = gr.LinePlot(
        x="x",
        y="y",
        overlay_point=True,
        tooltip=["x", "y"],
        x_lim=[0, 100],
        y_lim=[0, 60],
        width=350,
        height=300
    )
    
    speed.change(plot, [speed, angle], plot_output)
    angle.change(plot, [speed, angle], plot_output)

if __name__ == "__main__":
    demo.launch()
import pandas as pd import numpy as np import gradio as gr def plot(v, a): g = 9.81 theta = a / 180 * 3.14 tmax = ((2 * v) * np.sin(theta)) / g timemat = tmax * np.linspace(0, 1, 40) x = (v * timemat) * np.cos(theta) y = ((v * timemat) * np.sin(theta)) - ((0.5 * g) * (timemat**2)) df = pd.DataFrame({"x": x, "y": y}) return df with gr.Blocks() as demo: gr.Markdown( r""" Let's do some kinematics! Choose the speed and angle to see the trajectory. Remember that the range $R = v_0^2 \cdot \frac{\sin(2\theta)}{g}$ """, latex_delimiters=[{"left": "$", "right": "$", "display": False}] ) with gr.Row(): speed = gr.Slider(1, 30, value=25, label="Speed") angle = gr.Slider(0, 90, value=45, label="Angle") plot_output = gr.LinePlot( x="x", y="y", overlay_point=True, tooltip=["x", "y"], x_lim=[0, 100], y_lim=[0, 60], width=350, height=300 ) speed.change(plot, [speed, angle], plot_output) angle.change(plot, [speed, angle], plot_output) if __name__ == "__main__": demo.launch()