I have a gravity-related question. I am programming an orbit simulator. I have everything up and running, but I would like to render the smaller body's orbital path (the larger body is fixed). To do this, I need the parametric equations for the body's position for any given time (i.e. I need an x(t) and y(t) function). I have access to each body's position, velocity, and mass. I have no other accessible variables.
P.S. Here is a link to what I have so far. The equations currently used to plot the orbit are x(t)=x+vxt and y(t)=y+vyt.
Answer
It seems you've done the hard part already, which is to evolve the object's position as a function of time. And moreover, the simulation seems stable over a number of orbits. (But eventually things start to go wrong; you may want to look at an answer I wrote to What is the correct way of integrating in astronomy simulations?)
So my understanding is all you really need is the full orbit plotted. In that case, there's no need to make it a function of actual time (that's hard). Instead, we can fall back to Kepler's First Law, which says that the separation r between the bodies obeys r=rmax(1−e)1+ecos(θ).
Note that the convention is for θ to measure the angle from closest approach (i.e., θ=0 is the negative y-axis in your simulation). If you want θ to increase with time, then the (nonstandard) transformation to Cartesian coordinates is x=−rsin(θ)y=−rcos(θ),
No comments:
Post a Comment