Matlab: area with overlapping circles
I have a question for you...
Imagine a square with size A x A. Now let's simulate circles with diameter d randomly distributed inside this square, something like the image below (in this case d is the same, but this is not a rule, they can also be randomly distributed in a certain range, for example, from d1 to d2).
Let's say that circles are described in a matrix as:
circles(1, :) = [x, y, d];
circles(2, :) = [x, y, d];
...and so on
where x
, y
- coordinates, d
- diameter. Now the question is how to simulate these circles until the overflow parameter is reached c
? c
simply defined as: c = yellow area / square area (in this case A^2)
.
And second - let's say that everything is simulated and I want to check if any coordinate (x, y) is inside or outside the yellow area ... How to do this? I did this by checking if my (x, y) is within the area of each circle (but it gets harder when instead of circles I use, for example, round rectangles) one by one, but there must be some better way to do It. Thanks for the help:)
source to share
Here's the approach that should do the trick:
- Start with a large empty matrix (large enough to ensure that each formed shape is completely inside the matrix). Let's assume we do it like this:
color = zeros(100)
- while we haven't reached the wrap ratio yet: the midpoint and diameter of one circle, I guess you can control this
- change the color of all dots in the circle, for example by setting it to one.
- Calculate the crowding factor (something like
c = mean(mean(color))
Note that if you want to use part of the matrix (allow the shapes to partly fall out of the image), this can be achieved, for example, using mean(mean(color(11:end-11))
in step 4, ignoring 10 pixels near the edge.
Now if you want to know if point (x, y) is yellow, just check the value color(x,y)
. Or, if you want to ignore the edges, checkcolor(x+10,y+10)
source to share