For more realistic animation in VPython or other software, we need to apply Newtonian physics. The simplest way is to add up all the forces acting on an object as vectors, then divide by the total by the object's mass to obtain the acceleration.
$$ \sum \vec{F} =\vec{F}_{Total}= m \vec{a} $$
$$ \vec{a} = \frac{ \vec{F}_{Total} }{m} $$
Then we can apply Euler's Method to calculate step by step its velocity and next position. Euler's Method isn't really the best or most precise or accurate, but it is the simplest way. And provided the forces, acceleration and velocities don't change too quickly, it is quite adequate and the results convincing to the eye.
For more precise results one can use Runge-Kutta, but that is more complicated. It is more useful when the forces and acceleration change rapidly
This part shows how Euler's Method is derived. Acceleration is a derivative of velocity:
$$ \vec{a}= \frac{d\vec{v}}{dt} \approx \frac{\Delta \vec{v}}{\Delta t} $$
$$ \frac{\Delta \vec{v}}{\Delta t} = \frac{\vec{v}_{new}-\vec{v}_{old}}{\Delta t} =\vec{a} $$
Thus we obtain the new value of velocity from the previous value, and the current acceleration.
$$ \vec{v}_{new} = \vec{v}_{old} + \vec{a} \Delta t $$
Likewise, to obtain the new position \(\vec{x}_{new}\)
$$ \vec{x}_{new} = \vec{x}_{old} + \vec{v} \Delta t $$
The smaller the \(\Delta t\), the more accurate the simulation will be, but there will be more steps, and the program will run more slowly. But this is usually not a problem for smooth movements and slowly changing forces.
More precise results can be obtained using Runge-Kutta without making the \(\Delta t\) too small.
So the loop goes:
Forces:
According to Hooke's Law:
$$ F = m a = -k x $$
Current acceleration:
$$ a =- \frac{k}{m} x $$
Current velocity from previous velocity and current acceleration
$$ v_{new} = v_{old} + a \times \Delta t $$
Current position from previous position and current velocity.
$$ x_{new} = x_{old} + v \times \Delta t $$
See spring mass system here
A satellite with mass m is orbiting a planet with mass M. It is at distance r from the centre of the planet, moving with velocity vector \(\vec{v}\).
Initial position \(\vec{r}\)and velocity \(\vec{v}\),
$$ \vec{v}= \begin{pmatrix} v_x \\ v_y\\ v_z \end{pmatrix} $$$$ \vec{r}= \begin{pmatrix} x \\ y\\ z \end{pmatrix} $$
Distance from the massive body:
$$ |\vec{r}|= \sqrt{x^2 + y^2 + z^2} $$
Gravitational force:
$$ \vec{F} = m \vec{a} = -GM \frac{m}{|r|^2} \hat{r} $$
Divide by small m to get the acceleration
$$ \vec{a} = -GM \frac{1}{|r|^2} \hat{r} $$
Using Euler's Method to obtain the current velocity and current position:
$$ \vec{v}_{new} = \vec{v}_{old} + \vec{a} \times \Delta t $$
$$ \vec{r}_{new} = \vec{r}_{old} + \vec{v}_{new} \times \Delta t $$
You can see its implementation here:
Note: if the starting velocity is too high, the satellite will escape from the planet. If too low, it will fall into the planet. In between, it will follow an elliptical orbit.
For a very particular velocity, you get a circular orbit, when the centrifugal force just balances gravity:
Centrifugal = gravity
$$ \frac{m|v|^2}{r} = \frac{GMm}{r^2} $$Thus
$$ |v| =\sqrt{\frac{GM}{r}} $$A satellite at distance r, travelling at this velocity at right angles to the planet, will travel in a circular orbit.