1
$\begingroup$

I'm trying to create cross-sections through a 3d plot, but I want my cross sections to be a function of the x and y axes. For example:

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, 
 AxesLabel -> {"x", "y", "z"}, MeshFunctions -> {#1 &}, Mesh -> 5, 
 MeshStyle -> Directive[Red, Thick], PlotStyle -> Opacity[.5]]

This plots cross sections in the x direction only, and {#2 &} would plot in the y direction. How can I change the Mesh so that it that each line of Mesh corresponds to the relationship y=x^2, or y=2x for instance.

I tried this with MeshFunction but can't seem to get the cross sections running in the correct z plane.

$\endgroup$
  • 1
    $\begingroup$ ... MeshFunctions -> {#^2 - #2 &}, Mesh -> {{0}} ...? $\endgroup$ – Kuba Jan 5 '18 at 6:53
2
$\begingroup$
Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, 
 AxesLabel -> {"x", "y", "z"}, 
 MeshFunctions -> {#1 #1 - #2 &, 2 #1 - #2 &}, Mesh -> {{0}, {0}}, 
 MeshStyle -> {Directive[Red, Thick], Directive[Green, Thick]}, 
 PlotStyle -> Opacity[.5]]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks that works perfectly! $\endgroup$ – supagr8 Jan 5 '18 at 17:11
  • $\begingroup$ @supagr8 I had not seen Kuba comment. You can modify using his comment to make succinct. $\endgroup$ – ubpdqn Jan 5 '18 at 22:12

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.