3
$\begingroup$

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: Cube

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:

Finding face vertices from the face adjacency graph.

$\endgroup$
4
  • $\begingroup$ Try: Show @@ facesinstead of: Show /@ faces // combinepolys; $\endgroup$ Commented Jan 15, 2023 at 9:35
  • $\begingroup$ Just so you know, I am unable to reproduce the error you are mentioning. I have 13.2.0. $\endgroup$
    – bmf
    Commented Jan 15, 2023 at 10:15
  • $\begingroup$ Thank you for your reply. I have 13.2 Student Edition. $\endgroup$
    – P Teeuwen
    Commented Jan 16, 2023 at 13:05
  • $\begingroup$ Also I am looking more for the connectivity than the separate triangles. For example I would like to obtain an output of something like this: faces = {{1,2,3,4}, {5,6,7,8}, {1,2,5,6}, {2,3,6,7}, {3,4,7,8}, {4,1,5,8}}, where the numbers correspond with those that I put in as vertices. $\endgroup$
    – P Teeuwen
    Commented Jan 16, 2023 at 13:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.