Computing planet orbit's

About the actual programming of the game.

Computing planet orbit's

Postby croxis » Tue Aug 13, 2013 4:56 pm

As I mentioned here is a snippit of code that computes the x, y, z position of a celestial body relative to its parent based on its orbital elements

https://gist.github.com/croxis/6222986

The advantages of this method over nbody is that it is procedural (not the right word but best I can come up with). Floating point errors don't accumulate, except for the time variable, so the server wont have to update celestial positions to the client, just the time which will probably be done anyways. It also simplifies predicting future position of a body for NPC AI navigation and for the DCPU.
croxis
 
Posts: 282
Joined: Tue Aug 13, 2013 1:37 am

Re: Computing planet orbit's

Postby Nouht » Tue Aug 13, 2013 8:51 pm

Nice... Just make sure to calculate the normal's of all of the orbits for future reference :).
Also does the support elliptical orbits which of their parent normal's are not perpendicular to the planets equator?
Nouht
 
Posts: 5
Joined: Tue Aug 13, 2013 12:12 pm

Re: Computing planet orbit's

Postby rsgm123 » Tue Aug 13, 2013 9:22 pm

Is n-body out of the question? it may make for interesting gameplay, even if it is just for asteroids(if there are any).
rsgm123
 
Posts: 4
Joined: Tue Aug 13, 2013 12:50 pm

Re: Computing planet orbit's

Postby thelucster » Tue Aug 13, 2013 9:30 pm

It may be simpler (there is a lot of maths there) and more efficient to not have a 100% accurate system. Here some code I wrote for a simple orbital simulation:

Code: Select all
class OrbitalSystem extends Engine.System
  update: =>
    for entity in @world.getEntitiesWithComponent OrbitComponent
      @updateEntityOrbit entity

  updateEntityOrbit: (entity) ->
    position = entity.getComponent PositionComponent
    orbit = entity.getComponent OrbitComponent

    orbit.angle += (Math.PI / 2) * (1 / orbit.distance)

    parentPosition = orbit.parent.getComponent PositionComponent
    position.x = parentPosition.x + orbit.distance * Math.cos(orbit.angle)
    position.y = parentPosition.y + orbit.distance * Math.sin(orbit.angle)


It only deals with 2D orbits, however the majority of orbits are along the ecliptic plane in real life, so it isn't really that unrealistic. Don't forget that the maths for calculating orbits will also have to be duplicated in whatever DCPU navigation programs we write. This will need to be able to decide whether a given maneuverer (or set thereof) will result in a intercept with a target objects SOI - so the simpler the better. Actually it might be worth starting with that before deciding what will be used in the game :)
thelucster
 
Posts: 4
Joined: Tue Aug 13, 2013 9:14 pm

Re: Computing planet orbit's

Postby Eximius » Tue Aug 13, 2013 10:35 pm

The DCPU programs will almost certainly approximate things of this nature regardless of the server's math.
Eximius
 
Posts: 266
Joined: Mon Aug 12, 2013 9:33 pm

Re: Computing planet orbit's

Postby croxis » Tue Aug 13, 2013 11:12 pm

Nouht: To be honest I couldn't tell you. I'm an old fart (30 in a few months!) and took all my remaining math smart points to get that far ;)

rsgm123: I suppose if we really wanted to have players be able to sling asteroid around. But if we really wanted to do that as weapons or asteroid capture for a base the body can be derailed, replace its physics component with a dynamic one, then re rail the orbit once in position.

thelucster: Like I put in the comments there can be a lot of optimization and simplification. On the other hand we have plutos, comets, asteroids and moons around gas giants with interesting orbits that can create interesting settings. If we are keeping the near heat death of the universe lore then we might want a few more crazy systems too.
croxis
 
Posts: 282
Joined: Tue Aug 13, 2013 1:37 am

Re: Computing planet orbit's

Postby 20k » Mon Aug 19, 2013 3:18 pm

rsgm123 wrote:Is n-body out of the question? it may make for interesting gameplay, even if it is just for asteroids(if there are any).


From a server standpoint, n-body is a terrible idea. For a largish number of asteroids it requires an unreasonable amount of CPU power. On a realism standpoint, I believe asteroids are generally too far apart to exert any meaningful kind of gravitational pull on each other. A fixed elliptical orbit is probably realistic enough, with potentially the option of player's being able to move them coming at a later date
20k
 
Posts: 3
Joined: Sun Aug 18, 2013 9:45 pm

Re: Computing planet orbit's

Postby Vinylon » Mon Aug 19, 2013 5:52 pm

Asteroid belts could always just be generated to have stable orbits and avoid collisions. It may not be ideal, but it would really lighten the load on the server and it's not like asteroids would be likely to hit each other anyways given the distance between them.
User avatar
Vinylon
 
Posts: 98
Joined: Mon Aug 12, 2013 11:22 pm
Location: St Louis, MO

Re: Computing planet orbit's

Postby r4d2 » Tue Aug 20, 2013 2:13 pm

I like how the orbits are calculated/simulated in Kerbal. Does anybody have an Idea how they do it?

It' s definitely not n-body. I would guess they basically calculate a perfect elliptic orbit to the closest body (wrt. gravitational force), with some form of interpolation when the forces are almost identical.
r4d2
 
Posts: 1
Joined: Sun Aug 18, 2013 12:48 pm

Re: Computing planet orbit's

Postby mrout » Tue Aug 20, 2013 2:48 pm

r4d2 wrote:I like how the orbits are calculated/simulated in Kerbal. Does anybody have an Idea how they do it?

It' s definitely not n-body. I would guess they basically calculate a perfect elliptic orbit to the closest body (wrt. gravitational force), with some form of interpolation when the forces are almost identical.


The problem with KSP is that you don't get L points.
mrout
 
Posts: 731
Joined: Mon Aug 12, 2013 10:49 pm

Next

Return to Code

Who is online

Users browsing this forum: No registered users and 1 guest

cron