1
$\begingroup$
P0={0,0,0};P1={1,0,0};P2={0,1,0};P3={0,0,1};P4={1,1,1};P5={-1,-1,-1};
R[4]=ConvexHullMesh[{P0,P1,P3,P4},Frame->True,PlotRange -> Automatic,MeshCellStyle -> {{2,All}-> Opacity[.4, Red],{1,All}->Black,{0,All}->Blue}];

Show[Region[R[4], PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2},{-1.2,1.2}}, 
  Axes-> True, ImageSize -> Large,AxesOrigin->{0,0,0},LabelStyle ->{12,Bold,Black},AxesLabel->{x,y,z},AxesStyle->Thick,Boxed->True]]

I have the following 3D convex hull. How can I give different colors to different faces of the convex hull?

Thank you

$\endgroup$
2
  • $\begingroup$ "different sides" - you mean "different faces", yes? $\endgroup$ Apr 25 '20 at 11:05
  • $\begingroup$ Yes. Different faces. I will edit it. Thanks $\endgroup$
    – Epsilon
    Apr 25 '20 at 11:07
1
$\begingroup$
faces = MeshPrimitives[R[4], "Polygons"];
colors = {Red, Green, Blue, Orange};

Graphics3D[Transpose@{colors , faces}, 
 PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}, {-1.2, 1.2}}, Axes -> True, 
 ImageSize -> Large, AxesOrigin -> {0, 0, 0}, 
 LabelStyle -> {12, Bold, Black}, AxesLabel -> {x, y, z}, 
 AxesStyle -> Thick, Boxed -> True]

enter image description here

$\endgroup$
7
  • $\begingroup$ Thanks. Is it possible to change the opacity of the colors so that the we don't see the axis lines through the hull? $\endgroup$
    – Epsilon
    Apr 25 '20 at 11:22
  • 1
    $\begingroup$ @Sumit, you can define colors as colors = Opacity[.5, #]& /@ {Red, Green, Blue, Orange} $\endgroup$
    – kglr
    Apr 25 '20 at 11:44
  • $\begingroup$ Thanks a lot for your help. $\endgroup$
    – Epsilon
    Apr 25 '20 at 11:48
  • 1
    $\begingroup$ @Sumit, my pleasure. $\endgroup$
    – kglr
    Apr 25 '20 at 11:51
  • 1
    $\begingroup$ you can try something like Epilog -> {Inset[Style["text", 16, Red], {.5, .7}], Text[Style["text2", 16, Green], {.3, .4}]} $\endgroup$
    – kglr
    Apr 25 '20 at 12:09

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.