Jump to content

Drawing an ellipse from 3 points


d13
 Share

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?

 

 

Link to comment
Share on other sites

var detail = 12;
var pieDiv = 2/detail;
var divArray = [];
var radius = 0.5;
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(new BABYLON.Vector3((radius * Math.cos(divArray[i])+offset.x), (0+offset.y), (radius * Math.sin(divArray[i])+offset.x)));
	}
	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

Link to comment
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 :)

Link to comment
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? 

Link to comment
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.

http://www.html5gamedevs.com/topic/21594-camera-boom-prototype/?tab=comments#comment-122980

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

Link to comment
Share on other sites

just jack this:

 

{
		name: 'sun',
		title : 'The Sun',
		mass : 1.9891e30,
		radius : 6.96342e5,
		k : 0.01720209895 //gravitational constant (μ)
	},
	{
	 	name: 'mercury',
		title : 'Mercury',
		mass : 3.3022e23,
		radius:2439,
		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,
		radius : 6051,
		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,
		radius : 3443.9307 * ns.NM_TO_KM,
		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,
		radius : 3376,
		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,
		radius : 71492,
		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,
		radius : 58232,
		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,
		radius : 25559,
		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,
		radius : 24764,
		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,
		radius : 1153,
		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,
		radius : 50,
		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,
		radius : 1738.1,
		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
			}	
		}
	}

 

Link to comment
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?

 

Link to comment
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

Link to comment
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.

I have a question to your Playground Link: https://www.babylonjs-playground.com/#SI34M#5 

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.

Link to comment
Share on other sites

Hi @HerryKun!  Welcome to the forum.

https://www.babylonjs-playground.com/#SI34M#8

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...