I'm making a space exploration game and its in a 2d plane so no z axis, and I'm using Newton's law of universal gravity, I would really like to calculate anddraw the predicted trajectory of a body, how would I proceed with this problem, I have the global position of the objects and the orbital velocities of them
The easiest initial approach to this is probably to propagate your state forward in time steps, with a time
delta small enough to have reasonable accuracy.
You can then join the x-y points with line segments.
Say you have a state of a position
y, and velocity
delta = 0.001 //tradeoff performance and accuracy for many many steps time += delta drawLine(x, y, x + vx * delta, y + vy * delta) x += vx * delta y += vy * delta for body in bodies: //everything affecting you with gravity distance = sqrt((x - body.x)² + (y - body.y)²) acceleration = body.mass / distance² vx -= acceleration * (x - body.x)/distance * delta vy -= acceleration * (y - body.y)/distance * delta
With discrete steps, there's obviously some error which grows over time though. Separating the physics and graphics may also be something to look into asa screen is just a couple of thousand pixels anyway, so a few thousand line segments should look like a properly smooth trajectory, while the physics simulation could easily be run for millions of iterations if you want it to.
Alternatively, you can try to convert your state vectors to orbital elements, and draw those as circles or ellipses (tip: an ellipse is just a circle scaled along an axis).