# Calculating point on circle after time

I have a question that seems very similar to calculating-point-around-circumference-of-circle-given-distance-travelled and calculating-point-on-a-circle-given-an-offset, but I don't believe they are quite the same. I'm not very good at math :/

I have planets orbiting a center planet (sun). This is in 3d-space, but only 2 are used so this is safe. The things I know are:

1. The (x,y) position of the sun (Sx, Sy).
2. The (x,y) position of planet A (Ax, Ay).
3. The radius (or distance) from sun to A (r).
4. The speed in which A is traveling along the orbit in Radians/sec (s).
5. The time that has elapsed since A last moved along the orbit (t).

What I'm looking for is some kind of formula to calculate the next (x,y) coordinate of planet A, based on it's current position, speed, and time elapsed.

Please explain the math behind this.. I know a little trig and I'm interested in learning more, especially since I'm tackling a very realistic space-simulation.

-
In truth, planets orbit elliptically about the sun. Do you take this into account, or do you assume circular orbits? – J. M. Oct 3 '11 at 23:14
The first link you gave has the answer, for circular motion. You know the angle of travel $\phi$, so you don't even have to compute it, there is no need to calculate $D/r$. – André Nicolas Oct 3 '11 at 23:22
I know in real life they are elliptical, however I'm not sure how to implement this. I realize how to construct an ellipse (with 4 points as the "control" points), but as I said I know very little math and this seems more complicated. However, if anyone would like to answer in an elliptical case rather than circular, I would be ecstatic. – Snailer Oct 3 '11 at 23:25
If you want to pursue genuine orbits, you'll want to see this. – J. M. Oct 3 '11 at 23:32
JM, my head just exploded. I don't think I'll be able to accomplish elliptical orbits.. Andre, I just realize how dumb I was :( Yes, that does answer my question. I failed to realize I had "distance traveled" by having time and speed.. facepalm – Snailer Oct 3 '11 at 23:44

If the orbit is circular the calculation is simple: $A_x=S_x+r \cos (ts), A_y=S_y+r \sin (ts)$. Without the force law you don't know if the orbit is circular, which will happen if the speed is just right for the distance. Presumably you are using Newton's gravitational law, in which case you need the mass of the sun to plug in.

If the orbit is not circular, you can either solve Kepler's laws or integrate the differential equation. The differential equation lets you apply other forces that might change the orbit as you go along, like thrusting from a spaceship or gravity effects of other planets. A popular approach for the differential equation is a Runge-Kutta method, where $y$ in the Wikipedia page becomes a vector with one component for each space direction of location and another for each component of velocity.

-
If you use numerical integration methods, try to ensure that the total energy is conserved. This helps to stabilize the integration and reduce errors. This technique is known as geometric or symplectic. integration. – lhf Oct 4 '11 at 0:21
@lhf: Right, like the ones here. (I mean, OP did say s/he wanted a "very realistic" simulation...) – J. M. Oct 4 '11 at 0:30

The following is adapted from an answer I gave to a similar but not identical question.

Let the position of the (unmoving) sun be $(S_x,S_y)$. Drag this position to the origin. Let the current position of the planet be $(A_x,A_y)$. Our dragging procedure drags $(A_x,A_y)$ to $(A_x-S_x,A_y-S_y)$.

For simplicity of notation, let $u=A_x-S_x$, $v=A_y-S_y$. Now we determine the angle that the positive $x$-axis has to be rotated through (counterclockwise) to hit the line from the origin to $(u,v)$. Call this angle $\theta$.

Then $\theta$ is the angle, say in the interval $(-\pi,\pi]$, whose cosine is $u/r$, and whose sine is $v/r$, where $r$ is the radius of the circular orbit. So from now on we can take $\theta$ as a known angle. It can be calculated once and for all from knowledge of $(S_x,S_y)$ and $(A_x,A_y)$. (Be careful to take the signs of $u$ and $v$ into account when calculating $\theta$.)

Assume that we are travelling counterclockwise around the sun, at an angular speed of $\alpha$ radians per time unit. Then after elapsed time $t$, we have travelled through an angle $\alpha t$. (If we are travelling clockwise, use $-\alpha t$.)

After the travel, our angle with the positive $x$-axis is $\theta+\alpha t$. This means that we are at the point with coordinates $$(r\cos(\theta+\alpha t), \: \: r\sin(\theta+\alpha t)).$$

Now transform back, by adding $(S_x,S_y)$ to the point. We obtain $$(S_x+r\cos(\theta+\alpha t),\:\: S_y+r\sin(\theta+\alpha t)).$$ This is the position of the planet $t$ time units after it was in position $(A_x,A_y)$. All the components of this formula are known, so now we can compute.

Comment: By using the addition laws for cosine and for sine, we can obtain the following alternate (and for many purposes more useful) version of the answer. Let $(A_x(t), A_y(t)$ be the position of the planet at time $t$. So $(A_x, A_y)$ could also be written as $(A_x(0), A_y(0))$. We obtain $$A_x(t)=S_x+(A_x(0)-S_x)\cos(\alpha t)-(A_y(0)-S_y)\sin(\alpha t),$$ $$A_y(t)=S_y+(A_x(0)-S_x)\sin(\alpha t)+(A_y(0)-S_y)\cos(\alpha t).$$

Alternately, we could look up how to rotate a point around the origin by multiplying by a suitable matrix. In the long run, that is a better way of viewing the matter. The calculation we have done can be viewed as a derivation of that matrix formula.

-