コード例 #1
0
	double _stdcall LocusCrsAtPoint(const Locus & locus, const LLPoint & testPt, LLPoint & geoPt, double & dPerpCrs, const double dTol)
	{
		if(!PtIsOnLocus(locus, testPt, geoPt, dTol))
			return -1.0;

		double dLocusCrs = 0.0;
		double dPerpDist;

		InverseResult result;
		DistVincenty(testPt, geoPt, result);
		dPerpCrs = result.azimuth;
		dPerpDist = result.distance;

		DistVincenty(locus.geoStart, locus.geoEnd, result);
		double dGeoLen = result.distance;

		double dDistToLocus = DistToLocusP(locus, geoPt, dTol, Eps());
		double dSlope = atan((locus.endDist - locus.startDist) / dGeoLen);

		dPerpCrs = dPerpCrs + dSlope;

		if(dDistToLocus < 0)
			dLocusCrs = dPerpCrs - M_PI_2;
		else
			dLocusCrs = dPerpCrs + M_PI_2;

		if(dLocusCrs > M_2PI)
			dLocusCrs = dLocusCrs - M_2PI;

		return dLocusCrs;
	}
コード例 #2
0
ファイル: NQInt.cpp プロジェクト: jorik041/NQInt_Calculate
NQInt NQInt::cos(int Err)
{
	//косинус (а-ля синус)
	if (!NQInt(0).Compare(THIS)) return *(new NQInt(1));
	NQInt PI = NQInt(false);
	if (Err >= PI.underValueLeng)
		Err -= 1;
	else Err++;
	NQInt X = THIS %(PI+PI);
	X.errSize = errSize;
	X.Trancate(Err);
	X.deleteNullsItems();

	int n = 1;
	NQInt k;
	k.setErrSize(errSize);

	NQInt Eps(1);
	Eps.setErrSize(errSize);
	NQInt Resulted(1);
	Resulted.setErrSize(errSize);
	int SErr = Err;
	while (SErr > 0)
	{
		Eps = Eps/NQInt(10);
		Eps.setErrSize(errSize);
		SErr--;
	}
	do 
	{
		bool posit = n%2 - 1;
		NQInt PreX = (X.pow(NQInt(2*n)));
		PreX.Trancate(Err);
		PreX.setErrSize(errSize);
		PreX.deleteNullsItems();

		k = (NQInt(2*n).Fact());
		k.Trancate(Err);
		k = PreX/k;
		k.deleteNullsItems();

		if (!posit) 
			Resulted = Resulted - k; 
		else
			Resulted = Resulted + k;

		n++;

	} while (Eps.Compare(k) != 1);
	
	return Resulted;
}
コード例 #3
0
ファイル: NavFunc.cpp プロジェクト: AlexandreRio/route_pi
LLPoint DestVincenty(LLPoint pt, double brng, double dist, double* revAz)
	{
		double s = dist;
		double alpha1 = brng;
		double sinAlpha1 = sin(alpha1);
		double cosAlpha1 = cos(alpha1);

		double tanU1 = (1.0 - Flattening()) * tan(pt.latitude);
		double cosU1 = 1.0 / sqrt((1.0 + tanU1*tanU1));
		double sinU1 = tanU1 * cosU1;
		double sigma1 = atan2(tanU1, cosAlpha1);
		double sinAlpha = cosU1 * sinAlpha1;
		double cosSqAlpha = 1.0 - sinAlpha * sinAlpha;
		double uSq = cosSqAlpha * (SemiMajorAxis() * SemiMajorAxis() - SemiMinorAxis() * SemiMinorAxis()) /
                                  (SemiMinorAxis() * SemiMinorAxis());
		double A = 1.0 + uSq / 16384.0 * (4096.0 + uSq * (-768.0 + uSq * (320.0 - 175.0 * uSq)));
		double B = uSq / 1024.0 * (256.0 + uSq * (-128.0 + uSq * (74.0 - 47.0 * uSq)));

		double sigma = s / (SemiMinorAxis() * A);
		double sigmaP = M_2PI;
		double sinSigma = sin(sigma);
		double cosSigma = cos(sigma);
		double cos2SigmaM = cos(2.0 * sigma1 + sigma);
		int iterLimit = 0;
		while (fabs(sigma-sigmaP) > Eps() && ++iterLimit < 100) {
			cos2SigmaM = cos(2.0 * sigma1 + sigma);
			sinSigma = sin(sigma);
			cosSigma = cos(sigma);
			double cos2SigmaSq = cos2SigmaM * cos2SigmaM;
			double deltaSigma = B * sinSigma * (cos2SigmaM + B * 0.25 * (cosSigma * (-1.0 + 2.0 * cos2SigmaSq)-
				B / 6.0 * cos2SigmaM * (-3.0 + 4.0 * sinSigma * sinSigma) * (-3.0 + 4.0 * cos2SigmaSq)));

			sigmaP = sigma;
			sigma = s / (SemiMinorAxis() * A) + deltaSigma;
		}

		double tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1;
		double lat2 = atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1,
			(1.0 - Flattening()) * sqrt(sinAlpha * sinAlpha + tmp * tmp));
		double lambda = atan2(sinSigma * sinAlpha1, cosU1 * cosSigma - sinU1 * sinSigma * cosAlpha1);
		double C = Flattening() / 16.0 * cosSqAlpha * (4.0 + Flattening() * (4.0 -3.0 * cosSqAlpha));
		double L = lambda - (1.0 - C) * Flattening() * sinAlpha *
			(sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1.0 + 2.0 * cos2SigmaM * cos2SigmaM)));


    LLPoint return_value;
    return_value.latitude=lat2;
    return_value.longitude= pt.longitude + L;

    *revAz =atan2(sinAlpha, -tmp);
    return return_value;
	}
コード例 #4
0
ファイル: NQInt.cpp プロジェクト: jorik041/NQInt_Calculate
//синус
NQInt NQInt::sin(int Err)
{//чтобы увеличить точноть расчета уменьшим его точность
	
	if (!NQInt(0).Compare(THIS)) return *(new NQInt(0));
	NQInt PI = NQInt(false);
	if (Err >= PI.underValueLeng)
		Err -= 1;//уменьшаем если на критической
	else Err++;//увеличиваем если мы не на критической отметке
	NQInt X = THIS %(PI+PI);
	X.errSize = errSize;
	X.Trancate(Err);
	X.deleteNullsItems();

	int n = 1;
	NQInt k;
	k.setErrSize(errSize);

	NQInt Eps(1);
	Eps.setErrSize(errSize);
	NQInt Resulted = X;
	Resulted.setErrSize(errSize);
	int SErr = Err;
	while (SErr > 0)
	{//Накопление погрешности
		Eps = Eps/NQInt(10);
		Eps.setErrSize(errSize);
		SErr--;
	}
	do 
	{//Ряд Тейлора
		bool posit = n%2 - 1;
		NQInt PreX = (X.pow(NQInt(2*n+1)));
		PreX.Trancate(Err);
		PreX.setErrSize(errSize);
		PreX.deleteNullsItems();
		k = (NQInt(2*n+1).Fact());
		k.Trancate(Err);
		k = PreX/k;
		k.deleteNullsItems();

		if (!posit) //определение положительности
		Resulted = Resulted - k; 
		else
		Resulted = Resulted + k;

		n++;

	} while (Eps.Compare(k) != 1);
	if (!Positive) Resulted.Positive = !Resulted.Positive;
	return Resulted;
}
コード例 #5
0
ファイル: NQInt.cpp プロジェクト: jorik041/NQInt_Calculate
NQInt NQInt::sqrt(int Err)
{//Кто будет говорить, что корень не тригонометрия, тот ошибается =DD
	deleteNullsItems();
	
	NQInt Temp(0);
	if (!THIS.Positive) 

	{
		throw NQIntException(NQIntPositive);
	}

	if (!THIS.Compare(Temp))
		return NQInt(0);
	
	NQInt Eps(1);
	Eps.setErrSize(errSize);
	

	int SErr = Err;
	while (SErr > 0)
	{
		Eps = Eps/NQInt(10);
		Eps.setErrSize(errSize);
		SErr--;
	}
	Eps.valueLeng = 1;
	Eps.value = new int[Eps.valueLeng];
	Eps.value[0] = 0;

	NQInt X;
	NQInt NextX = THIS;
	NQInt Compared;
	do 
	{//разложим по формуле итерационной Герона
		X = NextX;
		
		NQInt Times = THIS/X;
		Times.setErrSize(errSize);
		NQInt Summary = (X + Times);
		Summary.setErrSize(errSize);
		NextX = Summary/NQInt(2);
		NextX.setErrSize(errSize);
		NextX.Trancate(Err);
		Compared = NextX - X;
		
	} while (Compared.Compare(Eps) == 1);
	return NextX;
}
コード例 #6
0
ファイル: NavFunc.cpp プロジェクト: AlexandreRio/route_pi
	bool DistVincenty(LLPoint pt1, LLPoint pt2, InverseResult * result)
	{
		double L = pt2.longitude - pt1.longitude;
		double U1 = atan((1-Flattening()) * tan(pt1.latitude));
		double U2 = atan((1-Flattening()) * tan(pt2.latitude));

		double sinU1 = sin(U1);
		double cosU1 = cos(U1);
		double sinU2 = sin(U2);
		double cosU2 = cos(U2);

		double dCosU1CosU2 = cosU1 * cosU2;
		double dCosU1SinU2 = cosU1 * sinU2;

		double dSinU1SinU2 = sinU1 * sinU2;
		double dSinU1CosU2 = sinU1 * cosU2;


		double lambda = L;
		double lambdaP = M_2PI;
		int iterLimit = 0;
		double cosSqAlpha;
		double sinSigma;
		double cos2SigmaM;
		double cosSigma;
		double sigma;
		double sinAlpha;
		double C;
		double sinLambda, cosLambda;

		do {
			sinLambda = sin(lambda);
			cosLambda = cos(lambda);
			sinSigma = sqrt((cosU2*sinLambda) * (cosU2*sinLambda) +
				(dCosU1SinU2 - dSinU1CosU2 * cosLambda) * (dCosU1SinU2 - dSinU1CosU2 * cosLambda));

			if (sinSigma==0)
			{
				(*result).reverseAzimuth = 0.0;
				(*result).azimuth = 0.0;
				(*result).distance = 0.0;
				return true;
			}
			cosSigma = dSinU1SinU2 + dCosU1CosU2 * cosLambda;
			sigma = atan2(sinSigma, cosSigma);
			sinAlpha = dCosU1CosU2 * sinLambda / sinSigma;
			cosSqAlpha = 1.0 - sinAlpha * sinAlpha;
			cos2SigmaM = cosSigma - 2.0 * dSinU1SinU2 / cosSqAlpha;

			if (!IsNumber(cos2SigmaM))
				cos2SigmaM = 0.0;  // equatorial line: cosSqAlpha=0 (§6)
			C = Flattening() / 16.0 * cosSqAlpha * (4.0 + Flattening() * (4.0 - 3.0 * cosSqAlpha));
			lambdaP = lambda;
			lambda = L + (1.0 - C) * Flattening() * sinAlpha *
				(sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1.0 + 2.0 * cos2SigmaM *cos2SigmaM)));
		} while (fabs(lambda-lambdaP) > Eps() && ++iterLimit < 100);

		double uSq = cosSqAlpha * (SemiMajorAxis() * SemiMajorAxis() - SemiMinorAxis() * SemiMinorAxis()) /
                                  (SemiMinorAxis() * SemiMinorAxis());
		double A = 1.0 + uSq / 16384.0 * (4096.0 + uSq * (-768.0 + uSq * (320.0 - 175.0 * uSq)));
		double B = uSq / 1024.0 * (256.0 + uSq * (-128.0 + uSq * (74.0 - 47.0 * uSq)));
		double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4.0 * (cosSigma * (-1.0 + 2.0 * cos2SigmaM * cos2SigmaM)-
			B / 6.0 * cos2SigmaM * (-3.0 + 4.0 * sinSigma * sinSigma) * (-3.0 + 4.0 * cos2SigmaM * cos2SigmaM)));

		(*result).distance = SemiMinorAxis() * A * (sigma - deltaSigma);
		(*result).azimuth = atan2(cosU2 * sinLambda, dCosU1SinU2 - dSinU1CosU2 * cosLambda);
		(*result).reverseAzimuth = M_PI + atan2(cosU1 * sinLambda, -dSinU1CosU2 + dCosU1SinU2 * cosLambda);

		if((*result).reverseAzimuth < 0.0)
			(*result).reverseAzimuth = M_2PI + (*result).reverseAzimuth;

		if((*result).azimuth < 0.0)
			(*result).azimuth = M_2PI + (*result).azimuth;
        if (iterLimit>98)
            return false;
        else
            return true;
	}
コード例 #7
0
ファイル: snapscale.c プロジェクト: Milkyway-at-home/nemo
void nemo_main()
{
    stream instr, outstr;
    real   mscale, pscale, xscale, tsnap, escale, dscale;
    vector rscale, vscale, ascale;
    string times;
    int i, nbody, bits, nrscale, nvscale, nascale, kscale;
    Body *btab = NULL, *bp;
    bool Qmass, Qphase, Qacc, Qpot, Qkey, Qaux, Qeps, Qdens;

    nrscale = nemoinpr(getparam("rscale"),rscale,NDIM);     /* RSCALE */
    if (nrscale==1) 
    	for (i=1; i<NDIM; i++)
    	   rscale[i] = rscale[0];
    else if (nrscale!=NDIM)
    	error("keyword rscale needs either 1 or %d numbers", NDIM);
    			

    nvscale = nemoinpr(getparam("vscale"),vscale,NDIM);     /* VSCALE */
    if (nvscale==1)
    	for (i=1; i<NDIM; i++)
    	   vscale[i] = vscale[0];
    else if (nvscale!=NDIM)
    	error("keyword vscale needs either 1 or %d numbers", NDIM);    

    nascale = nemoinpr(getparam("ascale"),ascale,NDIM);     /* ASCALE */
    if (nascale==1)
    	for (i=1; i<NDIM; i++)
    	   ascale[i] = ascale[0];
    else if (nascale!=NDIM)
    	error("keyword ascale needs either 1 or %d numbers", NDIM);    

    mscale = getdparam("mscale");
    pscale = getdparam("pscale");
    xscale = getdparam("xscale");
    dscale = getdparam("dscale");
    escale = getdparam("escale");
    kscale = getiparam("kscale");
    times = getparam("times");

    instr = stropen(getparam("in"), "r");   /* open files */
    outstr = stropen(getparam("out"), "w");

    get_history(instr);
    put_history(outstr);		
    for (;;) {
    	get_history(instr);		/* skip over stuff we can forget */
        if (!get_tag_ok(instr, SnapShotTag))
		break;			/* done with work in loop */
        get_snap(instr, &btab, &nbody, &tsnap, &bits);
        if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) {
	    continue;       /* just skip it's probably a diagnostics */
        }

        if ((bits & TimeBit) == 0)
	    tsnap = 0.0;
        else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ))
            continue;
        dprintf (1,"Scaling snapshot at time= %f bits=0x%x\n",tsnap,bits);

        Qmass  = MassBit & bits        && !uscalar(mscale);
        Qphase = PhaseSpaceBit & bits  &&(!uvector(rscale) || !uvector(vscale));
        Qacc   = AccelerationBit & bits&& !uvector(ascale);
        Qpot   = PotentialBit & bits   && !uscalar(pscale);
        Qaux   = AuxBit & bits         && !uscalar(xscale);
        Qkey   = KeyBit & bits         && (kscale!=1);
        Qdens  = DensBit & bits        && !uscalar(dscale);
        Qeps   = EpsBit & bits         && !uscalar(escale);

        dprintf(1,"Scaling: ");
        if (Qmass)  dprintf(1," mass");
        if (Qphase) dprintf(1," phase");
        if (Qacc)   dprintf(1," acc");
        if (Qpot)   dprintf(1," pot");
        if (Qaux)   dprintf(1," aux");
        if (Qkey)   dprintf(1," key");
        if (Qdens)  dprintf(1," dens");
        if (Qeps)   dprintf(1," eps");
        dprintf(1,"\n");

        if (Qmass || Qphase || Qacc || Qpot || Qaux || Qkey || Qdens || Qeps) {
            for (bp = btab; bp < btab+nbody; bp++) {
                if(Qmass) Mass(bp) *= mscale;
                if(Qphase) {
                    SMULVV(Pos(bp),rscale);
                    SMULVV(Vel(bp),vscale);
	        }
                if(Qpot) Phi(bp) *= pscale;
                if(Qacc) {
                    SMULVV(Acc(bp),ascale);
                }
                if(Qaux) Aux(bp) *= xscale;
                if(Qkey) Key(bp) *= kscale;
		if(Qdens) Dens(bp) *= dscale;
		if(Qeps) Eps(bp) *= escale;
            }
        } else {
            warning("No scaling applied to snapshot");
	}

        put_snap(outstr, &btab, &nbody, &tsnap, &bits);
    }
}
コード例 #8
0
ファイル: main.c プロジェクト: arnaldomandel/cte
/*
 * Main method.
 * Read arguments, alphabet and samples.
 * Starts the BIC calculator.
 * Runs the champion trees selector.
 * Then runs the bootstrap method to return the selected Context Tree.
 */
int main(int argc, char** argv) {
    /* Parameters and defaults */
    char* filename = NULL;
    unsigned int depth = 5;
    unsigned int size_resample_small = 30;
    unsigned int size_resample_large = 90;
    unsigned int number_resample_small = 10;
    unsigned int number_resample_large = 10;
    char *renewalstr = NULL;
    unsigned int seed = 0;
    char *c_method = NULL;
    int print_champs = 0;

    /* Process options */
    int c, e = 0;
    while (1) {
	static struct option long_options[] =  {
	    {"file",  required_argument, 0, 'f'},
	    {"depth",  required_argument, 0, 'd'},
	    {"small-sample-percentage",  required_argument, 0, 'p'},
	    {"large-sample-percentage",    required_argument, 0, 'P'},
	    {"number-samples",    required_argument, 0, 'n'},
	    {"number-large-samples",    required_argument, 0, 'N'},
	    {"renewal-string",    required_argument, 0, 'r'},
	    {"seed",    required_argument, 0, 's'},
	    {"scale",    required_argument, 0, 'k'},
	    {"champ-method",    required_argument, 0, 'c'},
	    {"print-champs", no_argument, 0, 'C'},
	    {0, 0, 0, 0}
	};
	int option_index = 0;
	c = getopt_long (argc, argv, "f:d:p:P:n:N:r:s:c:k:C", long_options, &option_index);
     
	if ( c == -1)
	    break;
	switch ( c ) {
	    SOPT('f', "filename", filename);
	    IOPT('d', "depth", depth);
	    IOPT('p', "small sample percentage", size_resample_small);
	    IOPT('P', "large sample percentage", size_resample_large);
	    IOPT('n', "small resample number", number_resample_small);
	    IOPT('N', "large resample number", number_resample_large);
	    IOPT('s', "seed", seed);
	    FOPT('k', "scale", scale);
	    SOPT('r', "renewal string", renewalstr);
	    SOPT('c', "champ method", c_method);
	    NOPT('C', print_champs);
	case '?':
	    e = 1;
	}
    }
    DEB("file %s\ndepth %d\nsmall p %d\nlarge p %d\nsmall num %d\nlarge num %d\nseed %d\nren %s\n",
	   filename,depth,size_resample_small,size_resample_large,number_resample_small,number_resample_large,seed,renewalstr);
    champ_method = !c_method || c_method[0] != 'o';
    
    if(e){
	usage();
	exit(0);
    }
    if (optind < argc && !filename)
	filename = strdup(argv[optind]);

    if(!filename)
	fatal_error(MISSING_FILENAME);
    
    Tree_node prob_root = Tree_create(PROB);
    Tree_node bic_root = Tree_create(BIC);
    
    char** sample = read_lines(filename);

    setup_BIC(sample, depth, prob_root, bic_root); // pre calculations
    
    // champions set calculation
    Champion_item champion_bics = champion_set(bic_root, Max_c(prob_root), Eps(prob_root)); 

    if (print_champs){
	ITERA(Champion_item, champion_item, champion_bics, next) {
	    printf("c=%f tree=[ ", champion_item->tau->c);
	    print_Tau(champion_item->tau);
	    printf("]\n");
	}
    }