Instantly share code, notes, and snippets.

# alexbeutel/gist:151142 Created Jul 21, 2009

Simple plotting in mathematica to demontrate wheel barrel effect
 (* Alex Beutel July 23, 2009 Simple script to show wagon-wheel effect / stroboscopic effect for a propeller in terms of the y coordinate vs. time and radians vs. time. Graphs both with varying "frame-rates." *) f1[x_] := Cos[x]; f2[x_] := Cos[x + 2 \[Pi]/3]; f3[x_] := Cos[x + 4 \[Pi]/3]; g1[x_] := Mod[x - .00001, 2 \[Pi]]; g2[x_] := Mod[x - .00001 + 2 \[Pi]/3, 2 \[Pi]]; g3[x_] := Mod[x - .00001 + 4 \[Pi]/3, 2 \[Pi]]; draw[o_] := (l1 = Line[{{0, 1.5}, {0 \[Pi], -1.5}}]; l2 = Line[{{4 \[Pi] - o, 1.5}, {4 \[Pi] - o, -1.5}}]; l3 = Line[{{8 \[Pi] - 2 o, 1.5}, {8 \[Pi] - 2 o, -1.5}}]; l4 = Line[{{12 \[Pi] - 3 o, 1.5}, {12 \[Pi] - 3 o, -1.5}}]; p1 = Point[{0 \[Pi], 1}]; p2 = Point[{4 \[Pi] - o, Max[f1[4 \[Pi] - o], f2[4 \[Pi] - o], f3[4 \[Pi] - o]]}]; p3 = Point[{8 \[Pi] - 2 o, Max[f1[8 \[Pi] - 2 o], f2[8 \[Pi] - 2 o], f3[8 \[Pi] - 2 o]]}]; p4 = Point[{12 \[Pi] - 3 o, Max[f1[12 \[Pi] - 3 o], f2[12 \[Pi] - 3 o], f3[12 \[Pi] - 3 o]]}]; l1a = Line[{{0 \[Pi], 0}, {0 \[Pi], 2 \[Pi]}}]; l2a = Line[{{4 \[Pi] - o, 0}, {4 \[Pi] - o, 2 \[Pi]}}]; l3a = Line[{{8 \[Pi] - 2 o, 0}, {8 \[Pi] - 2 o, 2 \[Pi]}}]; l4a = Line[{{12 \[Pi] - 3 o, 0}, {12 \[Pi] - 3 o, 2 \[Pi]}}]; p1a = Point[{0 \[Pi], Max[g1[0 \[Pi]], g2[0 \[Pi]], g3[0 \[Pi]]]}]; p2a = Point[{4 \[Pi] - o, Max[g1[4 \[Pi] - o], g2[4 \[Pi] - o], g3[4 \[Pi] - o]]}]; p3a = Point[{8 \[Pi] - 2 o, Max[g1[8 \[Pi] - 2 o], g2[8 \[Pi] - 2 o], g3[8 \[Pi] - 2 o]]}]; p4a = Point[{12 \[Pi] - 3 o, Max[g1[12 \[Pi] - 3 o], g2[12 \[Pi] - 3 o], g3[12 \[Pi] - 3 o]]}]; Show[Plot[{f1[x], f2[x], f3[x]}, {x, 0 \[Pi], 13 \[Pi]}, ImageSize -> Scaled[.6], AxesLabel -> {"time", "y"}], {Graphics[{Thick, Red, l1}], Graphics[{Thick, Red, l2}], Graphics[{Thick, Red, l3}], Graphics[{Thick, Red, l4}], Graphics[{PointSize[Large], Red, p1}], Graphics[{PointSize[Large], Red, p2}], Graphics[{PointSize[Large], Red, p3}], Graphics[{PointSize[Large], Red, p4}]}] Show[Plot[{g1[x], g2[x], g3[x]}, {x, 0, 13 \[Pi]}, ImageSize -> Scaled[.6], AxesLabel -> {"time", "radians"}], {Graphics[{Thick, Red, l1a}], Graphics[{Thick, Red, l2a}], Graphics[{Thick, Red, l3a}], Graphics[{Thick, Red, l4a}], Graphics[{PointSize[Large], Red, p1a}], Graphics[{PointSize[Large], Red, p2a}], Graphics[{PointSize[Large], Red, p3a}], Graphics[{PointSize[Large], Red, p4a}]}]) Manipulate[draw[y], {y, 0, 2 \[Pi]/3}] (* Enable the code below to save the above Manipulate command as a \ Flash movie *) (* Export["all.swf", %] *) Print["Standing still"] draw[0] Print["Going backwards"] draw[\[Pi]/6] Print["Flipping"] draw[\[Pi]/3] Print["Going forwards"] draw[\[Pi]/2] Print["Standing still again"] draw[2 \[Pi]/3]