circle spanning_circle(vector<point>& T)
{
    int n = T.size();

    random_shuffle(ALL(T));

    circle C(point(), -INFINITY);

    for (int i = 0; i < n; i++) if (!in_circle(C, T[i]))
        {
            C = circle(T[i], 0);

            for (int j = 0; j < i; j++) if (!in_circle(C, T[j]))
                {
                    C = circle((T[i] + T[j]) / 2, abs(T[i] - T[j]) / 2);

                    for (int k = 0; k < j; k++) if (!in_circle(C, T[k]))
                        {
                            point o = circumcenter(T[i], T[j], T[k]);
                            C = circle(o, abs(o - T[k]));
                        }
                }
        }

    return C;
}
Esempio n. 2
0
circle minimum_circle(vector<point> p) {
	circle ret;
	random_shuffle(p.begin(), p.end());
	for (int i = 0; i < (int)p.size(); ++i)
		if (!in_circle(p[i], ret)) {
			ret = circle(p[i], 0);
			for (int j = 0; j < i; ++j)
				if (!in_circle(p[j], ret)) {
					ret = make_circle(p[j], p[i]);
					for (int k = 0; k < j; ++k)
						if (!in_circle(p[k], ret))
							ret = make_circle(p[i], p[j], p[k]);
				}
		}
	return ret;
}
Esempio n. 3
0
double serial_execution(){
    int circle=0;
    for(int i=1;i<=ITERS;i++){
        int x = safe_rand()%100;
        int y = safe_rand()%100;
        circle += in_circle(x,y);
    }
    return circle/(double)ITERS;
}
Esempio n. 4
0
/*
* validate a link
*/
static halfedge_t* del_valid_link( halfedge_t *b )
{
	point2d_t	*g, *g_p, *d, *d_p;
	halfedge_t	*gd, *dd, *new_gd, *new_dd;
	int		a;

	g	= b->vertex;
	gd	= del_valid_left(b);
	g_p	= gd->vertex;


	d	= b->alpha->vertex;
	dd	= del_valid_right(b);
	d_p	= dd->vertex;

	if( g != g_p && d != d_p )
	{
		a	= in_circle(g, d, g_p, d_p);

		if( a != ON_CIRCLE )
		{
			if( a == INSIDE )
			{
				g_p	= g;
				gd	= b;
			}
			else
			{
				d_p = d;
				dd	= b->alpha;
			}
		}
	}

	/* create the 2 halfedges */
	new_gd	= halfedge_alloc();
	new_dd	= halfedge_alloc();

	/* setup new_gd and new_dd */

	new_gd->vertex	= gd->vertex;
	new_gd->alpha	= new_dd;
	new_gd->amgis	= gd;
	new_gd->sigma	= gd->sigma;
	gd->sigma->amgis	= new_gd;
	gd->sigma		= new_gd;

	new_dd->vertex	= dd->vertex;
	new_dd->alpha	= new_gd;
	new_dd->amgis	= dd->amgis;
	dd->amgis->sigma	= new_dd;
	new_dd->sigma	= dd;
	dd->amgis		= new_dd;

	return new_gd;
}
Esempio n. 5
0
/*
* pass through all the halfedges on the left side and validate them
*/
static halfedge_t* del_valid_left( halfedge_t* b )
{
	point2d_t		*g, *d, *u, *v;
	halfedge_t		*c, *du, *dg;

	g	= b->vertex;				/* base halfedge point */
	dg	= b;

	d	= b->alpha->vertex;			/* alpha(halfedge) point */
	b	= b->sigma;

	u	= b->alpha->vertex;			/* sigma(alpha(halfedge)) point */
	du	= b->alpha;

	v	= b->sigma->alpha->vertex;	/* alpha(sigma(sigma(halfedge)) point */

	if( classify_point_seg(g, d, u) == ON_LEFT )
	{
		/* 3 points aren't colinear */
		/* as long as the 4 points belong to the same circle, do the cleaning */
		while( v != d && in_circle(g, d, u, v) == INSIDE	)
		{
			c	= b->sigma;
			du	= b->sigma->alpha;
			del_remove_halfedge(b);
			b	= c;
			u	= du->vertex;
			v	= b->sigma->alpha->vertex;
		}
		if( v != d && in_circle(g, d, u, v) == ON_CIRCLE )
		{
			du	= du->amgis;
			del_remove_halfedge(b);
		}
	} else	/* treat the case where the 3 points are colinear */
		du		= dg;

	return du;
}
Esempio n. 6
0
/*
 * Function goes through a number of darts, each time randomly gets a pair of x,y coords that
 * are inside a 1x1 square. Checks if point is in circle, if so increments cnt.
 */
int throw_darts(unsigned int darts) {
	double x, y;
	int cnt = 0;

    for (unsigned int i = 0; i < darts; ++i) {
        x = rand() / (float)RAND_MAX;
        y = rand() / (float)RAND_MAX;

        if (in_circle(x, y, RADIUS))
            cnt++;
    }

	return cnt;
}
Esempio n. 7
0
/*
* pass through all the halfedges on the right side and validate them
*/
static halfedge_t* del_valid_right( halfedge_t *b )
{
	point2d_t		*g, *d, *u, *v;
	halfedge_t		*c, *dd, *du;

	b	= b->alpha;
	d	= b->vertex;
	dd	= b;
	g	= b->alpha->vertex;
	b	= b->amgis;
	u	= b->alpha->vertex;
	du	= b->alpha;

	v	= b->amgis->alpha->vertex;

	if( classify_point_seg(g, d, u) == ON_LEFT )
	{
		while( v != g && in_circle(g, d, u, v) == INSIDE )
		{
			c	= b->amgis;
			du	= c->alpha;
			del_remove_halfedge(b);
			b	= c;
			u	= du->vertex;
			v	= b->amgis->alpha->vertex;
		}
		if( v != g && in_circle(g, d, u, v) == ON_CIRCLE )

		{
			du	= du->sigma;
			del_remove_halfedge(b);
		}
	} else
		du	= dd;

	return du;
}
Esempio n. 8
0
double parallel_execution(int t){
    int circle=0;
    int i,x,y;

    omp_set_num_threads(t);
    double start_time = omp_get_wtime();

    #pragma omp parallel private(x,y) reduction(+:circle)
    {
        #pragma parallel for
            for(i=1;i<=ITERS;i++){
                x = safe_rand()%100;
                y = safe_rand()%100;
                circle += in_circle(x,y);
            }
    }
    printf("Threads: %d, Value: %lf, Time: %lf\n",t,circle/(double)ITERS*4, omp_get_wtime() - start_time);
}