# Drawing an ellipse from 3 points

## Recommended Posts

Hi Everyone!

This is another question related to my other post about drawing orbit lines for planets:

I've realized I need to pre-render these lines, without knowing in advance what all the points of the orbit will be.

Does anyone know how to use 3 captured points to calculate and then draw a complete ellipse?

##### Share on other sites

var detail = 12;
var pieDiv = 2/detail;
var divArray = [];
var offset = {x:0, y:0};

for(var i = 0; i < detail; i++){
divArray.push(Math.PI*(pieDiv*i));
}

var newPath= [];
for(var i = 0; i < divArray.length; i++){
}
newPath.push(newPath[0]);


As long as you know the radius this will work.

http://www.babylonjs-playground.com/#35LJSZ#5

http://www.babylonjs-playground.com/#35LJSZ#6

##### Share on other sites

@Pryme8Thank you so much!!!

I will try that. I could measure the distance of each planet from the sun to figure out the radius - it will probably be close enough for most.

Mercury and Pluto have a very eccentric orbits... there's probably a way to tweak the math... I'll explore and get back to you

##### Share on other sites

Yes I can shift to calculate ellipses as well, one second.

http://www.babylonjs-playground.com/#35LJSZ#7

MATH MUTHA F*****S

I'm planning on going back to take some more calculus and trig classes here soon... >_< starting to realize I'm losing it from not using it... getting older sucks.

##### Share on other sites

@Pryme8Aweome!

I'll try plugging in the correct eccentricity values for each planet and see what happens

By the way, what do the x and y offset do?

Some of the planets (like Venus) actually move up and down slightly when they orbit - could the x and y offset be used to account for that?

##### Share on other sites

the offset will move it around on a 2d plane, you can extend it to be 3d and then to make the tilt just adjust the rotation of the line system.

You can also use my Camera Boone prototype to animate the planets on the path as opposed to using cos/sin which will fix having to adjust your math for the tilt.

-> older example http://www.babylonjs-playground.com/#AGOCE#5

##### Share on other sites

P.S.  All the help I have been giving you I hope lands me a shout out in the credits of the scene when ever you're finished! <3

##### Share on other sites

@Pryme8 I'm actually getting the planet position data from here:

Probably there would be some way to actually use that data to pre-render the orbit path but I think an approximation (using your method) will be close enough.

##### Share on other sites

2 minutes ago, Pryme8 said:

P.S.  All the help I have been giving you I hope lands me a shout out in the credits of the scene when ever you're finished! <3

Of course, I'll add you to the credit list!

##### Share on other sites

just jack this:

{
name: 'sun',
title : 'The Sun',
mass : 1.9891e30,
k : 0.01720209895 //gravitational constant (μ)
},
{
name: 'mercury',
title : 'Mercury',
mass : 3.3022e23,
orbit : {
base : {a : 0.38709927 * ns.AU ,  e : 0.20563593, i: 7.00497902, l : 252.25032350, lp : 77.45779628, o : 48.33076593},
cy : {a : 0.00000037 * ns.AU ,  e : 0.00001906, i: -0.00594749, l : 149472.67411175, lp : 0.16047689, o : -0.12534081}
}
},
{
name: 'venus',
title : 'Venus',
mass : 4.868e24,
orbit : {
base : {a : 0.72333566 * ns.AU ,  e : 0.00677672, i: 3.39467605, l : 181.97909950, lp : 131.60246718, o : 76.67984255},
cy : {a : 0.00000390 * ns.AU ,  e : -0.00004107, i: -0.00078890, l : 58517.81538729, lp : 0.00268329, o : -0.27769418}
}
},
{
name:'earth',
title : 'The Earth',
mass : 5.9736e24,
sideralDay : ns.SIDERAL_DAY,
tilt : 23+(26/60)+(21/3600) ,
orbit : {
base : {a : 1.00000261 * ns.AU, e : 0.01671123, i : -0.00001531, l : 100.46457166, lp : 102.93768193, o : 0.0},
cy : {a : 0.00000562 * ns.AU, e : -0.00004392, i : -0.01294668, l : 35999.37244981, lp : 0.32327364, o : 0.0}
}
},
{
name:'mars',
title : 'Mars',
mass : 6.4185e23,
sideralDay : 1.025957 * ns.DAY,
orbit : {
base : {a : 1.52371034 * ns.AU ,  e : 0.09339410, i: 1.84969142, l : -4.55343205, lp : -23.94362959, o : 49.55953891},
cy : {a : 0.00001847 * ns.AU ,  e : 0.00007882, i: -0.00813131, l : 19140.30268499, lp : 0.44441088, o : -0.29257343}
}
},
{
name:'jupiter',
title : 'Jupiter',
mass : 1.8986e27,
orbit : {
base : {a : 5.20288700 * ns.AU ,  e : 0.04838624, i: 1.30439695, l : 34.39644051, lp : 14.72847983, o : 100.47390909},
cy : {a : -0.00011607 * ns.AU ,  e : -0.00013253, i: -0.00183714, l : 3034.74612775, lp : 0.21252668, o : 0.20469106}
}
},
{
name:'saturn',
title : 'Saturn',
mass : 5.6846e26,
tilt : 26.7,
orbit : {
base : {a : 9.53667594 * ns.AU ,  e : 0.05386179, i: 2.48599187, l : 49.95424423, lp : 92.59887831, o : 113.66242448},
cy : {a : -0.00125060 * ns.AU ,  e : -0.00050991, i: 0.00193609, l : 1222.49362201, lp : -0.41897216, o : -0.28867794}
}
},
{
name: 'uranus',
title : 'Uranus',
mass : 8.6810e25,
orbit : {
base : {a : 19.18916464 * ns.AU ,  e : 0.04725744, i: 0.77263783, l : 313.23810451, lp : 170.95427630, o : 74.01692503},
cy : {a : -0.00196176 * ns.AU ,  e : -0.00004397, i: -0.00242939, l : 428.48202785, lp : 0.40805281, o : 0.04240589}
}
},
{
name:'neptune',
title : 'Neptune',
mass : 1.0243e26,
orbit : {
base : {a : 30.06992276  * ns.AU,  e : 0.00859048, i: 1.77004347, l : -55.12002969, lp : 44.96476227, o : 131.78422574},
cy : {a : 0.00026291  * ns.AU,  e : 0.00005105, i: 0.00035372, l : 218.45945325, lp : -0.32241464, o : -0.00508664}
}
},
{
name: 'pluto',
title : 'Pluto',
mass : 1.305e22+1.52e21,
orbit : {
base : {a : 39.48211675 * ns.AU ,  e : 0.24882730, i: 17.14001206, l : 238.92903833, lp : 224.06891629, o : 110.30393684},
cy : {a : -0.00031596 * ns.AU ,  e : 0.00005170, i: 0.00004818, l : 145.20780515, lp : -0.04062942, o : -0.01183482}
}
},
{
name: 'halley',
title : 'Halley\'s Comet',
mass : 2.2e14,
orbit : {
base : {a : 17.83414429 * ns.AU ,  e : 0.967142908, i: 162.262691, M : 360 * (438393600 / (75.1 * ns.YEAR * ns.DAY)), w : 111.332485, o : 58.420081},
day : {a : 0 ,  e : 0, i: 0, M : (360 / (75.1 * 365.25) ), w : 0, o : 0}
}
},
{
name: 'moon',
title : 'The Moon',
mass : 7.3477e22,
sideralDay : (27.3215782 * ns.DAY) ,
tilt : 1.5424,
fov : 1,
relativeTo : 'earth',
orbitCalculator : MoonRealOrbit,
orbit: {
base : {
a : 384400,
e : 0.0554,
w : 318.15,
M : 135.27,
i : 5.16,
o : 125.08
},
day : {
a : 0,
e : 0,
i : 0,
M : 13.176358,//360 / 27.321582,
w : (360 / 5.997) / 365.25,
o : (360 / 18.600) / 365.25
}
}
}

##### Share on other sites

@Pryme8 Yes, I've been using it to move the planets and it works great - I just have no idea how to use that data to display pre-renderd orbit lines.

##### Share on other sites

Arrgh, those calculations turned out not to be accurate enough

It looks like I'm back to the drawing board again. I'll need to do one of these two things:

1. Calculate the ellipse dynamically by extrapolating from a few points of captured planet position data.

2. Figure out how to calculate an accurate ellipse using this data:

orbit : {
base : {a : 17.83414429 * ns.AU ,  e : 0.967142908, i: 162.262691, M : 360 * (438393600 / (75.1 * ns.YEAR * ns.DAY)), w : 111.332485, o : 58.420081},
day : {a : 0 ,  e : 0, i: 0, M : (360 / (75.1 * 365.25) ), w : 0, o : 0}
}

... Can anyone make sense out of that?

##### Share on other sites

a = Base distance in AU's from the sun
e = Orbital Eccentricity
i = Inclination of Orbit to Ecliptic
o = Orbit speed in km/s

Not sure the other stuff:
https://www.windows2universe.org/our_solar_system/planets_orbits_table.html

I think that's all you would need unless you want to do their spin as well.

##### Share on other sites

http://www.babylonjs-playground.com/#AEBA7P#6

Ill help out more here, I just gotta figure out if I want to do it in true scale, or to shrink the AU units.

Did you ever see my Celest System? For procedural creation Solar Systems.

##### Share on other sites

I'm scaling down by a factor of 100,000,000, but use a slider to scale up to 1:1.

No, I haven't Celest System

##### Share on other sites

Here is an old school prototype.

https://www.babylonjs-playground.com/#SI34M#3  //System seed: Rachel
https://www.babylonjs-playground.com/#SI34M#5 //Changed seed of system to Pryme8

you can change the seed on like 581

make sure you have the console up, that's where all the butter is.

Feel free to jack what ever you need.

Sidenote, if anyone can generate something other then a Class M star I would love to see it! They are super rare and the system is based on real world data.

and here is an update for the real world system : https://www.babylonjs-playground.com/#AEBA7P#9

##### Share on other sites

https://www.babylonjs-playground.com/#AEBA7P#13

So here is a question for you, what number represents the angle of the  Eccentricity.

In relation to the earths orbit? Basically the y Rotation of the orbit.

##### Share on other sites

Yes That's correct!

Pluto's weirdness is one of the reasons it was demoted as a planet.

##### Share on other sites

• 1 month later...

Hey guys, i was reading along and this post helped me a lot since i am quite a newbie in Babylon.

How do you create this amazing lighting from the center star? I currently use a glow layer but it kind of flickers and disappears if you zoom out.

##### Share on other sites

Hi @HerryKun!  Welcome to the forum.

Now that we have removed most of the data from @Pryme8's star-system-from-hell, we can more-easily see things.

A little diffuseColor, a little emissiveColor, and the fun VolumetricLightScattering (sometimes called VLS or GodRays) feature.

Post-processes such as VLS... are actually 2D... not 3D.  So, sometimes they have interesting "artifacts" when multiple VLS are active in a single scene... and they overlap (need depth-sorting).  I'm not an expert on these things.

Lines 32-35 are fun VLS values to play-with, so experiment, experiment, experiment.    Make edits to playgrounds, make more SAVES, you can't hurt anything in the playground.

If you create an interesting playground save, and you want to talk about it, then paste the URL into this thread so we can all see it (like you did perfectly in your first post), and we'll discuss it and PLAY with it.

VLS/GodRays are a pretty nice feature, eh?  I love 'em. I hope I've been helpful.

##### Share on other sites

Thank you @Wingnut for giving me the hint, it was exactly what I needed : )

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