2

I have an animation of traffic. I have 20 cars in road network, each car have a starting node and end node. Each car know how much distance does it need to travel in order to reach the end node. I move cars each 20 ms for 10 px. To move all cars from their start node to end node I need 60 iterations. That is 60*20ms = 1200ms.

Now I want to convert this time, or use data that I have, to a real time where car move 50km/h. How can I do that? Any idea?

Ivansek
  • 35
  • 3

1 Answers1

4

Distance between nodes / Speed = Travel time

1km / 50kmh = 0.02hours

That means that if you have 1km between your nodes the time it should take a car to drive it is 1.2minutes.

Each update then should move a car by Update step * Speed. In you case that is 1/60/60/50hours * 50 = 0,00027777 kilometers. (Note that measurement units should match) More conveniently put - each 20ms car travels 0.27meters.

Kromster
  • 10,643
  • 4
  • 53
  • 67
  • 2
    @Ivansek: What Krom shows here very well is that you get to define the scale. You get to choose how many pixels are equal to 1 meter and from that you can work out the 'real world' speed equivalents. – Baggers Aug 28 '12 at 10:30