Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

There are lots of great demonstrations that show how to get periodic functions in the unit circle. I'm wondering how hard it would be to simulate a "moving grid" similar to this video on youtube (at about 1 minute)

The circle and moving points are easy , but I don't know how to simulate that grid and sinusoid moving under the moving points. Any help would be appreciated.

Here is my start, lots of possibilities to make this look better cosmetically, but the moving "paper" is something that would really help to illustrate the idea.

Manipulate[Graphics[{
   Circle[],
   PointSize[0.012],
   Point[{Cos[t], Sin[t]}],
   Point[{0, Sin[t]}]
   }, PlotRange -> {{-1.1, 11}, {-1.1, 1.1}}, 
  ImageSize -> {500, 100}], {t, 0, 10}]
share|improve this question
    
Thanks to "ssch" for editing my original question, you made it easier to view and work with. –  Tom De Vries Jan 30 '13 at 15:59

3 Answers 3

up vote 6 down vote accepted

Here's a "compositional" approach. If you take things piece-by-piece it is not too hard to build up more complicalated demonstrations.

Animate[Module[
  {spazzyP, scrollingPaper, scrollingSine, circle,
   pCoords, yCoords, yellowDot, blueLine,
   offset = 1, range = 2 Pi, padding = 1, fmin = Floor[min]},

  pCoords = {min + offset - Cos[min + offset], Sin[min + offset]};
  spazzyP = Graphics[{
     {Red, Opacity[.8], Disk[pCoords, .2]},
     {Style[Text["P", pCoords], Bold]}}];

  yCoords = {min + offset, Sin[min + offset]};
  yellowDot = Graphics[{Yellow, Point[yCoords]}];

  blueLine = Graphics[{{Blue, Opacity[.6], Line[{pCoords, yCoords}]}}];

  circle = Graphics[{Darker@Green, Circle[{min + offset, 0}, 1]}];

  scrollingPaper = Graphics[{},
    GridLines -> {Range[fmin - padding, fmin + range + padding + 1], 
      Range[-1 - padding, 1 + padding, .5]},
    PlotRange -> {{min, min + range}, {-1, 1}},
    PlotRangePadding -> padding,
    GridLinesStyle -> Lighter[Gray, .6]];

  scrollingSine = 
   Plot[Sin[x], {x, min + offset, min + range + padding}, 
    PlotStyle -> {Thick, Red}];

  elements = {
    scrollingPaper,
    circle,
    scrollingSine,
    blueLine,
    yellowDot,
    spazzyP (* note: spazzyP fails to live up to its name *)
    };

  (* elements *) (* useful for 'debugging' individual components, if necessary *)
  Magnify@Show[elements]
  ]

 , {min, 2 Pi, -2 Pi}]

enter image description here

I encourage others to fix/build on this if they want to.

A general note: One of the powerful things about Mathematica is its symbolic evaluation scheme. In this code I save individual components in the form of Graphics objects, but I could have just as easily kept things as lists like this:

circle = {Darker@Green, Circle[{min + offset, 0}, 1]};

And then later wrapped them in Graphics or Show. The point is you're completely free to build things up piecemeal and compose them later on.

share|improve this answer
1  
Thank you for this, and indirectly, my students thank you. It's great to be able to add interactive things to the "bag of tricks" needed to teach concepts. I like this approach, and your modular approach will also help me as I work to design similar demonstrations. I appreciate your help, and the comments will help me understand your code. –  Tom De Vries Jan 30 '13 at 15:56

I first create the plot with GridLines -> Automatic:

plot = Plot[-Sin[x], {x, -10, 0},
  PlotRange -> {{-10, 1}, {-1.1, 1.1}},
  ImageSize -> {500, 100},
  Axes -> False,
  GridLines -> Automatic]

Then I combine your graphics object with plot using Inset:

Manipulate[
 Graphics[{Circle[], PointSize[0.012], Point[{Cos[t], Sin[t]}],
   ColorData[1, "ColorList"][[1]], Point[{0, Sin[t]}],
   Inset[plot, {0, 0}, {-t, 0}, {12.1, 2.2}]},
  PlotRange -> {{-1.1, 11}, {-1.1, 1.1}}, 
  ImageSize -> {500, 100}], {t, 0, 10}]

I also changed the second Point to match with the color in the plot. Notice how I use the thrid argument of Inset to get the plot exactly aligned with the graphic.

enter image description here

Edit: Of course you can also use your own GridLines. In this case it makes sense to place vertical lines at fractions of Pi:

...
  GridLines -> {Table[i Pi/4, {i, -12, 4}], 
    Table[i, {i, -1, 1, 1/4}]}
...

enter image description here

Edit 2: Since it was asked: Export can handle list of images/graphics.

plotlist=Table[
 Graphics[{Circle[], PointSize[0.012], Point[{Cos[t], Sin[t]}],
   ColorData[1, "ColorList"][[1]], Point[{0, Sin[t]}],
   Inset[plot, {0, 0}, {-t, 0}, {12.1, 2.2}]},
  PlotRange -> {{-1.1, 11}, {-1.1, 1.1}}, 
  ImageSize -> {500, 100}], {t, 0, 10, 0.2}];

Export["foo.gif", plotlist];

Likewise you can export to .avi using Export["foo.avi", plotlist].

share|improve this answer
1  
Thanks for sharing, I appreciate it. I learn a lot by looking at approaches to problems I have some "ownership" of. Lots of helpful things here. –  Tom De Vries Jan 30 '13 at 15:53

Same kind of approach as @einbandi's here but without insetting and the grid:

Manipulate[
    plot = Plot[-Sin[x - t], {x, 0, 10},
        PlotRange -> {{-10, 1}, {-1.1, 1.1}},
        ImageSize -> {500, 100},
        Axes -> False,
        PlotStyle -> Blue];
    line = Graphics@Line[{{0, Sin[t]}, {Cos[t], Sin[t]}}];
    circle = Graphics[{Circle[],
        {PointSize[0.02], Black, Point[{Cos[t], Sin[t]}]}, 
        {PointSize[0.02], Blue, Point[{0, Sin[t]}]}},
            PlotRange -> {{-1.1, 11}, {-1.1, 1.1}},
            ImageSize -> {500, 100}];
    Show[{line, circle, plot}]
, {t, 0, 2 \[Pi], \[Pi]/80, Animator}]

animated sin function

----EDIT----

Apologies, I only just saw the requirement for a grid (which I subconsciously skipped as I didn't like it) but the following modification seems to work and the grid gives the illusion of moving:

Manipulate[
    plot = Plot[-Sin[x - t], {x, 0, 10},
        PlotRange -> {{-10, 1}, {-1.1, 1.1}},
        ImageSize -> {500, 100},
        Axes -> False,
        PlotStyle -> Blue];
    line = Graphics@Line[{{0, Sin[t]}, {Cos[t], Sin[t]}}];
    circle = Graphics[{Circle[],
        {PointSize[0.02], Black, Point[{Cos[t], Sin[t]}]}, 
        {PointSize[0.02], Blue, Point[{0, Sin[t]}]}},
            PlotRange -> {{-1.1, 11}, {-1.1, 1.1}},
            ImageSize -> {500, 100}];
    gridx = Graphics[Table[{Line[{{0, i}, {10, i}}]}, {i, -1, 1, .5}]];
    gridy = Graphics[Table[{Line[{{i + Mod[t, π/4], -1}, {i + Mod[t, π/4], 1}}]}, {i, 0, 10, π/4}]];
    Show[{gridx, gridy,line, circle, plot}, PlotRange ->{{-1.1, 11}, {-1.1, 1.1}}]
, {t, 0, 2 π, π/80, Animator}]

animated sin function with grid

share|improve this answer
1  
Thanks for the excellent ideas. I too like the simple "graph", but many students have trouble with this idea (typically presented as a "ferris wheel" problem. The moving grid, like a piece of paper, helps reinforce the idea of height changing over time. –  Tom De Vries Jan 30 '13 at 15:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.