The Solar System Simulator Article of Your Dreams!

Nikhil Mishra
Curious Nikhil
Published in
6 min readApr 22, 2017
The Solar Simulator with Metrics

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 program something as COOL as this, you are stepping into a new world.

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.

Animation about Orbital Consepts

How does it Work?

Flowchart for Solar System Simulator

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.

Adding new Scenes

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

1.0 Mechanical Basis of Solar System.

If it wasn’t for Nicolas Copernicus, we would still believed in the Geocentric system. He formulated the model of the universe, where the Sun was in center, 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.

1.1 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.

image

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,

B is the origin(0, y)

A is the point with unknown location.

r is the radius of the circular orbit.

ϴ is the angle the radius and the x axis.

sin(angle) = Opposite/Hypotenuse

cos(angle) = Adjacent/Hypotenuse

So, In triangle ABC,

angle(ABC) is ϴ

sin(ϴ) = AC/AB = AC/r

cos(ϴ) = BC/r

So, now we know the location of the point by polar coordinates. It’s just a matter of convert Polar to Cartesian Coordinates.

sin(ϴ) = AC/AB = AC/r

AC = sin(ϴ)*r

cos(ϴ) = BC/r BC = cos(ϴ)*r

Voila, BC 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 = cos(ϴ)*r

Y = sin(ϴ)*r

Diagram

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 programme.

2.1 Elliptical Orbits

r = radius

a = semimajor axis

e = eccentricity

3.1 Kepler’s Law

4.1 Basics of Programming

5.1 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; };

Assumption and Limitations

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

MJupiter=141.324°

MJupiter=141.324° and

eJupiter=0.04849 eJupiter=0.04849 is equal to νJupiter=144.637°

νJupiter=144.637°.

For the Earth, the true anomaly that goes with

MEarth=357.009°

MEarth=357.009° and

eEarth=0.01671

eEarth=0.01671 is equal to νEarth=356.907°

νEarth=356.907°.

Inclination (i)

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

  1. 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.
  2. the angle that the magnetic field makes with the local surface.

Originally published at thecuriousnikhil.wordpress.com on April 22, 2017.

--

--