i'd like to calculate position, velocity and acceleration at a given time
when acceleration depends linearily on position.
Here is some code using integration to show what i mean:
float start = 0.8f;
float accFactor = -5.0f;
float timestep = 0.008f;
float p = start;
float v = 0;
float a;
for (float t = 0; t <= 2.0f; t += timestep) // position dependent acc
{
a = (1.0f - p) * accFactor;
v += a * timestep;
p += v * timestep;
float aA = how to calculate acceleration without integration?
float vA = ?
float pA = ?
RenderPoint (2, sVec3 (t, 5+aA, 0), 1,1,1);
}
Here is another snippet just for reference with constant acceleration.
No problem there to claculate position and velocity.
p = start;
v = 0;
a = -5.0f;
for (float t = 0; t <= 2; t += timestep) // constant acc
{
v += a * timestep;
p += v * timestep;
float pA = start + 0.5f * a * t*t;
float vA = a * t;
}
The jpg shows plots of this code, pos = red, vel = green, acc = blue (constant acc right).Any help appreciated!