Circles extending mainly in X and Y, WHY?

enter image description here

I created a loop using processing that draws circles, the overall shape should be a circle. However, they mostly stretch close to the X and Y axis. I randomized the angle to calculate its location, I don’t see where the problem is.

Enter the code as follows:

for (int omega = 0; omega<1080; omega++){ //loop for circle creation radius = (int)random(80); //random radius for each circle int color1= (int)random(100); //little variation of color for each circle int color2= (int)random(100); int locationY = (int)(sin(radians(omega))*random(width/2+1)); //location calcualtion int locationX = (int)(cos(radians(omega))*random(width/2+1)); fill(0,color1+200,color2+200,50); ellipse(locationX,locationY,radius,radius); //draw circles } 
+5
source share
2 answers

Good point @ Durendal (+1)

However, I have one more thought with random circles.

When you generate a random distance with this code:

 double distance = random( width/2 ); 

you produce from even distribution . I mean, all values ​​from 0 to width/2 have the same probability . But a circle with a radius of 3*r has 9 times the area, and then a circle with a radius of r . So, the smaller the distance from the center, the greater the density we see.

Thus, the generated cloud does not have a uniform density , as you can see in the first image. enter image description here

But if you change the probability density function so that larger values ​​are less likely than smaller ones, you can get a uniformly generated cloud.

Such a simple modification:

 double distance = Math.sqrt( random( width/2 * width/2 ) ); 

creates more evenly distributed circles, as you can see in the second image. enter image description here

Hope this can be helpful.

+5
source

Its artifact of how you calculate the location, you extract two different random values ​​for component X and Y:

 int locationY = (int)(sin(radians(omega))*random(width/2+1)); //location calcualtion int locationX = (int)(cos(radians(omega))*random(width/2+1)); 

You should use one random value "distance" from the center for X and Y, which will remove the clustering along the axes.

+5
source

Source: https://habr.com/ru/post/1207120/


All Articles