Skip to content
Curious Nikhil
Go back

Solar System Simulator

alt text

What is it?

This is a Solar System Simulator. It simulates the motion of planets in realtime using some pretty complex maths and also is able to plan interplanatry missions (not yet)

LINK TO PROGRAM

Solar System Animated

Why am I doing it?

Am a big fan of space flight and the journey it has still to cover. Nasa’s Curiosity Rover or ISRO’s Martian Orbital Mission truely inspired me,of how a group of like minded people can set out to do something impossible on the face of the planet.I love reading books, especially sci fi books, one of favourite is The Martian. Andy Weir the author of The Martian, used a physics simulator to simulate the motion of his fictional ship (Ares V) with respect to earth and mars, so that he could write in accurate dates in his book (Watch the video below for more context)

That was the starting point of this project. Back then, it didnt make any sense to start learning programming, but now since I had a goal to achieve, everything was different. Rest is history…

Why build a Solar System Simulator, in the first place, right? Why fuss over, complex Javascript Programming language when there are tonnes of way better software that simulate the universe, like Stellarium and NASA’s Eye. The answer to this is simple - it is the very fundamental character of human - DIY Life.

I love making things on my own, and I feel everyone feels the same way unless you are lazy. By doing projects as such, you are bound to change your perspective of the world, as you stop taking things for granted. When you programme something as COOL as this, you are stepping into a new world.

How does it work?

alt text

That’s a great question!

There are two way to build one of these sims (simulators): Accurate and not so accurate. Well I started of with the formal, and ever since have transversed to the latter eventually. I would recommend, building a simple planetary orbit first to understand the basic of programming and polar to cartesian coordinate conversions.(I am still a beginner) Yet, below is complete breakdown of how it works. Early flowchart


Calculations Flowchart


Version History

Version 1 - MAY 2017

Version 2 - JULY 2017

Version 3 - SEP 2017

Version 4 - Jan 2018


BUGS

WHAT TO DO?

Ideas

Inspiration

Milestones

Intro

So, maybe that’s not enough for you to step into programming simulation or just about anything that doesn’t fall in the mainstream category.

As with all things in nature, one can over complicate things or can choose to simplify the chaos. I, on the other hand, will give you two choices - EASY or HARD.

Prerequisites

EASY

  1. Trigonometry
  2. Kepler’s Law
  3. Off Course, Programming Javascript

This is recommended for people who are new to trigonometry and physics.

HARD

  1. All that of EASY
  2. Ellipse
  3. Object Oriented Programming
  4. J2000
  5. Ephemeris
  6. 3D Geometry

Mechanical Basis of Solar System.

If it wasn’t for Nicolaus Copernicus, we would still believed in the Geocentric system. He formulated the model of the universe, where the Sun was in centre, instead of Earth, around which other planets revolved including Earth. It was not readily accepted, by people back in his time. But nowadays taken for granted. Copernicus’s discovery gave rise to the very start of Heliocentric Coordinate System, which is basically GPS for planets in real-time.

EASY - Circular Orbits

It’s highly unlikely that you haven’t seen any pictures of our Solar System. Chances are, 99% of the pictures are depicted wrongly, where planets seem to be orbiting in circular orbits and seem so close to each other. These school - pictures of Solar System are not up to scale. This is inherently, invokes people’s perspective of how far or how big these planets are in reality.

Hence, I wanted to make it my utmost priority to take elliptical orbits into account. To Know More

If you are a beginner and want to just quickly finish. Go with Circular Orbits.A circle is a simple closed shape in Euclidean geometry.It is the set of all points in a plane that is at a given distance from the centre point.

What is a Cartesian Coordinate System?

Every object’s location is defined in such a way that it’s in reference to a universal point.In the Cartesian system, a point on the plane is determined by the distance from the origin in the X - Axis and Y - Axis. So, the point is at (X, Y). For 3D environment - (X, Y, Z).

What is Polar Coordinate System?

Unlike, Cartesian System, a point in Polar Coordinate System is determined by a distance from a reference point and an angle from a reference direction.

Now, it’s just a matter of unifying all the coordinates from different systems. We are going to create our Solar System in a Cartesian Environment. So we need to know the X and Y coordinates of the planet that is orbiting around the sun in a circular fashion.

Let’s find the Polar Coordinates of the Point:

In the Given Triangle ABC,

sin(angle) = Opposite/Hypotenuse cos(angle) = Adjacent/Hypotenuse

So, In triangle ABC,

ABC=θ\angle ABC = \theta

sin(θ)=ACAB=ACr\sin(\theta) = \frac{AC}{AB} = \frac{AC}{r}

cos(θ)=BCr\cos(\theta) = \frac{BC}{r}

cos(θ)=BCr\cos(\theta) = \frac{BC}{r}

BC=rcos(θ)BC = r\cos(\theta)

Voila, BCBC is the distance from the origin to the point in the X Axis and AC is the distance from the origin to the point in the Y Axis.

Therefore,

X=rcos(θ)X = r\cos(\theta)

Y=rsin(θ)Y = r\sin(\theta)

As the planet orbits or revolves around our Sun, The Angle with respect to Sun keeps changing with respect to time. So, now all that we have to do is just make a program that can over time change the angle by a certain amount every second. There you go! that ‘s it! Wasn’t really that hard. We used basics of trigonometry and implemented in our program.

Elliptical Orbits

Orbital Mechanics in Code

Creating an Object is essential as you have to call them many times. 

var earthX = sunX + orbitRadius*cos(angle); var earthY = sunX + orbitRadius*sin(angle);

Finding X, Y and Z Coordinates of the Planet. 

// X - COORDINATE
var hecX = function (hecR, omega, lcomega, hecnu, inclination) {
  var hecX =
    hecR(
      cos(omega) * cos(lcomega + hecnu) -
      sin(omega * cos(inclination) * sin(lcomega + hecnu))
    );
  return hecX;
};

// Y - COORDINATE
var hecY = function (hecR, omega, lcomega, hecnu, inclination) {
  var hecY =
    hecR(
      sin(omega) * cos(lcomega + hecnu) -
      cos(omega * cos(inclination) * sin(lcomega + hecnu))
    );
  return hecY;
};

// Z - COORDINATE
var hecZ = function (hecR, inclination, lcomega, hecnu) {
  var hecZ = hecR * sin(inclination) * sin(lcomega + hecnu);
  return hecZ;
};

Glossary

True Anomaly (ν )

The true anomaly ν [nu] is the angle between the line from the focus of the orbit (the Sun) to the perihelion of the orbit and the line from the focus to the planet. To calculate the true anomaly, you need to solve the Equation of Kepler.

For Jupiter, the true anomaly that goes with

For the Earth, the true anomaly that goes with

Inclination (i)

In astronomy, inclination is an angle between some direction and a standard plane. Inclination is used as name for

the angle between the orbit of a planet or other celestial body and the base plane of the coordinate system (usually the ecliptic for bodies in the Solar System). The inclination is one of the orbital elements. the angle that the magnetic field makes with the local surface.


Share this post on:

Previous Post
Google Personal Asistant – Raspberry Pi 3
Next Post
Making your own DIY Microscope