3
$\begingroup$

I'm using this code to show the convex hull of some points in 3D:

ClearAll["Global`*"]
p = {{6, 0, 0}, {0, 6, 4}, {1, 1, 1}, {0, 3, 0}, {0, 0, 5}, {9, 6, 0}, {3, 0, 7}};

chull = ConvexHullMesh[p];
Show[HighlightMesh[chull, Labeled[1, "Index"]], 
 Graphics3D[{Red, Sphere[p, 0.05], Blue, 
   Map[Text[#, # + {0., 0, 0.001}] &, p]}], Axes -> True, 
 Boxed -> True, AxesLabel -> {x, y, z}]

I need to give every triangle a color or number so I can know it when I change the convex hull.

$\endgroup$
3
$\begingroup$
colors = ColorData[97, "ColorList"][[;; MeshCellCount[chull,2]]];
styledfaces = Style[{2, #}, colors[[#]]]& /@ Range[MeshCellCount[chull, 2]];

Show[HighlightMesh[chull, {Labeled[1, "Index"], styledfaces}], 
 Graphics3D[{Red, Sphere[p, 0.05], Blue, Map[Text[#, # + {0., 0, 0.001}] &, p]}], 
  Axes -> True, Boxed -> True, AxesLabel -> {x, y, z}]

enter image description here

To get face colors with Opacity[1] use

colors = Opacity[1, #]& /@ ColorData[97, "ColorList"][[;; MeshCellCount[chull,2]]];

enter image description here

$\endgroup$
  • $\begingroup$ Thanks, Can you help me to make every triangle not transparent such that when I see one I can not see the one behind it. I hope i explain it well. $\endgroup$ – Ateq Alsaadi Feb 10 '18 at 22:09
  • $\begingroup$ @Ateq, please see the updated version. $\endgroup$ – kglr Feb 10 '18 at 22:21
  • $\begingroup$ Got it, thanks :) $\endgroup$ – Ateq Alsaadi Feb 10 '18 at 22:25

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.