What's the best way to implement one-dimensional collision detection?

Posted by cyclotis04 on Stack Overflow See other posts from Stack Overflow or by cyclotis04
Published on 2010-06-09T19:54:37Z Indexed on 2010/06/09 20:12 UTC
Read the original article Hit count: 177

I'm writing a piece of simulation software, and need an efficient way to test for collisions along a line.

The simulation is of a train crossing several switches on a track. When a wheel comes within N inches of the switch, the switch turns on, then turns off when the wheel leaves. Since all wheels are the same size, and all switches are the same size, I can represent them as a single coordinate X along the track. Switch distances and wheel distances don't change in relation to each other, once set.

This is a fairly trivial problem when done through brute force by placing the X coordinates in lists, and traversing them, but I need a way to do so efficiently, because it needs to be extremely accurate, even when the train is moving at high speeds. There's a ton of tutorials on 2D collision detection, but I'm not sure the best way to go about this unique 1D scenario.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET