Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import random as rand
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. def gen(R,N):
  5. r = []
  6. xarr = []
  7. yarr = []
  8. for i in range(N):
  9. check = 1
  10. while check:
  11. x = rand.uniform(-1 * R, R)
  12. y = rand.uniform(-1 * R, R)
  13. if (x ** 2 + y ** 2) < R**2:
  14. check = 0
  15. r.append((x ** 2 + y ** 2)**(1/2))
  16. xarr.append(x)
  17. yarr.append(y)
  18. return xarr,yarr,r
  19.  
  20. R = 10
  21. x,y,rarr = gen(R,100)
  22. theta = np.linspace(0, 2 * np.pi, 100)
  23. xr = R * np.cos(theta)
  24. yr = R * np.sin(theta)
  25. plt.plot(xr, yr)
  26. plt.scatter(x=x, y=y, marker='o', c='r', edgecolor='b')
  27. plt.axis('scaled')
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement