I've run into a problem that I'm having trouble solving. If you have an object with different acceleration/decceleration values, and it's moving from point A to point B, and you already know from previous calculations that it wouldn't have enough space to decelerate fully from its max speed. I'm trying to figure out how much acceleration it can do, so that it still has room to decelerate fully in time. The point is to get there as fast as possible, without overshooting.
Assuming the deccel is less than or equal to the accel, I could do:
accelSpace = distance * deccel/accel
deccelSpace = (1-accelSpace) * distance
This way, if accel is 10 and deccel is 2, you'd accel for 0.2 of the distance, then decel the rest.
But this only really works if the object isn't moving at all yet. If it's already moving, I'd have to figure out how much acceleration I can still get away with, while still having room to decelerate.
I think this might be like one of those optimization problems from Cal I. I'll describe where I'm at with solving this problem. I'll start with some equations:
How to know how much space you need to accelerate to a certain speed:
time to accel: t = (spd - curSpeed)/accel
accelSpace = 1/2(t^2)
Decceleration space from a certain speed:
time to deccel: t = spd/deccel
deccelSpace = 1/2(t^2)
Now here I am trying to solve this:
If I can get the max decelerable speed with:
dist - deccelSpace = 0
substituting the previous equations we get:
dist - 1/2(spd/deccel)^2 = 0
spd^2/2deccel = dist
spd = sqrt(2dist) * deccel
So that gives us the max speed I could decelerate from in that space. spd <= actual speed, we should just decelerate now, and not do any further calculations.
However, if spd > actual speed, we can probably accelerate a bit more before the end. So I turn to optimization problems from Cal I.
a = acceleration
d = deceleration
S = current speed
S1 = desired speed (unknown)
deltaS: S1 - S
we've got the functions we want to maximize:
accelSpace = deltaS^2/2a^2
decelSpace = (S + deltaS)/2d^2
we've got a constraint:
dist - accelSpace - decelSpace = 0
So I solve the constraint for accelSpace:
acccelSpace = dist - decelSpace;
Plug in the accelSpace function, solve for deltaS
deltaS^2/2a^2 = dist - decelSpace
deltaS^2 = 2a^2(dist - decelSpace)
deltaS = a * sqrt(2)sqrt(dist-decelSpace)
At this point, I think I'm supposed to substitute deltaS into the accelSpace function, then get the local maxima from a derrivative, then plug that into decelSpace, but I'm at a loss for what to do afterwards, because doing
just the first step leads me right back to the constraint
accelSpace = (a*sqrt(2)sqrt(dist - decelSpace)^2 / 2a^2
accelSpace = dist - decelSpace.
So there you have it, I'm lost. :/