U
U
Uncle_Savva2020-04-21 20:49:13
Programming
Uncle_Savva, 2020-04-21 20:49:13

How can gravity be programmed?

I want to make a starry sky type program, i.e. there will be some bodies (stars) that will be attracted to each other, their trajectory will be distorted, and in the end they will merge into one star. Please tell me in which direction to dig? I have already seen attempts to implement this, for example https://habr.com/ru/post/265211/, but there the stars simply fly through each other and do not merge into a single whole.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Ronald McDonald, 2020-04-21
@Zoominger

Wow, we have a Nobel Prize bid here.
As you solve the three-body problem, you can immediately go to Uganda (or where it is issued there).
I'm serious, this will be an insurmountable problem for you, unless, of course, you just have two stars.

D
Daddy_Cool, 2020-04-30
@Daddy_Cool

The level of detail is not very clear.
1. The task of gravitational interaction is relatively easy to program
en.wikipedia.org/wiki/Problem_of_three_bodies
you will have not three bodies, but many (N bodies). Those. you will need to solve a system of 3N ordinary differential equations.
The solution will be wrong (due to instability), but in general they are similar to the truth.
2. You also need to take into account that you do not have material points, but balls - i.e. when moving stars, take into account the distance not only between the centers, but also between the surfaces - when the surfaces touched - the merging begins.
3. How to describe the merging of stars. It's already difficult here. A star is a liquid. If you want to see how the surface shape changes, you need to solve the Navier-Stokes equation (well, or maybe just Euler) with the introduced electromagnetic and gravitational forces and track the surface shape by some method - for example, VOF (Volume of fluid). well, that's how it really is. If you just play around, then knowing the total volume, you can simply merge the stars like droplets without thinking about physics.
Good luck!

S
Sergey Sokolov, 2020-04-21
@sergiks

Maybe ready to look? For example harttle/universe ( demo )

X
xmoonlight, 2020-04-22
@xmoonlight

You need to look in the direction of the vector field towards the surface.
The easiest way is to do it with a magnetic field.
And when the bodies touch - "turn on" the flow of masses into each other at the point of contact according to the principle of a damped pendulum.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question