Skip to main content
5 of 9
needs more infix :o)
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

With the missing piece from How do I "read out" the vertex names on this graph? I can self-answer using Nearest and Graph. Please don't let this post discourage answering as I am eager to see other approaches.

Now as a function with at least a little reusability. The second parameter is the search radius.

order[data_, rad_: 0.0001] := Module[{dd, near, g},
  dd = Join @@ data;
  near = Nearest[dd -> Automatic, dd, {2, rad}] ~Cases~ {_, _};
  g = near ~Join~ Partition[Range @ Length @ dd, 2] // Graph;
  FindPath[g, ##][[1]] & @@ GraphPeriphery[g]
]

ListLinePlot[Part[Join @@ dat, order[dat]], Frame -> True]

enter image description here

It works on the set with gaps given a sufficient radius:

ListLinePlot[Part[Join @@ dat2, order[dat2, 0.0001]], Frame -> True]

enter image description here

The next step in improving this would be to extract direction data from the output of order to apply to full lines.

Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k