## Tuesday, June 14, 2016

### Orbital Aero Model: Kinematics (Translation)

All forces on all bodies have been calculated; it's now time to move them in space.

We'll start with the classic F = ma (Force equals mass times acceleration.)

In our prior function calls, we calculated the total force applied to the body. Since we know its mass, it's easy to calculate acceleration:

F is the force, in newtons.
m is the mass, in kilograms.
a is the acceleration, in meters per second squared.

And with the acceleration, we know how to propagate location and velocity:

p is the newly calculated position, in meters.
p0 is the initial position. in meters.
v0 is the initial velocity, in meters per second.
t is the time step of the simulation, in seconds.
a is the acceleration, in meters per second squared..

v is the newly calculated velocity, in meters per second.
v0 is the initial velocity, in meters per second.
a is the acceleration, in meters per second squared.
t is the time step of the simulation, in seconds.

The smaller the time step the more accurate the simulation. However, that also means it's more computational intensive for simulating the same period of time.

Rotation code is still a work in progress so that will have to wait for a future post.

https://en.wikipedia.org/wiki/Kinematics

### Orbital Aero Code - update()

A refresher of our update() function in the OrbitalAeroModel class.

// Primary function to process the physics and kinematics all bodies.
bool OrbitalAeroModel::update(double timeStep_seconds)
{
// It's important all forces are calculated before all positions are updated before all collisions
// are checked, etc. That way the order in which bodies are looped through does not affect how they
// affect other bodies in space.

// Calculate Motor Thrust (From control system and motor abilities.)

// Sum all the forces acting on every body, including forces from thrust, gravity, atmospheric drag,
// and friction.
processForces();

// Can now translate and rotate each body.
processKinematics(timeStep_seconds);

// After moving the body, check for collisions and adjust positions/velocities as appropriate.
processCollisions(timeStep_seconds);

return true;
}

### Orbital Aero Code - processKinematics()

And the new code:

//  Translate and rotate bodies based on their mass, moments of inertia, and forces.
bool OrbitalAeroModel::processKinematics(double timeStep_seconds)
{
// Loop through all bodies and reposition them based on the forces.
map <uint64, BodyModel>::iterator iteratorPrimaryBody = tableBodies.begin();
while (iteratorPrimaryBody != tableBodies.end())
{
BodyModel &primaryBody = iteratorPrimaryBody->second;
if (primaryBody.active)
{
// Translation
if (primaryBody.massTotal_kilograms() > 0.0)
{
primaryBody.acceleration_metersPerSecond2 = primaryBody.forceTotal_newtons() / primaryBody.massTotal_kilograms();
}
else
{
primaryBody.acceleration_metersPerSecond2 = 0.0;
}
primaryBody.location_meters += (primaryBody.acceleration_metersPerSecond2 * (0.5 * timeStep_seconds * timeStep_seconds)) + (primaryBody.velocity_metersPerSecond * timeStep_seconds);
primaryBody.velocity_metersPerSecond += primaryBody.acceleration_metersPerSecond2 * timeStep_seconds;

// Rotation
// Not yet complete.

} // (primaryBody.active)
iteratorPrimaryBody++;
} // (iteratorPrimaryBody != tableBodies.end())
return true;
}

### Results

Nothing really new to look at that we haven't seen in previous screenshots. So here's a screenshot of a satellite moving around the moon that's moving around the Earth (with history trails on)...