# How can I combine a list of Line[]'s into one continuous Line?

I have a huge list of Lines. Take this one as an example:

linelist1 = {Line[{{0.150, 0.099}, {0.151, 0.095}}], Line[{{0.149, 0.104}, {0.150, 0.099}}], Line[{{0.151, 0.095}, {0.152, 0.090}}], Line[{{0.149, 0.108}, {0.149, 0.104}}], Line[{{0.149, 0.114}, {0.149, 0.108}}], Line[{{0.152, 0.090}, {0.154, 0.087}}], Line[{{0.154, 0.087}, {0.157, 0.083}}], Line[{{0.157, 0.083}, {0.159, 0.080}}], Line[{{0.149, 0.119}, {0.149, 0.114}}], Line[{{0.149, 0.125}, {0.149, 0.119}}], Line[{{0.150, 0.132}, {0.150, 0.130}}], Line[{{0.150, 0.130}, {0.149, 0.125}}], Line[{{0.151, 0.136}, {0.150, 0.132}}], Line[{{0.162, 0.079}, {0.167, 0.076}}], Line[{{0.159, 0.080}, {0.162, 0.079}}], Line[{{0.167, 0.076}, {0.171, 0.076}}], Line[{{0.171, 0.076}, {0.179, 0.075}}], Line[{{0.152, 0.144}, {0.152, 0.141}}], Line[{{0.152, 0.141}, {0.151, 0.136}}], Line[{{0.154, 0.153}, {0.153, 0.148}}], Line[{{0.153, 0.148}, {0.152, 0.144}}], Line[{{0.154, 0.170}, {0.154, 0.153}}], Line[{{0.179, 0.075}, {0.184, 0.076}}], Line[{{0.184, 0.076}, {0.195, 0.079}}], Line[{{0.195, 0.079}, {0.202, 0.082}}], Line[{{0.202, 0.082}, {0.217, 0.089}}], Line[{{0.151, 0.182}, {0.151, 0.180}}], Line[{{0.151, 0.180}, {0.154, 0.170}}], Line[{{0.149, 0.193}, {0.151, 0.182}}], Line[{{0.149, 0.195}, {0.149, 0.193}}], Line[{{0.148, 0.204}, {0.149, 0.195}}], Line[{{0.147, 0.208}, {0.147, 0.206}}], Line[{{0.147, 0.219}, {0.147, 0.208}}], Line[{{0.147, 0.206}, {0.148, 0.204}}], Line[{{0.147, 0.220}, {0.147, 0.219}}], Line[{{0.147, 0.223}, {0.147, 0.220}}], Line[{{0.147, 0.235}, {0.147, 0.234}}], Line[{{0.147, 0.248}, {0.147, 0.235}}], Line[{{0.147, 0.234}, {0.147, 0.223}}], Line[{{0.217, 0.089}, {0.226, 0.094}}], Line[{{0.237, 0.102}, {0.246, 0.107}}], Line[{{0.236, 0.101}, {0.237, 0.102}}], Line[{{0.226, 0.094}, {0.236, 0.101}}], Line[{{0.246, 0.107}, {0.258, 0.115}}], Line[{{0.270, 0.126}, {0.283, 0.135}}], Line[{{0.258, 0.115}, {0.270, 0.126}}], Line[{{0.283, 0.135}, {0.297, 0.147}}], Line[{{0.147, 0.249}, {0.147, 0.248}}], Line[{{0.147, 0.251}, {0.147, 0.249}}], Line[{{0.149, 0.263}, {0.147, 0.251}}], Line[{{0.149, 0.265}, {0.149, 0.263}}], Line[{{0.149, 0.266}, {0.149, 0.265}}], Line[{{0.151, 0.278}, {0.149, 0.266}}], Line[{{0.151, 0.280}, {0.151, 0.278}}], Line[{{0.151, 0.281}, {0.151, 0.280}}], Line[{{0.154, 0.295}, {0.151, 0.281}}], Line[{{0.154, 0.296}, {0.154, 0.295}}], Line[{{0.154, 0.297}, {0.154, 0.296}}], Line[{{0.157, 0.310}, {0.154, 0.297}}], Line[{{0.158, 0.311}, {0.157, 0.310}}], Line[{{0.158, 0.312}, {0.158, 0.311}}], Line[{{0.162, 0.326}, {0.158, 0.312}}], Line[{{0.162, 0.327}, {0.162, 0.326}}], Line[{{0.167, 0.342}, {0.162, 0.327}}], Line[{{0.297, 0.147}, {0.312, 0.161}}], Line[{{0.312, 0.161}, {0.327, 0.175}}], Line[{{0.168, 0.343}, {0.167, 0.342}}], Line[{{0.167, 0.342}, {0.167, 0.342}}], Line[{{0.174, 0.358}, {0.173, 0.357}}], Line[{{0.173, 0.357}, {0.168, 0.343}}], Line[{{0.180, 0.372}, {0.174, 0.358}}], Line[{{0.180, 0.372}, {0.180, 0.372}}], Line[{{0.188, 0.386}, {0.180, 0.372}}], Line[{{0.188, 0.386}, {0.188, 0.386}}], Line[{{0.196, 0.399}, {0.188, 0.386}}], Line[{{0.196, 0.399}, {0.196, 0.399}}], Line[{{0.205, 0.412}, {0.196, 0.399}}], Line[{{0.205, 0.412}, {0.205, 0.412}}], Line[{{0.214, 0.423}, {0.205, 0.412}}], Line[{{0.215, 0.424}, {0.214, 0.423}}], Line[{{0.214, 0.423}, {0.214, 0.423}}], Line[{{0.224, 0.434}, {0.224, 0.434}}], Line[{{0.225, 0.435}, {0.224, 0.434}}], Line[{{0.224, 0.434}, {0.215, 0.424}}], Line[{{0.236, 0.445}, {0.235, 0.444}}], Line[{{0.235, 0.444}, {0.234, 0.444}}], Line[{{0.234, 0.444}, {0.225, 0.435}}], Line[{{0.245, 0.452}, {0.236, 0.445}}], Line[{{0.247, 0.454}, {0.246, 0.453}}], Line[{{0.246, 0.453}, {0.245, 0.452}}], Line[{{0.257, 0.460}, {0.247, 0.454}}], Line[{{0.258, 0.462}, {0.257, 0.461}}], Line[{{0.257, 0.461}, {0.257, 0.460}}], Line[{{0.271, 0.469}, {0.270, 0.469}}], Line[{{0.270, 0.469}, {0.269, 0.468}}], Line[{{0.269, 0.468}, {0.258, 0.462}}], Line[{{0.282, 0.475}, {0.281, 0.474}}], Line[{{0.283, 0.475}, {0.282, 0.475}}], Line[{{0.292, 0.480}, {0.283, 0.475}}], Line[{{0.281, 0.474}, {0.271, 0.469}}], Line[{{0.296, 0.481}, {0.295, 0.481}}], Line[{{0.293, 0.480}, {0.292, 0.480}}], Line[{{0.295, 0.481}, {0.293, 0.480}}], Line[{{0.307, 0.485}, {0.305, 0.485}}], Line[{{0.308, 0.485}, {0.307, 0.485}}], Line[{{0.305, 0.485}, {0.296, 0.481}}], Line[{{0.320, 0.489}, {0.318, 0.489}}], Line[{{0.330, 0.492}, {0.320, 0.489}}], Line[{{0.318, 0.489}, {0.308, 0.485}}], Line[{{0.327, 0.175}, {0.343, 0.190}}], Line[{{0.343, 0.190}, {0.358, 0.207}}], Line[{{0.358, 0.207}, {0.375, 0.224}}], Line[{{0.391, 0.241}, {0.405, 0.260}}], Line[{{0.405, 0.260}, {0.421, 0.278}}], Line[{{0.375, 0.224}, {0.391, 0.241}}], Line[{{0.421, 0.278}, {0.436, 0.296}}], Line[{{0.436, 0.296}, {0.448, 0.315}}], Line[{{0.448, 0.315}, {0.459, 0.331}}], Line[{{0.459, 0.331}, {0.471, 0.348}}], Line[{{0.332, 0.492}, {0.331, 0.492}}], Line[{{0.331, 0.492}, {0.330, 0.492}}], Line[{{0.343, 0.494}, {0.332, 0.492}}], Line[{{0.354, 0.495}, {0.344, 0.494}}], Line[{{0.344, 0.494}, {0.343, 0.494}}], Line[{{0.355, 0.496}, {0.354, 0.495}}], Line[{{0.356, 0.495}, {0.355, 0.496}}], Line[{{0.471, 0.348}, {0.480, 0.364}}], Line[{{0.486, 0.376}, {0.494, 0.390}}], Line[{{0.480, 0.364}, {0.486, 0.376}}], Line[{{0.494, 0.390}, {0.500, 0.403}}], Line[{{0.367, 0.496}, {0.366, 0.496}}], Line[{{0.366, 0.496}, {0.356, 0.495}}], Line[{{0.377, 0.496}, {0.377, 0.496}}], Line[{{0.387, 0.495}, {0.377, 0.496}}], Line[{{0.377, 0.496}, {0.367, 0.496}}], Line[{{0.387, 0.495}, {0.387, 0.495}}], Line[{{0.396, 0.493}, {0.387, 0.495}}], Line[{{0.397, 0.493}, {0.396, 0.493}}], Line[{{0.405, 0.490}, {0.397, 0.493}}], Line[{{0.405, 0.490}, {0.405, 0.490}}], Line[{{0.413, 0.487}, {0.405, 0.490}}], Line[{{0.413, 0.487}, {0.413, 0.487}}], Line[{{0.500, 0.403}, {0.502, 0.413}}], Line[{{0.504, 0.420}, {0.507, 0.429}}], Line[{{0.502, 0.413}, {0.504, 0.420}}], Line[{{0.427, 0.478}, {0.420, 0.483}}], Line[{{0.420, 0.483}, {0.413, 0.487}}], Line[{{0.432, 0.472}, {0.427, 0.478}}], Line[{{0.433, 0.472}, {0.432, 0.472}}], Line[{{0.437, 0.465}, {0.433, 0.472}}], Line[{{0.507, 0.429}, {0.507, 0.436}}], Line[{{0.507, 0.436}, {0.504, 0.444}}], Line[{{0.477, 0.451}, {0.473, 0.450}}], Line[{{0.473, 0.450}, {0.437, 0.465}}], Line[{{0.504, 0.444}, {0.502, 0.448}}], Line[{{0.483, 0.452}, {0.477, 0.451}}], Line[{{0.502, 0.448}, {0.499, 0.451}}], Line[{{0.489, 0.453}, {0.483, 0.452}}], Line[{{0.499, 0.451}, {0.493, 0.452}}], Line[{{0.493, 0.452}, {0.489, 0.453}}]};


Here's what it looks like graphically:

Graphics@linelist1


The problem I'm trying to solve is that I want to make this line dashed. However, if I do it right now, the line segments are all so small that the dashing doesn't work for most of it:

Graphics@{Dashed, linelist1}


Here's a semi-solution I've tried:

Boundary2SingleLine[inBd_] := (
pts = Flatten[inBd[[All, 1]], 1];
orderedpts = First@FindCurvePath@pts;
Return@Line[pts[[orderedpts]]];
)
Graphics@{Dashed, Boundary2SingleLine@linelist1}


Lookin good! However, if I do it with this set of lines:

linelist2={Line[{{0.217, 0.171}, {0.217, 0.166}}], Line[{{0.217, 0.166}, {0.218, 0.161}}], Line[{{0.218, 0.176}, {0.217, 0.171}}], Line[{{0.218, 0.177}, {0.218, 0.176}}], Line[{{0.220, 0.157}, {0.220, 0.156}}], Line[{{0.218, 0.161}, {0.220, 0.157}}], Line[{{0.218, 0.178}, {0.218, 0.177}}], Line[{{0.219, 0.182}, {0.218, 0.178}}], Line[{{0.219, 0.183}, {0.219, 0.182}}], Line[{{0.220, 0.186}, {0.219, 0.184}}], Line[{{0.219, 0.184}, {0.219, 0.183}}], Line[{{0.220, 0.189}, {0.220, 0.186}}], Line[{{0.222, 0.196}, {0.221, 0.192}}], Line[{{0.221, 0.192}, {0.220, 0.189}}], Line[{{0.220, 0.156}, {0.223, 0.152}}], Line[{{0.223, 0.152}, {0.228, 0.147}}], Line[{{0.234, 0.143}, {0.240, 0.141}}], Line[{{0.228, 0.147}, {0.234, 0.143}}], Line[{{0.223, 0.199}, {0.222, 0.196}}], Line[{{0.224, 0.202}, {0.223, 0.199}}], Line[{{0.225, 0.206}, {0.224, 0.202}}], Line[{{0.227, 0.213}, {0.226, 0.209}}], Line[{{0.229, 0.217}, {0.227, 0.213}}], Line[{{0.226, 0.209}, {0.225, 0.206}}], Line[{{0.230, 0.220}, {0.229, 0.217}}], Line[{{0.231, 0.224}, {0.230, 0.220}}], Line[{{0.232, 0.227}, {0.231, 0.224}}], Line[{{0.234, 0.234}, {0.232, 0.227}}], Line[{{0.235, 0.237}, {0.234, 0.234}}], Line[{{0.237, 0.243}, {0.235, 0.237}}], Line[{{0.240, 0.141}, {0.243, 0.140}}], Line[{{0.243, 0.140}, {0.250, 0.138}}], Line[{{0.250, 0.138}, {0.254, 0.138}}], Line[{{0.254, 0.138}, {0.263, 0.138}}], Line[{{0.263, 0.138}, {0.268, 0.138}}], Line[{{0.268, 0.138}, {0.278, 0.138}}], Line[{{0.239, 0.246}, {0.237, 0.243}}], Line[{{0.239, 0.248}, {0.239, 0.246}}], Line[{{0.240, 0.251}, {0.239, 0.248}}], Line[{{0.243, 0.259}, {0.242, 0.256}}], Line[{{0.245, 0.263}, {0.243, 0.259}}], Line[{{0.242, 0.256}, {0.240, 0.251}}], Line[{{0.248, 0.269}, {0.247, 0.267}}], Line[{{0.250, 0.273}, {0.248, 0.269}}], Line[{{0.247, 0.267}, {0.245, 0.263}}], Line[{{0.253, 0.281}, {0.252, 0.278}}], Line[{{0.252, 0.278}, {0.250, 0.273}}], Line[{{0.240, 0.335}, {0.253, 0.281}}], Line[{{0.278, 0.138}, {0.285, 0.140}}], Line[{{0.285, 0.140}, {0.296, 0.141}}], Line[{{0.296, 0.141}, {0.304, 0.144}}], Line[{{0.304, 0.144}, {0.316, 0.147}}], Line[{{0.316, 0.147}, {0.326, 0.150}}], Line[{{0.326, 0.150}, {0.338, 0.155}}], Line[{{0.338, 0.155}, {0.350, 0.160}}], Line[{{0.239, 0.336}, {0.240, 0.335}}], Line[{{0.239, 0.336}, {0.239, 0.336}}], Line[{{0.240, 0.337}, {0.239, 0.336}}], Line[{{0.242, 0.338}, {0.240, 0.337}}], Line[{{0.244, 0.339}, {0.242, 0.338}}], Line[{{0.248, 0.340}, {0.244, 0.339}}], Line[{{0.252, 0.341}, {0.248, 0.340}}], Line[{{0.257, 0.342}, {0.256, 0.342}}], Line[{{0.256, 0.342}, {0.252, 0.341}}], Line[{{0.262, 0.343}, {0.257, 0.342}}], Line[{{0.266, 0.343}, {0.262, 0.343}}], Line[{{0.295, 0.363}, {0.266, 0.343}}], Line[{{0.297, 0.366}, {0.295, 0.363}}], Line[{{0.299, 0.369}, {0.297, 0.366}}], Line[{{0.301, 0.373}, {0.299, 0.369}}], Line[{{0.303, 0.377}, {0.301, 0.373}}], Line[{{0.305, 0.381}, {0.303, 0.377}}], Line[{{0.307, 0.384}, {0.305, 0.381}}], Line[{{0.309, 0.389}, {0.307, 0.384}}], Line[{{0.311, 0.393}, {0.309, 0.389}}], Line[{{0.314, 0.397}, {0.311, 0.393}}], Line[{{0.316, 0.400}, {0.314, 0.397}}], Line[{{0.318, 0.404}, {0.316, 0.400}}], Line[{{0.321, 0.408}, {0.318, 0.404}}], Line[{{0.323, 0.412}, {0.321, 0.408}}], Line[{{0.325, 0.416}, {0.323, 0.412}}], Line[{{0.328, 0.420}, {0.325, 0.416}}], Line[{{0.330, 0.424}, {0.328, 0.420}}], Line[{{0.333, 0.428}, {0.330, 0.424}}], Line[{{0.335, 0.431}, {0.333, 0.428}}], Line[{{0.338, 0.436}, {0.335, 0.431}}], Line[{{0.340, 0.439}, {0.338, 0.436}}], Line[{{0.350, 0.160}, {0.362, 0.166}}], Line[{{0.362, 0.166}, {0.375, 0.172}}], Line[{{0.375, 0.172}, {0.386, 0.179}}], Line[{{0.386, 0.179}, {0.389, 0.181}}], Line[{{0.401, 0.188}, {0.411, 0.195}}], Line[{{0.389, 0.181}, {0.401, 0.188}}], Line[{{0.411, 0.195}, {0.415, 0.198}}], Line[{{0.415, 0.198}, {0.426, 0.205}}], Line[{{0.426, 0.205}, {0.440, 0.216}}], Line[{{0.440, 0.216}, {0.449, 0.224}}], Line[{{0.449, 0.224}, {0.454, 0.228}}], Line[{{0.454, 0.228}, {0.463, 0.236}}], Line[{{0.463, 0.236}, {0.471, 0.245}}], Line[{{0.475, 0.249}, {0.483, 0.257}}], Line[{{0.471, 0.245}, {0.475, 0.249}}], Line[{{0.483, 0.257}, {0.516, 0.272}}], Line[{{0.516, 0.272}, {0.524, 0.272}}], Line[{{0.550, 0.275}, {0.573, 0.280}}], Line[{{0.573, 0.280}, {0.586, 0.282}}], Line[{{0.524, 0.272}, {0.550, 0.275}}], Line[{{0.586, 0.282}, {0.610, 0.287}}], Line[{{0.610, 0.287}, {0.624, 0.295}}], Line[{{0.624, 0.295}, {0.636, 0.300}}], Line[{{0.636, 0.300}, {0.641, 0.309}}], Line[{{0.641, 0.309}, {0.640, 0.317}}], Line[{{0.640, 0.317}, {0.633, 0.326}}], Line[{{0.633, 0.326}, {0.619, 0.333}}], Line[{{0.619, 0.333}, {0.600, 0.341}}], Line[{{0.600, 0.341}, {0.583, 0.347}}], Line[{{0.343, 0.443}, {0.340, 0.439}}], Line[{{0.345, 0.446}, {0.343, 0.443}}], Line[{{0.348, 0.450}, {0.345, 0.446}}], Line[{{0.350, 0.454}, {0.348, 0.450}}], Line[{{0.353, 0.457}, {0.350, 0.454}}], Line[{{0.355, 0.460}, {0.353, 0.457}}], Line[{{0.358, 0.464}, {0.355, 0.460}}], Line[{{0.360, 0.466}, {0.358, 0.464}}], Line[{{0.363, 0.470}, {0.360, 0.466}}], Line[{{0.583, 0.347}, {0.541, 0.385}}], Line[{{0.541, 0.385}, {0.540, 0.392}}], Line[{{0.540, 0.392}, {0.539, 0.401}}], Line[{{0.368, 0.475}, {0.366, 0.473}}], Line[{{0.370, 0.478}, {0.368, 0.475}}], Line[{{0.366, 0.473}, {0.363, 0.470}}], Line[{{0.373, 0.481}, {0.370, 0.478}}], Line[{{0.375, 0.483}, {0.373, 0.481}}], Line[{{0.378, 0.485}, {0.375, 0.483}}], Line[{{0.381, 0.488}, {0.378, 0.485}}], Line[{{0.383, 0.490}, {0.381, 0.488}}], Line[{{0.385, 0.491}, {0.383, 0.490}}], Line[{{0.388, 0.494}, {0.385, 0.491}}], Line[{{0.392, 0.497}, {0.390, 0.495}}], Line[{{0.390, 0.495}, {0.388, 0.494}}], Line[{{0.395, 0.498}, {0.392, 0.497}}], Line[{{0.397, 0.500}, {0.395, 0.498}}], Line[{{0.399, 0.500}, {0.397, 0.500}}], Line[{{0.402, 0.501}, {0.399, 0.500}}], Line[{{0.539, 0.401}, {0.538, 0.407}}], Line[{{0.538, 0.407}, {0.536, 0.414}}], Line[{{0.536, 0.414}, {0.534, 0.420}}], Line[{{0.534, 0.420}, {0.532, 0.426}}], Line[{{0.532, 0.426}, {0.529, 0.432}}], Line[{{0.529, 0.432}, {0.526, 0.437}}], Line[{{0.526, 0.437}, {0.522, 0.443}}], Line[{{0.522, 0.443}, {0.519, 0.447}}], Line[{{0.519, 0.447}, {0.515, 0.452}}], Line[{{0.404, 0.502}, {0.402, 0.501}}], Line[{{0.406, 0.503}, {0.404, 0.502}}], Line[{{0.409, 0.503}, {0.406, 0.503}}], Line[{{0.411, 0.504}, {0.409, 0.503}}], Line[{{0.415, 0.504}, {0.411, 0.504}}], Line[{{0.421, 0.503}, {0.417, 0.504}}], Line[{{0.417, 0.504}, {0.415, 0.504}}], Line[{{0.423, 0.503}, {0.421, 0.503}}], Line[{{0.427, 0.501}, {0.423, 0.503}}], Line[{{0.428, 0.500}, {0.427, 0.501}}], Line[{{0.432, 0.498}, {0.428, 0.500}}], Line[{{0.515, 0.452}, {0.511, 0.455}}], Line[{{0.506, 0.459}, {0.502, 0.462}}], Line[{{0.511, 0.455}, {0.506, 0.459}}], Line[{{0.502, 0.462}, {0.497, 0.465}}], Line[{{0.433, 0.496}, {0.432, 0.498}}], Line[{{0.438, 0.492}, {0.437, 0.493}}], Line[{{0.437, 0.493}, {0.433, 0.496}}], Line[{{0.442, 0.488}, {0.438, 0.492}}], Line[{{0.493, 0.467}, {0.487, 0.470}}], Line[{{0.497, 0.465}, {0.493, 0.467}}], Line[{{0.487, 0.470}, {0.481, 0.472}}], Line[{{0.481, 0.472}, {0.477, 0.473}}], Line[{{0.470, 0.474}, {0.467, 0.475}}], Line[{{0.477, 0.473}, {0.470, 0.474}}], Line[{{0.467, 0.475}, {0.442, 0.488}}]}


It fails and only gets part of it:

Graphics@{Red, linelist2, Thickness -> .008, Black, Dashed,
Boundary2SingleLine@linelist2}


I figured out that for some reason FindCurvePaths is returning 2 lists in this case:

pts = Flatten[linelist2[[All, 1]], 1];
fcp = FindCurvePath@pts
Graphics@{Red, Line[pts[[fcp[[1]]]]], Blue, Line[pts[[fcp[[2]]]]]}


At this point I could manually finagle a way to attach these two lists, but I really have no guarantee it'll work generally, and I'm guessing this is an unnecessarily complicated solution anyway.

What's an easier way of doing this?

edit: Thank you for any advice. However, please show a solution working with the second example set of lines, as I already have a solution that works with the first.

edit: Here is @Michael E2's solution, which works on the second example:

Boundary2SingleLine[inBd_] := (
gr = Graph[inBd /. Line[List[v__]] :> UndirectedEdge[v]];
cycle = First@FindHamiltonianCycle[gr, 1];
Return@Line[Append[cycle[[All, 1]], cycle[[-1, 2]]]];
)
Graphics@{Dashing[.01], Boundary2SingleLine@linelist2}


• Why don't you edit your post in such a way that makes it easy to get to the information that is needed to help. Jul 8, 2016 at 19:14
• @user21, sorry if it isn't clear, but what do you mean? The 2nd example? If so, I tried to include it in the main body but the input area said I reached the character limit. Jul 8, 2016 at 19:17
• You put a huge list of line in the text that you are not really interested in but the one you are interested in a link. In other words the not important data is more prominent that the important one. Jul 8, 2016 at 19:34
• Why include the first example at all? And why have you copied one of the answers into the question? Jul 8, 2016 at 20:06
• In my opinion it would be sufficient just to state that Boundary2SingleLine works fine when FindCurvePath returns a single list. If you want to show the details then yes, I think you should put the working data in the link and the problem data in the post. Jul 8, 2016 at 21:17

Here's a graph-based solution:

gr = Graph[linelist1 /. Line[List[v__]] :> UndirectedEdge[v]];
cycle = First@FindHamiltonianCycle[gr, 1];
Graphics[{Dashing[0.01], Line[Append[cycle[[All, 1]], cycle[[-1, 2]]]]}]


• Excellent, this works great on the 2nd example! Jul 8, 2016 at 19:16
linelist1 = {Line[{{0.15042300130733277,
0.09918669845167598}, {0.15124668865085406, 0.09522452324491057}}],
Line[{{0.14961629841942972, 0.10444571885174352}, {0.15042300130733277,
0.09918669845167598}}],
Line[{{0.15124668865085406, 0.09522452324491057}, {0.15296330904994523,
0.09071834061461313}}],
Line[{{0.14933067532583966, 0.10873463230613303}, {0.14961629841942972,
0.10444571885174352}}],
Line[{{0.1492065391252379, 0.11459136282769972}, {0.14933067532583966,
0.10873463230613303}}],
Line[{{0.15296330904994523, 0.09071834061461313}, {0.15443233429278366,
0.08720754178169458}}],
Line[{{0.15443233429278366, 0.08720754178169458}, {0.15738657618834503,
0.0837116800119704}}],
Line[{{0.15738657618834503, 0.0837116800119704}, {0.1596507357294199,
0.08081800622081214}}],
Line[{{0.14938185651096897, 0.11910808435898695}, {0.1492065391252379,
0.11459136282769972}}],
Line[{{0.14978835086914977, 0.1254736636010152}, {0.14938185651096897,
0.11910808435898695}}],
Line[{{0.15077460730814868, 0.1327981842766949}, {0.15036790182308324,
0.13013455437855134}}],
Line[{{0.15036790182308324, 0.13013455437855134}, {0.14978835086914977,
0.1254736636010152}}],
Line[{{0.15120855329817068, 0.13696037633048153}, {0.15077460730814868,
0.1327981842766949}}],
Line[{{0.16277911871721887, 0.07929367135576196}, {0.16756504304577993,
0.07669208018087739}}],
Line[{{0.1596507357294199, 0.08081800622081214}, {0.16277911871721887,
0.07929367135576196}}],
Line[{{0.16756504304577993, 0.07669208018087739}, {0.17179084853507678,
0.07624695124973005}}],
Line[{{0.17179084853507678, 0.07624695124973005}, {0.17906280098426666,
0.07576450311212397}}],
Line[{{0.15257273308627697, 0.14470958676131765}, {0.15214869088284963,
0.14169046682959874}}],
Line[{{0.15214869088284963, 0.14169046682959874}, {0.15120855329817068,
0.13696037633048153}}],
Line[{{0.154380363176796, 0.15329508718925586}, {0.15336715187177208,
0.14894978414339125}}],
Line[{{0.15336715187177208, 0.14894978414339125}, {0.15257273308627697,
0.14470958676131765}}],
Line[{{0.15408201484170664, 0.17090212421388687}, {0.154380363176796,
0.15329508718925586}}],
Line[{{0.17906280098426666, 0.07576450311212397}, {0.1846655098267246,
0.07675733142107073}}],
Line[{{0.1846655098267246, 0.07675733142107073}, {0.19526513101961043,
0.07935442585321775}}],
Line[{{0.19526513101961043, 0.07935442585321775}, {0.2025793721147758,
0.08225275130107908}}],
Line[{{0.2025793721147758, 0.08225275130107908}, {0.2174515369686099,
0.0892027606755095}}],
Line[{{0.15130771769953516, 0.18272337857024754}, {0.15175791747769907,
0.1805607558081054}}],
Line[{{0.15175791747769907, 0.1805607558081054}, {0.15408201484170664,
0.17090212421388687}}],
Line[{{0.14947523641765, 0.19324727078363216}, {0.15130771769953516,
0.18272337857024754}}],
Line[{{0.14922075255141615, 0.195421957699875}, {0.14947523641765,
0.19324727078363216}}],
Line[{{0.14830703464564116, 0.20491305790082923}, {0.14922075255141615,
0.195421957699875}}],
Line[{{0.14786378115799406, 0.20890778773289803}, {0.14791166732629607,
0.20675668855532706}}],
Line[{{0.1473023145442782, 0.21917015209603855}, {0.14786378115799406,
0.20890778773289803}}],
Line[{{0.14791166732629607, 0.20675668855532706}, {0.14830703464564116,
0.20491305790082923}}],
Line[{{0.1471112448868429, 0.22098660364789832}, {0.1473023145442782,
0.21917015209603855}}],
Line[{{0.14727721615276837, 0.22307805371953965}, {0.1471112448868429,
0.22098660364789832}}],
Line[{{0.1471140525731194, 0.23582182314046962}, {0.14709509899938097,
0.23406594386910806}}],
Line[{{0.14783588435291467, 0.24801241612439603}, {0.1471140525731194,
0.23582182314046962}}],
Line[{{0.14709509899938097, 0.23406594386910806}, {0.14727721615276837,
0.22307805371953965}}],
Line[{{0.2174515369686099, 0.0892027606755095}, {0.22682413867491788,
0.09457182622878016}}],
Line[{{0.23712928145996623, 0.10232063183487138}, {0.2468063966900775,
0.10735408035037859}}],
Line[{{0.23617311839755725, 0.10167498697856284}, {0.23712928145996623,
0.10232063183487138}}],
Line[{{0.22682413867491788, 0.09457182622878016}, {0.23617311839755725,
0.10167498697856284}}],
Line[{{0.2468063966900775, 0.10735408035037859}, {0.258487721590078,
0.1157776125601875}}],
Line[{{0.2708808482807588, 0.12670886782426}, {0.28387897498993575,
0.13571165906064925}}],
Line[{{0.258487721590078, 0.1157776125601875}, {0.2708808482807588,
0.12670886782426}}],
Line[{{0.28387897498993575, 0.13571165906064925}, {0.2978272217864588,
0.14759488720466138}}],
Line[{{0.1477234246451498, 0.24947273784932386}, {0.14783588435291467,
0.24801241612439603}}],
Line[{{0.1479541145674177, 0.2511362254380753}, {0.1477234246451498,
0.24947273784932386}}],
Line[{{0.1491240645508071, 0.26387991264561694}, {0.1479541145674177,
0.2511362254380753}}],
Line[{{0.14921751200149097, 0.2652532987421324}, {0.1491240645508071,
0.26387991264561694}}],
Line[{{0.14965754343046883, 0.2667953281098005}, {0.14921751200149097,
0.2652532987421324}}],
Line[{{0.151331525973231, 0.2788746216617924}, {0.14965754343046883,
0.2667953281098005}}],
Line[{{0.1513023469154561, 0.28000225496294356}, {0.151331525973231,
0.2788746216617924}}],
Line[{{0.15159808750593176, 0.28126407977451784}, {0.1513023469154561,
0.28000225496294356}}],
Line[{{0.1542183286126348, 0.2951998224290116}, {0.15159808750593176,
0.28126407977451784}}],
Line[{{0.1543844511422373, 0.29622903636555487}, {0.1542183286126348,
0.2951998224290116}}],
Line[{{0.15487515594649698, 0.2973588777162937}, {0.1543844511422373,
0.29622903636555487}}],
Line[{{0.1579674954611141, 0.3106502784721332}, {0.15487515594649698,
0.2973588777162937}}],
Line[{{0.15801884123013382, 0.31149526756373586}, {0.1579674954611141,
0.3106502784721332}}],
Line[{{0.15837231170577926, 0.3124103567537063}, {0.15801884123013382,
0.31149526756373586}}],
Line[{{0.16249412038258731, 0.3268594270632616}, {0.15837231170577926,
0.3124103567537063}}],
Line[{{0.1627258634053209, 0.32761076950461077}, {0.16249412038258731,
0.3268594270632616}}],
Line[{{0.1677923104797096, 0.3421155216709148}, {0.1627258634053209,
0.32761076950461077}}],
Line[{{0.2978272217864588, 0.14759488720466138}, {0.3120103725148076,
0.16185946995643472}}],
Line[{{0.3120103725148076, 0.16185946995643472}, {0.32775672771374703,
0.17512244347152398}}],
Line[{{0.16831982916051622, 0.3434042241910501}, {0.16791854046841395,
0.3427532989898076}}],
Line[{{0.16791854046841395, 0.3427532989898076}, {0.1677923104797096,
0.3421155216709148}}],
Line[{{0.17421155114809514, 0.3581968200459465}, {0.17392151465705788,
0.35763372336909505}}],
Line[{{0.17392151465705788, 0.35763372336909505}, {0.16831982916051622,
0.3434042241910501}}],
Line[{{0.18069422094150786, 0.37205702305025484}, {0.17421155114809514,
0.3581968200459465}}],
Line[{{0.180891236025593, 0.37258053248480366}, {0.18069422094150786,
0.37205702305025484}}],
Line[{{0.18830785455803709, 0.38637151726676766}, {0.180891236025593,
0.37258053248480366}}],
Line[{{0.18865265276787174, 0.3868486426773692}, {0.18830785455803709,
0.38637151726676766}}],
Line[{{0.19640017190085496, 0.3994058587164615}, {0.18865265276787174,
0.3868486426773692}}],
Line[{{0.19666833626667307, 0.3999132604697406}, {0.19640017190085496,
0.3994058587164615}}],
Line[{{0.20531029788487257, 0.41211763157731013}, {0.19666833626667307,
0.3999132604697406}}],
Line[{{0.20571216030393039, 0.4126101422556851}, {0.20531029788487257,
0.41211763157731013}}],
Line[{{0.2145020546238386, 0.4233429398459504}, {0.20571216030393039,
0.4126101422556851}}],
Line[{{0.21537048933945666, 0.42440920138360355}, {0.2148469636279404,
0.42392452797297386}}],
Line[{{0.2148469636279404, 0.42392452797297386}, {0.2145020546238386,
0.4233429398459504}}],
Line[{{0.224937909314532, 0.4347906814830722}, {0.22447106274957196,
0.43419502129876153}}],
Line[{{0.2255708635091629, 0.4352755122957541}, {0.224937909314532,
0.4347906814830722}}],
Line[{{0.22447106274957196, 0.43419502129876153}, {0.21537048933945666,
0.42440920138360355}}],
Line[{{0.2362387193659058, 0.44519046171637694}, {0.23550854177430175,
0.44469711425577}}],
Line[{{0.23550854177430175, 0.44469711425577}, {0.23493104304809412,
0.4440809402390221}}],
Line[{{0.23493104304809412, 0.4440809402390221}, {0.2255708635091629,
0.4352755122957541}}],
Line[{{0.2458063880151631, 0.4529965121115738}, {0.2362387193659058,
0.44519046171637694}}],
Line[{{0.24729866193283856, 0.45414958092958785}, {0.24648326240945,
0.45363954361140574}}],
Line[{{0.24648326240945, 0.45363954361140574}, {0.2458063880151631,
0.4529965121115738}}],
Line[{{0.2570213951396619, 0.46095021578202966}, {0.24729866193283856,
0.45414958092958785}}],
Line[{{0.25867545846199563, 0.4621600936383677}, {0.2577865151619174,
0.4616258862109966}}],
Line[{{0.2577865151619174, 0.4616258862109966}, {0.2570213951396619,
0.46095021578202966}}],
Line[{{0.2713565274343649, 0.46964096460519306}, {0.27029474445148616,
0.46923832388523573}}],
Line[{{0.27029474445148616, 0.46923832388523573}, {0.2693435427651083,
0.4686736095095178}}],
Line[{{0.2693435427651083, 0.4686736095095178}, {0.25867545846199563,
0.4621600936383677}}],
Line[{{0.2820834503649971, 0.47540708814525406}, {0.28108085796610294,
0.4748070587399311}}],
Line[{{0.28317996258778066, 0.47583890202372664}, {0.2820834503649971,
0.47540708814525406}}],
Line[{{0.2929264508462746, 0.4800548651057634}, {0.28317996258778066,
0.47583890202372664}}],
Line[{{0.28108085796610294, 0.4748070587399311}, {0.2713565274343649,
0.46964096460519306}}],
Line[{{0.2962869754197271, 0.4814350589126312}, {0.2950906392127613,
0.48115832533184144}}],
Line[{{0.293969971604404, 0.48069317434650516}, {0.2929264508462746,
0.4800548651057634}}],
Line[{{0.2950906392127613, 0.48115832533184144}, {0.293969971604404,
0.48069317434650516}}],
Line[{{0.3070188184813319, 0.4856253611147443}, {0.30588411540871324,
0.4851249910683927}}],
Line[{{0.3082111485742116, 0.48593284952392213}, {0.3070188184813319,
0.4856253611147443}}],
Line[{{0.30588411540871324, 0.4851249910683927}, {0.2962869754197271,
0.4814350589126312}}],
Line[{{0.3200745284695116, 0.4896040338211999}, {0.31889586095955874,
0.4892654893053082}}],
Line[{{0.3306538583299412, 0.49210181021046007}, {0.3200745284695116,
0.4896040338211999}}],
Line[{{0.31889586095955874, 0.4892654893053082}, {0.3082111485742116,
0.48593284952392213}}],
Line[{{0.32775672771374703, 0.17512244347152398}, {0.34339600647788815,
0.19037157889533632}}],
Line[{{0.34339600647788815, 0.19037157889533632}, {0.3584920715847559,
0.20748513832003038}}],
Line[{{0.3584920715847559, 0.20748513832003038}, {0.37529647269459104,
0.22416045439778076}}],
Line[{{0.391394006394934, 0.24187639988977794}, {0.40595760835145256,
0.26052294423977673}}],
Line[{{0.40595760835145256, 0.26052294423977673}, {0.4211937389690042,
0.2783989008665915}}],
Line[{{0.37529647269459104, 0.22416045439778076}, {0.391394006394934,
0.24187639988977794}}],
Line[{{0.4211937389690042, 0.2783989008665915}, {0.4360859857909327,
0.29688362962532056}}],
Line[{{0.4360859857909327, 0.29688362962532056}, {0.44849554349384785,
0.31513488497582964}}],
Line[{{0.44849554349384785, 0.31513488497582964}, {0.45950702525841847,
0.3312352642133482}}],
Line[{{0.45950702525841847, 0.3312352642133482}, {0.47168951000586257,
0.3485013232084075}}],
Line[{{0.3329811696167614, 0.49261958674849604}, {0.33180955627977493,
0.49246904090890936}}],
Line[{{0.33180955627977493, 0.49246904090890936}, {0.3306538583299412,
0.49210181021046007}}],
Line[{{0.3433488889598254, 0.4945445748405384}, {0.3329811696167614,
0.49261958674849604}}],
Line[{{0.3546249958718492, 0.495842695338322}, {0.3444697509923371,
0.49471602188622743}}],
Line[{{0.3444697509923371, 0.49471602188622743}, {0.3433488889598254,
0.4945445748405384}}],
Line[{{0.3556865540320001, 0.4960280715277968}, {0.3546249958718492,
0.495842695338322}}],
Line[{{0.3567177912758346, 0.49597308113395}, {0.3556865540320001,
0.4960280715277968}}],
Line[{{0.47168951000586257, 0.3485013232084075}, {0.48077950746507786,
0.3644837993542871}}],
Line[{{0.4860140377063631, 0.37629909992727895}, {0.494713514709459,
0.3908117600585477}}],
Line[{{0.48077950746507786, 0.3644837993542871}, {0.4860140377063631,
0.37629909992727895}}],
Line[{{0.494713514709459, 0.3908117600585477}, {0.5001882062215272,
0.4033850666119429}}],
Line[{{0.36750825194268794, 0.4965078617110783}, {0.36656376103364224,
0.49656032955172325}}],
Line[{{0.36656376103364224, 0.49656032955172325}, {0.3567177912758346,
0.49597308113395}}],
Line[{{0.37788302207581576, 0.4962518669896069}, {0.37703288668338875,
0.4963125224987447}}],
Line[{{0.3870248630651093, 0.4952799609069687}, {0.37788302207581576,
0.4962518669896069}}],
Line[{{0.37703288668338875, 0.4963125224987447}, {0.36750825194268794,
0.4965078617110783}}],
Line[{{0.3877734346697613, 0.49519893336654924}, {0.3870248630651093,
0.4952799609069687}}],
Line[{{0.39647039041779775, 0.49345442085222035}, {0.3877734346697613,
0.49519893336654924}}],
Line[{{0.397110731984245, 0.4933399169989696}, {0.39647039041779775,
0.49345442085222035}}],
Line[{{0.4053005892876792, 0.4908254279842213}, {0.397110731984245,
0.4933399169989696}}],
Line[{{0.40582676815159685, 0.49066402514110335}, {0.4053005892876792,
0.4908254279842213}}],
Line[{{0.4134479680115215, 0.48738189051877207}, {0.40582676815159685,
0.49066402514110335}}],
Line[{{0.41385501671116315, 0.4871604717762271}, {0.4134479680115215,
0.48738189051877207}}],
Line[{{0.5001882062215272, 0.4033850666119429}, {0.5026656466799566,
0.41378366311013043}}],
Line[{{0.5049910805017521, 0.42092707055693956}, {0.5073345408466324,
0.4298919589211338}}],
Line[{{0.5026656466799566, 0.41378366311013043}, {0.5049910805017521,
0.42092707055693956}}],
Line[{{0.4274391169072527, 0.47801529681458305}, {0.42084769258955246,
0.48311400029769436}}],
Line[{{0.42084769258955246, 0.48311400029769436}, {0.41385501671116315,
0.4871604717762271}}],
Line[{{0.4329580876836497, 0.47231834863067207}, {0.4274391169072527,
0.47801529681458305}}],
Line[{{0.4331675034193015, 0.4720847717913544}, {0.4329580876836497,
0.47231834863067207}}],
Line[{{0.437890159746943, 0.46566606263920335}, {0.4331675034193015,
0.4720847717913544}}],
Line[{{0.5073345408466324, 0.4298919589211338}, {0.507075192557166,
0.43670292340445127}}],
Line[{{0.507075192557166, 0.43670292340445127}, {0.5049458541122729,
0.4449675445229827}}],
Line[{{0.4776009750118953, 0.4514099006447918}, {0.4730868229244228,
0.45077008810913194}}],
Line[{{0.4730868229244228, 0.45077008810913194}, {0.437890159746943,
0.46566606263920335}}],
Line[{{0.5049458541122729, 0.4449675445229827}, {0.5029083407423581,
0.44889688974935993}}],
Line[{{0.4838758910848437, 0.45289412540402957}, {0.4776009750118953,
0.4514099006447918}}],
Line[{{0.5029083407423581, 0.44889688974935993}, {0.49919310111973014,
0.45113398227358853}}],
Line[{{0.4890646389147416, 0.45348782067176335}, {0.4838758910848437,
0.45289412540402957}}],
Line[{{0.49919310111973014, 0.45113398227358853}, {0.49332267538788155,
0.45296691617990653}}],
Line[{{0.49332267538788155, 0.45296691617990653}, {0.4890646389147416,
0.45348782067176335}}]};


Convert lines to points

pts = Flatten[linelist1 /. Line -> Identity, {2}][[1]];

ListCurvePathPlot[pts,
Frame -> True,
Axes -> False,
PlotStyle -> Dashed]


curve = FindCurvePath[pts];

ListLinePlot[pts[[curve[[1]]]],
Frame -> True,
Axes -> False,
AspectRatio -> Automatic,
PlotStyle -> Dashed,
ImageSize -> 350]


• You coded Flatten with the optional second argument between curly braces. Where is this use documented? In the documenation for Flatten I have access to this argument is without braces. Thanks Jul 13, 2016 at 21:38
• @SigisK - See the tutorial Levels in Expressions Jul 13, 2016 at 23:11

The goal here is to turn the collection of Line objects into a BoundaryMeshRegion, and then extract the boundary from that region. This is similar to user21's solution, but a bit more robust for this application.

mr = BoundaryDiscretizeGraphics[linelist2];
MeshPrimitives[mr, 2] /. Polygon[a__] :> Line[a] //
Graphics[{Dashing[0.01], #}] &


• Thanks, but the point of my post is that this doesn't work for my 2nd example. My first attempt at a solution does this already. Jul 8, 2016 at 18:59
• Thanks for the edit, that looks good. Unfortunately I already chose an answer, thank you though! Jul 8, 2016 at 19:22
• @YungHummmma You're free to change your selection, if you think this is better than mine. It's close, and in a tie, one tends to prefer one's own children, so to speak. :) This is also why some advise waiting a while before accepting, to see what answers come in. (+1, Jason.) Jul 8, 2016 at 23:56
• @MichaelE2 Thank you. I wanted to point out that there are other ways to show approval of an answer than accepting, lol. I find it interesting that the graph path solution works where the FindCurvePath fails. Jul 9, 2016 at 1:00
• @MichaelE2 I think I may have actually found a way in which yours fails, but for now it's working for me so I'll stick with it. (when I did the same shape, but with fewer points, I think, something broke.) Jul 9, 2016 at 22:25

You can use DiscretizeGraphics for this:

mr = DiscretizeGraphics[linelist1]


and if you want a graphics out of it:

Graphics[GraphicsComplex[
MeshCoordinates[mr], {Dashed,
MeshCells[mr, {1, All}, Multicells -> True]}]]

• Thank you. However, the dashing problem still fails with this. Try Dashing[.01] and you'll see that it still does it unevenly. Jul 8, 2016 at 19:01
sTour = FindShortestTour[data = Flatten[First /@ linelist1, 1]];
Graphics[{Dashing[0.01], Line[data[[sTour [[2]]]]]}]


What about literal replacing lines with dashed lines?

Graphics@linelist1 /. Line[a_] -> {Dashed, Line[a]}

• Thanks, but for me this produces the uneven dashing in my post above. Jul 8, 2016 at 19:18

Here's my solution, which doesn't rely on any fancy functions:

appendNextSegment[{acc_, rest_}] := Module[{closeness, nearest, pos, next},
closeness = Map[Norm[(Last@acc) - First@#] &, rest];
nearest = Min[closeness];
pos = Position[closeness, nearest][[1, 1]];
next = rest[[pos]];
Return[{acc~Join~next, Delete[rest, pos]}]
]
lineJoin[listOfLines_] := Line[Nest[
appendNextSegment,
({First@listOfLines, Rest@listOfLines} /. Line -> Sequence),
Length[listOfLines] - 1][[1]]
]


Then

Graphics@{Dashed, lineJoin@linelist1}
Graphics@{Dashed, lineJoin@linelist2}


produce nice graphics (that I can't paste here, as imgur is blocked at work).

• Wait, what qualifies a function as "fancy"? :-P Jul 9, 2016 at 1:16
• My working definition is that a function is fancy if you can't immediately understand by looking at its name what inputs you should pass it or what the output ought to be. Jul 9, 2016 at 1:18