Advertisement
jotto

Untitled

May 24th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from numpy import random
  2. from numpy import sqrt
  3. from pylab import show, plot
  4.  
  5. rand = random
  6.  
  7. p = [(rand.random_integers(0, 100), rand.random_integers(0, 100)) for x in range(30)]
  8. c1 = (rand.random_integers(0, 100), rand.random_integers(0, 100))
  9. c2 = (rand.random_integers(0, 100), rand.random_integers(0, 100))
  10.  
  11. c1p = []
  12. c2p = []
  13.  
  14. for point in p:
  15.     x1 = point[0] - c1[0]
  16.     y1 = point[1] - c1[1]
  17.     dist1 = sqrt(x1**2 + y1**2)
  18.     x2 = point[0] - c2[0]
  19.     y2 = point[1] - c2[1]
  20.     dist2 = sqrt(x2**2 + y2**2)
  21.     c1p.append(point) if dist1 < dist2 else c2p.append(point)
  22.  
  23. plot(*c1, marker='o', c='red', ls='')
  24. plot(*zip(*c1p), marker='x', c='red', ls='')
  25. plot(*c2, marker='o', c='blue', ls='')
  26. plot(*zip(*c2p), marker='x', c='blue', ls='')
  27. show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement