生成无界的环形随机点权重

时间:2019-02-18 10:01:22

标签: algorithm random

我目前正在写一种对一个点(2D平面)进行随机化的方法,而随机化的点在圆的圆周附近的可能性更高。但是,当我尝试通过随机设置2个加权圆并将它们重叠来解决此问题时,出现了以下问题,我不确定如何进行。

首先,随机点始终位于较大的圆界内,但我不希望随机值有任何上限和下限。 (想象一下量子力学中粒子位置的随机性)

第二,很多点实际上是在圆的圆周附近随机分配的。用数学图解释,我对每个圆的加权函数生成了指数图,但我希望我的图呈S形。

// This is Processing code. You can copy the entire thing and put it in draw function. If You don't have Processing you can run this at http://semmy.me/ide/
background(255);

// Temporary Value
float ringRadius = 100;
int pointNum = 5000;
// Inner Circle
for (int i = 0; i < pointNum; i++) {
    float weightedIndex = 3; // Uniformly Distributed = 2
    float angle = random(TWO_PI);
    float radius = pow(random(pow(ringRadius, weightedIndex)), 1/weightedIndex); // Weighted done by power it then root it with the same number

    float x = width/2 + radius*cos(angle), y = height/2 + radius*sin(angle);
    point(x, y);
}
// Outer Circle
for (int i = 0; i < pointNum*2; i++) {
    float weightedIndex = 1.3; // Uniformly Distributed = 1 (different radius makes it different from the Inner Circle)
    float angle = random(TWO_PI);
    float radius = pow(random(pow(ringRadius, 1/weightedIndex)), weightedIndex);

    float x = width/2 + (ringRadius+radius)*cos(angle), y = height/2 + (ringRadius+radius)*sin(angle);
    point(x, y);
}

如果有一个图,其中x是到圆心的距离,y是被随机化的概率,我的预期结果是在上面绘制一个圆顶形图,如果x> = 0则y> 0但我当前的结果是2个彼此面对的指数图,在其上产生一个尖锐的三角形。

我认为我应该做的是改变加权的方式(for循环的第一行),但是我不知道如何进行,我陷入了困境。当然,我有足够的钱可以做家庭作业,但我的好奇心仍然存在。

PS。如果可以的话,我希望能找到解决方案,使我可以将圆环的形状从圆形变成椭圆形。

0 个答案:

没有答案