This repository explores a simple but interesting question: can a neural network learn the flight trajectory of a badminton shuttlecock from a small set of initial conditions?
The project combines two layers:
- A physics-inspired simulator for shuttlecock motion with gravity and linear drag.
- A neural network surrogate model that learns to predict the full trajectory directly from the initial shot conditions.
Rather than treating the problem as a pure black box, this project first generates synthetic trajectory data from a simplified physical model and then trains a multilayer perceptron (MLP) to imitate that mapping.
A shuttlecock behaves very differently from many standard projectiles because aerodynamic drag is large and the speed decays rapidly after impact. In this repository, the trajectory is modeled using:
- gravity
- a simplified drag term
- initial launch conditions provided by the user
The model takes four input variables:
- initial speed (
v0, km/h) - contact height (
height, m) - launch angle (
angle, degrees) - initial court position (
x_init, m)
The output is the full predicted trajectory over time, represented as a sequence of:
- horizontal position
x - vertical position
y - time
t
The workflow is:
initial shot parameters → physics-based simulator → synthetic dataset → neural network training → trajectory prediction
This makes the repository a small hybrid modeling project:
- the simulator provides structured training data
- the MLP acts as a fast surrogate for trajectory prediction
shuttlecock_flight_train.py # data generation, model training, loss curve, example prediction
shuttlecock_flight_test.py # model loading, interactive inference, comparison with simulator output
The repository defines a Shuttlecock class that updates position and velocity step by step under gravity and drag. This is used to generate reference trajectories.
A dataset is created by sampling random initial conditions across a specified range and simulating the corresponding shuttlecock paths.
Each sample contains:
- a 4D input vector of launch conditions
- a resampled trajectory with a fixed number of time steps
A multilayer perceptron is trained to map the 4D input directly to the full trajectory sequence.
The network predicts a trajectory tensor of shape:
(200, 3)
corresponding to:
[x, y, t]
at 200 time steps.
After training, the model can be used to predict a shuttlecock path for user-provided launch conditions. The scripts visualize the predicted trajectory and, in the test script, also compare it with the simulator-based trajectory.
At the moment, the scripts are still close to their original Google Colab form. In particular:
- the code uses interactive
input()prompts - model weights are saved to / loaded from Google Drive paths
- the repository is best viewed as a project prototype / coursework-style implementation, not yet a fully packaged Python project
That is completely fine for a learning and demonstration repository, but it also means some path adjustments may be needed if you want to run it locally outside Colab.
This project is small, but it touches on several useful ideas:
- physics-based simulation
- synthetic data generation
- surrogate modeling
- neural network regression for time-series outputs
- visualization of model predictions
It is also a nice example of using machine learning not as a replacement for physical reasoning, but as a compact approximation to a known simulation pipeline.
Natural next steps for this repository would be:
- refactor the Colab-exported scripts into cleaner Python modules
- remove hard-coded Google Drive paths
- add a requirements file
- save example figures in the repository
- evaluate prediction error quantitatively on a held-out test set
- compare the MLP with alternative models such as RNNs, CNN-based sequence predictors, or physics-informed approaches
This is a simplified modeling project. The shuttlecock dynamics implemented here are not intended to be a high-fidelity aerodynamic model of real badminton play. The goal is to explore the pipeline from simulation to learning-based approximation.
这个仓库围绕一个很直观但也很有意思的问题展开:能不能只根据几个初始击球条件,让神经网络预测羽毛球完整的飞行轨迹?
项目由两层组成:
- 一个带有重力和简化阻力项的物理启发式轨迹模拟器
- 一个学习该映射关系的神经网络代理模型(surrogate model)
也就是说,这不是一个纯黑箱项目。这里先用一个简化的物理模型生成合成轨迹数据,再训练多层感知机(MLP)去逼近“初始条件 → 整条轨迹”这条映射。
羽毛球和一般抛体很不一样。它的空气阻力很大,击出后速度衰减也很快。因此,这个项目没有把它当作最普通的抛物线,而是用一个包含以下因素的简化模型来描述:
- 重力
- 简化阻力项
- 用户给定的初始击球条件
模型输入包含 4 个变量:
- 初速度
v0(km/h) - 击球点高度
height(m) - 击球仰角
angle(degree) - 击球位置
x_init(m)
模型输出是整条飞行轨迹,用随时间变化的一系列点表示,包括:
- 水平位置
x - 竖直位置
y - 时间
t
整个流程可以概括为:
击球初始参数 → 基于物理的轨迹模拟 → 合成数据集 → 神经网络训练 → 轨迹预测
所以这个仓库本质上是一个小型的混合建模项目:
- 模拟器负责提供结构化训练数据
- MLP负责学习一个快速的近似映射
shuttlecock_flight_train.py # 数据生成、模型训练、loss 曲线、示例预测
shuttlecock_flight_test.py # 加载模型、交互式测试、与模拟器轨迹对比
仓库中定义了一个 Shuttlecock 类,在重力和阻力作用下逐步更新羽毛球的位置和速度,并据此生成参考轨迹。
程序会在给定范围内随机采样初始条件,并调用模拟器生成对应的轨迹数据。
每个样本包含:
- 一个 4 维输入向量(击球条件)
- 一条经过统一重采样的固定长度轨迹
这里使用一个多层感知机(MLP),直接学习从 4 维输入到整条轨迹序列的映射关系。
网络输出的轨迹张量形状为:
(200, 3)
对应 200 个时间步上的:
[x, y, t]
训练完成后,可以输入新的击球条件,让模型预测轨迹,并将预测结果可视化。在测试脚本中,还会把神经网络预测轨迹与模拟器轨迹放在一起进行直观比较。
目前这两个脚本仍然比较接近最初的 Google Colab 导出形式。具体来说:
- 代码中使用了交互式
input()输入 - 模型权重保存和读取依赖 Google Drive 路径
- 这个仓库目前更适合被看作一个原型性质 / 课程项目风格的实现,而不是已经彻底工程化封装好的 Python 项目
这本身没有问题,作为学习和展示用项目是完全成立的。但如果你想在本地环境里直接运行,通常还需要对路径和组织方式做一些整理。
虽然项目规模不大,但它覆盖了几个很有代表性的思路:
- 基于物理的模拟
- 合成数据生成
- surrogate modeling(代理建模)
- 面向时间序列输出的神经网络回归
- 预测结果可视化
更重要的是,它体现的不是“拿机器学习替代物理”,而是:先有结构化模拟,再让机器学习去近似这个模拟器。
这个仓库后续很自然的改进方向包括:
- 把 Colab 导出的脚本重构成更清晰的 Python 模块
- 去掉硬编码的 Google Drive 路径
- 增加
requirements.txt - 在仓库中保存示例结果图
- 在独立测试集上定量评估预测误差
- 将 MLP 与 RNN、序列卷积模型或 physics-informed 方法做比较
这是一个简化建模项目。这里采用的羽毛球动力学并不是高保真空气动力学模型,不能把它直接看作对真实比赛中羽毛球飞行的精确复现。这个项目的重点是展示一条从简化物理模拟到学习型近似模型的完整流程。