Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* this code is really slow, and could be sped up by caching the number of bounces before t calculation*)
- g = 0.05;
- c = 0.9;
- path[vx_, t_] :=
- Module[{\[Tau] = (2 Sqrt[1 - vx^2])/g, found, m, prev},
- found = False; m = 0; prev = 0; While[found == False && m < 100,
- found = Sum[(2 c ^n Sqrt[1 - (vx)^2])/g, {n, 0, m}] > t; m++;
- If[! found,
- prev = Sum[(2 c ^n Sqrt[1 - (vx)^2])/g, {n, 0, m - 1}];];];
- \[Tau] = Sum[(2 c ^n Sqrt[1 - (vx)^2])/g, {n, 0, m - 1}];
- {vx t, (c^(m - 1) Sqrt[1 - (vx) ^2] tt - 1/2 g tt^2) /. {tt ->
- t - prev}}];
- xmax = 50;
- anim[T_] :=
- Show[
- Table[
- ParametricPlot[path[vx, t], {t, 0, T},
- PlotRange -> {{-xmax, xmax}, {-1, 10}}, Axes -> None,
- PlotStyle -> RGBColor[0.8, 0.6, 0.3]],
- {vx, -0.9, 0.9, 1.8/40}
- ],
- Graphics[
- {Thick, RGBColor[0.6, 0.8, 0.9],
- Line[{{-xmax, 0}, {xmax, 0}}],
- Black, PointSize[Medium],
- Table[
- Point[path[vx, T]]
- ,
- {vx, -0.9, 0.9, 1.8/40}
- ]
- }]
- , ImageSize -> 300, AspectRatio -> 1];
- frames = Table[Rasterize@anim[x], {x, 0.01, 100}];
- Export["bounces.gif", frames];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement