Art
Art

Reputation: 1335

matlab: area under overlapping circles

I have a question to you...

Imagine square with size A x A. Now lets simulate circles with diameter of d, randomly distributed within this square, something like on the image below (in this case d's are the same, but its not the rule, they might be also randomly distributed within some range like d1 to d2).

simulation example

Lets say that circles are described in matrix as:

circles(1, :) = [x, y, d]; 
circles(2, :) = [x, y, d]; 
...and so on

where x, y are coordinates, d is diameter. Now the question is, how to simulate this circles, until given crowding parameter c is reached? c is simply defined as: c = yellow area / square area (in this case A^2).

And the second thing - lets say that everything is simulated and I want to check if some coordinate (x,y) is within or outside yellow area... How to do it? I was doing it by checking if my (x,y) is within area of each circle (but its getting more difficult when instead of circles I use i.e. round shape rectangles), one by one, but there must be some better way of doing it. Thanks for help : )

Upvotes: 3

Views: 1360

Answers (1)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

Here is an approach that should do the trick:

  1. Start with a large empty matrix (big enough to guarantee that every shape generated is fully inside the matrix). Suppose we do it like this color = zeros(100)
  2. while we have not yet reached the cowding ratio: the midpoint and diameter of one circle, I assume you can manage this
  3. change the color of all points in the circle, for example by setting it to one.
  4. Calculate the crowding ratio (something like c = mean(mean(color))

Note, if you only want to use part of the matrix (enable shapes to fall partially out of the picture) this can for example be achieved by using mean(mean(color(11:end-11)) in step 4, ignoring the 10 pixels near the edge.

Now if you want to know whether point (x,y) is yellow, simply check the value of color(x,y). Or if you want to ignore the edges check color(x+10,y+10)

Upvotes: 1

Related Questions