Project 17: Ballistics and Trigonometry Simulator
A self-contained deep-dive from the canonical Math from Foundations to Machine Learning curriculum.
- Difficulty: Beginner-Intermediate
- Time: 8-14 hours
- Language: Python (alternatives: JavaScript, C++)
- Prerequisites: Projects 5 and 16
- Source:
HS P03
What You Will Build
Build a deterministic projectile-motion simulator for a constant-gravity, no-air-resistance world. Accept launch speed, angle, initial height, gravitational acceleration, and time step with explicit units. Decompose the launch velocity with sine and cosine, compute analytic position, flight time, horizontal range, and maximum height, then independently advance the state with fixed discrete time steps. Plot the trajectory and velocity components, interpolate the landing event between samples, and report analytic-versus-simulated error as the step size changes.
Real World Outcome
A command such as --speed 30 --angle 45 --height 2 --dt .02 prints initial velocity components, predicted apex, flight time, and range; saves a labeled trajectory; and tabulates simulation errors. A step-size sweep visibly converges toward the analytic solution. Impossible or ambiguous inputs—negative speed, nonpositive gravity, unsupported units—fail with deterministic messages.
Core Question
How do trigonometric components and constant-acceleration equations predict a curved trajectory, and what error appears when continuous motion is sampled in discrete time?
Concepts You Must Understand First
- Unit-circle trigonometry: horizontal and vertical components are
v cos θandv sin θ. - Position, velocity, and acceleration: gravity changes vertical velocity at a constant rate.
- Projectile equations:
x=x0+vxtandy=y0+vyt-(g/2)t^2form a parabola. - Quadratic root selection: landing time is the meaningful future root of
y(t)=0. - Time stepping and interpolation: a simulated point may pass below ground between samples.
Build Milestones
- Validate parameters/units and derive horizontal and vertical velocity components.
- Implement analytic position, apex, landing time, and range with edge-case classification.
- Implement fixed-step simulation and stop/interpolate at ground crossing.
- Plot trajectory and component/time graphs; annotate launch, apex, and landing.
- Run step-size sweeps and compare metrics against analytic references.
Hints in Layers
- Solve the vertical quadratic for time and select the largest nonnegative root.
- Keep analytic and simulated implementations separate so one can validate the other.
- When consecutive y values straddle zero, linearly interpolate the final time/x instead of accepting a below-ground sample.
Common Pitfalls and Debugging
- Symptom: a 45-degree shot travels almost nowhere. Cause: degrees were passed directly to radian trig functions. Fix: convert once at input and test cardinal angles.
- Symptom: the simulated range jumps as
dtchanges. Cause: landing was rounded to the first below-ground point. Fix: interpolate the crossing and report residual error. - Symptom: initial height produces the wrong flight time. Cause: a ground-launch shortcut was used. Fix: solve the full vertical equation.
Definition of Done
- Inputs use explicit units and enforce valid ranges.
- Analytic metrics match hand-computed baseline cases.
- Simulation tracks position/velocity and interpolates landing.
- Plots label launch, apex, landing, axes, and units.
- Step-size experiments demonstrate and quantify convergence.
- Documentation states the no-drag/flat-ground assumptions.
Navigation
Previous: Project 16 · Complete learning path · Next: Project 18