I have a list of points from which I am trying to generate a mesh:
{{{261.324, 937.805}, {1139.98, 937.843}}, {{261.324,
937.805}, {261.014, 57.1923}}, {{1140.95, 505.675}, {705.906,
57.3194}}, {{1578.03, 507.712}, {1139.98, 937.843}}, {{261.014,
57.1923}, {705.906, 57.3194}}, {{1140.95, 505.675}, {1578.03,
507.712}}}
fldd
is a list of coordinates (without duplicates) generated by flattening the given array and using the DeleteDuplicates
command. That definitely works. However, the BoundaryElements
part of the command is giving me issues.
I use the following code to generate the connectivity array which tells Mathematica in what order to connect the points:
cn = {}
For[c1 = 1, c1 <= len, c1++,
For[c2 = 1, c2 <= 2, c2++,
holder = Position[lines, lines[[c1, c2]]];
sholder = Sort[holder];
Print[sholder];
If[FreeQ[cn, {sholder[[1, 1]], sholder[[2, 1]]}],
Print["In If"];
AppendTo[cn, {sholder[[1, 1]], sholder[[2, 1]]}]
]
]
]
When I run the code below to actually generate the boundary mesh, I get an error:
bmesh = ToBoundaryMesh["Coordinates" -> fldd[[1 ;; Length[fldd]]],
"BoundaryElements" -> {LineElement[cn[[1 ;; Length[cn]]]]}]
ToBoundaryMesh::fememib: The input has or generated an intersecting boundary and cannot be processed. >>
I can't really see what's going wrong. I know that the loop above generates a list of numbers of the form:
{{startpoint1, endpoint1}, ..., {startpointN, endpointN}}
This looks identical to the examples I've seen. I also know that the points I want connected are connected, and each point is listed as a vertex for 2 lines, which is what I want geometrically. Any help would be greatly appreciated.
Full code is:
lines = {
{{261.324, 937.805}, {1139.98, 937.843}},
{{261.324, 937.805}, {261.014, 57.1923}},
{{1140.95, 505.675}, {705.906, 57.3194}},
{{1578.03, 507.712}, {1139.98, 937.843}},
{{261.014, 57.1923}, {705.906, 57.3194}},
{{1140.95, 505.675}, {1578.03, 507.712}}
};
len = Length[lines];
fl = Flatten[lines, 1];
fldd = DeleteDuplicates[fl];
(*To find connectivity (Uggh)*)
cn = {};
For[c1 = 1, c1 <= len, c1++,
For[c2 = 1, c2 <= 2, c2++,
holder = Position[lines, lines[[c1, c2]]];
sholder = Sort[holder];
Print[sholder];
If[FreeQ[cn, {sholder[[1, 1]], sholder[[2, 1]]}],
Print["In If"];
AppendTo[cn, {sholder[[1, 1]], sholder[[2, 1]]}]
]
]
]
bmesh = ToBoundaryMesh[
"Coordinates" -> fldd[[1 ;; Length[fldd]]],
"BoundaryElements" -> {LineElement[cn[[1 ;; Length[cn]]]]}
]
bmesh["Wireframe"]
emesh = ToElementMesh[bmesh]
emesh["Wireframe"]