Advertisement
Matthen

Packing Dots

Apr 10th, 2012
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. b = 0.3;
  2. (*
  3. can take a while to calculate points[i] i=1:100*maxiter - could be sped up but doesn't really matter
  4. *)
  5. maxiter = 3;
  6. Density[points_, x_, y_] :=
  7. Total[Map[Exp[-Norm[# - {x, y}]^2/b^2] &, points]] -
  8. 3 Exp[-x^2 - y^2];
  9. points[0] = RandomReal[NormalDistribution[0, 1], {100, 2}];
  10. j = 0;
  11. xs = Table[xt, {xt, -2, 2, 4/100}];
  12. Do[
  13. Do[
  14.  
  15. {x, y} = points[j][[i]];
  16. ps = Join[ points[j][[;; i - 1]], points[j][[i + 1 ;;]]];
  17. vals = Table[Density[ps, xt, y], {xt, xs}];
  18.  
  19. {x, y} = {xs[[
  20. Position[vals, Min[vals]][[1]][[1]]
  21. ]], y};
  22.  
  23. vals = Table[Density[ps, x, yt], {yt, xs}];
  24.  
  25. {x, y} = {x, xs[[
  26. Position[vals, Min[vals]][[1]][[1]]
  27. ]]};
  28.  
  29. j += 1;
  30. points[j] =
  31. Join[ points[j - 1][[;; i - 1]], {{x, y}},
  32. points[j - 1][[i + 1 ;;]]];
  33. (* rotate to get rid of coordinate effects*)
  34. points[j] = Map[N[RotationMatrix[1].#] &, points[j]];
  35. , {i, Length[points[0]]}];
  36. , {iter, maxiter}];
  37. Manipulate[
  38. Graphics[Point[ Map[N[RotationMatrix[-i].#] &, points[i]]],
  39. PlotRange -> 4], {i, 0, 100*maxiter, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement