in reply to Closed geometry: a train track problem

If you think about each piece in terms of adding a delta x and delta y (change of position) and delta angle (change of direction) to your current location and direction, it shouldn't be too difficult to lay pieces end-to-end until you either get a collision or a correct match, or you run out of pieces. Switches are indeed more difficult, especially switches with a numerical frog angle, but I think if you solve the issues in placing a curve to turn left vs a curve to turn right, you'll be well on the way.

As has been stated, this is a graph theory situation, and Winston's AI book is well worth checking out.

Don Wilde
"There's more than one level to any answer."
  • Comment on Re: Closed geometry: a train track problem

Replies are listed 'Best First'.
Re^2: Closed geometry: a train track problem
by pajout (Curate) on Jan 04, 2006 at 12:34 UTC
    Oh yes, delta x,y,alfa is the clever sight, but, it cannot describe possibility of track crossing (without some special crossing piece), for instance.
      "an exercise for the reader"... :)

      Okay, how about this: calculate some intermediate points, and store them in an x-y array. If a new piece tries to add points that are too close to an old point, it's a collision.

      Actually, I like Dr. Mu's concept of transforming successful closed layouts, although I wouldn't necessarily do it as a 'parsing problem' because that gets trickier as pieces become more varied in length, angle and radius. Either the programmer or the program need to figure out what transformations work geometrically, and I'd much rather it be the program. Heesh's right to focus on successful layouts rather than random ones, because that will give you more solutions more quickly. Won't be as entertaining to watch, though! :D

      Don Wilde
      "There's more than one level to any answer."
        Yes, Dr. Mu's concept is exact, but it need to solve collisions, too - generally, problems related with real dimensions of pieces.
        Ad intermediate points - imho, my concept of occupied squares is better (but not exhausting collision problems), of course, when it is possible to split every piece into set of square-unit.
      If the only crossings permitted are bridges, then this is easily solved. A bridge needs:
      • an ascending section of track;
      • a raised but level section of track;
      • a descending section of track
      Presumably you have a set number of support pieces for these, so if you allow any piece of track to alter the z co-ordinate if necessary, you just need to keep track of how many times you've changed z (ie how many ascents and descents you have) and how many times z has remained constant but non-zero (ie how many raised level sections you have). Detecting when you need a bridge to cross over another piece of track is easy.

      If you can have flat cross-overs, then you need to model the crossover as a special case.