# RegionPlot3D contour problem

I have a little problem and didn't succeed trying to solve it on my own. Situation is, I need a visualization of the function $s - 3\cdot s\cdot q + q$ as a region on p == 0 if function's value is less than zero, a region on p == 1 if the function > 0, and a contour if the function equals to zero.

What I've done:

RegionPlot3D[(s - 3q*s + q > 0 && p == 0) || (s - 3q*s + q <= 0  && p == 1),
{q, 0, 1}, {s, 0, 1}, {p, 0, 1}, AxesLabel -> Automatic]


which give me this: but what I need to add is a contour $s - 3\cdot s\cdot q + q = 0$ to this plot, but also remain able to intersect this set with others.

The contour is simple:

ContourPlot3D[s - 3 q*s + q == 0, {p, 0, 1}, {q, 0, 1}, {s, 0, 1}] I've tried to use a little hint with inequality range

RegionPlot3D[(s - 3 q s + q > 0 && p == 0) || (s - 3 q s + q <= 0 &&
p == 1) || Abs[s - 3 q s + q] < 0.01, {q, 0, 1}, {s, 0, 1}, {p,
0, 1}, AxesLabel -> Automatic, PlotPoint -> 100]


This is sufficiently accurate, but produces a 3d set, instead of a surface.

Any ideas how to reach my goal?

P.S. the best would be a solution to such kind of problems in general, because, sometimes the contour equation can be not that simple.

## 2 Answers

Solution using Show needs to rearrange the order of ranges in ContourPlot3D, e.g. :

Show[RegionPlot3D[(s - 3 q*s + q > 0 && p == 0) ||
(s - 3 q*s + q <= 0 && p == 1),
{q, 0, 1}, {s, 0, 1}, {p, 0, 1}, AxesLabel -> Automatic],
ContourPlot3D[s - 3 q*s + q == 0, {q, 0, 1}, {s, 0, 1}, {p, 0, 1}]] Edit

Here is another solution without Show, using only Plot3D and HeavisideTheta function :

Plot3D[ HeavisideTheta[-s + 3 q*s - q], {q, 0, 1}, {s, 0, 1},
Exclusions -> None, PlotPoints -> 100, PerformanceGoal -> "Quality",
ColorFunction -> Function[{x, y, z}, RGBColor[x, y, 1]],
MeshFunctions -> {#1 &, #2 &, #3 &}, BoxRatios -> {1, 1, 2/3}] • Hi, Artes! Thanks a lot for this answer, it's very helpful. Although, would I be able to intersect the contour part with other bool sets? I mean, what if I add another condition, using other equation, would it intersect the contour part with it ass well? – Sergey Aganezov jr Mar 19 '12 at 4:23
• @SergeyAganezovjr You can always use Plot3D[{f1[x,y],f2[x,y],...,fn[x,y]},{x,xmin,xmax},{y,ymin,ymax},options] to plot n functions. Instead of HeavisideTheta you can use e.g. UnitStep. The latter may depend on more variables. – Artes Mar 19 '12 at 11:24

I am not sure I understand your question. What is a "3D set" and a "3D surface"?

If you need to combine two 3D graphics, use Show[graphic1, graphic2]. Your surface can be plotted using Plot3D as well, but the quality of the discontinuous part will not be excellent:

Plot3D[Boole[s - 3 q*s + q < 0], {q, 0, 1}, {s, 0, 1},
ExclusionsStyle -> Automatic, BoxRatios -> 1] Using Show to combine two pieces:

Show[
ContourPlot3D[s - 3 q*s + q == 0, {q, 0.1, 1}, {s, 0.1, 1}, {p, 0, 1}],
Plot3D[Boole[s - 3 q*s + q < 0], {q, 0, 1}, {s, 0, 1}]
] • Congrats with your 10k. I hadn't noticed before. – Sjoerd C. de Vries Mar 18 '12 at 21:13
• Well, the difference is that 3D set has a range of s values with constant q, while surface doesn't. – Sergey Aganezov jr Mar 19 '12 at 4:27