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
  • 2
    $\begingroup$ Use RegionFunction to restrict the region of a plot $\endgroup$ Jan 16, 2017 at 21:44
  • $\begingroup$ @SimonWoods Thanks! $\endgroup$
    – larry
    Jan 17, 2017 at 2:36

1 Answer 1

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$
1
  • $\begingroup$ Hi, it works great, thanks! $\endgroup$
    – larry
    Jan 17, 2017 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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