In the (accepted) answer to this post, @SimonWoods gives an awesome alternative to RegionPlot3D that gives better definition to the faces and edges of the plotted regions. The code he introduces is

contourRegionPlot3D[region_, {x_, x0_, x1_}, {y_, y0_, y1_}, {z_, z0_, z1_}, 
  opts : OptionsPattern[]] := Module[{reg, preds},
  reg = LogicalExpand[region && x0 <= x <= x1 && y0 <= y <= y1 && z0 <= z <= z1];
  preds = Union@Cases[reg, _Greater | _GreaterEqual | _Less | _LessEqual, -1];
  Show @ Table[ContourPlot3D[
     Evaluate[Equal @@ p], {x, x0, x1}, {y, y0, y1}, {z, z0, z1}, 
     RegionFunction -> Function @@ {{x, y, z}, Refine[reg, p] && Refine[! reg, ! p]},
     opts], {p, preds}]] 

which can be implemented, for example, via

 (x < 0 || y > 0) && 0.5 <= x^2 + y^2 + z^2 <= 0.99,
 {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, Mesh -> None]

similarly to RegionPlot3D.

I'm interested in tweaking this so that I can choose a color for each face of my region. Can anyone figure out a way to do that?

One of the things the code above does is it generates each face lying on the region where each inequality is an equality, constrained to the region bounded by the other faces. Being rather new to Mathematica though, I cannot detect where this occurs, so I'm not sure where to begin experimenting.

Application: I'm using this to show a fundamental domain for a manifold, where certain sides are identified by isometries. I want to color pairs of identified faces the same color.

I like @ScottWoods way of plotting the regions the best out of everything I've found so far, but if there's an alternative way of assigning colors to a region defined by a system of inequalities, I'd also be interested to learn about that.

Thanks in advance.

  • 1
    $\begingroup$ Can you try this? Add i=1 in the variable list of the Module. Add ContourStyle -> Directive[Specularity[], ColorData[97][i++]] at the end of the ContourPlot3D. This will create a new colour for each iteration of the Table. ColorData[97] is the default colour function, ColorData[97][i] is a different colour for each i (well, it probably repeats after a while). Specularity[] resets the ugly white-shiny look added by ContourPlot3D $\endgroup$ – Szabolcs Oct 5 '17 at 14:02
  • $\begingroup$ @Szabolcs That is certainly a step in the right direction, but I also want to control what gets what color. Especially, I want to color specific pairs of sides the same. Is it possible to replace ColorData[97] with my own color list to iterate through? $\endgroup$ – j0equ1nn Oct 5 '17 at 14:16
  • 1
    $\begingroup$ @j0equ1nn - you can take Szabolcs's snippet and replace ColorData[97][++] with myColorList[[i++]] where you've predefined the list of colors, and are certain it has the same size as the list of inputs. $\endgroup$ – Jason B. Oct 5 '17 at 14:24
  • $\begingroup$ Wouldn't it be easier to just plot these surfaces manually with ContourPlot3D? You can replace the >= with == yourself. Then you can give a specific ContourStyle to each one. $\endgroup$ – Szabolcs Oct 5 '17 at 14:52
  • $\begingroup$ @Szabolcs It might be in some cases, but I think then I would run into different rendering issues. The contourRegionPlot3D trick is very smooth and I find has less accuracy errors. I think I like the other idea about switching out ColorData[97][++]. $\endgroup$ – j0equ1nn Oct 5 '17 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.