Alex Pyzhianov
Alex Pyzhianov

Reputation: 540

Orbital mechanics for a Solar System visualisation in Three.js (x,y,z for planets)

I'm working on a Solar System visualisation in Three.js. For now my planets have basic circular orbits and I want to make my model as realistic as possible. I looked through wiki and some articles but this stuff is pretty advanced.

I don't really care about the orbits in thousands and millions years, I just want a close-to-beeing realistic model which will demonstrate:

  1. Correct eliptic orbits
  2. Inclination
  3. Dynamicly changing speed (faster in perihelion)

I wonder if there is a adequately complex way to calculate x,y,z for my planets at given t (which dynamicly changes) probably using orbital elements.

Hope, I made my idea clear. Thanks

Upvotes: 3

Views: 3220

Answers (3)

SyntaxRules
SyntaxRules

Reputation: 2206

Here is some code for completing the task in c++. Albeit it does not take a date as it parameter. That is a little more complex. However- replacing i with the right value should do the trick. (I used this code to draw the orbital path around the sun.

double x = distanceFromSun * orbitScaleFactor;
double y = sin(inclination) * distanceFromSun * orbitScaleFactor;
double z = semiMinorAxis * orbitScaleFactor;

for (double i = 0; i < 2.0 * PI; i += PI / 32.0) {
    x = cos(i) * x;
    y = cos(i + lonOfAscendingNode) * y;
    z = sin(i) * z;
}

P.S I don't feel guilty giving you c++ code even though your question specifically refers to javascript- I think the equation is what you are really looking for.

You can see my full code here: https://github.com/SyntaxRules/SolarSystemSimulation/blob/master/src/Planet.cpp

You can find information for the variables there too. :)

Upvotes: 1

user1864610
user1864610

Reputation:

If you're happy with an approximation to show a few key elements than you could try calculating a look-up table for all planets for a period of some years. The orbital period of, say, Neptune is 164 years so calculating the positions of all the planets each month over that period should give a table of relatively manageable proportions. To get a visual representation of the change of orbital speed you'd need finer resolution. Once calculated you just need to construct an animation to plot the positions.

The calculations are quite involved. I'm not going to repeat the computation here - it's just too long - but you can find a good description here, along with a sample program written in QBasic

The principle steps are:

Find the position of the planet in its orbit - Find the number of days since the date of the elements - Find the mean anomaly from the Mean Longitude and the daily motion - Find the true anomaly using the Equation of Centre - Find the radius vector of the planet

Refer that position to the Ecliptic - hence find the heliocentric ecliptic coordinates of the planet

Once you have the heliocentric coordinates transform them to your own frame of reference (The linked page shows how to do this for geocentric coordinates but that won't be useful. You'll need to work this out for yourself.) Add the coordinates to your table.

You could try running the calculations in real time, which would be more flexible but might limit the frame rate. Some experimentation might be needed here.

Thanks to Keith Burnett (author of linked page) for the details which I have condensed above.

Upvotes: 1

Pax Vobiscum
Pax Vobiscum

Reputation: 2639

Maybe you should try a two dimensional projection of the orbits. In that case you only have to parameterize the ellipe as a vector function say ɣ(x(t), y(t)).

Then for the sake applying the physical aspect, imagine two centers of mass, the sun M and a given planet μ. The force on the planet F is given by F=GμM/|ɣ|², and the acceleration follows by Newton's second law, a=GM/|ɣ|², always pointing towards the larger mass, M.

In order to set up the curve ɣ, you can use http://en.wikipedia.org/wiki/Ellipse#Equations

Upvotes: 1

Related Questions