# Using ContourPlot3D on a region in $\mathbb{R}^3$

I have a fundamental region in $\mathbb{R}^3$ defined solely by inequalities (i.e. the region is the intersection of 5 half-spaces and is a kind of square pyramid), and a function which is only well-defined inside that region.

I would like to plot that function's level surfaces inside the region using ContourPlot3D. However there is no easy way to stipulate the region simply in the form of {a,a_min,a_max}-type declarations as Mathematica seems to require. Does anyone know how to do this please?

-

You can use the RegionFunction option with ContourPlot3D as follows:

  ContourPlot3D[x^2 + y^2 + z^2, {x, -3, 3}, {y, -3, 3}, {z, -3, 3},
Contours -> 4,
RegionFunction -> Function[{x, y, z}, -4 < x + y < 4 && -4 < y + 2 z < 4 && -4 < x + z < 3],
ContourStyle -> {Red, Green, Yellow, Orange}, Mesh -> None]


which gives

Or, for a specific contour with the same region function, you can use

  ContourPlot3D[x^2 + y^2 + z^2 == 10, {x, -3, 3}, {y, -3, 3}, {z, -3, 3},
RegionFunction ->  Function[{x, y, z}, -4 < x + y < 4 && -4 < y + 2 z < 4 && -4 < x + z < 3],
ContourStyle -> {Red, Green, Yellow, Orange}, Mesh -> None]


to get

-
Wow - thanks a lot! – gazza Apr 17 '12 at 11:14
@gazza, my pleasure. – kglr Apr 17 '12 at 11:22