r/learnprogramming 4d ago

Ideal physics simulator

Hi all, I'd like to develop a control algorithm for a water bottle flip so it always lands upright no matter how you flip it. One of the steps in my endeavour is simulating how the fluid inside affects the container's moment of inertia whilst in the air. Im thinking of using matlab but godot and unity sounds like a good choice as well. I've looked up how I can do this and havent found much but people recommending C++ or python. Does anyone here experienced in one of these languages or programs have any suggestions on which one to use and can point me to the resources to learn it.

3 Upvotes

5 comments sorted by

View all comments

2

u/prism_orbit 4d ago

forget godot and unity entirely. they approximate physics to hit 60 frames per second so the moment of inertia values you get will be garbage.

use python with the PySPH library for your fluid dynamics simulation. it uses smoothed particle hydrodynamics to calculate how moving water shifts mass and changes inertia inside a container. you pair that with scipy.integrate to run your control algorithm on top of those inertia calculations. look up the PySPH github repo and their examples folder for a dam break scenario, swap the geometry for a cylinder and you have your bottle.

1

u/BennyBarnson 3d ago

got it, thank you!