Hello Everyone,
This is my first request to the group. I’ve been trying to import dxf files with 2D drawings. Depending on the dxf source, I get often simple “exploded” lists like that:
{Line[{{-16.73, 61.8, 0.}, {-16.53, 61.8, 0.}}],
Line[{{-16.53, 61.8, 0.}, {-16.53, 61.9, 0.}}],
Line[{{-16.53, 61.9, 0.}, {-16.58, 61.9, 0.}}],
Line[{{-16.58, 61.9, 0.}, {-16.58, 62.7, 0.}}],
Line[{{-16.58, 62.7, 0.}, {-16.44, 62.7, 0.}}],
Line[{{-16.44, 62.7, 0.}, {-16.44, 61.9, 0.}}],
Line[{{-16.44, 61.9, 0.}, {-16.49, 61.9, 0.}}],
Line[{{-16.49, 61.9, 0.}, {-16.49, 61.76, 0.}}],
Line[{{-16.49, 61.76, 0.}, {-16.61, 61.76, 0.}}],
Line[{{-16.61, 61.76, 0.}, {-16.61, 61.1747, 0.}}],
Line[{{-16.61, 61.1747, 0.}, {-18.2904, 60.376, 0.}}]}
This (generally huge) list of independant segments constitutes (in the design I import) a set of many polygonal paths (closed or not) that I want to identify and store as such (in the form of {Line{p1,p2,p3,…pn},Line{q1,q2,q3,…qm},etc…},each “Line” object storing a different polygon. I have built a pedestrian approach by starting with the first segment of the list and seaching the next neighbor segment by selecting the segment that a common vertex (it is assumed that there are no branches, so only polygonals contour, closed or not, are expected) and so on, removing the extracted lines from the initial list. It is slow , painfull and not very cleanly written I must admit.
Has someone a neat one-liner to propose to perform the function? Or even a built-in funtion that does the job?
Unfortunately enough , some crazy dxf are not so neat so I may find sometimes two aligned segments (with a shared intersection) that I should merge in a first phase (otherwise the above algorithm is lost in the middle of a polygon) . It takes some time to check all possible pairs of segments, check if they are aligned and in that case check if they intersect, then replace them by their union. So same question for this preparatory work: is there a clever way to do it ?
Thanks in advance for your comments
Christian