2
$\begingroup$

I have a surface

s = Plot3D[{x,y,F[x,y]},{x,-1,1},{y,-1,1}]

with $F$ predefined, and a curve

c = ParametricPlot3D[{g1[t],g2[t],F[g1[t],g2[t]]},{t,0,1}]

with $g1,g2$ predefined. $c$ is therefore a curve on the surface $s$. If I want to show both the objects together I can use

Show[s,c]

but how can I animate the trajectory described by the curve $c$ on the surface $s$?

$\endgroup$
  • 3
    $\begingroup$ Check out Animate and replace {t,0,1} with {t,0,u}, and let u be the changing variable in Animate. $\endgroup$ – C. E. Oct 27 '13 at 16:21
  • $\begingroup$ Read the documentation. $\endgroup$ – Sektor Oct 27 '13 at 16:32
7
$\begingroup$

Without functions, let's make up our own. I'm going to take a guess here that the definition of s in the question really requires ParametricPlot3D:

F[x_, y_] := Sin[x] Cos[y];
g1[t_] := t;
g2[t_] := Cos[t];

Generate the surface:

s = ParametricPlot3D[{x, y, Sin[x] Cos[y]}, {x, -Pi, Pi}, {y, -Pi, 
   Pi}, Mesh -> None, PlotStyle -> Opacity[0.9]]

Create an animate of the contour by animating over the end value of the contour:

Animate[  
 Show[s, ParametricPlot3D[{g1[u], g2[u], F[g1[u], g2[u]]}, {u, -Pi, 
    endu}, PlotStyle -> Thick, BoxRatios -> {1, 1, 1}]], {endu, -Pi, 
  Pi}]

enter image description here

Use a Table instead of Animate to create a series of images that can be exported as an animated gif as described in the documentation.

$\endgroup$
  • $\begingroup$ Thanks! Just one last question: how can I export it into a gif? $\endgroup$ – albatross Oct 27 '13 at 16:47
  • 1
    $\begingroup$ If you're new to Mathematica you'll want to have a look around this site for lots of good information. Creating animated gifs can be found here among other places. $\endgroup$ – bobthechemist Oct 27 '13 at 17:01

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.