Find total area of all circles
이전 댓글 표시
How can we calculate the total area covered by all the circles together using Monte Carlo method?
댓글 수: 5
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
2023년 1월 17일
@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
2023년 1월 17일
Image Analyst
2023년 1월 17일
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?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Triangulations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
