From f6d2141a480dd6b5b8ee0e48d43bb64773232791 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 26 Mar 2024 23:38:14 -0600 Subject: add header ids --- docs/posts/2023-04-30-n-body-simulation.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'docs/posts/2023-04-30-n-body-simulation.html') diff --git a/docs/posts/2023-04-30-n-body-simulation.html b/docs/posts/2023-04-30-n-body-simulation.html index 1174d27..9a7c7a2 100644 --- a/docs/posts/2023-04-30-n-body-simulation.html +++ b/docs/posts/2023-04-30-n-body-simulation.html @@ -6,13 +6,13 @@ - n-body solution generator + id="n-body-solution-generator">n-body solution generator - - + n-body solution generator" /> + n-body solution generator" /> @@ -44,7 +44,7 @@
-

n-body solution generator

+

n-body solution generator

This post requires JavaScript to be viewed properly :(

@@ -61,7 +61,7 @@

To workaround memory issues, the simulations are only run on-demand when the user clicks the respective button. Scroll down to the bottom of the page to see the results.

-

The n-body problem

+

The n-body problem

The n-body problem is a classic puzzle in physics (and thus astrophysics) and mathematics that deals with predicting the motion of multiple celestial objects that interact with each other through gravitational forces.

@@ -71,7 +71,7 @@

As the number of objects increases, finding an exact solution becomes impossible, and we rely on analytical approximations.

-

Visualising a basic orbit

+

Visualising a basic orbit

If we want to create a n-body simulation in our browser, we need to figure out how we are going to visualise the motion of the objects. There are a few ways to do this, but the easiest is to use Plotly.js, a JavaScript library for creating interactive graphs. (An alternative is to use the HTML5 canvas element).

@@ -138,7 +138,7 @@ Next, the function dR takes the position r and velocity v of Earth as input and

Finally, we normalize the position data by dividing it by the astronomical unit (AU) to make it more visually meaningful. We also create a circle for reference, which represents a perfect circular orbit. The code ends with the data for the Sun's position, Earth's orbit, and the reference circle ready to be plotted.

-

Plotting the orbit

+

Plotting the orbit

Now that we have the data for the Sun's position, Earth's orbit, and the reference circle, we can plot them using Plotly.js.

@@ -212,7 +212,7 @@ Next, the function dR takes the position r and velocity v of Earth as input and -

Figure of 8 orbit

+

Figure of 8 orbit

The figure of 8 solution[2] in the three-body problem refers to a unique and special trajectory where three celestial bodies (e.g., planets, stars) move in a figure of 8 shaped pattern around their mutual center of mass. This is special because it represents a stable and periodic solution to the three-body problem, which is known for its complexity and lack of general solutions.

@@ -226,7 +226,7 @@ Next, the function dR takes the position r and velocity v of Earth as input and
  • It looks cool!

  • -

    Show me the code

    +

    Show me the code

    The code for this simulation is very similar to the Earth-Sun orbit simulation, except that we now have three bodies instead of two. We also use a different set of initial conditions to generate the figure of 8 orbit.

    @@ -318,7 +318,7 @@ Next, the function dR takes the position r and velocity v of Earth as input and

    Finally, a loop iterates over each time step, updating the positions and velocities of the celestial bodies using the step function. The updated coordinates are stored in the X, Y, VX, and VY arrays.

    -

    Animation?

    +

    Animation?

    Now that we have time-series data, we need to animate it. We can use Plotly's animate function, as this does not force a full re-render, saving us some precious GPU and CPU cycles when we are trying to run this in the browser itself

    @@ -438,9 +438,9 @@ Next, the function dR takes the position r and velocity v of Earth as input and -

    "General" N-Body Solver

    +

    "General" N-Body Solver

    -

    Show me the code!

    +

    Show me the code!

    function step(coords, masses, deltaT, nBodies = 3, G = 6.67408313131313e-11) {
    @@ -675,7 +675,7 @@ Next, the function dR takes the position r and velocity v of Earth as input and
     
    -

    Playground

    +

    Playground

    @@ -759,7 +759,7 @@ function plotRandomNBodySimulation() { -

    References

    +

    References

    1. Barrow-Green, June (2008), "The Three-Body Problem", in Gowers, Timothy; Barrow-Green, June; Leader, Imre (eds.), The Princeton Companion to Mathematics, Princeton University Press, pp. 726–728
    2. -- cgit v1.2.3