0

I'm no longer able to follow the differentials and derivation of orbital mechanics. Given a heavy star like mass W located at (x1, y1, z1) and a small mass at (x2, y2, z2) with a motion/velocity of (dx, dy, dz) in a unit of time I'd like to calculate the new (x3, y3, z3) at a subsequent point in time along with the new direction vector and velocity (dx2, dy2, dz2) such that I can animated something that looks reasonable in Java. Of course, depending on the speed there may be no orbit and just a parabola.

Is there a straight forward formula I can use?

Dan Wood
  • 11
  • 2
  • Does the position of star $W$ change? – Farcher May 24 '22 at 07:44
  • My naïve assumption is there would be 3 cases; 1) W is stationary; 2) W is moving at a fixed velocity; or 3) W is accelerating.

    I just be happy to get a solution for the simple stationary case. I assume the fixed velocity case wouldn't be hard for me to figure out once I have a formula. I also assume that it might be slightly more complex if the satellite has enough mass such that they rotate about the center of mass.

    – Dan Wood May 26 '22 at 04:05
  • How are you defining "straight forward"? – Kyle Kanos May 27 '22 at 13:55
  • Hmmm, add substract multiple divide powers roots and trig functions. Maybe ABS(). Is there a simple calculation or not? Will I need any matrix multiplication for the purpose of coordinate rotation or other reasons? The simpler the code to do this is the more it approaches a straight forward solution. – Dan Wood May 28 '22 at 05:21

1 Answers1

0

Orbital motions still follow Newton's laws, so you can always use $$F=m\vec a=m\frac{\mathrm d^2\vec x}{\mathrm dt^2},$$ where $\vec F$ is the net force, $\vec a$ the acceleration, $m$ the mass and $\vec x$ the time-dependent position. For two bodies, the gravitational force is, $$\vec F_{21}=G\frac{m_1m_2}{\vert \vec x_2-\vec x_1\vert^3}\times\left(\vec x_2-\vec x_1\right) $$ with $G$ the gravitational constant and where $\vec F_{12}=-\vec F_{21}$.

For these types of simulations, however, it is more convenient to break that formula into two equations: \begin{align} \vec F&=m\frac{\mathrm d\vec v}{\mathrm dt}\approx m\frac{\Delta \vec v}{\Delta t} \\ \vec v&=\frac{\mathrm d\vec x}{\mathrm dt}\approx\frac{\Delta \vec x}{\Delta t}\end{align} with $\vec v$ the velocity and $\Delta$ meaning a (finite) change in position/velocity/time. These can be re-arranged to be a two-step process for evolving the orbital motion: \begin{align} \vec v_\text{new}&=\vec v_\text{old}+\frac{\vec F}{m}\Delta t \\ \vec x_\text{new}&=\vec x_\text{old}+\vec v_\text{new}\Delta t \end{align} Note that this is applied for each object in the system you are considering, though you only need to compute half the forces since $\vec F_{12}=-\vec F_{21}$.

A simple outline of an algorithm would be,

// initialize variables such as masses, times, etc
while (t < t_end) {
    for (body1 in bodies) {
        for (body2 in bodies) {
            if (body1 == body2) continue;
            // compute force returns a vector G.m1.m2.(x1-x2)/|x1-x2|^3
            accel_12 = compute_force(body1, body2);
            accel[body1] = accel_12;
            accel[body2] = -accel_12;
        }
    }
    for (body in bodies) {
        body.v += accel[body] * dt / body.m;
        body.x += body. * dt;
    }
    // do your displaying positions/velocities/accel here?
    t += dt
}

Your object body ought to contain mass, velocity and position data for the object (though if you want to animate this, you might need more than just that, I'm not really sure).

Wikipedia has a decent boilerplate for our solar system in C/C++ that should be easily adaptable to your case. Rosetta code has a Java implementation that might be useful for you.

Kyle Kanos
  • 28,229
  • 41
  • 68
  • 131
  • Thanks Kyle. It's been 45 years since I knew how to read the math you showed. However, in looking at the actual Java code in the link you provided I got it. I forgot how easy vector math was and how I don't have to worry about applying acceleration individually to the X, Y and Z components. Since that program doesn't do any animation I've created my own Java animation of a blue earth in orbit around a yellow sun against a dark starry sky. Works great! Wish I could include a picture. It also handles multi-body. FYI, ".times(.5)" in their code is wrong. – Dan Wood May 31 '22 at 00:23