2
$\begingroup$

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.

  • 0
    Someone can probably close this question as a duplicate.2011-10-03

2 Answers 2

3

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.

  • 1
    @lhf: Right, like the ones [here](http://www.unige.ch/~hairer/software.html). (I mean, OP did say s/he wanted a "very realistic" simulation...)2011-10-04
3

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.