Monte-Carlo method to find the intersecting area of 5 circles.

Computer Science Level pending

Use the Monte-Carlo method to find the area of 5 intersecting circle

Circle Center RADIUS-SQUARED
1 (-2 , 3.5) 1.00
2 (2.00 , 2.00) 25.00
3 (-6.25 , 4.00) 16.00
4 (-2.87 , 3.64) .50
5 (-2.50 , 5.00) 3.00


The answer is 0.363.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Frank Petiprin
Mar 15, 2021
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
xcir1,ycir1,xcir2,ycir2,xcir3,ycir3,xcir4,ycir4=-2,3.5,2,2,-6.25,4,-2.87,3.64
xcir5,ycir5=-2.5,5
SqRadc1,SqRadc2,SqRadc3,SqRadc4,SqRadc5,cntTrue=1,25,16,.5,3,0
#Finds The x,y Intervals Of The Smallest Circle
xl,xr=xcir4-np.sqrt(SqRadc4),xcir4+np.sqrt(SqRadc4)
yl,yr,Ssize=ycir4-np.sqrt(SqRadc4),ycir4+np.sqrt(SqRadc4),40000000
TargetBox=(xr-xl)*(yr-yl) # Target Box contains The Smallest Circle
X,Y=np.random.uniform(xl,xr,Ssize),np.random.uniform(yl,yr,Ssize)
torfc1=(X-xcir1)**2+(Y-ycir1)**2<=SqRadc1
torfc2=(X-xcir2)**2+(Y-ycir2)**2<=SqRadc2
torfc3=(X-xcir3)**2+(Y-ycir3)**2<=SqRadc3
torfc4=(X-xcir4)**2+(Y-ycir4)**2<=SqRadc4
torfc5=(X-xcir5)**2+(Y-ycir5)**2<=SqRadc5
TorF=torfc1 & torfc2 & torfc3 & torfc4 & torfc5
cntTrue=np.sum(TorF)
cntFalse=len(TorF)-cntTrue
#input('test')
print('Count True',cntTrue,'Count False',cntFalse)
approx=((cntTrue/Ssize)*TargetBox)
print('Approx five Circles',approx,'Sample Size',Ssize)
# Various runs from 100Million to 1000Million on a Mac Book Pro
#Count True 18196295 Count False 81803705
#Approx five Circles 0.36392589999999997 Sample Size 100000000

#Count True 18202392 Count False 81797608
#Approx five Circles 0.36404783999999996 Sample Size 100000000

#Count True 36395670 Count False 163604330
#Approx five Circles 0.36395669999999997 Sample Size 200000000

#Count True 36393023 Count False 163606977
#Approx five Circles 0.36393022999999997 Sample Size 200000000

#Count True 36393907 Count False 163606093
#Approx five Circles 0.3639390699999999 Sample Size 200000000

#Count True 36407905 Count False 163592095
#Approx five Circles 0.36407904999999996 Sample Size 200000000

#Count True 54594144 Count False 245405856
#Approx five Circles 0.36396095999999994 Sample Size 300000000

#Count True 54608783 Count False 245391217
#Approx five Circles 0.36405855333333326 Sample Size 300000000

#Count True 72792465 Count False 327207535
#Approx five Circles 0.3639623249999999 Sample Size 400000000

#Count True 72799601 Count False 327200399
#Approx five Circles 0.36399800499999996 Sample Size 400000000

#Count True 181991583 Count False 818008417
#Approx five Circles 0.36398316599999997 Sample Size 1000000000 

Steven Chase
Mar 26, 2021

I did a numerical double integral in polar coordinates over the interior of circle #1. An infinitesimal area patch is added to the running total if it also lies within the other four circles. My lowest resolution integral had one million area patches, and my highest resolution integral had twenty five million patches.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import math

x1 = -2.0
y1 = 3.5

x2 = 2.0
y2 = 2.0

x3 = -6.25
y3 = 4.0

x4 = -2.87
y4 = 3.64

x5 = -2.5
y5 = 5.0

R1 = math.sqrt(1.0)
R2 = math.sqrt(25.0)
R3 = math.sqrt(16.0)
R4 = math.sqrt(0.5)
R5 = math.sqrt(3.0)

#########################################

N = 5000

dr = R1/N
dtheta = 2.0*math.pi/N

#########################################

A = 0.0

r = 0.0

while r <= R1:

    theta = 0.0

    while theta <= 2.0*math.pi:

        x = x1 + r*math.cos(theta)
        y = y1 + r*math.sin(theta)

        D2sq = (x - x2)**2.0 + (y - y2)**2.0
        D3sq = (x - x3)**2.0 + (y - y3)**2.0
        D4sq = (x - x4)**2.0 + (y - y4)**2.0
        D5sq = (x - x5)**2.0 + (y - y5)**2.0

        if (D2sq<R2**2.0) and (D3sq<R3**2.0) and (D4sq<R4**2.0) and (D5sq<R5**2.0):

            dA = r*dr*dtheta
            A = A + dA

        theta = theta + dtheta

    r = r + dr

#########################################

print N
print A

#########################################

#>>> 
#1000
#0.364026425284
#>>> ================================ RESTART ================================
#>>> 
#2000
#0.363963840831
#>>> ================================ RESTART ================================
#>>> 
#4000
#0.36396537815
#>>> ================================ RESTART ================================
#>>> 
#5000
#0.363963931064
#>>> 

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...