Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

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

enter image description here

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

enter image description here

share|improve this answer
    
Wow - thanks a lot! –  gazza Apr 17 '12 at 11:14
    
@gazza, my pleasure. –  kguler Apr 17 '12 at 11:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.