Eccentric 3D Orbits

BlitzMax Forums/MiniB3D Module/Eccentric 3D Orbits

Krischan(Posted February) [#1]
I need some help with my planet orbits code. Currently I can only create planets orbiting a star at the same Y position of a plane in 3D using Sinus and Cosinus. The question is: how to alter the following code to have eccentric 3D orbits in the Y coordinate (Y1/Y2), too? I've already googled around but couldn't find a solution.




Floyd(Posted February) [#2]
You could look up the math for 3d rotations. Then calculate for the (x,z) plane, as you are doing now. Rotate the orbit to wherever you want it to be.

I don't know how much of Blitz3d is supported in minib3d. Can you make the planet a child of a pivot? If so you can rotate the pivot and do orbit calculations locally in the pilot's x,z plane.

NOTE: Didn't look at the code until now. I see that you can make an entity the child of a pivot.

I don't have minib3d handy. Here is a crude example in Blitz3D, with Mars (red dot) in a tilted orbit.

Graphics3D 800, 500, 0, 2
SetBuffer BackBuffer()

sun = CreateSphere( 12 )
EntityColor sun, 255,255,0

earth = CreateSphere()
ScaleEntity earth, 0.2, 0.2, 0.2
EntityColor earth, 0, 255, 0

mars = CreateSphere()
ScaleEntity mars, 0.1, 0.1, 0.1
EntityColor mars, 255, 0, 0

cam = CreateCamera()
PositionEntity cam, 0, 10, -20
PointEntity cam, sun

piv = CreatePivot()
EntityParent mars, piv, False
TurnEntity piv, 15, 0, 30

m# = 0  ; angles for mars and earth
e# = 0

While Not KeyDown(1)
	PositionEntity earth, 10*Sin(e), 0, 10*Cos(e)
	e = e + 0.25
	PositionEntity mars , 15*Sin(m), 0, 15*Cos(m)
	m = m + 0.125
	RenderWorld
	Flip
	
Wend



Krischan(Posted February) [#3]
Your example works fine. But I'd rather looking for a code which "knows" the XYZ coordinates of the angle steps to correctly draw the orbital lines using the Line3D function. And the planet should follow this line which can be done using the pivot it is parented to already.

It's more about the lines. Perhaps I could precalculate the line coordinates using a parented pivot and read its position on its way around the star but there must be a simple mathematic formula which does that, too (which I'd prefer).


Krischan(Posted February) [#4]
Whoah I solved it but it was a hard piece of work. It only works using Quaternion rotation and I've added the solution to the code archives. Have fun to play around with.

http://www.blitzbasic.com/codearcs/codearcs.php?code=3307

eccentricity = 0.0


eccentricity = 45.0



Rick Nasher(Posted February) [#5]
Nice. So using this one could represent orbits like pluto's more accurate right?




Krischan(Posted February) [#6]
Not quite as my orbits are *perfect* circles while Pluto (and the other planets) have elliptical orbits which is impossible to simulate using my pivoted Quaternion solution. For a real simulation you must calculate the orbits like Kepler did. For my game, perfect circles are sufficient :-)

Oh, by the way here is a screenshot of my current WIP using the new code, perhaps I'll release a Tech Demo if I can fix some other nasty bugs soon (click image for full resolution)




Rick Nasher(Posted February) [#7]
Very spacious. ;-) Looking great.

I'm not a mathematician(by far actually), but I do remember seeing demo's back in the days of early home computing, in which they were able to use plot x,y and commands such as cos, sin and tan to draw just about anything including egg like shaped ovals.

I have no clue of how they did all that though. Concentric circles and smiley's where already a major achievement for me back then.

I did a quick search, but not easy to find on the net. It's like a forgotten art.