Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Earth[t_] := 100 {Sin[(2 Pi t)/365], Cos[(2 Pi t)/365]};
- bodies = 100;
- tmax = 2;
- G = 10;
- initxs = RandomReal[NormalDistribution[1.8, 0.8], bodies];
- initys = RandomReal[NormalDistribution[100, 3], bodies];
- initposes = Partition[Riffle[initxs, initys], 2];
- initvs = RandomReal[{-0.1, 0.1}, {bodies, 2}];
- soln = NDSolve[
- Flatten[Table[{
- x[i][0] == initxs[[i]], y[i][0] == initys[[i]],
- x[i]'[0] == initvs[[i, 1]], y[i]'[0] == initvs[[i, 2]],
- x[i]''[t] == -((
- G (x[i][t] -
- Earth[t][[1]]))/((x[i][t] - Earth[t][[1]])^2 + (y[i][t] -
- Earth[t][[2]])^2)^1.5),
- y[i]''[t] == -((
- G (y[i][t] -
- Earth[t][[2]]))/((x[i][t] - Earth[t][[1]])^2 + (y[i][t] -
- Earth[t][[2]])^2)^1.5)
- }, {i, bodies}]],
- Flatten[Table[{x[i], y[i]}, {i, bodies}]],
- {t, 0, tmax}
- ];
- posn0[i_, tt_] := First[{x[i][t], y[i][t]} /. soln /. {t -> tt}];
- posn[i_, tt_] :=
- If[collisiontimes[[i]] > tt,
- First[{x[i][t], y[i][t]} /. soln /. {t -> tt}], {0, 0}];
- Clear[collisiontime];
- collisiontime[i_] := Module[{dt = 0.001, hits},
- hits =
- Position[
- Table[Norm[posn0[i, tt] - Earth[tt]] < 0.53, {tt, 0, tmax, dt}],
- True];
- If[Length[hits] == 0,
- \[Infinity],
- dt hits[[1, 1]]
- ]
- ];
- collisiontimes = Table[collisiontime[i], {i, bodies}];
- earthimg =
- Import["http://www.clker.com/cliparts/J/O/b/M/v/6/earth-southern-\
- hemisphere-th.png"];
- DrawEarth[
- tt_] := {Inset[Rotate[earthimg, -2 Pi tt],
- Earth[tt], {Center, Center}, 1], Opacity[0.6], Black,
- Disk[Earth[tt], 0.53, {Pi, 0}], Opacity[1], White,
- Text["AM", Earth[tt] + {1, 0.2}],
- Text["PM", Earth[tt] - {1, -0.2}]};
- Manipulate[
- Graphics[{
- GrayLevel[0.5],
- Table[Point[posn[i, tt]], {i, bodies}],
- {
- Dashed, Red, Line[Table[Earth[ttt], {ttt, -5, 5, 0.01}]],
- DrawEarth[tt]
- }
- , White,
- Table[If[Abs[collisiontimes[[i]] - tt + 0.1] < 0.1,
- Disk[posn0[i, collisiontimes[[i]]], 0.1], Opacity[1]], {i,
- bodies}]
- }
- , PlotRange -> {{-4, 4}, {96, 104}}, ImageSize -> 300,
- Background -> Black]
- , {tt, 0, tmax}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement