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.

I'm interested in learning to implement graphics like to those shown here

My pendulum c++ code (source & csv's located here) outputs the positions of each mass into separate csv files.

-== My plan is to:

a. ListPlot the the first rows of my csv files

b. Draw lines between the focal point and each mass.

d. Fix dashed axes onto each mass (like shown in the video)

d. Export a jpg

e. Rinse and repeat for next row of data in csv fles.

-== My Questions are:

1.) How do I draw a line between the focus and a mass whose position is given inside a csv file?

2.) How do I draw a line between two masses whose positions are given in separate csv files?

3.) How do I fix a set of axes on each mass as shown with dotted lines in the video linked above?

share|improve this question

closed as too localized by Jens, m_goldberg, Sjoerd C. de Vries, Artes, whuber May 14 '13 at 16:27

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Here is a screenshot of my ListPlotting a two-mass pendulum: http://i.imgur.com/hlORORK.png –  dk0r May 9 '13 at 14:16
3  
Why don't you solve the equations in Mathematica? –  belisarius May 9 '13 at 15:25
    
Somewhat related: Exporting a Video of a Simulation of Pendulum Motion and links therein. –  Jens May 9 '13 at 22:11
add comment

1 Answer 1

Here is one approach doing the animation directly in Mathematica:

data1 = Import["https://raw.github.com/dk0r/comp-phys/master/Final_Project/M1_position.csv"];
data2 = Import["https://raw.github.com/dk0r/comp-phys/master/Final_Project/M2_position.csv"];

params = {xmin -> -3, xmax -> 3, ymin -> -2, ymax -> 2, trail -> 50, 
   diskradius -> 0.2};

    plotFrame[data1_, data2_, k_, params_] := Module[{x1, y1, x2, y2, g1, g2, 
     n = length[data]},
  {x1, y1} = data1[[k]];
  {x2, y2} = data2[[k]];
  g1 = Graphics[{
      Disk[{x1, y1}, diskradius /. params],
      Disk[{x2, y2}, diskradius /. params],
      Thick, Line[{{0, 0}, {x1, y1}, {x2, y2}}],
      Dotted, Thin, Line[{{x2, ymin}, {x2, ymax}}], 
      Line[{{xmin, y2}, {xmax, y2}}], Line[{{x1, ymin}, {x1, ymax}}], 
      Line[{{xmin, y1}, {xmax, y1}}]
      }] /. params;
  g2 = ListPlot[data2[[Max[1, k - trail/.params] ;; k]]];
  Show[g1, g2]
  ]

    Animate[plotFrame[data1, data2, k, params], {k, 1, Length[data2], 1}, 
 AnimationRate -> 24]

If you still want to export and do the animation somewhere else just make a loop over something like this

Export["frame100.png", plotFrame[data1, data2, 100, params]]
share|improve this answer
    
SEngstrom, thanks for this! While your script addresses my first and third questions, how do you recommend approaching question#2? 2.) How do I draw a line between two masses whose positions are given in separate csv files? –  dk0r May 9 '13 at 15:00
    
Right. Call with both datasets and draw a Line[] between them - let me edit the answer... –  SEngstrom May 9 '13 at 15:15
    
Changing "trail -> 50" to "trail -> 50000" does not seem to cause any change. Neither does changing "PointSize[Large]" to "PointSize[Small]". 1.) What do these options affect? Also, 2.) How may I modify the rate, size, etc, at which mass-2 leaves the trail of blue dots? If you have the chance please append some comments to relevant sections so that I may better understand the effects of your scripts. –  dk0r May 9 '13 at 21:41
    
I provided a parameter for the trail length but then hardcoded it in the example :) Change Max[1, k - 50] to Max[1, k - trail/.params] to use the parametrized version. Also changed the way I sized the mass representation from Point[] to Disk[], so the PointSize[] token can be removed. You control the size of the disk symbol with radius in Disk[{x,y},radius] –  SEngstrom May 9 '13 at 21:46
    
You probably need to look at some basic definitions of what these Mathematica functions do - an easy way to do it from within the program is to highlight a keyword and hit F1 on your keyboard. –  SEngstrom May 9 '13 at 21:48
add comment

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