I need a representation of a 3D Sierpinski gasket as a graph to perform some simulations on. The 2D version is included in GraphData[]
, but the 3D one is nowhere to be found, so I was wondering if there is a way to convert Graphics3D
objects to Graph
s.
Say we have some geometry: (or even something as simple as Cuboid[]
):
(*From Wiki =>*)
vect[1] = {0, 0, 0};
vect[2] = {1, 0, 0};
vect[3] = {0.5, 3^0.5/2, 0};
vect[4] = {0.5, 1/3*3^0.5/2, ((3^0.5/2)^2 - (1/3*3^0.5/2)^2)^0.5};
Tetron[{i_, j_, k_}] :=
Tetrahedron[{vect[1] + {i, j, k}, vect[2] + {i, j, k},
vect[3] + {i, j, k}, vect[4] + {i, j, k}}];
SiPyramid[0, {i_, j_, k_}] := {Tetron[{i, j, k}]};
SiPyramid[n_, {i_, j_, k_}] :=
Module[{s = {}},
Do[s = Union[s,
SiPyramid[n - 1, 2^(n - 1)*vect[u] + {i, j, k}]], {u, 4}]; s];
b = Graphics3D[SiPyramid[2, {1, 1, 1}]];
list = Cases[b, {x_?NumericQ, y_?NumericQ, z_?NumericQ}, Infinity];
Length[list];
lattice[L_List, r_: 1] :=
With[{d = Length[L],
LL = Reverse@FoldList[Times, 1, Reverse@Abs@L][[1 ;; -2]]},
With[{Δ =
Pick[#, UnitStep[# - 1] UnitStep[r^2 - #] &@Total[#^2, {2}],
1] &@Tuples[Range[-#, #] &@Ceiling[r], d]},
Module[{Id =
Join @@ Table[
Transpose[{#, # + Δ[[i]]}, {2, 3, 1}], {i,
Length[Δ]}] &@Transpose@Tuples[Range /@ Abs[L]] -
1}, Do[If[L[[i]] > 0,
Id = Pick[Id,
UnitStep[#] UnitStep[L[[i]] - 1 - #] &@Id[[All, 2, i]], 1],
Id[[All, All, i]] = Mod[Id[[All, All, i]], -L[[i]]]], {i, d}];
SparseArray[1 + Id.LL -> ConstantArray[1, Length[Id]]]]]];
AdjacencyGraph[lattice[{8, 8}, 1], VertexCoordinates -> list]
This is how far I've gotten with this, but obviously some of the edge connections are wrong. Is there a more general way to perform this "conversion", or fix this method so that the links are right? Perhaps convert an .obj to a graph where vertices are nodes and edges are links?
Link to Lattice to Adjacency Matrix Source
UPDATE:
The figure can also be defined as
TetraVec[i_] := 2 IntegerDigits[3 i - 2, 2, 3] - 1;
tetrix[-1, p_: {0, 0, 0}] := Polygon /@ Array[TetraVec[#] +
p & /@ Delete[Range[4], #] &, 4];
tetrix[n_, p_: {0, 0, 0}] :=
Array[tetrix[n - 1, p + TetraVec[#] 2^n] &, 4];