My God, It’s Full Of Stars: The N-Body-Problem Series

I thought it would be a very nice idea to start my blog with a small project I wanted to do since a long time. A small tool/solver of the n-body-problem. It’s not just only the interest of solving a challenging mathematical problem with modern C++. I also love clean, concise and readable code, which is also something I would like to train and share with this project. You can find the empty repository setup at GitHub. I will always try to tag the end state of the repository after each post of this blog series.

So lets start with the bare minimum of theory we need. We want to start with a simple example of two still standing masses (or stars if you like) which get attracted to each other. For the sake of simplicity we consider them as point masses which mean they are infinitesimal small, or in other words, they have no volume.

Kinematics
Kinematic quantities of a classical particle of mass m: position r, velocity v, acceleration a [Wikipedia]

From the image above we can see that a particle is moving the path dr , with its velocity v and accelerated by a . From this point we get the equations of motion of one such point as

r=r_{0}+vt+\frac{1}{2}at^{2}

with r as the resulting position, r_{0} as the starting position, v as the velocity, t as the time step and a as the acceleration. We also know that the force is defined by the product of mass m and the acceleration a

F=ma

We know as well that the force due to gravity between two masses can be calculated as

F=G\frac{m_{1}m_{2}}{r^2}

with the gravitational constant G the two masses of them and their distance r . With the equations of the force and the force due to gravity, we can derive the acceleration a a mass point is experiencing while he is attracted by another mass point.

a=G\frac{m_{1}m_{2}}{m_{1}r^2}

As a result we get our final equation which is deriving the change of position of a mass point by its starting position, its velocity and its acceleration.

r=r_{0}+vt+\frac{1}{2}G\frac{m_{1}m_{2}}{m_{1}r^2}t^{2}

With this I will close this post and we will proceed next time with setting up a basic CMAKE example project which is building our solver library and a separate test library.

Did you like this post?

What are your thoughts on this post?

Feel free to comment and share the post.

Processing…
Success! You're on the list.

9 thoughts on “My God, It’s Full Of Stars: The N-Body-Problem Series

    1. Yes and no, yes they have no volume, but they have mass. These objects are called point masses and their property is to be infinite small (singularity) but have full mass of the object. Therefore m > 0

      Like

  1. Is there any reason you don’t simplify your expression for “a” so that is “a = G*(m_2 / r^2)” ? (sorry, I don’t know if your comment boxes allow LaTeX or similar)! Excited to see the rest of these articles

    Like

    1. Just for sake of readability. You’re right, clearly m_1 has no meaning in the equation anymore, and it would have been also better to name a into a_1.

      Like

      1. Oh good, I was worried I greatly missed something. I do like the subscript idea, but I’m joining your party late so don’t let me get in the way.

        Like

  2. Wouldn’t be better to use two distinct variable names for the position (r) and the distance between the two particles (r). I suggest using p for the position and keep using r for the distance between the particles

    Like

Leave a Reply to bmahr Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.