3
$\begingroup$

Given the 3D plot Plot3D[Sin[x y], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}], how can one highlight the portion with $x+y=1$.

$\endgroup$
3
$\begingroup$
Clear["Global`*"]

x + y == 1 is the border between the two regions

Show[
 Plot3D[Sin[x y], {x, 0, 2 π}, {y, 0, 2 π},
  PlotStyle -> Red,
  RegionFunction -> Function[{x, y, z}, x + y < 1]],
 Plot3D[Sin[x y], {x, 0, 2 π}, {y, 0, 2 π},
  PlotStyle -> Opacity[0.5, ColorData[97][2]],
  RegionFunction -> Function[{x, y, z}, x + y > 1]]]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ But the region is an equality... not an inequality. $\endgroup$ – David G. Stork Jul 25 at 20:46
  • $\begingroup$ @DavidG.Stork - the equality is the shared border of the two regions $\endgroup$ – Bob Hanlon Jul 25 at 20:50
3
$\begingroup$

You can use the options MeshFunctions and Mesh as follows:

Plot3D[Sin[x y], {x, 0, 2 π}, {y, 0, 2 π}, 
 MeshFunctions -> {# + #2 &}, Mesh -> {{{1, Directive[Blue, Thick]}}}]

enter image description here

Alternatively, style the mesh line using the option MeshStyle:

Plot3D[Sin[x y], {x, 0, 2 π}, {y, 0, 2 π}, 
 MeshFunctions -> {# + #2 &}, 
 Mesh -> {{1}}, 
 MeshStyle -> Directive[Blue, Thick]]

same picture

If you wish you can use different styles for the regions x + y < 1 and x + y > 1 using the option MeshShading:

Plot3D[Sin[x y], {x, 0, 2 π}, {y, 0, 2 \[Pi]}, 
 MeshFunctions -> {# + #2 &},
 Mesh -> {{1}}, 
 MeshStyle -> Directive[Blue, Thick],
 MeshShading -> {Pink, Yellow}, 
 BoundaryStyle -> None, 
 PlotLegends -> Column[{SwatchLegend[{Pink}, { "x + y < 1"}], 
    LineLegend[{Directive[Blue, Thick]}, { "x + y == 1"}], 
    SwatchLegend[{Yellow}, { "x + y > 1"}]}]]

enter image description here

| improve this answer | |
$\endgroup$
2
$\begingroup$
a = Plot3D[Sin[x y],
  {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]},
  PlotPoints -> 80,
  PlotStyle -> Opacity[0.5]];

b = Graphics3D[
  InfinitePlane[{ 1/2, 1/2,0}, {{0, 0, 1}, {1/2, -1/2, 0}}]];

Show[a,b]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$
Show[Plot3D[{ConditionalExpression[ Sin[x y], x + y > 1], 
   ConditionalExpression[ Sin[x y], x + y < 1]}, {x, 0, 2 \[Pi]}, {y, 
   0, 2 \[Pi]}, PlotPoints -> 50, Mesh -> None, 
  PlotStyle -> {LightCyan, Yellow}, Lighting -> "Neutral"], 
 ContourPlot3D[
   x + y == 1, {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}, {z, -1, 1}, 
   MeshStyle -> Directive[Red, Thickness[0.0125]]] /. {x_Real, y_Real,
     z_Real} -> {x, y, Sin[x y]}, Boxed -> False, Axes -> False]

enter image description here

| improve this answer | |
$\endgroup$

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.