在圆内均匀分布点

转载自: https://www.cnblogs.com/yunlambert/p/10161339.html

import numpy as np
import matplotlib.pyplot as plt
import random
import math

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) #about uniform see http://www.runoob.com/python/func-number-uniform.html
        x = math.cos(theta) * (r ** 0.5)
        y = math.sin(theta) * (r ** 0.5)
        plt.plot(x, y, '*', color="blue") #print the point in the canvas

def main():
    pi = np.pi
    theta = np.linspace(0, pi * 2, 1000) #about linespace see https://blog.youkuaiyun.com/You_are_my_dream/article/details/53493752
    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()
    os.system("pause")

main()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值