Calculating Distance Interval

Ok I’m totally confusing myself here and drawing a blank…

If I have change in x and change in y (dx and dy) over a specified amount of time in milliseconds, and I calculate time intervals by (time / dx) and (time / dy), how do
I calculate the distance intervals for each time period?

This is a stupid math question… but I’m seriously just blanking out here…

How about using 2 more variables oldDxInterval and oldDyInterval? Then you do:

oldDxInterval = interval;
interval = time /dx;
DxDistance = oldDxInterval - interval; //Or viceversa, don't know lol
interval = time / dy;
DyDistance = oldDyInterval - interval;

I hope it helps :slight_smile:

Uhhhh why would you divide time by the deltaX and deltaY? You want the other way around to get the distance for each time period:


x += dx / time;
y += dy / time;

Time intervals not distance intervals.

Should it just be:


dintx = dx / time;
dinty = dy / time;
tintx = time /dx;
tinty = time /dy;

Wait… what does that do? Could you clarify a bit :stuck_out_tongue: ?

I think what you’re looking for is:


distanceintervalx = dx * time period / time
distanceintervaly = dy * time period / time

Example:

dx = 5m, dy = 10m, dt = 2s
If you want a time period of 1s, then:

distanceintervalx = 5 * 1 / 2 = 2.5 m/s
distanceintervaly = 10 * 1 / 2 = 5 m/s

That’s what we usually call speed ;D