Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random as rand
- import matplotlib.pyplot as plt
- import numpy as np
- def gen(R,N):
- r = []
- xarr = []
- yarr = []
- for i in range(N):
- check = 1
- while check:
- x = rand.uniform(-1 * R, R)
- y = rand.uniform(-1 * R, R)
- if (x ** 2 + y ** 2) < R**2:
- check = 0
- r.append((x ** 2 + y ** 2)**(1/2))
- xarr.append(x)
- yarr.append(y)
- return xarr,yarr,r
- R = 10
- x,y,rarr = gen(R,100)
- theta = np.linspace(0, 2 * np.pi, 100)
- xr = R * np.cos(theta)
- yr = R * np.sin(theta)
- plt.plot(xr, yr)
- plt.scatter(x=x, y=y, marker='o', c='r', edgecolor='b')
- plt.axis('scaled')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement