I've got an expression involving x
and y
that I want to use as a MeshFunction
:
mymesh = x + y
Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1}, MeshFunctions -> {Function[{x, y, z}, mymesh]}]
This works just fine. But now I want to create a plotting function that takes the mesh function as an argument, like so:
myplot[mesh_] := Plot3D[x^2 + y^2, {x, -1, 1}, {y, -1, 1},
MeshFunctions -> {Function[{x, y, z}, mesh]}]
myplot[mymesh]
This produces the following error:
MeshFunctions::invmeshf:
"MeshFunctions->Function[{x$,y$,z$},x+y] must be a pure function or a list of pure functions"
It seems like it's making local variables x$, y$, z$
and then keeping them distinct from the x,y
in mymesh
.
Any suggestions how to make this work? I'd like to keep mymesh
in the symbolic form, because the plot I'm actually interested in doing is much more complicated, and uses the mymesh
function a second time as part of the function to plot.
I'm going to add some more to this question, because I have a few answers, all of which suggested not passing mymesh
in it's current form to the function. But I explicitly want to pass mymesh
as it is.
Here's the actual code I'm using it for. It plots the solutions to c==0
on the unit sphere, where c
is a homogeneous polynomial in x,y,z
.
elliptic = z y^2 - x^3 + z^2 x
curveSpherePlot[c_] := ContourPlot3D[
{x^2 + y^2 + z^2 == 1, c == 0},
{x, -1, 1}, {y, -1, 1}, {z, -1, 1},
MeshFunctions -> {Function[{x, y, z}, x^2 + y^2 + z^2 - 1 - c]},
MeshStyle -> {{Thick, Black}},
Mesh -> {{0}},
ContourStyle -> {Opacity[0.9], None},
BoundaryStyle -> None
]
curveSpherePlot[elliptic]
Notice that the argument c
appears in the equation as well as in the mesh function. Not only that, but I manipulate the curve symbolically with other functions in the package, so I really don't want to switch it to a different type of object if I can help it.