Sphere-filling curve 2: scalable self-avoiding paths on a sphere via traveling salesman tours, geodesic polyhedra and Hamiltonian cycles

Intro

In the previous post, we construct a special example of sphere filling curve. However, we noted that it (as many other known examples) are not truly scalable and self-similar. Such constructions simply copy fragments of known curves that fill sections of the plane. Here we propose several methods for obtaining really scalable self-similar sphere filling curves.

Utilites

Graphics Code
Clear[geo, geoDist];

geoDist = Chop@ArcCos@Clip[#1 . #2, {-1, 1}] &;

geo[{p1_?VectorQ, p2_?VectorQ}] :=
With[{w = geoDist @@ {p1, p2},
u = Normalize[p2 - p1 (p1 . p2)]},
p1 Cos[w #] + u Sin[w #] &];

Clear[ths, g3D, splineCurve];
(*Scaled thickness*)
ths = 10.^Rescale[#, {10, 1000}, {-1.8, -2.1}] &;

sCol = Gray;
bCol = RGBColor[0.659, 0.749, 0.769];
cCol = RGBColor[0.871, 0.816, 0.737];

(*General 3D presentation*)
g3D[objs_, size_ : 200] :=
Framed[Graphics3D[
{objs}
, Lighting -> AmbientLight@sCol, Boxed -> False
, SphericalRegion -> True, ImageSize -> size, ImagePadding -> 10]
, RoundingRadius -> 20, Background -> bCol, FrameStyle -> None];

splineCurve[pts_, type_, rate_ : 5, th_ : 0.01, sd_ : 2,
cls_ : True] :=
Block[{bsf =
BSplineFunction[pts, SplineDegree -> sd, SplineClosed -> cls],
divs = Subdivide[0, 1, rate *Length@pts]},
If[type == 1
, {Thickness@th, Line[bsf@# & /@ divs]}
, Tube[Normalize[bsf@#] & /@ divs, th]
]];

Simple examples

FindShortestTour built-in provides a wide range of options for building self-avoiding paths. It represents the solution to the travelling salesman problem, so it has no self-intersections. We can apply it to random points as well as evenly spaced points, by obtaining sphere filling curves.

With[{numPts = 500},
{tours = FindShortestTour[# -> "Elements"] & /@
{RandomPoint[Sphere[], numPts], SpherePoints@numPts}},
Row[g3D[{sCol, Sphere[], cCol,
splineCurve[#, 5, 5, 0.02, 2]}] & /@ tours]]

Controllable entanglement

Using the combination of MeshConnectivityGraph and FindShortestTour, we can get truly scalable curves with varying degrees of tortuosity.

Clear[rndTourDF];
rndTourDF[pts_, rnd_] :=
With[{graph = MeshConnectivityGraph[ConvexHullMesh@pts,
AnnotationRules -> None]},
{adjQ = GraphDistance[graph, ##] == 1 &,
spaceDist = EuclideanDistance[pts[[#1]], pts[[#2]]] &},
{distFun = If[adjQ@##2,
RandomVariate[NormalDistribution[spaceDist@##2, #1]],
[Infinity]] &},

pts[[Last@FindShortestTour[Range@Length@pts,
DistanceFunction -> (distFun[rnd, ##] &)]]]
];

With[{numPts = 777},
{tours =
Most@rndTourDF[SpherePoints@numPts, #] & /@ {0.001, 0.02, 0.3}},
Row[g3D[{sCol, Sphere[], cCol,
splineCurve[#, 5, 5, 0.02, 2]}] & /@ tours]]

Hamiltonian cycle

It is possible to get a more predictable and rigorous version by using geodesic polyhedra. Kardoš (2022) proved that every 3-connected cubic planar graph with faces not more than 6 vertices have a Hamiltonian cycle. Because the dual graphs of octahedral geodesic polyhedra have this property, we can use these polyhedra to construct a closed sphere-filled curve. In the previous post, we filled each border with a special self-similar curve. But we can use the dual graph itself as a base for SFC!

With[{lev = 8},
{polyh = GeodesicPolyhedron["Octahedron", lev]},
{graph = MeshConnectivityGraph[polyh, 2, AnnotationRules -> None],
dPolyh = DualPolyhedron@polyh},
{cycle =
First /@ RandomChoice@FindHamiltonianCycle[graph, 10^3] /.
UndirectedEdge -> List},

g3D[{sCol, Sphere[], cCol,
splineCurve[dPolyh[[1]][[cycle]], 2, 5, 0.02, 1]}]]

Since the vertices construction algorithm and HamiltonianCycle are known, one can try analytically assess how this curve approaches each point of the sphere.

Quasi-periodic patterns

To obtain specific effects, interesting to use not DistanceFunction but EdgeWeight. Patterns obtained resemble some pagan culture patterns.

Clear[rndTourEW];
rndTourEW[pts_, n_, k_] :=
With[{graph = MeshConnectivityGraph[
ConvexHullMesh@pts,
AnnotationRules -> None]},
{ews = Table[[LeftCeiling] 2. n Cos[1. k Mod[i, n]]^2[RightCeiling],
{i, EdgeCount@graph}]},

FindShortestTour[Graph[graph,
EdgeWeight -> ews] -> "Indices"]
];

With[
{numPts = 777, n = 667, k = 337},
{pts = SpherePoints@numPts},
{tour = rndTourEW[pts, n, k]},
g3D[{sCol, Sphere[], cCol,
splineCurve[pts[[tour]], 2, 5, 0.02, 1]}]]

3 Likes

Congratulations. The Editorial Board has selected this contribution for inclusion in Staff Picks. You are now recognized among our Featured Authors, and your profile bears the Staff-Pick badge. Thank you for contributing your work to the broader exchange of knowledge.