# Estimate area of cropped circle with Monte Carlo

I looking around and not finding anything, I developed a simple function for estimating the area of a possibly cropped circle inside a frame. It uses a very basic MC implementation.

It is pretty fast but I think it could be made simpler. Any thoughts are appreciated.

import numpy as np
from scipy.spatial import distance

def circFrac(cx, cy, rad, x0, x1, y0, y1, N_tot=100000):
"""
Use Monte Carlo to estimate the fraction of the area of a circle centered
in (cx, cy) with a radius of 'rad', that is located within the frame given
by the limits 'x0, x1, y0, y1'.
"""
# Generate a square containing the circle.

# Generate 'N_tot' uniform random points inside that square.
xr = np.random.uniform(xmin, xmax, N_tot)
yr = np.random.uniform(ymin, ymax, N_tot)

# Obtain the distances of those points to the center of the circle.
dist = distance.cdist([(cx, cy)], np.array([xr, yr]).T)[0]

# Find the points within the circle.

# Find the points that are within the frame, from the points that are
# within the circle.
msk_xy = (xr[msk_in_circ] > x0) & (xr[msk_in_circ] < x1) &\
(yr[msk_in_circ] > y0) & (yr[msk_in_circ] < y1)

# The area is the points within circle and frame over the points within
# circle.
return msk_xy.sum() / msk_in_circ.sum()

# Define the (x, y) limits of the frame
x0, x1 = 0., 1.
y0, y1 = 0., 1.

for _ in range(10):
# Random center coordinates within the frame
cx = np.random.uniform(x0, x1)
cy = np.random.uniform(y0, y1)