Exemple #1
0
void check_dx_dy(long double *dx, long double *dy){
    if(double_abs(*dx) > MAX_DISPLACEMENT){
        *dx = MAX_DISPLACEMENT * sign(*dx);
    }
    if(double_abs(*dy) > MAX_DISPLACEMENT){
        *dy = MAX_DISPLACEMENT * sign(*dy);
    }
}
Exemple #2
0
inline long double point_distance_from_line(long double x0, long double y0, line *L){
    if(L->sqrtAB == 0){
        return -1;
    }else{
        return double_abs((L->A * x0 + L->B * y0 + L->C) / L->sqrtAB);
    }
}
Exemple #3
0
/**
    This function uses do_segments_intersect
    */
bool get_segment_intersection(const point *A1, const point *A2,
                              const point *B1, const point *B2,
                              point *I){
    if(do_segments_intersect(A1, A2, B1, B2)){
        long double dxA = A1->x - A2->x,
               dxB = B1->x - B2->x,
               dyA = A1->y - A2->y,
               dyB = B1->y - B2->y,
               denom = dxA * dyB - dyA * dxB,
               dxyA,
               dxyB;
        /**
            If segments cover each other
            function does nothing
            */
        if(double_abs(denom) < eps){
            return false;
        }else{
            dxyA = A1->x * A2->y - A1->y * A2->x;
            dxyB = B1->x * B2->y - B1->y * B2->x;

            I->x = (dxyA * dxB - dxA * dxyB) / denom;
            I->y = (dxyA * dyB - dyA * dxyB) / denom;
            return true;
        }
    }else{
        return false;
    }
}
Exemple #4
0
long double vector_angle(long double x, long double y){
   if(x != 0){
		long double b;
		b = atan(double_abs(y / x));
		if(y == 0){
			if(x < 0){
				b = PI;
			}
		}
		else if(x < 0){
			if(y > 0){
				b = PI - b;
			}else{
				b += PI;
			}
		}
		else if(y < 0){
			b = dwaPI - b;
		}
        return b;
    }
    else{
		if(y == 0){
			return 0;
		}else if(y > 0){
			return PIpol;
		}else{
            return PI32;
		}
    }
}
Exemple #5
0
int clust_invert(
  double **a,      /* input/output matrix */
  int    n,        /* dimension */
  double *det_man, /* determinant mantisa */
  int    *det_exp, /* determinant exponent */
  /* scratch space */
  int    *indx,    /* indx = G_alloc_ivector(n);  */
  double **y,      /* y = G_alloc_matrix(n,n); */
  double *col      /* col = G_alloc_vector(n); */
)
{
	int  i,j;
	double  d_man;
        int d_exp;

        d_exp = 0;
        if(ludcmp(a,n,indx,&d_man)) {
          for(j=0; j<n; j++) {
            d_man *= a[j][j];
            while( double_abs(d_man)>10 ) {
              d_man = d_man/10;
              d_exp++;
            }
            while( (double_abs(d_man)<0.1)&&(double_abs(d_man)>0) ) {
              d_man = d_man*10;
              d_exp--;
            }
          }
          *det_man = d_man;
          *det_exp = d_exp;
	  for(j=0; j<n; j++) {
	    for(i=0; i<n; i++) col[i]=0.0;
	    col[j]=1.0;
	    lubksb(a,n,indx,col);
	    for(i=0; i<n; i++) y[i][j]=col[i];
	  } 

	  for(i=0; i<n; i++)
	  for(j=0; j<n; j++) a[i][j]=y[i][j];
          return(1);
        }
        else {
          *det_man = 0.0;
          *det_exp = 0;
          return(0);
        }
}
Exemple #6
0
long double count_hp_loss(long double d_vx, long double d_vy){
    d_vx = d_vx * d_vx + d_vy * d_vy;
    if( !(double_abs(d_vx) < eps) ){
        return d_vx * PLAYER_DAMAGE_MULTIPLIER;
    }else{
        return 0;
    }
}
Exemple #7
0
long double square_equation(long double r0, long double fi){
	fi -= PI4;
	long double s = sin(fi),
          c = cos(fi);
	s = (s + sign(s * c) * c);
	if(s == 0){
		s = 1;
	}
	return double_abs(r0 / s);
}
Exemple #8
0
static signed char window_spike(
            const double *sub_array, 
            size_t window_len, 
            size_t window_index, 
            double N, 
            double ACC) 
{
    size_t j=0;
    double focus;
    double max=0;
    double min=0;
    double mean=0;
    double R=0;
    char initialized=0;
    for(j=0;j<window_len;j++) {
        if(j==window_index) { 
            /*
             * If j is the focus of this window then set it and continue
             */
            focus = sub_array[j];
            continue;
        }
        if(!initialized) {
            /*
             * If we haven't initialized max, min do so now
             */
            max = min = sub_array[j]; 
            initialized = 1;
        }
        if(sub_array[j] > max)
            /*
             * Keep track of the max value in the sub_array
             */
            max = sub_array[j];
        if(sub_array[j] < min)
            /*
             * Keep track of the min as well
             */
            min = sub_array[j];
        /*
         * Sum the elements to make a mean later
         */
        mean+= sub_array[j];
    }
    mean = mean/(window_len-1);
    R = max - min;
    R = double_max(R, ACC);
    if( double_abs(focus - mean) > (N*R)) {
        /*
         * If the deviation of the focus exceeds N*R then it is a spike value
         */
        return 0;
    }
    return 1;
}
Exemple #9
0
long double coefficient_multiplier(long double v){
    v = double_abs(v) / MACH_SPEED;
    if(v < 1){
        return exp(v * 1.3862943611198906);
    }else if(v < 1.5){
        v -= 1;
        return -4 * v * v + 4.0;
    }else{
        return 0.538859 * exp(-v * 1.098612 + 3.295837) + 0.2;
    }
}
Exemple #10
0
long double norm(long double fi){
	if(fi > 0){
		while(fi - dwaPI > eps){
			fi -= dwaPI;
		}
	}else
		while(fi < 0){
			fi += dwaPI;
		}
    if(double_abs(fi - dwaPI) < eps){
        fi = 0;
    }
	return fi;
}
Exemple #11
0
long double rectangle_equation(long double r0, long double fi, long double fi0, long double fi02, long double wsp1, long double wsp2){
    fi += fi02;
    long double res = sin(fi);

    if(rectangle_wsp(fi, fi0)){
        res -= wsp1 * cos(fi);
    }else{
        res -= wsp2 * cos(fi);
    }
    if(res != 0){
        res = double_abs(r0 / res);
    }

    return res;
}
Exemple #12
0
/**
    Computing the point on the circle that is
    closest to segment and then if it collides
    during this quantum of time  dt using
    get_segment_intersection and dividing
    one segment by another...
    That was one way to do it unntil I didn't
    include changing radius. Now I use the
    line equation to compute when distance will
    be equal to radius already modified at that
    point. Then I check if ball moved to that
    point collides - if the collision point
    is within segment constraints
    */
long double check_collision_between_ball_and_segment(long double x, long double y, long double dx, long double dy, long double r, long double dr, segment *seg){
    long double cs = cos(seg->ang),
           sn = sin(seg->ang),
           d_into = sign(dy * cs - dx * sn),
    dt = seg->line_equation.A * dx + seg->line_equation.B * dy + d_into * seg->line_equation.sqrtAB * dr;
    if(double_abs(dt) < double_eps){
        return EMPTY_COLLISION_TIME;
    }else{
        dt = (-d_into * seg->line_equation.sqrtAB * r - seg->line_equation.A * x - seg->line_equation.B * y - seg->line_equation.C) / dt;
        if(dt >= 0 && dt <= 1){
            r += dr * dt;
            point A = {x, y},
                  B = {x + 2 * (dx - r * sn * d_into),
                       y + 2 * (dy + r * cs * d_into)};
            if(do_segments_intersect(&A, &B, &seg->A, &seg->B)){
                return dt;
            }else{
                return EMPTY_COLLISION_TIME;
            }
        }else{
            return EMPTY_COLLISION_TIME;
        }
    }
}
Exemple #13
0
/*
 * comp_res
 * Returns true if the difference between a and b is less than res
 */
static int comp_res(double a, double b, double res) 
{
    return (double_abs(b-a) < res);
}
int clust_invert(
  double **a,      /* input/output matrix */
  int    n,        /* dimension */
  double *det_man, /* determinant mantisa */
  int    *det_exp, /* determinant exponent */
  /* scratch space */
  int    *indx,    /* indx = G_alloc_ivector(n);  */
  double **y,      /* y = G_alloc_matrix(n,n); */
  double *col      /* col = G_alloc_vector(n); */
)
{
        int  i,j,f,g;
        double  d_man;
        int d_exp;
        if(VERBOSE) {
            printf("\n\nR matrix before LU decomposition:\n");
            for(i=0; i<n; i++) {
                for(j=0; j<n; j++) {
                    printf("%.2f ",a[i][j]);
                }
                printf("\n");
            }
        }

        d_exp = 0;
        if(ludcmp(a,n,indx,&d_man)) {
            if(VERBOSE) {
                printf("Determinant mantissa after LU decomposition: %f\n",d_man);
                printf("\n\nR matrix after LU decomposition:\n");
                for(i=0; i<n; i++) {
                    for(j=0; j<n; j++) {
                        printf("%.2f ",a[i][j]);
                    }
                    printf("\n");
                }
            }
            
          for(j=0; j<n; j++) {
            d_man *= a[j][j];
            while( double_abs(d_man)>10 ) {
              d_man = d_man/10;
              d_exp++;
            }
            while( (double_abs(d_man)<0.1)&&(double_abs(d_man)>0) ) {
              d_man = d_man*10;
              d_exp--;
            }
          }
          
          *det_man = d_man;
          *det_exp = d_exp;
          if(VERBOSE) {
              printf("det: %fE%d\n",d_man,d_exp);
          }
          
          for(j=0; j<n; j++) {
            for(i=0; i<n; i++) col[i]=0.0;
            col[j]=1.0;
            lubksb(a,n,indx,col);
            for(i=0; i<n; i++) y[i][j]=col[i];
          } 

          for(i=0; i<n; i++)
          for(j=0; j<n; j++) a[i][j]=y[i][j];
          
          if(VERBOSE) {
              printf("\n\nMatrix at end of clust_invert function:\n");
              for(f=0; f<n; f++) {
                  for(g=0; g<n; g++) {
                      printf("%.2f ",a[f][g]);
                  }
                  printf("\n");
              }
          }
          return(1);
        }
        else {
          *det_man = 0.0;
          *det_exp = 0;
          return(0);
        }
}