I have been looking into constructing a polyhedron from the coordinates of its vertices as discussed in the question linked below.
Construct a polyhedron from the coordinates of its vertices and calculate the area of each face
I am wondering if there is a way to obtain the resulting graph or its list of faces. As an example I am trying a cube with the below vertices.
vCube = {{17.4877, 11.4891, 26.5296}, {13.9888, 5.01303, 14.5038}, {5.50276,
7.35705, 32.6075}, {11.6408, 23.4421, 22.3037}, {-4.39205, 13.0431,
16.0778}, {-0.893153, 19.5181, 28.1046}, {7.59287, 17.1751,
10.0009}, {1.45487, 1.08901, 20.3047}}
Then, I used the answer from the question linked before to construct the polyhedron:
reg = DelaunayMesh[vCube];
bdypolys = Cases[Normal@Show[BoundaryMesh[reg]], _Polygon, Infinity];
coplanarQ[pts_?MatrixQ] :=
MatrixRank[Transpose@pts - pts[[1]], Tolerance -> 10^(-2)] == 2;
faces = RegionUnion @@@ Gather[bdypolys, coplanarQ[Flatten[{##} /. Polygon -> Identity, 1]] &];
combinepolys = # //. {
{x___,
{p___, a_Integer, b_Integer, q___}, y___,
{s___, b_, a_, r___}, z___} :> {x, {p, a, r, s, b, q}, y, z},
{x___,
{p___, a_Integer, b_Integer, q___}, y___,
{a_, r___, b_}, z___} :> {x, {p, a, r, b, q}, y, z},
{x___,
{b_Integer, p___, a_Integer}, y___,
{s___, b_, a_, r___}, z___} :> {x, {b, p, a, r, s}, y, z},
{x___,
{b_Integer, p___, a_Integer}, y___,
{a_, r___, b_}, z___} :> {x, {b, p, a, r}, y, z},
(* update: cut out singular edges *)
{x___, a_Integer, b_Integer, a_, y___} :> {x, a, y},
{b_Integer, a_Integer, x___, a_} :> {a, x},
{a_Integer, x___, a_, b_Integer} :> {a, x}
} &;
Show /@ faces // combinepolys ; (* shows each individual face *)
Y = Graphics3D[{EdgeForm[{Thick, Black}],
{RandomColor[], Cases[Normal@#, _Polygon, Infinity]}
}] & /@ combinepolys[Show /@ faces];
Show[Y]
I obtained this image by tweaking the tolerance in a way it recognizes the quadrilaterals:
Even though the polyhedron is plotted just fine, I do get this error:
Show::gtype: Polygon is not a type of graphics.
I am interested in seeing whether it is possible to obtain the graph or the list of faces from the resulting polyhedron. I want to use this method then also to obtain the graph of other polyhedrons besides this cube. Obtaining the faces from a graph was detailed in this question:
Show @@ faces
instead of:Show /@ faces // combinepolys;
$\endgroup$13.2.0
. $\endgroup$