Waves from Circles with Mathematica

March 12th, 2014 | Categories: general math, just for fun, mathematica | Tags:

A recent Google+ post from Mathemania4u caught my attention on the train to work this morning. I just had to code up something that looked like this and so fired up Mathematica and hacked away. The resulting notebook can be downloaded here. It’s not particularly well thought through so could almost certainly be improved on in many ways.

The end result was a Manipulate which you’ll be able to play with below, provided you have a compatible Operating System and Web browser. The code for the Manipulate is

Manipulate[
 Graphics[Map[dotCirc, 
   circArray[circrad, theta, pointsize, extent, step, phase, 
    showcirc]]]
 , {{showcirc, True, "Show Circles"}, {True, False}}
 , {{theta, 0, "Dot Angle"}, 0, 2 Pi, Pi/10, Appearance -> "Labeled"}
 , {{pointsize, 0.018, "Dot Size"}, 0, 1, Appearance -> "Labeled"}
 , {{phase, 2, "Phase Diff"}, 0, 2 Pi, Appearance -> "Labeled"}
 , {{step, 0.25, "Circle Separation"}, 0, 1, Appearance -> "Labeled"}
 , {{extent, 2, "Plot Extent"}, 1, 5, Appearance -> "Labeled"}
 , {{circrad, 0.15, "Circle Radius"}, 0.01, 1, Appearance -> "Labeled"}
 , Initialization :>
  {
   dotCirc[{x_, y_, r_, theta_, pointsize_, showcirc_}] := If[showcirc,
     {Circle[{x, y}, r], PointSize[pointsize], 
      Point[{x + r Cos[theta], y + r Sin[theta]}]}
     ,
     {PointSize[pointsize], 
      Point[{x + r Cos[theta], y + r Sin[theta]}]}]
   ,
   circArray[r_, theta_, pointsize_, extent_, step_, phase_, 
     showcirc_] := Module[{},
     Partition[
      Flatten[Table[{x, y, r, theta + x*phase + y*phase, pointsize, 
         showcirc}, {x, -extent, extent, step}, {y, -extent, extent, 
         step}]], 6]
     ]}]

If you can use the Manipulate below, I suggest clicking on the + icon to the right of the ‘Dot Angle’ field to expose the player controls and then press the play button to kick off the animation.

I also produced a video – The code used to produce this is in the notebook.
)

  1. March 19th, 2014 at 18:36
    Reply | Quote | #1

    Nice. Here is a EMT version. Looks cleaner. But cannot be “manipulated”.

    >function nice () ...
    $n=10; x=0:n; y=x'; r=0.5; m=100;
    $repeat
    $   for a=(0:m-1)/m*2pi;
    $       d=a+(x+y)/n*2*pi;
    $       plot2d(x+r*cos(d),y+r*sin(d),>points,<grid,style="o#");
    $       wait(0);
    $   end;
    $   until testkey();
    $end;
    $endfunction
    >nice
    
  2. March 20th, 2014 at 00:07
    Reply | Quote | #2
Comments are closed.