How do I extract start and endpoints of each defined interval of iteration n
of CantorMesh[n]
? The furthest I can go is
In[16]:= RegionBoundary[CantorMesh[3]]
I'm unable to find anything in the documentation. Any help would be appreciated.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow do I extract start and endpoints of each defined interval of iteration n
of CantorMesh[n]
? The furthest I can go is
In[16]:= RegionBoundary[CantorMesh[3]]
I'm unable to find anything in the documentation. Any help would be appreciated.
How about
MeshCoordinates@CantorMesh[3] // Partition[#, 2] & // Map[Flatten]
(*
{{0., 0.037037}, {0.0740741, 0.111111}, {0.222222, 0.259259}, {0.296296, 0.333333},
{0.666667, 0.703704}, {0.740741, 0.777778}, {0.888889, 0.925926}, {0.962963, 1.}}
*)
Use MeshPrimitives
.
MeshPrimitives[
CantorMesh[3],
1
]
(* {Line[{{0.}, {0.037037}}], Line[{{0.0740741}, {0.111111}}],
Line[{{0.222222}, {0.259259}}], Line[{{0.296296}, {0.333333}}],
Line[{{0.666667}, {0.703704}}], Line[{{0.740741}, {0.777778}}],
Line[{{0.888889}, {0.925926}}], Line[{{0.962963}, {1.}}]} *)
There are no guarantees about the ordering of the MeshCoordinates
, so I would not personally rely solely on that.
A quick, but partially undocumented way to extract the edge coordinates.
R = CantorMesh[3];
edges = MeshCells[R, 1, "Multicells" -> True][[1, 1]];
pairs = Partition[Flatten[MeshCoordinates[R][[Flatten[edges]]]], 2]
{{0., 0.037037}, {0.0740741, 0.111111}, {0.222222, 0.259259}, {0.296296, 0.333333}, {0.666667, 0.703704}, {0.740741, 0.777778}, {0.888889, 0.925926}, {0.962963, 1.}}
As Szabolcs said, one should not rely here on the correct ordering. But you can do, e.g.,
{start, end} = Transpose[Sort[MinMax /@ pairs]];
to obtain the ordered lists start
and end
of all start and end points, respectively.
f1 = ## & @@@ ## & @@@ MeshPrimitives[#, 1] &;
f1 @ CantorMesh[3]
{{0., 0.037037}, {0.0740741, 0.111111}, {0.222222, 0.259259}, {0.296296, 0.333333}, {0.666667, 0.703704}, {0.740741, 0.777778}, {0.888889, 0.925926}, {0.962963, 1.}}
Also
f2 = Map[Flatten @* First] @ MeshPrimitives[#, 1] &;
and
f3 = Cases[Normal@Show[#], Line[x_] :> First /@ x, All] &;
f1 @ CantorMesh[3] == f2 @ CantorMesh[3] == f3 @ CantorMesh[3]
True