I'm trying to base mesh on the slope of the function. That's why there is a Cross of two partial derivatives.

With[{R = Function[If[Abs[#1] < \[Pi]/4, 1, Sec[Abs[#1] - \[Pi]/4]]]},
  With[{F = 
    Function @@ {{\[CurlyPhi], 
       h}, {Sin[\[CurlyPhi]] R[\[CurlyPhi], h], 
       Cos[\[CurlyPhi]] R[\[CurlyPhi], h], h}}}, 
     F[\[CurlyPhi], h], {\[CurlyPhi], -(\[Pi]/2), \[Pi]/2}, {h, -1, 
      1}, MeshFunctions -> #1, 
     Mesh -> {{0}}] &@{Function @@ {{\[CurlyPhi], h}, 
      Norm[{#1, #2, #3}] & @@ Cross[\!\(
\*SubscriptBox[\(\[PartialD]\), \(h\)]\(F[\[CurlyPhi], h]\)\), \!\(
\*SubscriptBox[\(\[PartialD]\), \(\[CurlyPhi]\)]\(F[\[CurlyPhi], 

The graph is plotted, but the mesh is not, and there is an error message:

MeshFunctions::invmeshf: "MeshFunctions->Function[{φ,h},Sqrt[Abs[Cos[<<1>>] If[<<3>>]+If[<<3>>] Sin[<<1>>]]^2+Abs[-Cos[<<1>>] If[<<3>>]+If[<<3>>] Sin[<<1>>]]^2]] must be a pure function or a list of pure functions."

Quite suddenly, when R is replaced by Function[1], the error disappears. But I don't need 1.

I tried renaming the arguments to the mesh function (to no avail), I turned the option into an argument to ParametricPlot3D& (to no avail), I turned Function[] into Function@@{} (to no avail). Now I'm at a loss.

  • $\begingroup$ Should be MeshFunctions -> {#1 &} $\endgroup$
    – cvgmt
    Jul 18, 2021 at 23:45
  • $\begingroup$ @cvgmt You missed the whole point. This is not a newbie question. $\endgroup$ Jul 18, 2021 at 23:58

1 Answer 1


Sorry for my careless.

Maybe Abs can't be differential in Mathematica,so we have to use RealAbs instead.

And it seems that we need to set Mesh -> {{1}}.

With[{R = If[RealAbs[#1] < Pi/4, 1, Sec[RealAbs[#1] - Pi/4]] & }, 
 With[{F = 
    Function @@ {{φ, 
       h}, {Sin[φ]*R[φ, h], 
       Cos[φ]*R[φ, h], h}}}, 
      F[φ, h], {φ, -(Pi/2), Pi/2}, {h, -1, 1}, 
      MeshFunctions -> #1, MeshStyle -> {Thick, Red}, 
      Mesh -> {{1}}] & )[
       {Function @@ {{φ, h}, (Norm[{#1, #2, #3}] & ) @@ 
       Cross[D[F[φ, h], h], 
        D[F[φ, h], φ]]}}]]]

enter image description here

  • $\begingroup$ This works, and it's even backportable to V9 (by adding a definition for RealAbs). Thanks! $\endgroup$ Jul 19, 2021 at 13:54
  • $\begingroup$ Also I had to use Function[{#4, #5} /. {φ_, h_} :> val] /. val ->#3/Norm[{#1, #2, #3}] & @@ Cross[], but that's unrelated to the error message. $\endgroup$ Jul 27, 2021 at 9:14

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.