Beispiel #1
0
double findShape(Point2f &ctr, vector<Point> contour){
    unsigned int cnt = contour.size();
    vector<double> dist;
    double mean = 0.0;
    for(unsigned int i = 0; i < cnt; i++){
        double d = sqrt(sqre(contour[i].x - ctr.x)+sqre(contour[i].y - ctr.y));
        dist.push_back(d);
        mean += d;
    }
    mean = mean/cnt;

    float standDev= 0.0;
    for(unsigned int i = 0; i < cnt; i++){
        standDev += sqre(dist[i]-mean);
    }
    standDev = sqrt(standDev/cnt);
    return standDev;
}
Beispiel #2
0
double dist_square(Point &p1, Point &p2){
    return (sqre(p1.x - p2.x)+sqre(p1.y -p2.y));
}
Beispiel #3
0
int King_model(double w0, double rmin, double dlogr, int Nmax,
	       double *radius, double *potential, double *mass)
/*
Purpose:
     This function will compute a king model of parameter w0 from rmin
     up to the tidal radius of the cluster, logarithmically stepping 
     by dlogr.
Arguments:
     double w0      - King parameter, the higher the deeper.
     double rmin    - starting radius, will be radius[0],
     double dlogr   - log radius bin
     int Nmax       - Maximum number of points we want
     double *radius - Malloc'd (Nmax) array
     double *potential - Malloc'd (Nmax) array
     double *mass   - Malloc'd (Nmax) array
Returns:
     nrg - actual number of data points stored in the arrays
*/
{
/* ERROR CONTROL */
    double eps = 1e-6;

/* MISC VARIABLES */
    double sigma2=1.0;
    double den1=1.0;
    int i,j,nok,nbad,nk,nr,nrg;
    int nvar = 2, Nrmax = Nmax;

    double h1=1e-3, hmin = 1e-8;
    double r1, r2, rt, ppot, a,b;
    double oldpot1, oldpot2;
    double p,tote,totm,h,r0,p0,ss,d0;

    double pot[2];
    double *den = ALLOC(Nrmax, double);
    double *dene = ALLOC(Nrmax, double);
    double *denm = ALLOC(Nrmax, double);
    double *dene2 = ALLOC(Nrmax, double);
    double *denm2 = ALLOC(Nrmax, double);
    double *der = ALLOC(Nrmax, double);
    double *v2 = ALLOC(Nrmax, double);
   
    pot[0] = w0 * sigma2;
    pot[1] = 0;
    r2 = rmin;

/*--------------------------------------------------------------------
       Integrate outward to tidal boundary. Store potential and
       density, and mass at every step.
--------------------------------------------------------------------*/
    for( nr=0; nr<Nrmax; nr++ ){
	r1 = r2;
	r2 = pow(10, log10(r1)+dlogr);
	oldpot1 = pot[0];
	oldpot2 = pot[1];
	odeint( pot, nvar, r1, r2, eps, h1, hmin, &nok, &nbad, 
	        sigma2 , den1, potdir, rkqs);
	//printf("nr %d pot %le %le \n", nr, pot[0], pot[1]);

	if(pot[0] > 0){
	    /*  Have not reached rt yet; store data and continue.*/
	    radius[nr] = r2;
	    potential[nr] = pot[0];
	    mass[nr] = -pot[1]*r2*r2;
	    p = pot[0]/sigma2;
	    den[nr] = den1 * ( exp(p) * erf(sqrt(p)) - 
	                      sqrt(4.*p/M_PI)*(1. +2.*p/3) );
	}else{
	    if (pot[0] == 0){ 
		break; 
	    }
	    /* Have passed rt. Use bisection to find it.*/
	    for( i=0; i<20; i++ ){
		pot[0] = oldpot1;
		pot[1] = oldpot2;
		rt = 0.5 * (r1+r2);
		odeint( pot, nvar, r1, rt, eps, h1, hmin, &nok, 
	               &nbad, sigma2 , den1, potdir, rkqs);
		if(pot[0] > 0){
		    r1 = rt;
		    oldpot1 = pot[0];
		    oldpot2 = pot[1];
		}else if(pot[0] < 0){ 
		    r2 = rt; 
		}else{ 
		    break; 
		}
	    }
	    radius[nr] = rt;
	    potential[nr] = 0;
	    mass[nr] = -pot[1]*r2*r2;
	    den[nr] = 0;
	    break;
	}
	if(den[nr] < 0) break;

    }
    nrg = nr;

/*-------------------------------------------------------------------
           Compute total mass and energy.
--------------------------------------------------------------------*/
    for( nr=0; nr<nrg; nr++ ){
	dene[nr] = radius[nr]*radius[nr] * den[nr] * potential[nr];
	denm[nr] = radius[nr]*radius[nr] * den[nr];
    }
    spline(radius, dene, nrg, 0, 2e30, dene2);
    spline(radius, denm, nrg, 0, 2e30, denm2);
    tote = 0;
    totm = 0;

    for( nr=0; nr<nrg-1; nr++ ){
	h = radius[nr+1]-radius[nr];
	tote = tote + 0.5*h*( dene[nr+1] + dene[nr] ) -
	    cub(h)/24.*( dene2[nr+1] + dene2[nr] );
	totm = totm + 0.5*h*( denm[nr+1] + denm[nr] ) -
	    cub(h)/24.*( denm2[nr+1] + denm2[nr] );
    }

    totm = 4.*M_PI*totm;
    tote = 2.*M_PI*tote + 0.5*totm*totm/radius[nrg-1];
    tote = 0.5*tote;

    r0 = 4.*tote/sqre(totm);
    p0 = totm/(4.*tote);
    d0 = pow(totm,5)/cub(4.*tote);

    for( nr=0; nr<nrg; nr++ ){
        radius[nr] = r0*radius[nr];
        potential[nr] = p0*potential[nr];
        mass[nr] = mass[nr]/totm;
	den[nr] = d0*den[nr];
    }

/*--------------------------------------------------------------------
       Get the mean square velocity v2 as a function of radius.
--------------------------------------------------------------------*/
    /* for( nr=0; nr<nrg; nr++ ){ */
    /* 	nk = 2; */
    /* 	ppot = potential[nr]; */
    /* 	a = 0; b = sqrt(2*ppot); */
    /* 	ss = qromo(a, b, eps, kgvfnc, midpoint, nk, ppot, sigma2); */
    /* 	v2[nr] = ss; */
    /* 	nk = 0; */
    /* 	ss = qromo(a, b, eps, kgvfnc, midpoint, nk, ppot, sigma2); */
    /* 	v2[nr] = v2[nr]/ss; */
    /* } */

    free(v2);
    free(den); free(dene); free(denm);
    free(dene2); free(denm2); free(der);

    return nrg;
}