How to apply different color to RegionPlot3D surfaces?
mesh = {Range[-1, .75, 1.75/15], Range[-1, .75, 1.75/15], Range[-1, 1, 2/15]};
pp3d = ParametricPlot3D[{{x, .75, z}, {.75, x, z}}, {x, -1, 0.75}, {z, -1, 1},
RegionFunction -> (#^2 + #2^2 + #3^2 <= 1 &), PlotStyle -> {Glow @ Red, Glow @ Blue},
MeshFunctions -> {# &, #2 &, #3 &}, Mesh -> mesh];
cp3d = ContourPlot3D[x^2 + (y)^2 + z^2 == 1, {x, -1, 0.75}, {y, -1, 0.75}, {z, -1, 1},
ImageSize -> 400, Boxed -> True, Axes -> True,
MeshFunctions -> {# &, #2 &, #3 &}, Mesh -> mesh,
Lighting -> {{"Directional", Gray, ImageScaled[{2, 0, 2}]}}]
Show[cp3d, pp3d]
Update: an alternative way to post-process RegionPlot3D
output:
rp3d = RegionPlot3D[x^2 + y^2 + z^2 <= 1, {x, -1, 0.75}, {y, -1, 0.75}, {z, -1, 1},
ImageSize -> 400, Boxed -> True, Axes -> True,
Lighting -> {{"Directional", Gray, ImageScaled[{2, 0, 2}]}}];
Normal[rp3d] /. {p : Polygon[{{a_, _, _} ..}, ___] :> {Glow @ Blue, p},
p : Polygon[{{_, b_, _} ..}, ___] :> {Glow @ Red, p}}
Update 2: if you don't mind blending of colors you can also use Lighting
option settings
lighting = {{"Directional", Gray, ImageScaled[{2, 0, 2}]},
{"Spot", Blue, {1.5, 0, 0}, Pi/2}, {"Spot", Red, {0, -.75, 0}, Pi}};
RegionPlot3D[x^2 + (y)^2 + z^2 <= 1, {x, -1, 0.75}, {y, -1, 0.75}, {z, -1, 1},
ImageSize -> 400, Boxed -> True, Axes -> True, Lighting -> lighting]
Replace the polygons of the clipped surface according to their x or y coordinates. The tricky business is that the polygons of the two clipped faces are mixed together in two groups, as @Henrik observed, so I reconstructed an equivalent polygon for each face using ConvexHullMesh
. This necessitates projecting the points on each face to 2D and then lifting the convex hull back up to 3D.
plot = RegionPlot3D[
x^2 + y^2 + z^2 <= 1, {x, -1, 0.75}, {y, -1, 0.75}, {z, -1, 1},
ImageSize -> 400, Boxed -> True,
Axes -> True,(*Lighting->{{"Ambient", White}},*)
Lighting -> {{"Directional", Gray, ImageScaled[{2, 0, 2}]}},
AxesLabel -> Automatic]
With[{coords = Cases[plot, GraphicsComplex[c_, __] :> c, Infinity]},
plot /. p_Polygon /;
coords[[1, p[[1, 2, 2]], 1]] == 0.75 ||
coords[[1, p[[1, 2, 2]], 2]] == 0.75 :>
{Red, Cases[
Cases[plot, {_, 0.75, _}, Infinity][[All, {3, 1}]] //
ConvexHullMesh // Show // Normal,
Polygon[ch_] :>
Polygon[RotateLeft[PadRight[ch, {Automatic, 3}, 0.75], {0, 1}]],
Infinity],
Blue,
Cases[Cases[plot, {0.75, _, _}, Infinity][[All, {2, 3}]] //
ConvexHullMesh // Show // Normal,
Polygon[ch_] :> Polygon[PadLeft[ch, {Automatic, 3}, 0.75]],
Infinity]}
]
The odd lighting makes the blue color almost black, except at certain angles. This is as easy as it is because the desired surfaces are exactly on the plot boundaries (and because the faces are convex).