0
$\begingroup$

I have a particle bouncing in a rigid box, my code is this:

L = 5;
L2 = 8;
L3 = 10;
a[x_] := 1 - 2 Boole@OddQ@Quotient[x, L];
a2[x_] := 1 - 2 Boole@OddQ@Quotient[x, L2];
a3[x_] := 1 - 2 Boole@OddQ@Quotient[x, L3];

dir = Normalize[{1, 2, 3}];
x0 = {0, L2/2, L3/2};

x[t_] := (t*dir + x0).{1, 0, 0};
x2[t_] := (t*dir + x0).{0, 1, 0};
x3[t_] := (t*dir + x0).{0, 0, 1};
P[t_] := {Mod[a[x[t]] x[t], L] , Mod[a2[x2[t]] x2[t], L2],Mod[a3[x3[t]]x3[t], L3]};

ParametricPlot3D[P[t], {t, 0, 30},  PlotRange -> {{0, L}, {0, L2}, {0, L3}}]

Now i want to calculate the time needed to the particle to reach a little square of 1x1 of area at the top of the box, something like a "Findroot" but with an interval as entry. Any susgestions please?

$\endgroup$
  • $\begingroup$ do you realise this is a linear equation on time, don't you? You can write the analytical solution in this case. Also, maybe you could consider to link the question where that code comes from, it looks eerily familiar. $\endgroup$ – tsuresuregusa Apr 21 '16 at 4:03
  • $\begingroup$ @tsuresuregusa The equations are probably from this answer. $\endgroup$ – shrx Apr 21 '16 at 9:57
1
$\begingroup$

I presume you wish to find the first time that P[t] reaches L3. This is given by

FindRoot[P[t][[3]] == L3, {t, 6}]
(* {t -> 6.2361} *)

Addendum

It is helpful to plot the curve (here as far as t == 35) along with points at integer values of t.

Show[ParametricPlot3D[P[t], {t, 0, 35}, PlotRange -> {{0, L}, {0, L2}, {0, L3}}], 
ListPointPlot3D[Table[P[t], {t, 0, 35}], PlotStyle -> Directive[Red, PointSize -> Medium]]]

enter image description here

The time for the second instance that the path reaches L3 can then be seen to be about t == 30. For completeness,

FindRoot[P[t][[3]] == L3, {t, 30}]
(* {t -> 31.1805} *)

Second Addendum

The OP in a comment below asks to find when the path reaches L3 and lies within the range 2.4 < P[t][[1]] < 2.6 || 3.9 < P[t][[2]] < 4.1 in the other two coordinates. It turns out that this never happens, as can be seen from

ParametricPlot3D[P[t], {t, 0, 10000}, PlotRange -> {{0, L}, {0, L2}, {0, L3}}, 
    PlotPoints -> 1000]

enter image description here

or from

lt = Quiet@Table[FindRoot[P[t][[3]] == L3, {t, 6 + 25 i}], {i, 0, 10000}];
lp = P[t] /. lt;
ListPlot[#[[1 ;; 2]] & /@ lp, PlotRange -> {{0, L}, {0, L2}}, 
    PlotStyle -> PointSize[Small]]

enter image description here

To find a time for which the path reaches L3 and comes near, for instance, {5., 6.} in the other two coordinates, use

i = 0; p1 = -1; p2 = -1; 
Quiet@While[! (4.9 < p1 < 5.1 && 5.9 < p2 < 6.1), {t0, p1, p2} = {t, P[t][[1]], P[t][[2]]}
     /. FindRoot[P[t][[3]] == L3, {t, 6 + 25 i}]; i = i + 1]; t0
(* 168.375 *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Not just L3, but a subset of the top face, something like: P[t][[3]]==L3, but at the same time 2.4 < P[t][[1]] < 2.6 || 3.9 < P[t][[2]] < 4.1. I guess with a "If" but perhaps there's a more elegant way. $\endgroup$ – jesus Apr 20 '16 at 17:31
  • $\begingroup$ @jesus The curve does not intersect this area, as shown in an addendum to my answer. So, I found where it intersected another area. $\endgroup$ – bbgodfrey Apr 21 '16 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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