# Problem with animation

I am trying to animate an elastic collision and i don't how to code to describe the motion after the impact. Here's a piece of code:

S1i[t_, V1i_] := 0.2 + t*V1i;
S2i[t_, V2i_] := 0.8 + t*V2i;
S1f[t_, V1f_] := 0.2 + ts*V1ie + t*V1f;
S2f[t_, V2f_] := 0.8 + ts*V2ie + t*V2f;
V1f[m1_, m2_, V1i_, V2i_] := 2 (m1*V1i + m2*V2i)/(m1*m2) - V1i;
V2f[m1_, m2_, V1i_, V2i_] := 2 (m1*V1i + m2*V2i)/(m1*m2) - V2i;
ts := (0.6 - r1 - r2)/(V1ie - V2ie);
y = 0.4;
r1 = 0.06;
r2 = 0.06;
V1ie = 0.2;
V2ie = -0.1;
m1e = 0.03;
m2e = 0.03;
V1fe = 2 (m1e*V1ie + m2e*V2ie)/(m1e*m2e) - V1ie;
V2fe = 2 (m1e*V1ie + m2e*V2ie)/(m1e*m2e) - V2ie;
xy[t_] := {S1i[t, V1ie], y};
zy[t_] := {S2i[t, V2ie], y};
py[t_] := {S1f[t, V1fe], y};
qy[t_] := {S2f[t, V2fe], y};
traj1 = Table[xy[t], {t, 0, ts, 0.1}];
traj2 = Table[zy[t], {t, 0, ts, 0.1}];
traj3 = Table[py[t], {t, ts, 4, 0.1}];
traj4 = Table[qy[t], {t, ts, 4, 0.1}];
Manipulate[
Show[ListPlot[traj1, PlotRange -> {{-1, 10}, Automatic}],
ListPlot[traj2, PlotRange -> {{-1, 10}, Automatic}],
ListPlot[traj3, PlotRange -> {{-1, 10}, Automatic}],
ListPlot[traj4, PlotRange -> {{-1, 10}, Automatic}],
Graphics[If[
t <= ts, {Black, Circle[xy[t], r1], Red,
Circle[zy[t], r2]}, {Black, Circle[py[t], r1], Red,
Circle[qy[t], r2]}]],
AspectRatio -> Automatic], {t, 0, 4}]


Where tsis the time of the impact and S1f[t_, V1f_] := t*V1f, S2f[t_, V2f_] := t*V2ffunctions that describe the motion of the Black and the Red ball (respectively), after the impact.

I would very much appreciate you input. Thank you.

• In your Table commands, change your xy to xy[t], etc for the others. You then get a plot, but I'm not really sure what you are after. You also need to expand your PlotRange in the Show command to see the whole plot. – Bill Watts Feb 7 at 23:11
• @BillWatts Thank you sir, would you mind looking at my edited code? the movement of disks after the collision starts far away from the coordinates of the impact, but i can't fix it – zare023 Feb 7 at 23:46
• Check your V1f and V2f equations carefully. The after velocities calculated from your code are inconsistent with an elastic collision. – Bill Watts Feb 8 at 1:49
• @zare023 it does not appear to me that your code will properly deliver the necessary parameters to V1f and V2f. I recommend you comb through your code step by step & remove the several redundancies. It might make it better to see what went wrong. – CA Trevillian Feb 10 at 3:32