10
$\begingroup$

Consider the following plot of two surfaces

Plot3D[{Sin[x y], x^3 + y}, {x, -1, 1}, {y, -1, 1}, PlotRange -> {{x, -1, 1}, {y, -1, 1}, {z, -1, 1}}, Mesh -> None]

plot

How can I produce a plot where I limit the the surface plot of $\sin(x y)$, to be shown only when its values are above $x^3+y$, or any other given function.

$\endgroup$

2 Answers 2

15
$\begingroup$

ConditionalExpression

Plot3D[ConditionalExpression[Sin[x y], Sin[x y] > x^3 + y], 
  {x, -1,  1}, {y, -1, 1}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Mesh -> None]

enter image description here

To show both functions

Plot3D[{ConditionalExpression[Sin[x y], Sin[x y] > x^3 + y], x^3 + y }, 
  {x, -1,  1}, {y, -1, 1}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, 
  Mesh -> None, BaseStyle -> Opacity[.7]]

enter image description here

MeshFunctions, MeshShading

 Plot3D[Sin[x y], {x, -1, 1}, {y, -1, 1}, 
  PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, 
  MeshFunctions -> {Sin[# #2] - #^3 - #2 &}, Mesh -> {{0}}, 
  MeshShading -> {None, Automatic}, BoundaryStyle -> None] 

enter image description here

ImplicitRegion

ir = DiscretizeRegion @ ImplicitRegion[Sin[x y] > x^3 + y, {{x, -1, 1}, {y, -1, 1}}];

Plot3D[Sin[x y], {x, y} ∈ ir, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Mesh -> None]

enter image description here

$\endgroup$
7
$\begingroup$

You can utilize the option RegionFunction for that:

Plot3D[{Sin[x y], x^3 + y}, {x, -1, 1}, {y, -1, 1},
 Mesh -> None,
 RegionFunction -> ({x, y, z} \[Function] Sin[x y] > (x^3 + y))
 ]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Equivalently: reg = BoundaryDiscretizeRegion[ImplicitRegion[Sin[x y] > (x^3 + y), {{x, -1, 1}, {y, -1, 1}}]]; Plot3D[Sin[x y], {x, y} ∈ reg] $\endgroup$ Oct 6, 2018 at 9:59

Your Answer

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

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