# Help with solving speed/time/distance traversal problem

I'm not any sort of math wiz, and I've run up against a problem that is fairly complex for me to solve. A friend suggested this site might be able to provide some help. So let me try to describe the issue as best I can. Let me start out by saying that I had prepared a couple of images to help explain all this, but I'm not allowed to use them in this post as I'm a new user. Hence, some references to graphs are less meaningful. I have tried to describe what the graphs depicted.

I have a path of a known distance, that must be traversed in a fixed amount of time. However, I must start the traversal of the path and end the traversal at a specific speed. So, for example, if I need to traverse 1200 feet in 10 seconds, and my entry & exit speeds must both be 120 ft./sec, then I can simply stay at the constant speed of 120 ft./second to accomplish my goal. If I graph speed against time, the area under the graph represents distance traveled as so:

(Figure 1 shows speed in the vertical axis, time in the horizontal axis, with points marked for 120 ft./sec. on the vertical and 10 seconds on the horizontal. It shows a rectangular area under the horizontal line at Speed 120 ft/sec. starting a 0 seconds and going until 10 seconds. The area shown represents the 1200 feet that would be traversed).

However, if I have to travel only 700 feet in that same 10 second interval, things get ugly. I thought about decelerating at a constant rate until I could then accelerate at a constant rate to end up with my speed curve carving a triangle out of the graph in Figure 1 above, whose area above the curve would be 500 ft. However that would yield a discontinuity in the acceleration/deceleration that is unacceptable.

I then figured I could use a segment of a circle to do the same thing as shown below:

(Cool image shows a similar graph to the one above, but with a segment of a circle cutting into the shaded area from the image above, such that the segment intersects horizontal line at time = 0 and speed = 120 ft/sec on one side and 120 ft./sec and 10 seconds on the other side, with the segment dipping down to carve out 500 "feet" from the area under the horizontal line representing a constant speed of 120 ft/sec)

Here the orange area would represent the 500 ft less than the distance traveled by a constant speed. Following the speed curve indicated by the circle segment should be pretty trivial. And so it would seem that I have solved my problem. However, when I try to actually implement this into an algorithm, I run into the problem that the area calculations for the segment of a circle doesn't seem to yield units that make any sense. Perhaps it would be better to say that I don't know how to set up the problem so that the units make sense. Sure I can calculate the area of the segment, but what does 10 seconds mean when used as the chord of the circle, and what should the units of the radius be. I guess the value of theta is still easy at least. ;) Unfortunately I'm sort of stumped on the rest. I'm not even sure that this approach is viable.

I'd be just as interested in a numerical approach to the solution as a mathematical approach.

Any help you can offer to help me get my head around this would be greatly appreciated.

= Ed =

-
The circle idea is attractive. I looked at it, but only a little. Explicit formula for acceleration at time $t$ may be difficult. Here is another approach. You don't want abrupt change of acceleration. Take the $700$ foot example. Say we "accelerate" at rate $-kt(5-t)$ for first $5$ seconds, then really accelerate, at the symmetric rate, for next $5$ seconds. So initial deceleration is $0$ is strongest at $t=2.5$, goes down to $0$ at $t=5$. The mathematics is straightforward, but uses calculus. It turns out that $k=24/5$, but I would need to check. Acceleration is continuous. (Continued) –  André Nicolas Dec 8 '11 at 5:46
If this sort of approach might be useful, I can work out details, with numbers of your choice. –  André Nicolas Dec 8 '11 at 5:47
I wrote my answer assuming that you do not want an abrupt change in speed but an abrupt change in acceleration (say from -20 ft/sec to +20 ft/sec) is acceptable. Depending on the parameters of the problem this change can be drastic and may require aggressive use of brakes/accelerator in a physical context. If an abrupt change in acceleration is also not acceptable then André's suggested approach may be the way to go. –  tards Dec 8 '11 at 6:00
add comment

## 2 Answers

The "circle" idea is a good one. We'll convert it into more algebraic language to get a decent (general) answer.

Assume that time goes from $0$ to $T$ and the total distance travelled is $D$. Let $f$ be the velocity function, with $f(0)=v_0$ and $f(T)=v_1$. Then $$\int_0^T f(t)\; dt=D$$ Such an $f$ is definitely not unique, but we can find a simple $f$ by assuming it is a quadratic polynomial $$f(t)=a+b\cdot t+c\cdot t^2$$ The boundary value conditions imply that $a=v_0$ and $b=(v_1-v_0-c\cdot T^2)/T$. Plug this in, integrate, set equal to $D$, and solve for $c$ to find that $c=(3T\cdot(v_0+v_1)-6D)/T^3$ (I used WolframAlpha to speed things up). Thus $$f(t)=v_0+{6D-2T(v_1+2v_0)\over T^2}\cdot t+{3T(v_0+v_1)-6D\over T^3}\cdot t^2$$ satisfies our constraints.

Let's do an example. Take $D=1230$, $v_0=v_1=120$, $T=10$. Then $$f(t)=120+{9\over 5}t-{9\over 50}t^2$$ WolframAlpha calculates the integral and draws us a picture.

Another one. Take $D=700$, $v_0=v_1=120$, $T=10$. Then $$f(t)=120-30\cdot t+3\cdot t^2$$ WolframAlpha again for the picture.

Finally, I want to show how we can "normalize" the problem so that we can assume $D$ and $T$ both equal $1$.

We have a simple solution to the problem $$f(0)=w_0,\ f(1)=w_1,\ {\rm and}\ \int_0^1 f(t)\; dt=1$$ given by $$f(t)=w_0+(6-2w_1-4w_0)\cdot t+3(w_0+w_1-2)\cdot t^2$$ We can transform this into a solution of the problem $$F(0)=v_0,\ F(T)=v_1,\ {\rm and}\ \int_0^T F(t)\; dt=D$$ by setting $w_0=T\cdot v_0/D$, $w_1=T\cdot v_1/D$ in the above formula for $f$ and using $$F(t)={D\over T}\cdot f\big(t/T\big)$$ Then $F(0)={D\over T}\cdot f(0)={D\over T}\cdot w_0=v_0$, $F(T)={D\over T}\cdot f(1)=v_1$, and $$\int_0^T F(t)\; dt={D\over T}\int_0^T f\big(t/T\big)\; dt=D\int_0^1 f(t)\; dt=D$$ where the second equality uses the change of variables $t\rightarrow T\cdot t$.

For example, using $v_0=v_1=3$, $T=2$, and $D=4$, we have $w_0=w_1=6/4$ and $$f(t)={6\over 4}-3\cdot t+3\cdot t^2$$ Then $$F(t)=2\cdot f(t/2)=3-3\cdot t+{3\over 2}\cdot t^2$$

-
Wow, that seems pretty simple to implement as swell. I will give this a try and get back to you. –  Gonzo Dec 8 '11 at 17:04
In thinking this over a bit, I'm still not clear on how to actually use this. If I understand this correctly, in order to use this for my purposes, I would need to scale something in this function to give me the actual distance (700 feet in my original example). I would also need to scale my speed appropriately in order to account for t going from 0 to 1, meaning that I must scale v0 and v1 by 0.1 if I wanted my actual time to be 10 seconds? Also, as I said, I need to scale somewhere to get the total distance to be the actual value I need. I'm just not clear on how to use this practically. –  Gonzo Dec 8 '11 at 17:17
Thanks B R. I will give it a try and get back to everyone. –  Gonzo Dec 8 '11 at 18:41
After numerous interruptions today, I finally had a chance to code this up and try it. I used the original formula, attempting to use v0/D, and keep the rest of the equation the same. In my test case v0 = v1 = 120 ft/sec. Total Distance = 1229.605 For v0 = v1 = 120/1229.605 = 0.976 (rounded) at t=0.1 f(t) = 0.976 + (6- 0.1952 - 0.3904) * 0.1 + 3(0.976+0.976 - 2) * 0.01 = 0.976 + 0.58048 + -0.05414 = 0.6239 I assumed that I should then multiply this once again by 1220.605 but that gives a whacky result. Other values of t yeild equally weird results. What am I doing wrong? –  Gonzo Dec 9 '11 at 1:19
Uhm, I have to edit that, but I waited too long. it should break down to v0/D = 0.0976 and replace that everywhere it appears incorrect. Then f(t) = 0.0976 + 0.54144 + (-0.054144) = 0.5849. Once again, the numbers don't seem to make sense as I should some how get very near to 120 ft/sec and increase very gradually over the time period. I'm still missing something basic here. Thanks for all of the help so far. –  Gonzo Dec 9 '11 at 1:34
show 4 more comments

The physics of the problem can be represented by the following equation:

$$s = ut + \frac{a t^2}{2}$$

where,

$s$ is distance traveled in time $t$,

$u$ is the starting velocity and

$a$ is the acceleration.

Now, by symmetry, you need to travel 350 ft in a 5 second interval. Thus, using the above equation, we have:

$$350 = 120 \cdot 5 + \frac{a \cdot 5^2}{2}$$

Thus, you should deccelrate at: 20 ft per second.

Your speed at the end of the first leg would be given by: $v = u + at = 120 -20 \cdot 5 = 20 \ \text{ft/sec}$

Over the second leg, you need to end up with a speed of 120 ft/sec in 5 seconds. Thus, you need to accelerate at a speed of:

$$\frac{120-20}{5} = 20 \ \text{ft/sec}$$

and you travel a distance of:

$$S = \frac{1}{2} (u+v)t = \frac{1}{2} (20+120)5 =350$$

Thus, you have traveled 700 ft with the desired starting and ending speeds with an appropriate acceleration and deceleration.

See equations of motion at the wiki for more details.

General Approach

Known Quantities:

$u$ be the initial velocity,
$v$ be the final velocity,
$s$ be the distance you need to travel and
$t$ the time in which you need to travel the above distance.

Let:

$a$ represent desired acceleration (if needed) and
$d$ represent desired deceleration (if needed)

Assuming $v \ge u$, if the following set of equations has the same solution for $a$ then you are done:

$$s = ut + \frac{a t^2}{2}$$

$$v = u + at$$

If the set of equations do not have a single solution for $a$ it must be the case that either $v$ is too high relative to $u$ so that you overshoot $s$ in the given time $t$ or $v$ is too low so that you do not travel the full distance $s$ in the given time $t$.

In the first case you need to decelerate first so that you do not travel as much distance in the first few seconds and then accelerate to reach your desired speed over the remaining distance and time. How much you decelerate/accelerate and the time spent on each leg will depend on the relative magnitudes of the known quantities.

In the second case, you need to accelerate first and then decelerate. Again the magnitude of the acceleration/deceleration and times spent on each leg would depend on the magnitude of the known quantities.

In either case, you should be able to set up equations in three unknowns: $a$ (i.e., unknown acceleration), $d$ (i.e., unknown deceleration) and $t'$ (i.e., the amount of time for the first leg of the journey) and solve the resulting system to find out the appropriate values.

-
This is also an excellent reduction of the problem. I think BR gave a solution that might be easier to implement since it has fewer constraints. As I mentioned, I will try solution #2 first. I really appreciate all the help! –  Gonzo Dec 8 '11 at 17:07
add comment