projectchrono / chrono

High-performance C++ library for multiphysics and multibody dynamics simulations
http://projectchrono.org
BSD 3-Clause "New" or "Revised" License
2.18k stars 456 forks source link

Gravitational force by a planet/moon #511

Closed wedesoft closed 1 week ago

wedesoft commented 3 weeks ago

Hi, I would like to use ProjectChrono for a space simulator. How can I implement a force (i.e. gravitation) which depends on the position of a spacecraft relative to a planet's or moon's position in order to simulate takeoff, orbiting and landing of a spacecraft? Kind regards Jan

wedesoft commented 3 weeks ago

Also the position of the planet or especially moon can change over time.

rserban commented 3 weeks ago

The most flexible way to do this is probably to use ChLoadBodyBody.

Derive your own class from this and implement the virtual method ComputeBodyBodyForceTorque. You can access the two bodies with GetBodyA and GetBodyB to get their current positions and orientations.

See ChLoadBodyBodyBushingGeneric for an example.

wedesoft commented 3 weeks ago

Thanks for your response! Ok, will try. In the past I have successfully used Runge Kutta 4 integration to get stable orbits :)

wedesoft commented 3 weeks ago

Awesome, it seems to work as long as the time steps are small enough (source code: chronoorbit.cc). I had to compile it with option -DEIGEN_MAX_ALIGN_BYTES=32 because it was crashing otherwise. orbit

wedesoft commented 1 week ago

Thanks 👍