4
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

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.}}
*)
| improve this answer | |
$\endgroup$
4
$\begingroup$

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.

| improve this answer | |
$\endgroup$
4
$\begingroup$

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.

| improve this answer | |
$\endgroup$
4
$\begingroup$
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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.