Skip to content

Code to estimate and simulate the trajectory of a ball undergoing projectile motion with a linear drag model.

Notifications You must be signed in to change notification settings

TanWeiXuan/Simple_Ball_Trajectory_Estimation_And_Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Ball Trajectory Estimation And Simulation

Code to estimate and simulate the trajectory of a ball undergoing projectile motion.

Trajectory is modeled using linear drag (see Wiki)

Trajectory Modelling

The estimator in misc/estimate_ball_trajectory.py assumes the ball follows a linear-drag model:

  • Velocity: dv/dt = g - β v
  • Position: dp/dt = v

For a time offset Δt = t - t₀, the closed-form solution becomes:

  • p(t) = p₀ + A(Δt, β) v₀ + B(Δt, β) g
  • v(t) = exp(-β Δt) v₀ + A(Δt, β) g
  • A = (1 - exp(-β Δt)) / β
  • B = Δt/β - (1 - exp(-β Δt)) / β²

When β → 0, the model smoothly reduces to the standard ballistic solution (A → Δt, B → 0.5 Δt²).

Trajectory Estimation

The fit_trajectory method of the BallTrajectoryEstimator class in misc/estimate_ball_trajectory.py fits the parameters p₀, v₀, and drag β using timestamped position measurements (Time, TX, TY, TZ). The implemented method is:

  1. Data validation: requires at least N recent samples with finite values and sufficient upward Z velocity before fitting.
  2. Solve for β = 0 baseline: computes a no-drag solution for comparison.
  3. Optimize drag coefficient: performs a 1D search over β (bounded between beta_min and beta_max) with SciPy's minimize_scalar.
  4. Variable projection for p₀ and v₀: for each candidate β, solves the linear system p = p₀ + A v₀ + B g via least squares to obtain the best p₀ and v₀.
  5. Select best fit: keeps the (p₀, v₀, β) combination with the lowest sum of squared residuals and stores it for prediction.

Predicted positions use the stored parameters and the same closed-form equations to evaluate p(t) for any desired timestamps.

Misc:

  • Included is BallTrajectoryEstimator_KalmanFilter in misc/estimate_ball_trajectory.py, that estimates trajectories using a Linear Kalman Filter and a gravity only model.

About

Code to estimate and simulate the trajectory of a ball undergoing projectile motion with a linear drag model.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published