# Find total area of all circles

4 Ansichten (letzte 30 Tage)
Elysi Cochin am 17 Jan. 2023
Bearbeitet: Elysi Cochin am 18 Jan. 2023
How can we calculate the total area covered by all the circles together using Monte Carlo method?
##### 5 Kommentare3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
Elysi Cochin am 17 Jan. 2023
Using the code in the comment by @Askic V I could compute the area of all the circles by inputting the x,y coordinate and radius using a loop. But my doubt is, is that code sufficient to compute the area of two intersecting circles?
Image Analyst am 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?

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Image Analyst am 17 Jan. 2023
You need to generate an (x,y) point, like in an outer loop. Then in the inner loop you need to loop over all the known circles. If the point is inside a circle, increment the count, and skip checking the rest of the circles by calling "break" so that you don't count a point twice if it's in two circles. Here's a start, assuming xc and yc is a list of the circle center coordinates, and radii is a list of the corresponding radii.
numPoints = 100000; % Whatever
count = 0;
for k = 1 : numPoints
x = whatever, get random number in the range.
y = whatever
for c = 1 : numCircles
if sqrt(x - xc(c)).^ 2 + (y - yc(c))^2) < radii(c)
% Then it's inside this circle
count = count + 1
break; % Skip checking the rest of the circles.
end
end
end
percentArea = count / numPoints
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by