Ordinate 2D Marketplace Community Open the studio

Marketplace › From Ordinate 2D

Experiment: launch angles and range

Script by Ordinate 2D ✓ · Mechanics

Launch a ball at five angles, one after the other; the table has the range against R = v₀² sin 2θ / g.

Use in Ordinate 2DOpens in the Script tab: it runs when you press Run. Free, no account needed.
"""Experiment: how far a ball flies against its launch angle (no air), against R = v0² sin(2θ) / g.

One run: each time the ball comes back down to its launch height the script records the range, puts the ball back at
the start and launches it at the next angle. The rows go to the Script sheet (Table tab) — chart range against angle.

Runs in the studio (Script tab → Run) and locally:  python3 projectile_sweep.py
"""
import math
import studio as s

V0 = 8.0                          # launch speed, m/s
ANGLES = [15, 30, 45, 60, 75]     # degrees

s.clear()
s.gravity = (0, -9.81)
s.air_density = 0
s.ground(-0.5, width=30)
ball = s.circle(0, 0, 0.08, mass=0.2, name="Ball", color="#e5484d", collide=False)
shot = 0


def launch():
    a = math.radians(ANGLES[shot])
    ball.position = (0, 0)
    ball.velocity = (V0 * math.cos(a), V0 * math.sin(a))


launch()


@s.on_step
def watch(t, dt):
    global shot
    if ball.vy < 0 and ball.y <= 0:                       # back at the launch height, on the way down
        x = ball.x - ball.y * ball.vx / ball.vy           # where it crossed y = 0 within the last step
        g = -s.gravity[1]
        theory = V0 ** 2 * math.sin(2 * math.radians(ANGLES[shot])) / g
        s.record(angle=ANGLES[shot], range=x, theory=theory, error_pct=100 * (x - theory) / theory)
        print(f"{ANGLES[shot]:>3}°: range {x:.3f} m, theory {theory:.3f} m")
        shot += 1
        if shot < len(ANGLES):
            launch()
        else:
            s.stop()


s.run(30)

table experiment events