2
\$\begingroup\$

Calculate and draw the path of an orbit in a 2 body problem given the mass, current velocity, and distance of both bodies?

We're working in Unity and will be using the default rigidbody.mass to start while we craft a deterministic and event driven gravitational orbit calculation system.

We've got a lot of this done but need to know if anyone here speaking from experience can suggest the most optimal and the most accurate route for going about this.

Okay, so here's the intended system.

  1. Objects have a collider-trigger sphere which represents their sphere of gravitational influence. When objects enter an SOI, they begin to be effected by that object's gravity. This represents an "encounter" event and this is where we grab initial values to determine the trajectory the object will take with those initial parameters. It will take this path as long as nothing changes. We only worry about "significant bodies" such as planets and large asteroids. We're not giving every ship an SOI but we do give them mass values so we can properly perform consistent calculations.

  2. When a "path change event" occurs, the system will recalculate when the event is over and new velocities are established. This prevents the system from constantly calculating the force on objects every physics step and greatly reduces the overhead of the system.

  3. The system has a way to "snapshot" everything for saves. positions, velocities, and paths. Basically from what I understand, we'd be getting arrays of velocities that we lerp between based on an array of position vectors. I was talking about how the system would to the motion, there.

So, instead of using Unity's built-in physics and forces, we bypass that for a much more efficient and customizable system. Instead of applying constant force to effect the positions of objects, we calculate the path ahead of time and assume the object will follow that path until something changes.

\$\endgroup\$
  • \$\begingroup\$ It's difficult to tell what your specific question is. Your title is about drawing an orbit path, but you posted code about finding eccentricity, and you asked for the best solution for a deterministic system. You also mentioned having trouble, but not what the trouble is. Can you edit your question down to only the subject you need assistance with? \$\endgroup\$ – Seth Battin Apr 23 '15 at 4:56
  • \$\begingroup\$ Also, your code in its current state will not function at all due to mismatched parentheses. If you need debugging assistance, it's important to provide enough (working) code to see the process. But it's also important not to overwhelm with superfluous code. Your goal should be to provide the minimum amount of code that both works and demonstrates the issue. See sscce.org \$\endgroup\$ – Seth Battin Apr 23 '15 at 4:59
  • 1
    \$\begingroup\$ @SethBattin we have an SE official version of that -> stackoverflow.com/help/mcve -- also, @ Thundax this sounds like a homework problem more than something you're actually trying to do on your own. If it is, we highly recommend asking the teacher for help as they generally know the problem best. \$\endgroup\$ – mcmonkey4eva Apr 23 '15 at 17:59
  • \$\begingroup\$ While revising the question, please also define where you draw the line between "real gravity" and determinism. Implementing "real gravity" gives the two bodies the opportunity to eventually collide or break free from each other. Both are probably undesirable loss conditions. \$\endgroup\$ – Jon Apr 24 '15 at 9:10
  • \$\begingroup\$ Alright, so this is not for a homework assignment. This is code in progress from a programmer that works for me. I'm not sure any of the programmers actually understand it fully since I've seen basically the same code from three different people and none of them started out the way I thought they would. One guy got it closer than the others, but still not exactly right. And yes, this code deals with determining the eccentricity and such. We need that to determine the path. I'll edit my question to contain no code and see the generalized solutions \$\endgroup\$ – Thundax Apr 25 '15 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.