将x点均匀分布在一个圆内 [英] Uniformly distribute x points inside a circle

查看:268
本文介绍了将x点均匀分布在一个圆内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个圆内均匀分布一组预定的点.通过均匀分布,我的意思是它们应该彼此等距隔开(因此,随机方法将行不通).我尝试了六角形方法,但是在始终达到最外半径时遇到了问题.

I would like to uniformly distribute a predetermined set of points within a circle. By uniform distribution, I mean they should all be equally distanced from each other (hence a random approach won't work). I tried a hexagonal approach, but I had problems consistently reaching the outermost radius.

我当前的方法是嵌套的for循环,其中每次外部迭代都会减小半径&点的数量,每个内部循环将点平均分配到新半径上.本质上,它是一堆嵌套的圈子.不幸的是,还差得远.有关如何正确执行此操作的任何提示?

My current approach is a nested for loop where each outer iteration reduces the radius & number of points, and each inner loop evenly drops points on the new radius. Essentially, it's a bunch of nested circles. Unfortunately, it's far from even. Any tips on how to do this correctly?

推荐答案

目标是使区域内的分布均匀,边界冲突时的分布均匀;任何解决方案都是两者之间的折衷方案.我用一个附加参数alpha扩展了向日葵种子排列,该参数指示人们在乎均匀度边界.

The goals of having a uniform distribution within the area and a uniform distribution on the boundary conflict; any solution will be a compromise between the two. I augmented the sunflower seed arrangement with an additional parameter alpha that indicates how much one cares about the evenness of boundary.

alpha=0给出典型的向日葵排列,带有锯齿状的边界:

alpha=0 gives the typical sunflower arrangement, with jagged boundary:

使用alpha=2时,边界更平滑:

(进一步增加alpha值是有问题的:边界上的点太多了).

(Increasing alpha further is problematic: Too many points end up on the boundary).

该算法放置n个点,其中第k个点置于距边界的距离sqrt(k-1/2)(索引以k=1开头),并且极角为2*pi*k/phi^2,其中phi为黄金比例.例外:最后一个alpha*sqrt(n)点位于圆的外边界上,其他点的极半径也按比例缩放以解决此问题.极半径的计算是在函数radius中完成的.

The algorithm places n points, of which the kth point is put at distance sqrt(k-1/2) from the boundary (index begins with k=1), and with polar angle 2*pi*k/phi^2 where phi is the golden ratio. Exception: the last alpha*sqrt(n) points are placed on the outer boundary of the circle, and the polar radius of other points is scaled to account for that. This computation of the polar radius is done in the function radius.

它在 MATLAB 中进行了编码.

function sunflower(n, alpha)   %  example: n=500, alpha=2
    clf
    hold on
    b = round(alpha*sqrt(n));      % number of boundary points
    phi = (sqrt(5)+1)/2;           % golden ratio
    for k=1:n
        r = radius(k,n,b);
        theta = 2*pi*k/phi^2;
        plot(r*cos(theta), r*sin(theta), 'r*');
    end
end

function r = radius(k,n,b)
    if k>n-b
        r = 1;            % put on the boundary
    else
        r = sqrt(k-1/2)/sqrt(n-(b+1)/2);     % apply square root
    end
end

这篇关于将x点均匀分布在一个圆内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆