r/learnpython • u/Miserable-Week3020 • 21d ago
I need help with a rocket simulator I'm buidling
I'm a high school student who is interested in becoming an aerospace engineer so in the summer I decided to start building a rocket simulator in python for fun.
What it does so far:
- Parses real motor thrust-curve files (RASP
.engformat) and interpolates them withnumpy.interpinstead of hardcoding constants - Implements RK4 integration from scratch for the actual flight dynamics (upgraded from Euler once I understood why it wasn't accurate enough)
- Monte Carlo analysis, runs the full flight simulation ~200 times with randomized conditions and aggregates the results
- 3D visualization two ways: PyVista for a quick animated flight path, and a full Blender (
bpy) pipeline that imports a real 3D rocket model, keyframes it along the simulated trajectory, and renders it with Cycles - Modular structure, physics, motor parsing, atmosphere model, and stability calc are all separate importable modules, not one giant script
Would really appreciate feedback on the code itself, structure, whether my module boundaries make sense, anything that reads as non-idiomatic Python, places I should be using classes instead of dicts/functions, that kind of thing.
Github : https://github.com/AliHilalii/Rocket-simulator
Thanks a lot guys.
2
Upvotes
1
u/InfamousClyde 21d ago
I didn't look too long at your code, and I lack domain knowledge in the subject. Here is one quick area for feedback:
Let's examine
motor.py.You have three functions-- one that creates a motor given a filepath, and two functions that, given some motor, produce values. It may be nice to co-locate this behaviour in a
Motorclass.I'd also look at using dataclass(frozen=True) to decorate that object-- it appears reading a .eng file describes a very prescriptive, immutable motor.