Problem: Compute a polyline from unordered edges

A polyline is a list of sorted edges where the end point of each edge is the start point of the next edge.

G# allows computing poylines from a list of completly unordered edges. The result may be a single polyline if all lines are connected or multiple polylines if the lines are piecewise disconnected.

Branching is not feasible for polylines. If multiple options exist, the result will be arbitrary at the branching point.

The number of relevant decimal digits specifies how many decimal digits after the decimal separator have to be identical in order to consider start or end vertex, respectively, of two adjoining line segments to be identical. The coordinates of all vertices will be rounded to the specified value.


Solution using G#

  1.        public static void PolylineExample()
  2.         {
  3.             // Create a sample list of unordered edges
  4.             List<Edge> edges = new List<Edge>(); //get it from somewhere
  5.             //Permutation is not necessary, just to make sure that the edges
  6.             //are really randomly ordered for demonstration.
  7.             Edge.RandomPermute(ref edges);
  9.             // Generate the poyline(s)
  10.             int zeros = 0;
  11.             List<Polyline> pLines =
  12.                 Polyline.ConstructFromUnorderedSegments(edges, 8, ref zeros, true);    
  13.         }


Four 3d polylines with branching (one highlighted), generated from 10 line segments.
201 polylines (one selected), generated at once from 35330 individual (contour) line segments.

<< back