3
$\begingroup$

I´m trying with

alfa = 0.75
p = {{1, 0, 0}, {alfa, 0, 1 - alfa}, {alfa, 1 - alfa, 0}, {0, alfa, 
   1 - alfa}, {0, 1 - alfa, alfa}}

chull = ConvexHullMesh[p];
Show[HighlightMesh[chull, Labeled[1, "Index"]], 
 Graphics3D[{Red, Sphere[p, 0.05]}], Axes -> True, Boxed -> True, 
 AxesLabel -> {x, y, z}]

but only create the convexhull of the first 4 points.

I don´t know what´s the problem to create the convexhull with the last.

$\endgroup$
  • $\begingroup$ Yes @Öskå , I know :-) but it is not important for this case :-) $\endgroup$ – Mika Ike Jan 10 '15 at 12:33
  • $\begingroup$ @Öskå When coding sometimes I use alfa instead alpha because in spanish both words sounds in the same way. I ought to use the latin letters with the esc ... esc sequence :-) but... I´m not used to use it but it´s a good thing, Yes :-) $\endgroup$ – Mika Ike Jan 10 '15 at 12:43
3
$\begingroup$

If you generate random points using p = RandomReal[{-1, 1}, {5, 3}] then your code works fine -- suggesting that the problem has to do with the fact that all your points lie in a plane. A simple solution is to perturb one of the points slightly outside the plane:

alfa = 0.75;
p = {{1,0,0}, {alfa,0,1-alfa}, {alfa,1-alfa,0}, {0,alfa,1-alfa}, {0,1-alfa,alfa+0.0000001}};    
chull = ConvexHullMesh[p];
Show[HighlightMesh[chull, Labeled[1, "Index"]], 
 Graphics3D[{Red, Sphere[p, 0.05]}], Axes -> True, Boxed -> True, AxesLabel -> {x, y, z}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you. Do you think that´s an error that should be commented to wolfram? $\endgroup$ – Mika Ike Jan 10 '15 at 14:58
  • 1
    $\begingroup$ @MikaIke The docs say "Convex hull meshes are full dimensional", i.e, in 3D the hull should be a 3D region. I think it ought to give a warning message at the least. For instance, DelaunayMesh[p] gives an error. $\endgroup$ – Michael E2 Jan 10 '15 at 16:37
4
$\begingroup$

There's a related question, A problem on generating convex hull, and I can adapt my answer there to this case. The basic approach is to map the points in the plane to a 2D coordinate system, find the hull in 2D, and embed the hull in the plane in 3D.

I inserted an extra point in the interior, because that sometimes causes trouble when it is dropped in the BoundaryMesh. The ConvexHull is basically the BoundaryMesh of the DelaunayMesh of the points.

alfa = 0.75;
p = {{1, 0, 0}, {alfa, 0, 1 - alfa}, {alfa, 1 - alfa, 0}, {0, alfa, 
    1 - alfa}, {0, 1 - alfa, alfa}};
p = Insert[p, Mean[p], 3];

coordMat =                        (*coordinate projection matrix*)
  DeleteCases[Orthogonalize @ Differences @ p, v_ /; v == {0, 0, 0}];
coords = p.Transpose[coordMat];   (*2D coordinates*)

hull = DelaunayMesh[coords];

At this point we have a triangulation of the convex hull in hull. The simplest thing is to map this back to 3D. A little more work is needed to convert it to a BoundaryMeshRegion like ConvexHullMesh, which appears as the second solution.

chull = MeshRegion[p, MeshCells[hull, 2]];
Show[
 HighlightMesh[chull, Labeled[1, "Index"]],
 Graphics3D[{Red, Sphere[p, 0.05]}],
 Boxed -> True, Axes -> True]

Mathematica graphics

The BoundaryMeshRegion version:

bhull = BoundaryMesh@hull;
nf = Nearest[MeshCoordinates[hull] -> Automatic];
tobpts =                        (* needed because BoundaryMesh drops interior points *)
  MapIndexed[First@#2 -> First@nf[#] &, MeshCoordinates[bhull]];
chull = MeshRegion[p, MeshCells[bhull, 2] /. tobpts];
Show[
 HighlightMesh[chull, Labeled[1, "Index"]],
 Graphics3D[{Red, Sphere[p, 0.05]}],
 Boxed -> True, Axes -> True]

Mathematica graphics

Note that there is an important difference between them, if you want to highlight the line elements.

$\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.