# How can i eliminate the diagonal lines from this ListLinePlot?

I'm trying to plot a finite element mesh with its node id's. But i'm facing a problem with the ListLinePlot, which connects all poits, instead connect only the neighbour node. I need to eliminate the diagonal lines from the following ListLinePlot:

topol={{4, 1, 5, 8, 3, 2, 6, 7}, {5, 13, 17, 8, 10, 15, 11, 6},
{30, 37, 35, 26, 33, 36, 31, 28}, {35, 32, 24, 26, 34, 29, 25, 31},
{17, 23, 18, 8, 20, 21, 12, 11}, {4, 8, 18, 14, 7, 12, 16, 9},
{24, 14, 18, 26, 19, 16, 22, 25}, {26, 18, 23, 30, 22, 21, 27, 28}};

nnodes = {{0, 6}, {0, 4.5}, {2.5, 6}, {0, 3}, {2.5, 3}, {0, 1.5}, {5, 6},
{5, 4.5}, {5, 3}, {0, 0}, {2.5, 0}, {5, 1.5}, {7.5, 6}, {5, 0},
{7.5, 3}, {7.5, 0}, {10, 6}, {10, 4.5}, {10, 3}, {10, 1.5}, {10, 0}};

allcoords = {{{5, 0}, {5, 3}, {0, 3}, {0, 0}, {5, 1.5}, {2.5, 3}, {0, 1.5}, {2.5, 0}},
{{10, 0}, {10, 3}, {5, 3}, {5, 0}, {10, 1.5}, {7.5, 3}, {5, 1.5}, {7.5, 0}},
{{5, 3}, {5, 6}, {0, 6}, {0, 3}, {5, 4.5}, {2.5, 6}, {0, 4.5}, {2.5, 3}},
{{10, 3}, {10, 6}, {5, 6}, {5, 3}, {10, 4.5}, {7.5, 6}, {5, 4.5}, {7.5, 3}}};

nodeids =
ListPlot[Table[Labeled[nnodes[[i]], i], {i, Length@nnodes}],
AspectRatio -> Automatic];
undefplot =
ListLinePlot[Tooltip[allcoords], AspectRatio -> Automatic,
PlotMarkers -> Automatic, PlotStyle -> {Thick}];
Show[nodeids, undefplot]


I need something like this:

Needs["NDSolveFEM"]
q = QuadElement[topol]
mesh = ToElementMesh["Coordinates" -> nnodes, "MeshElements" -> {q}]
Show[mesh["Wireframe"],
mesh["Wireframe"["MeshElement" -> "PointElements",
"MeshElementStyle" -> Directive[Red, PointSize[0.02]],
"MeshElementIDStyle" -> Blue]]]


But in the figure above is missing the interior nodes.

How can i do that? Thank you!

• How did you get your allcoords? Is it output from some code? Jan 5, 2017 at 21:07
• Yes: allcoords = Table[nnodes[[ topol[[i]][[j]] ]], {i, 1, Length[topol]}, {j, 1, 8}]; Jan 5, 2017 at 21:10
• And topo is ...? It will be useful if you show a plot of desired result - maybe hardcoding coordinates fro demonstration purposes. Jan 5, 2017 at 21:11
• topol = Transpose@Drop[Transpose@Import["file.txt", "Table"], 1]; Jan 5, 2017 at 21:12
• topol={{4, 1, 5, 8, 3, 2, 6, 7}, {5, 13, 17, 8, 10, 15, 11, 6}, {30, 37, 35, 26, 33, 36, 31, 28}, {35, 32, 24, 26, 34, 29, 25, 31}, {17, 23, 18, 8, 20, 21, 12, 11}, {4, 8, 18, 14, 7, 12, 16, 9}, {24, 14, 18, 26, 19, 16, 22, 25}, {26, 18, 23, 30, 22, 21, 27, 28}} Jan 5, 2017 at 21:13

## 1 Answer

ord = FindCurvePath /@ allcoords // Flatten[#, 1] &;

allcoordsNEW = MapThread[Part[#1, #2] &, {allcoords, ord}];
(* or *)
allcoordsNEW = Table[allcoords[[i, ord[[i]]]], {i, 1, Length@ord}];

undefplot =
ListLinePlot[Tooltip[allcoordsNEW], AspectRatio -> Automatic,
PlotMarkers -> Automatic, PlotStyle -> {Thick}];

Show[nodeids, undefplot]


• A bit overkill for FindCurvePath.. I was sure the OP wants triangular mesh Jan 5, 2017 at 21:48
• Some text to accompany code is usually nice... Jan 6, 2017 at 2:19