Advertisement
Matthen

Perseids in the AM

Aug 14th, 2011
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Earth[t_] := 100 {Sin[(2 Pi t)/365], Cos[(2 Pi t)/365]};
  2. bodies = 100;
  3. tmax = 2;
  4. G = 10;
  5. initxs = RandomReal[NormalDistribution[1.8, 0.8], bodies];
  6. initys = RandomReal[NormalDistribution[100, 3], bodies];
  7. initposes = Partition[Riffle[initxs, initys], 2];
  8. initvs = RandomReal[{-0.1, 0.1}, {bodies, 2}];
  9. soln = NDSolve[
  10. Flatten[Table[{
  11. x[i][0] == initxs[[i]], y[i][0] == initys[[i]],
  12. x[i]'[0] == initvs[[i, 1]], y[i]'[0] == initvs[[i, 2]],
  13. x[i]''[t] == -((
  14. G (x[i][t] -
  15. Earth[t][[1]]))/((x[i][t] - Earth[t][[1]])^2 + (y[i][t] -
  16. Earth[t][[2]])^2)^1.5),
  17. y[i]''[t] == -((
  18. G (y[i][t] -
  19. Earth[t][[2]]))/((x[i][t] - Earth[t][[1]])^2 + (y[i][t] -
  20. Earth[t][[2]])^2)^1.5)
  21. }, {i, bodies}]],
  22. Flatten[Table[{x[i], y[i]}, {i, bodies}]],
  23. {t, 0, tmax}
  24. ];
  25. posn0[i_, tt_] := First[{x[i][t], y[i][t]} /. soln /. {t -> tt}];
  26. posn[i_, tt_] :=
  27. If[collisiontimes[[i]] > tt,
  28. First[{x[i][t], y[i][t]} /. soln /. {t -> tt}], {0, 0}];
  29. Clear[collisiontime];
  30. collisiontime[i_] := Module[{dt = 0.001, hits},
  31. hits =
  32. Position[
  33. Table[Norm[posn0[i, tt] - Earth[tt]] < 0.53, {tt, 0, tmax, dt}],
  34. True];
  35. If[Length[hits] == 0,
  36. \[Infinity],
  37. dt hits[[1, 1]]
  38. ]
  39. ];
  40. collisiontimes = Table[collisiontime[i], {i, bodies}];
  41.  
  42. earthimg =
  43. Import["http://www.clker.com/cliparts/J/O/b/M/v/6/earth-southern-\
  44. hemisphere-th.png"];
  45. DrawEarth[
  46. tt_] := {Inset[Rotate[earthimg, -2 Pi tt],
  47. Earth[tt], {Center, Center}, 1], Opacity[0.6], Black,
  48. Disk[Earth[tt], 0.53, {Pi, 0}], Opacity[1], White,
  49. Text["AM", Earth[tt] + {1, 0.2}],
  50. Text["PM", Earth[tt] - {1, -0.2}]};
  51.  
  52.  
  53.  
  54. Manipulate[
  55. Graphics[{
  56. GrayLevel[0.5],
  57. Table[Point[posn[i, tt]], {i, bodies}],
  58. {
  59. Dashed, Red, Line[Table[Earth[ttt], {ttt, -5, 5, 0.01}]],
  60. DrawEarth[tt]
  61. }
  62. , White,
  63. Table[If[Abs[collisiontimes[[i]] - tt + 0.1] < 0.1,
  64. Disk[posn0[i, collisiontimes[[i]]], 0.1], Opacity[1]], {i,
  65. bodies}]
  66. }
  67. , PlotRange -> {{-4, 4}, {96, 104}}, ImageSize -> 300,
  68. Background -> Black]
  69.  
  70. , {tt, 0, tmax}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement