Find total area of all circles
Show older comments
How can we calculate the total area covered by all the circles together using Monte Carlo method?
5 Comments
I gues the following code would do:
% Circle is given with (xc, yc, rc)
% (xc, yc) coordinates of center, rc is radius
% Monte Carlo algorithm works by creating a square having x and y points in range [-rc ; rc]
% around center point (xc, yc)
xc = 5; yc = 4; rc = 2;
t = linspace(0, 360);
x = xc + rc*cosd(t);
y = yc + rc*sind(t);
plot(x,y)
axis equal
in_circle = 0;
total = 0;
nr_points = 1e6;
for i = 1:nr_points
x = 2*rc*rand - rc + xc;
y = 2*rc*rand - rc +yc;
if (x-xc)^2+(y-yc)^2 <= rc^2
in_circle = in_circle + 1;
end
total = total +1;
area = (2*rc)^2 * in_circle/total;
end
Monte Carlo method estimates area by calculating ratio of total number of points inside a circle of radius rc and total number of generated points.
Jan
on 17 Jan 2023
@Elysi Cochin: What are trhe given inputs?
- Enclose the area in which all circles are comprised by a rectangle with side lengths a and b.
- Generate N random points uniformly distributed in the rectangle.
- For each random point, loop over all circles and check the in_circle condition.
- If the condition is true for at least one circle, set in_circle = in_circle + 1.
- An approximation for the area of the circles is then area = in_circle/N * (a*b)
Elysi Cochin
on 17 Jan 2023
Image Analyst
on 17 Jan 2023
Did you see my Answer below?
Why would you want to compute the area of overlap? If you did, how do you think you'd handle it? Remove the break, right? What else?
Accepted Answer
More Answers (0)
Categories
Find more on Triangulations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!