# Calculating elliptical planet orbits

## Recommended Posts

Hi Everyone!

I'm bust building a semi-realistic solar system model.

I found this example extremely helpful:

But, I have a question about how calculate realistic elliptical orbits.

I know that an ellitical orbit can be calculated by modifying this line of code:

``planet.position = new BABYLON.Vector3(10 * Math.sin(alpha), planet.parent.position.y, 10 * Math.cos(alpha));``

And, the eccentricity of each planet is well documented:

I know that an ellitical orbit can be calculated by modifying this line of code:

But what I don't yet know is how calculate an ellipse based on those numbers.

Can anyone help?

Thanks!

##### Share on other sites

easy way : just set a different radius on x and on z (5 and 10 instead of both 10)

##### Share on other sites

Thanks Jerome!

In trying to come up with realistic orbits I need to somehow incorporate the actual eccentricity data.

For example, Earth's is 0.017.

My guess is that I should integrate it something like this?

``planet.position = new BABYLON.Vector3((10 - 0.017) * Math.sin(alpha), planet.parent.position.y, 10 * Math.cos(alpha));``

##### Share on other sites

There is a cool lib for this:
https://github.com/mgvez/planet-positions

it returns Three.Vector3, but you can .copyFrom that to BABYLON.

##### Share on other sites

Where point on ellipse is given by  (a.cos(theta), b.sin(theta)) with b < a and with eccentricity e, then b = a.sqrt(1 - e2)

##### Share on other sites

Thanks John!

Could you explain how I could integrate that into the current formula?

##### Share on other sites

``new BABYLON.Vector3(10 * Math.sqrt(1 - 0.017 * 0.017) * Math.cos(alpha), planet.parent.position.y, 10 * Math.sin(alpha));``

##### Share on other sites

Oh I see!!

That makes perfect sense now, thank you!!

##### Share on other sites

Hey d13/others... if a more-finished playground version of that solar system... ran across the forum floor and pooped on my shoe... I wouldn't mind at all.

thx.  That would be a VERY popular playground, I suspect.  If it uses elevation data to form the planets, it will surely earn a slot on the BJS Main Website demos.

And that means... a party!  YAY!

##### Share on other sites

@Wingnut:
I'm doing my version of solar system right now.

But I don't think I can get Neil Degrasse Tyson to narrate it from a silver spaceship... But who knows, the weekend is long and prosper(ous).

##### Share on other sites

@Wingnut

Hey

An alpha version is more or less working now:
https://www.bitofgold.com/solarsystem/

Saturn has no rings (yet), and it's hard to position the sky to the correct rotation. (the earth axis is near  the north star, but other stars are not perfectly in the right direction...)
I used only CC or free texture maps.

I always wanted to do a planetarium or solar system model. It took less than a day. BABYLON is awesome!

superb !

##### Share on other sites

did you know that another famous BJS user did some planetarium project too ?

##### Share on other sites

No I didn't, it looks rad! It has even the famous moons.
I even learnt some things about the solar system, like I never imagined the enormous Jupiter turns every 10 hours. Never imagined it so fast.

##### Share on other sites

On 2017-10-20 at 8:31 PM, Wingnut said:

If it uses elevation data to form the planets, it will surely earn a slot on the BJS Main Website demos.

Where would be the best place to start to implement such a feature?

##### Share on other sites

Hi d13!  First, may I say that I love this topic.  I'm enjoying EVERYONE's comments and demos, and I am learning TONS!  You guys are interesting and FUN!!!

Others will surely have other implementation opinions, but in MY opinion... I'd say start-with a big bottle of Jack Daniel's Tennessee Sippin'-Whiskey.  Yum.    Perhaps some herbal enjoyments, too.  (shhh)

Next, say the term "DEM" a few times... see how it feels.  "DEM" will soon control your "worlds".

Ok, that's some basic info about DEM... written by DEM-guys.

Ok, next, let's go to Mercury.  https://www.melown.com/mercury/?pos=obj,-61.627417,7.456315,fix,-35.19,123.56,-13.42,0.00,58772.15,55.00

Notice that... "bumpy-ness" can be simulated via texture colors/baked shadows... at ANY higher altitudes above the planet.  Not until the camera is placed in a low-altitude position with the horizon-line in-view... do we see the planet's TRUE heightMap elevation data (its bumps).  So, although "a purist" would want to use THE BEST resolution DEM data that NASA will give us for free... and have each planet pre-rendered max-rez at the beginning of the scene-start, it might not be wise to do so (practically speaking).

This might be a great use for "incremental loading"... or incremental LODing.    With me?  If so, have another shot of booze, cuz you ain't drunk enough, yet.  heh.

One last thing.  You can be SURE that a couple thousand other demented 3D scientists... have already tried to do this.  (This solar system is a rather popular subject, worldwide.  Maybe more popular than BJS!)   SO... there is certainly code to steal, hidden in various worldwide dumpsters (neglected folders).  But perhaps more importantly, there are already JSON files containing planetary DEM data for ALL nearby NASA-noticed planets... freely available.

Where?  I dunno.  You need to go fishing.  Put various pertinent keywords onto your hook, and cast into the logs and lily pads... where "big fish" hang-out.

It might not be SUPER hi-rez data, but it is "reasonable" and manageable.  And there's surely more than one resolution available, too.... for each planet.  Some planets might not have completed elevation data... so you may need to design a "fudging engine" that fills-in the areas where you have no DEM data.

Wow, huh?  phew.  I'm pooped.  You?    Party on!  [fun link]  (mouse-dragging/wheeling active).  Fudging engine!  Artificial intelligence fuzzy-logic body-putty generator... filling-in the cracks.    (Wingnut sprays some Jaggy-B-Gone on the BJS CSG system, just... cuzzzz)

##### Share on other sites

On 2017-10-17 at 11:37 AM, BitOfGold said:

There is a cool lib for this:
https://github.com/mgvez/planet-positions

it returns Three.Vector3, but you can .copyFrom that to BABYLON.

This is awesome, thanks so much for sharing it!!!

I've just started using it and it's basically done all my work for me

I've got the entire solar system working with accurate orbits, and I even used the radius values supplied by `planet-positions.js`

My next step is scaling: I'm experimenting with ways of keeping the relative sizes of the planets accurate but aesthetically scaling the distances between them so that the entire solar system could be viewed as a whole from one camera.

I would love to accurately space the planets, but the problem there is that the solar system is very, very big and very, very empty:

Although, I might add a slider to let users set the scale to a realistic 1:1 if they want to.

##### Share on other sites

On 2017-10-21 at 7:50 PM, BitOfGold said:

An alpha version is more or less working now:
https://www.bitofgold.com/solarsystem/

(I've very new to using BabylonJS so I'm not sure how this is typically done.)

I've been using simple HTML tags and this bit of code to make them follow the planet positions:

``````  planetMeshes.forEach((planet, index) => {
scene.updateTransformMatrix();

let label = planetLabels[index];
var position2D = V3.Project(
planet.position,
BABYLON.Matrix.Identity(),
scene.getTransformMatrix(),
camera.viewport.toGlobal(engine.getRenderWidth(), engine.getRenderHeight())
);

label.style.left = position2D.x + "px";
label.style.top = position2D.y + "px";
});``````

... the only problem with that is that the labels are on <div> layer above the scene.

So it looks a bit weird when a planet passes behind another because its label still floats on top.

##### Share on other sites

First you make a full screen GUI:

`````` scene.gui = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("UI");
``````

After that, add a label connected to each planet mesh (planet.model is a BABYLON.Mesh):

``````var rect1 = new BABYLON.GUI.Rectangle();
rect1.width = "150px";
rect1.height = "40px";
rect1.color = "rgba(255,255,255,0.37)";
rect1.thickness = 0;
rect1.background = "transparent";
var label = new BABYLON.GUI.TextBlock();
label.text = planet.title;

``````

##### Share on other sites

@Deltakosh and @BitOfGold Thank you so much!!

I will try that and let you know hot it goes!

##### Share on other sites

If you would travel at the 99% of speed of light, from the spaceship's view it would take only about 6.1 minutes to reach Jupiter. And Jupiter would look as a flat ellipsioid, not a sphere, about 1/14th width of the diameter.
(But, the video would be shorter )

##### Share on other sites

And you would not see anything in front of you, only a band of stars at the sides, as light would turn into red and then infrared. Behind you the light would turn blue and into ultraviolet.

##### Share on other sites

• 1 year later...

Actually, if you assume that Jupiter is at perihelion at the same time as it is in opposition (with Earth) - making the two worlds closest together - it would take 32.8 mins at 100% the speed of light to travel from Earth to Jupiter. The 6.1 minutes to reach Jupiter is, in my opinion, a little optimistic. Full marks for enthusiasm though

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.