I am writing a piece of simulation software and need an effective way to test collision along the line.
Simulation is a train crossing several switches on a track. When the wheel enters the N inch of the switch, the switch turns on and then turns off when the wheel leaves. Since all wheels are the same size and all the switches are the same size, I can imagine them as one X coordinate along the track. The shift distance and the distance between the wheels do not change with respect to each other after installation.
This is a pretty trivial problem when it is executed with brute force by putting the X coordinates on the lists and moving them, but I need a way to do this efficiently because it needs to be extremely accurate even when the train is moving at high speeds. There's a ton of tutorials on detecting two-dimensional collisions, but I'm not sure what the best way is to make this unique 1D scenario.
There seems to be some confusion as to how my data looks.
I mimic one site, not the entire region. Trains can be of any length, with different types of cars, but there is only one train. My train data is in the form {48,96,508,556,626,674,...}, indicating the distances from the front of the train ( 0) to the center of the axis.
(The train data will most likely come to me in the form of an ordered list of objects Car, each of which has a length and a list of integers representing the distance of the axis from the front of this car, but it all gets combined into one list, since all the axes are for me are the same.)
My switches are within a few hundred feet and will often be completely covered by train. The switches can be in any interval from hundreds of feet to several inches from each other and are in the same form as the train: {0,8,512,520,...}indicating the distance from the beginning of the site to the center of the switch.
Finally, I know the distance at which the wheel activates the switch in inches.
, 8 , X = 0 , X = 40, , 40 . X = 48, X = 8 . X = 56 , X = 64 . , .
10 /, . ( 30 , .)