# Calculating object position with non-constant speed

1. Apr 11, 2013

### caibbor

The problem (long story short) to use an analogy... if I stand here, and then immediately run 5mph for an hour, after 30 minutes I have run 2.5 miles. But if I instead linearly drop from 5mph to 1mph over the course of that hour, where do I stand after 30 minutes?

The speed is linear so I don't think this quite breaks into calculus, but I've been banging my head over this for a while.

Reasoning:

I'm trying to program a particle engine and calculate movement without storing origins since they won't be drawn on screen unless they're within the view frustum and therefore particles off screen that are moving around that suddenly come on screen would not be in the proper place. So the calculations have to be made without any state variables.

2. Apr 11, 2013

### Curious3141

I don't know about the particle engine part, but the calculation of distance run is easy - sketch a graph of velocity vs time. The area under that graph will be the distance covered. In this case, your area will be a trapezoid.

Before you sketch the graph, you have to be clear whether you're decelerating from 5mph to 1mph over 1 hour or half-hour. It makes a big difference.

3. Apr 11, 2013

### caibbor

Well, I've got some food for thought on this. I gave a more explicit variation of the problem to a friend which goes as follows:

A particle at is going to travel past three non-evenly separated points A, B, and C in a straight line on the x-axis. The particle starts at 0.0 seconds at point A at (0,0) moving at 5 units right per second. It linearly slows down until it reaches point C at 1.0 seconds moving 1.0 units per second. Along the way, it passes through point B at 0.5 seconds. Where is point B and C?

The friend gave the following answer, where A is accelleration.

Iv = 5.0 u/s
A = -1.0 u/s/s

x_pos at 0.0 Sec
Final Velocity = 5.0 + (-1.0 * 0) = 5.0
Distance = .5 * (5.0 * 5.0) * 0 = 0

x_pos at 0.5 Sec
Final Velocity = 5.0 + (-1.0 * 0.5) = 4.5
Distance = .5 * (5.0 + 4.5) * (0.5) = 2.375

x_pos at 1.0 Sec
Final Velocity = 5.0 + (-1.0 * 1) = 4.0
Distance = .5 * (5.0 + 4.0) * (1) = 4.5

relevant: http://en.wikipedia.org/wiki/Equations_of_motion

4. Apr 12, 2013

### HallsofIvy

As long as acceleration is constant, as here, the "average speed" is just the arithmetic average of the speeds at the beginning and ending. If speed drops linearly from 5 to 1 mph then the average speed over that time is (5+1)/2= 3 mph. In 1/2 hour you will have gone 3/2 mile.

5. Apr 12, 2013

### caibbor

So my friend was wrong. How did you calculate that?

6. Apr 12, 2013

### AlephZero

Close, but no cigar!!

The average speed for 1 hour is 3 mph so you go 3 miles in the full hour.

But, the average speed for the first half hour is 4 mph and the average for the second half hour is 2 mph. So you go 2 miles in the first half hour, and 1 mile in the second.

7. Apr 12, 2013

### AlephZero

The method is OK.
But A = -4.0, not - 1.0.

8. Apr 12, 2013

### caibbor

x_pos at 0.0 Sec
Velocity = 5.0 + (-4.0 * 0.0) = 5.0
Distance = .5 * (5.0 + 5.0) * (0.0) = 0

x_pos at 0.5 Sec
Velocity = 5.0 + (-4.0 * 0.5) = 3.0
Distance = .5 * (5.0 + 3.0) * (0.5) = 2

x_pos at 1.0 Sec
Velocity = 5.0 + (-4.0 * 1.0) = 1.0
Distance = .5 * (5.0 + 1.0) * (1.0) = 3

yes? if this method is "okay," is there a better one? more accurate or, perhaps simpler?