go ahead... be a heretic | |
PerlMonks |
Re: Closed geometry: a train track problemby Dr. Mu (Hermit) |
on Jan 03, 2006 at 20:19 UTC ( [id://520718]=note: print w/replies, xml ) | Need Help?? |
I think I'd treat this as a grammar/parsing problem. First, determine what the simplest closed circuit is. With the set you describe, it would be four quarter circles arranged to form a circle: LLLLwhere L is a quarter circle that "turns left". This assumes that counter-clockwise is the canonical direction of travel. R could then be a quarter circle that turns right. (But RRRR would not be a valid circuit, since it violates the canonical direction of travel.) Next figure out what transformations you can make to any valid closed circuit to yield another valid closed circuit. For example, in pseudo-regexp terms: LL => SLLSi.e. Add straight segments to the ends of any left-turning semi-circle. So LLLL could become LSLLSL, a short oval. Likewise, RR => SRRSwould also be a valid operation. Also, some general rules may prove helpful. For instance: ^xy$ => yxi.e. commutativity, where x and y are any two sequences which, together, comprise an entire valid closed path. This just says that a valid closed path is valid, regardless of where you start. This means that LSLLSL from the example above can become SLLSLL, perhaps, in preparation for applying another rule. After you've defined your "transformational grammar", you can design an algorithm to parse potential layouts with it, so you can determine whether a given track arrangement is valid. Parsing with transformational grammars is, in general, not for the faint of heart. But simple Euclidean geometry may come to your rescue, in place of a fancy parsing algorithm. Nonetheless, you may have more fun just applying a random number generator to your transformation rules to see what kinds of layouts you come up with. Have fun!
In Section
Seekers of Perl Wisdom
|
|