4
$\begingroup$

I want to gradually render the surface like this
enter image description here enter image description here
For parametric curves, it can be drawn gradually in the following way. After generating a graph, then extract the data for plotting, avoid some duplicate calculations, this should be faster.

plt = ParametricPlot[{Sin[t], Sin[2 t]}, {t, 0, 2 Pi}, ColorFunction -> (Hue[#3] &)];
len = Cases[plt, Line[x_, rest_] :> Length[x], -1][[1]];
Manipulate[plt /. Line[x_, rest_] :> Line[Take[x, i], rest], {i, 1, len, 1}]

For parametric surfaces, my current attempt, the mesh was not generated in the way I expected, I think it's a little slow, because there are a lot of repeated calculations. Do you have a good way?

With[{surf = {Cos[t] (3 + r Cos[t/2]), Sin[t] (3 + r Cos[t/2]), r Sin[t/2]},
  opts = Sequence[Axes -> False, Mesh -> {4, 15}, 
    PlotRange -> {{-3.43, 4.4}, {-4.12, 4.12}, {-1.12, 1.12}}, 
    BoundaryStyle -> Black, PerformanceGoal -> "Quality", ImageSize -> 300]},
 Manipulate[Row@{
    ParametricPlot3D[surf, {r, -1, 1}, {t, 0, u}, ColorFunction -> (Hue[#5] &), opts],
    ParametricPlot3D[surf, {r, -1, 1}, {t, 0, u}, MeshShading -> {{Cyan, Orange}, {Orange, Cyan}},
 opts]}, {u, 0.001, 2 Pi}]]

enter image description here

$\endgroup$

2 Answers 2

5
$\begingroup$

I tried setting ColorFunctionScaling->False and manually scaling the range based on the max for u. Also I set MeshFunctions manually to not simply subdivide up to u, but up to 2Pi -- unfortunately the Floor function results in very wonky divisions.

With[{surf = {Cos[t] (3 + r Cos[t/2]), Sin[t] (3 + r Cos[t/2]), r Sin[t/2]},
opts = Sequence[Axes -> False, Mesh -> {4, 15}, 
PlotRange -> {{-3.43, 4.4}, {-4.12, 4.12}, {-1.12, 1.12}}, 
BoundaryStyle -> Black, PerformanceGoal -> "Quality", ImageSize -> 300,
    (* modified *) ColorFunctionScaling->False,MeshFunctions->{#4&,Floor[16#5/Pi]&}
]},
Manipulate[Row@{
ParametricPlot3D[surf, {r, -1, 1}, {t, 0, u}, ColorFunction -> (Hue[
    (* modified *) #5/(2Pi)
] &), opts],
ParametricPlot3D[surf, {r, -1, 1}, {t, 0, u},
MeshShading -> {{Cyan, Orange}, {Orange, Cyan}},opts]}, {u, 0.001, 2 Pi}]]

So the hack I recommend instead is to plot with {t,0,2Pi} and simply set surf={0,0,0} if t>u, i.e.

With[{
  surf=If[t<=u,{Cos[t](3+r Cos[t/2]),Sin[t](3+r Cos[t/2]),r Sin[t/2]},{0,0,0}],
opts=...]

animation

$\endgroup$
4
$\begingroup$
  • We draw the full surface and use RegionFunction to cut the surface by RegionFunction -> Function[{x, y, z, r, t}, t <= u].
  • We manual set the Mesh by Mesh -> {Subdivide[-1, 1, 4 + 1], Subdivide[0, 2 π, 15 + 1]} instead of {4,15}.
surf = {Cos[t] (3 + r Cos[t/2]), Sin[t] (3 + r Cos[t/2]), 
  r Sin[t/2]};
Manipulate[
 ParametricPlot3D[surf, {r, -1, 1}, {t, 0, 2 π}, PlotPoints -> 60,
   MaxRecursion -> 4, MeshFunctions -> {#4 &, #5 &}, 
  Mesh -> {Subdivide[-1, 1, 4 + 1], Subdivide[0, 2 π, 15 + 1]}, 
  ColorFunction -> Function[{x, y, z, u, v}, Hue[v/(2 π)]], 
  ColorFunctionScaling -> False, 
  RegionFunction -> Function[{x, y, z, r, t}, t <= u], Axes -> False, 
  PlotRange -> {{-3.43, 4.4}, {-4.12, 4.12}, {-1.12, 1.12}}, 
  BoundaryStyle -> Black, PerformanceGoal -> "Quality", 
  ImageSize -> 300], {u, $MachineEpsilon, 2 Pi}, 
 ControlPlacement -> Top]

enter image description here

  • For the second gif, we use the same way.
surf = {Cos[t] (3 + r Cos[t/2]), Sin[t] (3 + r Cos[t/2]), 
  r Sin[t/2]}; 
Manipulate[
 ParametricPlot3D[surf, {r, -1, 1}, {t, 0, 2 π}, 
  MeshFunctions -> {#4 &, #5 &}, 
  Mesh -> {Subdivide[-1, 1, 4 + 1], Subdivide[0, 2 π, 15 + 1]}, 
  MeshShading -> {{Cyan, Orange}, {Orange, Cyan}}, 
  RegionFunction -> Function[{x, y, z, r, t}, t <= u], Axes -> False, 
  PlotRange -> {{-3.43, 4.4}, {-4.12, 4.12}, {-1.12, 1.12}}, 
  BoundaryStyle -> Black, PlotPoints -> 60, MaxRecursion -> 4, 
  PerformanceGoal -> "Quality", 
  ImageSize -> 300], {u, $MachineEpsilon, 2 Pi}, 
 ControlPlacement -> Top]

enter image description here

  • Integrate the animation as OP.
With[{surf = {Cos[t] (3 + r Cos[t/2]), Sin[t] (3 + r Cos[t/2]), 
    r Sin[t/2]}, 
  opts = Sequence[Axes -> False, 
    Mesh -> {Subdivide[-1, 1, 4 + 1], Subdivide[0, 2 π, 15 + 1]}, 
    PlotRange -> {{-3.43, 4.4}, {-4.12, 4.12}, {-1.12, 1.12}}, 
    BoundaryStyle -> Black, PerformanceGoal -> "Quality", 
    ImageSize -> 300]}, 
 Manipulate[
  Row@{ParametricPlot3D[surf, {r, -1, 1}, {t, 0, 2 π}, 
     ColorFunction -> (Hue[#5/(2 π)] &), 
     ColorFunctionScaling -> False, opts, 
     RegionFunction -> Function[{x, y, z, r, t}, t <= u]], 
    ParametricPlot3D[surf, {r, -1, 1}, {t, 0, 2 π}, 
     MeshShading -> {{Cyan, Orange}, {Orange, Cyan}}, opts, 
     RegionFunction -> 
      Function[{x, y, z, r, t}, t <= u]]}, {u, $MachineEpsilon, 
   2 Pi}]]

enter image description here

$\endgroup$

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.