% Script P1
% Disjoint Disk Simulation
clc
% The number of trials in each simulation...
N = 10000;
disp('  r     Probabilty Disjoint')
disp('-------------------------------')
for r = .02:.02:.50
   % Perform the simulation with disks that have radius r.
   % The x and y coordinate of a disk center can never be bigger 
   % than s in absolute value where
   s = 1-r;
   % A variable to keep track of the number of disjoint instances...
   count = 0;   
   for k=1:N
      % The disk centers must fall randomly in the square with
      % vertices (s,s),(-s,s), (-s,-s), (s,-s)....
      x1 = -s+2*s*rand(1); y1 = -s+2*s*rand(1);
      x2 = -s+2*s*rand(1); y2 = -s+2*s*rand(1);
      x3 = -s+2*s*rand(1); y3 = -s+2*s*rand(1);
      % Compute  the three center-to-center distances...
      d12 = sqrt((x1-x2)^2+(y1-y2)^2);
      d23 = sqrt((x2-x3)^2+(y2-y3)^2);
      d31 = sqrt((x3-x1)^2+(y3-y1)^2);
      % Each of these must be greater than 2r for the three disks to 
      % be disjoint...
      if d12>=2*r && d23>=2*r && d31>=2*r
         count = count+1;
      end
   end
   % Compute the probability estimate and report the value...
   prob = count/N;
   fprintf('%4.2f       %6.4f\n',r,prob)
end
