# How to avoid these garbage and missing mesh lines in ParametricPlot3D?

What I did:

f[t_,z_] := Cos[z/2]^0.5 * (1+HeavisideTheta[z-0.35 Pi]);
ParametricPlot3D[{f[t,z] Cos[t],f[t,z] Sin[t],-z}, {t,-Pi, Pi},{z,-Pi,Pi},
PlotRange -> All,Exclusions->None]


and then I reoriented the plot.

What I got:

What I hoped for: mesh lines without garbage (see west of pointer) and omissions (see north-northeast).

• Increase the number of PlotPoints, say, PlotPoints -> 101 Jul 28 '15 at 23:45
• Thanks. That works, albeit at considerable cost. If you enter your response as an answer, I can accept it. Jul 28 '15 at 23:58

f[t_, z_] = Cos[z/2]^(1/2)*(1 + HeavisideTheta[z - 35/100 Pi]);


Increase the number of PlotPoints

ParametricPlot3D[
{f[t, z] Cos[t], f[t, z] Sin[t], -z},
{t, -Pi, Pi}, {z, -Pi, Pi},
PlotRange -> All,
Exclusions -> None,
PlotPoints -> 101]


What you're seeing is the result of a discontinuous function (HeavisideTheta). The mesh algorithms assume things are continuous and do not always work well when they're not. It might be worth breaking up the plot according to the discontinuity, and inserting a sheet connecting the two pieces of the plot.

f[t_, z_] := Cos[z/2]^0.5*(1 + HeavisideTheta[z - 0.35 Pi]);
zmesh = Subdivide[-Pi, Pi, 16];
Show[
ParametricPlot3D[{f[t, z] Cos[t], f[t, z] Sin[t], -z}, {t, -Pi,
Pi}, {z, -Pi, 0.35 Pi}, Mesh -> {14, zmesh}],
ParametricPlot3D[{f[t, z] Cos[t], f[t, z] Sin[t], -z}, {t, -Pi,
Pi}, {z, 0.35 Pi, Pi}, Mesh -> {14, zmesh}],
ParametricPlot3D[
{r Cos[t], r Sin[t], -0.35 Pi},
{t, -Pi, Pi},
{r, f[0, z] /. HeavisideTheta -> (0 &) /. z -> 0.35 Pi,
f[0, z] /. HeavisideTheta -> (1 &) /. z -> 0.35 Pi},
Mesh -> {14, 0}],
PlotRange -> All
]


• 1) "The mesh algorithms assume things are continuous and do not always work well when they're not." Disappointing... esp. since what's being meshed (polygonised) is not the discontinuous function but the continuous surface. And surprising, because the docs say the mesh follows polygon edges, so I guess the polygons there are garbaged too. 2) "It might be worth breaking up the plot ..." Yes if that was automatable, but otherwise no for me since the shape is dynamically variable. Thanks anyway for the suggestion and for that code - a more-generally valuable tutorial for me. Jul 29 '15 at 23:45
• @Chris Re 1), your definition (i.e., f) of the surface is not continuous and the surface defined this way is not continuous. If you can give a continuous symbolic description, Mathematica can probably oblige you. Output is rarely better than input. Hanlon's method is a dodge, not a bad one mind you, but you've seen the consequences of an undefined gradient. Re 2), how do you know it's not automatable? -- Good luck sorting it out1 :) Jul 30 '15 at 0:42