/* * Monte Carlo calculations of the area of intersection of * a circle and an ellips * * x = sin(t), y = cos(t); x = sin(t + pi/4), y = cos(t) */ #include #include double area(long m, gsl_rng *r) { double x, y; /* x,y coordinate, both between 0 and 1 */ long count = 0L, n; for (n = 0; n < m; n++) { /* generate random coordinates */ x = 2*gsl_rng_uniform(r) - 1; y = 2*gsl_rng_uniform(r) - 1; /* count when a point lands in the area of interest */ if ( (x*x + y*y < 1) && (x*x + y*y + sqrt(2.)*x*y < 0.5) ) { count += 1; } } return(((double)count)/((double)m)); }