最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何在圆形分布中生成随机点

SEO心得admin47浏览0评论
本文介绍了如何在圆形分布中生成随机点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道如何生成出现在循环分布中的随机数.

I am wondering how i could generate random numbers that appear in a circular distribution.

我能够在矩形分布中生成随机点,以使这些点在(0< = x< 1000,0< = y< 1000)的平方内生成:

I am able to generate random points in a rectangular distribution such that the points are generated within the square of (0 <= x < 1000, 0 <= y < 1000):

我将如何继续在圆内生成点,使得:

How would i go upon to generate the points within a circle such that:

(x-500)^ 2 +(y-500)^ 2< 250000吗?

(x−500)^2 + (y−500)^2 < 250000 ?

推荐答案

import random import math # radius of the circle circle_r = 10 # center of the circle (x, y) circle_x = 5 circle_y = 7 # random angle alpha = 2 * math.pi * random.random() # random radius r = circle_r * math.sqrt(random.random()) # calculating coordinates x = r * math.cos(alpha) + circle_x y = r * math.sin(alpha) + circle_y print("Random point", (x, y))

在您的示例中,circle_x是500,而circle_y是. circle_r是500.

In your example circle_x is 500 as circle_y is. circle_r is 500.

基于此答案的另一种计算半径以获得均匀分布点的方法

Another version of calculating radius to get uniformly distributed points, based on this answer

u = random.random() + random.random() r = circle_r * (2 - u if u > 1 else u)
发布评论

评论列表(0)

  1. 暂无评论