3
$\begingroup$

I'm using this code to show the convex hull.

I want to give every sides color because I'm doing some changes in convex hull and I need to see every sides alone.

  ClearAll["Global`*"]
M = x^4 + x y z + y^4 + z^4 + x^2 z^2
p = CoefficientRules[M, {x, y, z}][[All, 1]]
chull = ConvexHullMesh[p];
Show[HighlightMesh[chull, Labeled[1, "Index"]], 
 Graphics3D[{Red, Sphere[p, 0.05], Black, 
   Map[Text[#, # + {0., 0, 0.1}] &, p]}]
   , Axes -> True, Boxed -> True, AxesLabel -> {x, y, z}]

Another step: Can I cut part of the convex hull (or can I just see part of convex hull) because in my work I will just focus on the part from the view from (0,0,0) Here is two view for the convex hull

Thank you

$\endgroup$
  • $\begingroup$ Not sure if it matters, but your convex hull mesh has six 2D faces. It might be easier to work with if you drop the unnecessary point {2, 0, 2}. So q = Drop[p, {2}]; newchull = ConvexHullMesh[q]; will give you a mesh with the expected four faces. Of course, you may want 6 faces. In which case, nevermind. $\endgroup$ – aardvark2012 Oct 28 '17 at 7:25
  • $\begingroup$ @aardvark2012 thank you for your comment, but {2,0,2} will not count because it is on the plane. however, I need a part of the convex hull because when I have a system of equations i will face many planes on my convex hull then I need something call the main part of my work which is the part from the view from the point (0,0,0). $\endgroup$ – Ateq Alsaadi Oct 28 '17 at 7:42
3
$\begingroup$

Mathematica graphics always have a corresponding Graphics or Graphics3D expression. i.e. functions like Plot and ConvexHull don't generate graphics, they generate code. We can take the code and adapt it as required. The code can usually be seen using FullForm, but in this case we also need to use Show:

(gr = chull // Show) // FullForm

Note in the output of the preceding expression the following:

Annotation[
 Polygon[List[List[1, 3, 4], List[3, 5, 4], List[4, 5, 2], 
   List[5, 3, 2], List[3, 1, 2], List[1, 4, 2]]], "Geometry"]

This is clearly the polygons in the figure. (The coordinates are integers which are translated into coordinates by GraphicsComplex, which wraps this expression.) Here is how we can change this expression to color the sides:

gr /. RuleDelayed[
  Annotation[Polygon[polygons__List], "Geometry"],
  Annotation[
   MapIndexed[{ColorData[97, First[#2]], Polygon[#]} &, polygons]]
  ]

Mathematica graphics

The operations that you apply to these polygons are arbitrary. You can also use it to remove planes as what you ask for.

$\endgroup$
  • $\begingroup$ Thank you for your answer. I'm new in mathematica can you please write the full code of my equation. The idea that I'm working on convex hull and I want to see the view of (0,0,0) with color which exactly the one you add in your answer. $\endgroup$ – Ateq Alsaadi Oct 29 '17 at 15:11
  • $\begingroup$ @AteqAlsaadi I'm sorry, but I don't know what that means. The chull variable is from your question, so it is already based on your equation. $\endgroup$ – C. E. Oct 31 '17 at 12:12

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.