5
$\begingroup$

Let say I have this

ParametricPlot3D[{Sin[u], Cos[u], u/10}, {u, 0, 20}, Mesh -> {{1}}]

Mathematica graphics

Since Filling is not supported with ParametricPlot3D, how can I color the surface between the lines?

$\endgroup$
7
$\begingroup$

How about this?

p = ParametricPlot3D[{Sin[u], Cos[u], u/10}, {u, 0, 20}, 
   Mesh -> {{1}}, PlotPoints -> 30];

Show[ParametricPlot3D[{Sin[u], Cos[u], c u/10}, {u, 0, 20}, {c, 0, 1},
   Mesh -> None, PlotPoints -> 30], p]

filled

$\endgroup$
4
$\begingroup$

Interpreting "between the lines" strictly...

Another model for filling

The original answer (below) fills between the curve and the part of the curve just below it. It has the advantage that the filling surface does not overlap itself on the helix, which is what happens if you fill to the bottom. A slight modification lets the bounds of the filling be any two curves. With this approach, one can fill to the bottom or to the curve, or to whatever.

Block[{f, f2},
 f[u_] := {Sin[u], Cos[u], u/10};
 f2[u_] := f[u - 2 Pi];
 Show[
  ParametricPlot3D[f[u], {u, 0, 20}, Mesh -> {{1}}],
  ParametricPlot3D[(1 - t) f[u] + (t) f2[u],
   {u, 2 Pi, 20}, {t, 0, 1},
   Mesh -> None, PlotPoints -> {40, 7}, PlotStyle -> Opacity[0.5]]
  ]
 ]

Mathematica graphics

Filling to the bottom (like @Jens's), in which the surface overlaps itself where the curve lies above itself.

Block[{f, f2, u},
 f[u_] := {Sin[u], Cos[u], u/10};
 f2[u_] = ReplacePart[f[u], 3 -> f[0][[3]]]; (*bottom*)
 Show[
  ParametricPlot3D[f[u], {u, 0, 20}, Mesh -> {{1}}],
  ParametricPlot3D[(1 - t) f[u] + (t) f2[u],
   {u, 0, 20}, {t, 0, 1},
   Mesh -> None, PlotPoints -> {40, 7}, PlotStyle -> Opacity[0.5]]]]

Mathematica graphics

Filling to the bottom without overlapping filling; the use of Max[] in f2[] clips the filling to the low point of the plot of f (code updated):

Block[{f, f2, u, p, bottom},
 f[u_] := {Sin[u], Cos[u], u/10};
 p = ParametricPlot3D[f[u], {u, 0, 20}, Mesh -> {{1}}];
 bottom = Min[Cases[p, GraphicsComplex[pts_, __] :> pts[[All, 3]], Infinity]];
 f2[u_] = MapAt[Max[bottom, #] &, f[u - 2 Pi], 3];
 Show[
  p,
  ParametricPlot3D[(1 - t) f[u] + (t) f2[u],
   {u, 0, 20}, {t, 0, 1},
   Mesh -> None, PlotPoints -> {50, 5}, PlotStyle -> Opacity[0.5], 
   Exclusions -> None]
  ]
 ]

Mathematica graphics

Original answer

I assume there is some function offset[u] that determines how far back is the corresponding point below f[u]: that is, f[u - offset[u]] is to be considered "directly below" f[u]. For the example helix, the offset is the period 2 Pi.

Block[{f, offset},
 f[u_] := {Sin[u], Cos[u], u/10};
 offset[u_] := 2 Pi;
 Show[
  ParametricPlot3D[f[u], {u, 0, 20}, Mesh -> {{1}}],
  ParametricPlot3D[(1 - t) f[u] + (t) f[u - offset[u]],
   {u, offset[0], 20}, {t, 0, 1},
   Mesh -> None, PlotPoints -> {40, 7},  PlotStyle -> Opacity[0.5]]
  ]
 ]
 (*  same as first plot above  *)

The distance between the lines does not have to be constant:

Block[{f, offset},
 f[u_] := {Sin[u], Cos[u], u/10 + Cos[Sqrt[30] u]/30};
 offset[u_] := 2 Pi;
 Show[
  ParametricPlot3D[f[u], {u, 0, 20}, Mesh -> {{1}}],
  ParametricPlot3D[(1 - t) f[u] + (t) f[u - offset[u]],
   {u, offset[0], 20}, {t, 0, 1},
   Mesh -> None, PlotPoints -> {40, 7}, PlotStyle -> Opacity[0.5]]
  ]
 ]

Mathematica graphics

What is considered "directly above" is given by the definition of offset (and f), and the points do not have to be aligned vertically (on left).

Block[{f, offset},
 f[u_] := {(1 + Sin[Sqrt[10] u]/10) Sin[u], (1 + Sin[4.5 u]/10) Cos[
     u], u/10 + Cos[Sqrt[30] u]/30};
 offset[u_] := 2 Pi;
 Show[
  ParametricPlot3D[f[u], {u, 0, 20}, Mesh -> {{1}}],
  ParametricPlot3D[(1 - t) f[u] + (t) f[u - offset[u]],
   {u, offset[0], 20}, {t, 0, 1},
   Mesh -> None, PlotPoints -> {50, 7}, PlotStyle -> Opacity[0.5]]
  ]
 ]

Update: The plot on the right shows filling to z == 0 using the first filling-to-the-bottom method above. One might have reasons for preferring one to the other.

$\endgroup$
  • 3
    $\begingroup$ Here is what it looks like when the FE has done enough graphing for one session and is about to crash: !Mathematica graphics $\endgroup$ – Michael E2 Sep 5 '16 at 18:09

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.