lundi 18 février 2019

Generate Random Point Weight in a Ring Shape Without Bound

I'm currently writing a method to random a point (2D plane) and the randomed point have higher probability of being near a circle's circumference. However, the following problem occured while I try to solved this by doing 2 weighted circle random and overlap them and I'm not sure how to proceed.

First, The randomed points always stay within the larger circle bound but I don't want there to be any upper and lower bound to randomed value. (Imagine the randomness of particle position in quantum mechanics)

Second, There're a lot of point that were being randomed really close to the circle's circumference. Explained in mathmatical graph, my weighted function for each circle produced exponential graph but I want my graph to be in an S shape.

// 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);
}

if there's a graph where x is the distance from the center of the circle and y is the probability of being randomed, my expected result is to draw a dome shaped graph on it where if x >= 0 then y > 0 but my current result is 2 exponential graph facing each other producing a pointy triangle on it.

I think what I should do is change how the weighting is done (first line in for loop) but I don't know how and I'm stuck. Granted, the one I have is enough to send in as a homework but my curiosity still remained.

PS. If possible, I'd appreciated if there're solutions which allow me to turn the ring's shape from circle to ellipse.

Aucun commentaire:

Enregistrer un commentaire