0
$\begingroup$

I recently need to plot a 3d function that satisfies certain constraints, like

x^2+y^2+z^2<=1

or things similar. So I wonder how to plot the part that only lies within the constraints?

An example surface can be

z=x^2-y^2

More interestingly, is it possible to do that for an implicit function, e.g. x^2+y^2-z^3-z=0, without solving for the equation? Thanks a lot!

$\endgroup$
  • 2
    $\begingroup$ Use RegionFunction to restrict the region of a plot $\endgroup$ – Simon Woods Jan 16 '17 at 21:44
  • $\begingroup$ @SimonWoods Thanks! $\endgroup$ – larry Jan 17 '17 at 2:36
3
$\begingroup$

@SimonWoods hit the nail on the head here:

Plot3D[x^2 - y^2, {x, -1, 1}, {y, 0 - 1, 1}, 
 RegionFunction -> Function[{x, y, z}, x^2 + y^2 + z^2 <= 1]]

enter image description here

Or with your implicit surface:

ContourPlot3D[
 x^2 + y^2 + z^2 - z == 0, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
 RegionFunction -> Function[{x, y, z}, x^2 + y^2 + z^2 <= 1]]

enter image description here

$\endgroup$
  • $\begingroup$ Hi, it works great, thanks! $\endgroup$ – larry Jan 17 '17 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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