# 圆内的均匀随机点

## 圆内随机点

### 方法1:

def random_point_in_circle(point_num, radius):
for i in range(2,point_num+1):
y=random.uniform(-y_max,y_max)
plt.plot(x,y,'*',color="blue")

def main():
pi = np.pi
theta = np.linspace(0, pi * 2, 1000)
R = 1
x = np.sin(theta) * R
y = np.cos(theta) * R

plt.figure(figsize=(6, 6))
plt.plot(x, y, label="cycle", color="green", linewidth=2)
plt.title("random_points_in_circle")
random_point_in_circle(4000, R)
plt.legend()
plt.show()

if __name__=="__main__":
main()


### 方法2:

def random_point_in_circle(point_num, radius):
for i in range(2,point_num+1):
while True:
break
plt.plot(x,y,'*',color="blue")

def main():
pi = np.pi
theta = np.linspace(0, pi * 2, 1000)
R = 1
x = np.sin(theta) * R
y = np.cos(theta) * R

plt.figure(figsize=(6, 6))
plt.plot(x, y, label="cycle", color="green", linewidth=2)
plt.title("random_points_in_circle")
random_point_in_circle(4000, R)
plt.legend()
plt.show()

if __name__=="__main__":
main()


### 方法3:

def random_point_in_circle(point_num, radius):
for i in range(2,point_num+1):
theta=random.random()*2*np.pi
x=r*math.cos(theta)
y=r*math.sin(theta)
plt.plot(x,y,'*',color="blue")

def main():
pi = np.pi
theta = np.linspace(0, pi * 2, 1000)
R = 1
x = np.sin(theta) * R
y = np.cos(theta) * R

plt.figure(figsize=(6, 6))
plt.plot(x, y, label="cycle", color="green", linewidth=2)
plt.title("random_points_in_circle")
random_point_in_circle(4000, R)  # 修改此处来显示不同算法的效果
plt.legend()
plt.show()

if __name__=="__main__":
main()


### 方法4:

$y=r*sin(\theta)=\sqrt{R}*sin(\theta)$

$\iint h[g_{1}(x,y),g_{2}(x,y)]f(x,y)dx dy=\iint h(\mu,\upsilon)p(\mu,\upsilon)d\mu d\upsilon$

def random_point(car_num,radius):
for i in range(1, car_num + 1):
theta = random.random() * 2 * np.pi
r = random.uniform(0, radius)
x = math.cos(theta) * (r ** 0.5)
y = math.sin(theta) * (r ** 0.5)
plt.plot(x, y, '*', color="blue")

def main():
pi = np.pi
theta = np.linspace(0, pi * 2, 1000)
R = 1
x = np.sin(theta) * R
y = np.cos(theta) * R

plt.figure(figsize=(6, 6))
plt.plot(x, y, label="cycle", color="green", linewidth=2)
plt.title("random_points_in_circle")
random_point(4000, R)  # 修改此处来显示不同算法的效果
plt.legend()
plt.show()

if __name__=="__main__":
main()


posted @ 2018-12-22 15:52  MrYun  阅读(12726)  评论(3编辑  收藏  举报