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?

-

1 Answer

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. – kguler Apr 17 '12 at 11:22
lang-mma
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 2, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.8216035962104797, "perplexity_flag": "middle"}