예제 #1
0
파일: auxi.c 프로젝트: solmir/projet42
t_vec		*vector_proj_vector(t_vec *v1, t_vec *v2) // project vector 1 in vector 2
{
	t_vec	*ret;

	ret = vec_mult(v2, dot_prod(v1, v2) / dot_prod(v2, v2));
	return (ret);
}
예제 #2
0
/* --------------------------------------------------------------------
 Computes kernel function for a-th and b-th.

 The base address for the 1st argument is dataA and for the 2nd
 argument is dataB.
-------------------------------------------------------------------- */
double kernel( long a, long b )
{
   double c = 0;

   ker_cnt++;

   switch( ker ) {
      /* linear kernel */
      case 0:
         c = dot_prod( a, b );
         break;
      /* polynomial kernel */
      case 1:
         c = pow( (dot_prod( a, b) + arg1[1]), arg1[0] );
         break;
      /* radial basis functions kernel*/
      case 2:
         c = exp( -0.5*sub_dot_prod( a, b)/(arg1[0]*arg1[0]) );
         break;
      /* sigmoid */
      case 3:     
         c = tanh( arg1[0]*dot_prod( a,b) + arg1[1] );
         break;
      /* "custom": here comes definition of user's own kernel. 
      Currently, the linear kernel is used. */
      case 4:     
         c = dot_prod( a, b ); 
         break;
      default:
         c = 0;
   }
   return( c );
}
예제 #3
0
파일: dfs.cpp 프로젝트: veeskochill/Routing
node* dfs(node start, point end){

	if(start.pos.x == end.x && start.pos.y == end.y)
		return NULL;
	
	std::ofstream myfile;
	myfile.open("best_route.dat", std::ofstream::out | std::ofstream::app);
	//node current_edge = start;
	//float* dot_products = (float*)malloc(num_edges*sizeof(float));
	std::vector<float> dot_products;
	for(int ui =0 ; ui < start.num_edges; ui++){
		point to_dest = subtract(start.pos, end);
		point to_next = subtract(start.pos, start.edges[ui]->pos);
		float result_value = dot_prod(to_dest, to_next)/sqrt(dot_prod(to_dest,to_dest))/sqrt(dot_prod(to_next,to_next));
		dot_products.push_back(result_value);
	}
	int ui = std::distance(dot_products.begin(),std::max_element(dot_products.begin(), dot_products.begin()+start.num_edges));
	//for(int ui=0;ui<start.num_edges;ui++)
	//	printf("%f\n", dot_products[ui]);
	//for(int ui=0; ui< start.num_edges; ui++){
		//printf("%d\n", ui);
	printf("%d : %f, %f --> %f, %f\n", ui, start.pos.x, start.pos.y, start.edges[ui]->pos.x, start.edges[ui]->pos.y);
	point diff = subtract(start.pos, start.edges[ui]->pos);
	myfile << start.pos.x << " " << start.pos.y << " " << diff.x << " " << diff.y << " " << std::endl;
	
		if(dfs(*start.edges[ui], end) != NULL){
			myfile.close();
			//printf("%d : %d, %d\n", ui, start.pos.x, start.pos.y);
			return start.edges[ui];
		}
	//}
	myfile.close();
	return NULL;
};
예제 #4
0
파일: calc2.c 프로젝트: gabfou/RT
inline t_vec		vector_proj_vector(const t_vec v1, const t_vec v2)
{
	t_vec	ret;

	ret = vec_mult(v2, dot_prod(v1, v2) / dot_prod(v2, v2));
	return (ret);
}
예제 #5
0
/* --------------------------------------------------------------------
 Computes kernel function for a-th and b-th.

 The base address for the 1st argument is dataA and for the 2nd
 argument is dataB.
-------------------------------------------------------------------- */
double kernel( long a, long b )
{
   double c = 0;

   ker_cnt++;

   switch( ker ) {
      /* linear kernel */
      case 0:
         c = dot_prod( a, b );
         break;
      /* polynomial kernel */
      case 1:
         c = pow( (dot_prod( a, b) + arg1[1]), arg1[0] );
         break;
      /* radial basis functions kernel*/
      case 2:
         c = exp( -0.5*sub_dot_prod( a, b)/(arg1[0]*arg1[0]) );
         break;
      /* sigmoid */
      case 3:     
         c = tanh( arg1[0]*dot_prod( a,b) + arg1[1] );
         break;
      default:
         c = 0;
   }
   return( c );
}
예제 #6
0
// draw triangle with per-vertex colors
void POV3DisplayDevice::tricolor(const float * xyz1, const float * xyz2, const float * xyz3,
                                 const float * n1,   const float * n2,   const float * n3,
                                 const float *c1, const float *c2, const float *c3) {
  float vec1[3], vec2[3], vec3[3], norm1[3], norm2[3], norm3[3];
  float leg1[3], leg2[3], trinorm[3], ang1, ang2, ang3;

  // transform the world coordinates
  (transMat.top()).multpoint3d(xyz1, vec1);
  (transMat.top()).multpoint3d(xyz2, vec2);
  (transMat.top()).multpoint3d(xyz3, vec3);

  // and the normals
  (transMat.top()).multnorm3d(n1, norm1);
  (transMat.top()).multnorm3d(n2, norm2);
  (transMat.top()).multnorm3d(n3, norm3);

//  write_materials();

  // Don't write degenerate triangles -- those with all normals more than 90
  // degrees from triangle normal or its inverse.
  vec_sub(leg1, vec2, vec1);
  vec_sub(leg2, vec3, vec1);
  cross_prod(trinorm, leg1, leg2);
  ang1 = dot_prod(trinorm, norm1);
  ang2 = dot_prod(trinorm, norm2);
  ang3 = dot_prod(trinorm, norm3);
  if ( ((ang1 >= 0.0) || (ang2 >= 0.0) || (ang3 >= 0.0)) &&
       ((ang1 <= 0.0) || (ang2 <= 0.0) || (ang3 <= 0.0)) ) {
    degenerate_triangles++;
    return;
  }

  // If all verticies have the same color, don't bother with per-vertex
  // coloring
  if ( (c1[0] == c2[0]) && (c1[0] == c3[0]) &&
       (c1[1] == c2[1]) && (c1[1] == c3[1]) &&
       (c1[2] == c2[2]) && (c1[2] == c3[2]) ) {
    fprintf(outfile, "VMD_triangle(");
    fprintf(outfile, "<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,",
        vec1[0], vec1[1], -vec1[2], vec2[0], vec2[1], -vec2[2], 
        vec3[0], vec3[1], -vec3[2]);
    fprintf(outfile, "<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,",
        norm1[0], norm1[1], -norm1[2], norm2[0], norm2[1], -norm2[2], 
        norm3[0], norm3[1], -norm3[2]);
    fprintf(outfile, "rgbt<%.3f,%.3f,%.3f,%.3f>)\n",
        c1[0], c1[1], c1[2], 1 - mat_opacity);
  }
  else {
    fprintf(outfile, "VMD_tricolor(");
    fprintf(outfile, "<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,",
        vec1[0], vec1[1], -vec1[2], vec2[0], vec2[1], -vec2[2], 
        vec3[0], vec3[1], -vec3[2]);
    fprintf(outfile, "<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,<%.8g,%.8g,%.8g>,",
        norm1[0], norm1[1], -norm1[2], norm2[0], norm2[1], -norm2[2], 
        norm3[0], norm3[1], -norm3[2]);
    fprintf(outfile, "rgbt<%.3f,%.3f,%.3f,%.3f>,rgbt<%.3f,%.3f,%.3f,%.3f>,rgbt<%.3f,%.3f,%.3f,%.3f>)\n",
        c1[0], c1[1], c1[2], 1 - mat_opacity, c2[0], c2[1], c2[2], 
        1 - mat_opacity, c3[0], c3[1], c3[2], 1 - mat_opacity);
  }
}
예제 #7
0
    void compute_zenith_color()
    {
        float chi ((4.f/9.f - turbidity_/120.f) * (3.1415927f - 2.f * thetas_));

        // Zenith luminance in Kcd/m2
        zenith_color_.Y() = (4.0453f * turbidity_ - 4.9710f) * std::tan(chi) - 0.2155f * turbidity_ + 2.4192f;

        if (zenith_color_.Y() < 0.001f)
            zenith_color_.Y() = 0.001f;

        float t2(turbidity_ * turbidity_);
        //vector4<float> th (thetas_*thetas_*thetas_, thetas_*thetas_, thetas_, 1.f);
        vector4<float> th (0,0,0, 1.f);

        static const vector4<float> xcoef1 ( 0.00616f, -0.00375f,  0.00209f,  0.0f    ),
                                    xcoef2 (-0.02903f,  0.06377f, -0.03202f,  0.00394f),
                                    xcoef3 ( 0.11693f, -0.21196f,  0.06052f,  0.25886f),

                                    ycoef1 ( 0.00275f, -0.00610f,  0.00317f,  0.0f    ),
                                    ycoef2 (-0.04214f,  0.08970f, -0.04153f,  0.00516f),
                                    ycoef3 ( 0.15346f, -0.26756f,  0.06670f,  0.26688f);

        zenith_color_.x() = t2 * dot_prod(xcoef1, th) + turbidity_ * dot_prod(xcoef2, th) + dot_prod(xcoef3, th);
        zenith_color_.y() = t2 * dot_prod(ycoef1, th) + turbidity_ * dot_prod(ycoef2, th) + dot_prod(ycoef3, th);
    }
예제 #8
0
파일: triangle.c 프로젝트: gabfou/RT
void			set_triangle(t_triangle *tr)
{
	tr->u = (sub_vec(tr->p2, tr->p1));
	tr->v = (sub_vec(tr->p3, tr->p1));
	tr->uu = dot_prod(tr->u, tr->u);
	tr->uv = dot_prod(tr->u, tr->v);
	tr->vv = dot_prod(tr->v, tr->v);
	tr->d = tr->uv * tr->uv - tr->uu * tr->vv;
	tr->n = normalizator_ret(prod_vector(tr->u, tr->v));
}
예제 #9
0
static void compute_improvement( const double *delta, const double *v1,
               const double *v2, double *d1, double *d2)
{
   const double b = 2. * dot_prod( delta, v1);
   const double c = 2. * dot_prod( delta, v2);
   const double d = 2. * dot_prod( v1, v2);
   const double e = dot_prod( v1, v1);
   const double f = dot_prod( v2, v2);

   *d1 = (d * c - 2. * f * b) / (4. * e * f - d * d);
// *d2 = (d * b - 2. * e * c) / (4. * e * f - d * d);
   *d2 = -(b + 2. * e * *d1) / d;
}
예제 #10
0
void orthonormal_basis(const float b[9], float e[9]) {
  float ob[3*3];
  vec_copy(ob+0, b+0);
  vec_copy(e+0, ob+0);
  vec_normalize(e+0);
  vec_triad(ob+3, b+3, -dot_prod(e+0, b+3), e+0);
  vec_copy(e+3, ob+3);
  vec_normalize(e+3);
  vec_triad(ob+6,  b+6, -dot_prod(e+0, b+6), e+0);
  vec_triad(ob+6, ob+6, -dot_prod(e+3, b+6), e+3);
  vec_copy(e+6, ob+6);
  vec_normalize(e+6);
}
int true_anomaly(binary * b)
{
	double x,y,z,vx,vy,vz,r,v,k,h[3],R[3],V[3],e_vec[3],vxh1[3],vxh2[3],R_temp[3],theta,edotr;
	int rv=1;
	
	//First translate to mass 1 rest frame
	x = b->x2[0] - b->x1[0];
	y = b->x2[1] - b->x1[1];
	z = b->x2[2] - b->x1[2];
	vx = b->v2[0] - b->v1[0];
	vy = b->v2[1] - b->v1[1];
	vz = b->v2[2] - b->v1[2];
	r = sqrt(x*x + y*y + z*z);
	v = sqrt(vx*vx + vy*vy + vz*vz);
	k = G*b->mass1 + G*b->mass2;							//here k is the standard gravitational parameter G(m1 + m2)

	//put together vectors of r and v
	R[0] = x;
	R[1] = y;
	R[2] = z;
	V[0] = vx;
	V[1] = vy;
	V[2] = vz;

	//calculate vector h
	cross_prod(R,V,h);

	//calculate the eccentricity vector
	cross_prod(V,h,vxh1);
	vect_mult_scalar(vxh1, 1/k, vxh2, 3);
	vect_mult_scalar(R,-1/r,R_temp,3);

	vect_add(vxh2,R_temp,e_vec,3);

	//find true anomaly from r
	edotr = dot_prod(e_vec,R,3);

	theta = acos(edotr / ( mag(e_vec,3) * mag(R,3) ) );

	if(dot_prod(R,V,3) < 0)
	{
		rv = 0;
		//printf("\nold theta = %.3f\nnew theta = %.3f\n",theta,2*PI-theta);
		theta = 2*PI - theta;
	}

	b->true_anomaly = theta;

	return rv;

}
/*--- calc_T: calculates the current kinetic energy T(P) ---*/
double calc_T(CHAIN * C)
{

	double T = 0, mk, mkp1;

	for(int k=0; k<C->N-1; k++){
		mk = C->mass[C->chain[k]];
		mkp1 = C->mass[C->chain[k+1]];
		T += 0.5 * (1/mk + 1/mkp1) * dot_prod(C->W[k],C->W[k],3);
		if(k > 0)
			T -= dot_prod(C->W[k-1],C->W[k],3)/mk;
	}

	return T;
}
예제 #13
0
파일: opticator.c 프로젝트: gabfou/RT
double			trans_calculator(t_thr *f, t_inter *inter,
	t_transroi *n, t_pd *pd)
{
	FLOAT_SIZE	scalc;
	FLOAT_SIZE	angle;
	t_vec		t;

	t.x = 0;
	t.y = 0;
	t.z = 0;
	angle = 0;
	scalc = 0;
	angle = M_PI_2 - acos(dot_prod(pd->dir, inter->norm));
	angle = (angle > 0) ? -angle : angle;
	if (sin(angle) > (AIR_INCI / GLASS_INCI))
		return (1);
	scalc = carre(AIR_INCI / GLASS_INCI) * carre(1 - carre(cos(angle)));
	t.x = ((AIR_INCI / GLASS_INCI) * pd->dir.x) + ((AIR_INCI / GLASS_INCI)
		* cos(angle) - fabs(1 - scalc)) * inter->norm.x;
	t.y = ((AIR_INCI / GLASS_INCI) * pd->dir.y) + ((AIR_INCI / GLASS_INCI)
		* cos(angle) - fabs(1 - scalc)) * inter->norm.y;
	t.z = ((AIR_INCI / GLASS_INCI) * pd->dir.z) + ((AIR_INCI / GLASS_INCI)
		* cos(angle) - fabs(1 - scalc)) * inter->norm.z;
	n->transpd.dir = normalizator_ret(t);
	n->transpd.pos = inter->pos;
	impactor(f->env, &n->transpd, f, &n->transinter);
	return (0);
}
예제 #14
0
/** compute a missing value based on PMF algorithm */
float pmf_predict(const vertex_data& user, 
    const vertex_data& movie, 
    const float rating, 
    double & prediction,
    void * pedge){


  prediction = dot_prod(user.pvec, movie.pvec);
  //truncate prediction to allowed values
  prediction = std::min((double)prediction, maxval);
  prediction = std::max((double)prediction, minval);

  float err = 0; 
  if (iiter > pmf_burn_in){
     if (pedge){
       if (iiter == pmf_burn_in+1)
         (*(float*)pedge) = 0;
       (*(float*)pedge) += prediction;
       err = pow(((*(float*)pedge) / (iiter - pmf_burn_in)) - rating, 2);
     }
  }
  else {
     err = pow(prediction - rating,2);
  }
  assert(!std::isnan(err));
  if (!pedge) 
        rmse_index++;
  return err; 

}
예제 #15
0
// Calculates cartesian axes based on coords of nuclei in ring
// using cremer-pople algorithm. It is assumed that the
// centre of geometry is the centre of the ring.
void ring_axes(const float * X, const float * Y, const float * Z, int N, 
             float x[3], float y[3], float z[3]) {
  float Rp[3] = {0.0, 0.0, 0.0}; float Rpp[3] = {0.0, 0.0, 0.0};
  int j;
  for (j=0; j<N; j++) {
    float ze_angle = 2.0f * float(VMD_PI) * float(j-1) / float(N);
    float ze_sin = sinf(ze_angle);
    float ze_cos = cosf(ze_angle);
    vec_incr(Rp, X[j]*ze_sin, Y[j]*ze_sin, Z[j]*ze_sin);
    vec_incr(Rpp, X[j]*ze_cos, Y[j]*ze_cos, Z[j]*ze_cos);
  }

  cross_prod(z, Rp, Rpp);
  vec_normalize(z);

  /* 
   * OK, now we have z, the norm to the central plane, we need
   * to calculate y as the projection of Rp onto the plane
   * and x as y x z
   */
  float lambda = dot_prod(z, Rp);
  y[0] = Rp[0] - z[0]*lambda;
  y[1] = Rp[1] - z[1]*lambda;
  y[2] = Rp[2] - z[2]*lambda;
  vec_normalize(y);
  cross_prod(x, y, z);    // voila !
}
예제 #16
0
float PSDisplayDevice::compute_light(float *a, float *b, float *c) {
   float norm[3];
   float light_scale;

   // compute a normal vector to the surface of the polygon
   norm[0] =
      a[1] * (b[2] - c[2]) +
      b[1] * (c[2] - a[2]) +
      c[1] * (a[2] - b[2]);
   norm[1] =
      a[2] * (b[0] - c[0]) +
      b[2] * (c[0] - a[0]) +
      c[2] * (a[0] - b[0]);
   norm[2] =
      a[0] * (b[1] - c[1]) +
      b[0] * (c[1] - a[1]) +
      c[0] * (a[1] - b[1]);

   // if the normal vector is zero, something is wrong with the
   // object so we'll just display it with a light_scale of zero
   if (!norm[0] && !norm[1] && !norm[2]) {
      light_scale = 0;
   } else {
      // otherwise we use the dot product of the surface normal
      // and the light normal to determine a light_scale
      vec_normalize(norm);
      light_scale = dot_prod(norm, norm_light);
      if (light_scale < 0) light_scale = -light_scale;
   }

   return light_scale;
}
예제 #17
0
void basis_change(const float *base, const float *obase, float *newcoor, int n) {
  int i, j;
  for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
      newcoor[n*i+j] = dot_prod(&base[n*j], &obase[n*i]);
    }
  }
}
예제 #18
0
flt_dbl calc_loglikelihood_distance( sparse_flt_dbl_vec & datapoint,  flt_dbl_vec &cluster, flt_dbl sqr_sum, flt_dbl sqr_sum_datapoint){
  flt_dbl intersection = dot_prod(datapoint, cluster);
  flt_dbl logLikelihood = twoLogLambda(intersection,
                                        sqr_sum - intersection,
                                        sqr_sum_datapoint,
                                        datapoint.size() - sqr_sum_datapoint);
   return 1.0 - 1.0 / (1.0 + logLikelihood);
}
예제 #19
0
 skylight(yaw_pitch sun_position, float turbidity = 6.0f)
     : sun_pos_    (from_spherical(sun_position))
     , turbidity_  (turbidity)
 {
     thetas_ = std::acos(dot_prod(sun_pos_, vector(0, 0, 1)));
     compute_zenith_color();
     compute_distribution_coefficients();
     compute_term();
 }
예제 #20
0
void vector_norm(const vec_3d *a, float *n)
{
  dot_prod(a, a, n);
#ifdef LIBQUAT_ARM
  arm_sqrt_f32(*n, n);
#else
  *n = sqrtf(*n);
#endif
}
예제 #21
0
파일: coord.c 프로젝트: psas/libsim
double vertical_velocity(state r)
{
  vec velocity = r.v;
  vec unit_pos = unit_vec(r.x);

  double v_vel = dot_prod(unit_pos, velocity);
  
  return v_vel;
}
예제 #22
0
flt_dbl calc_tanimoto_distance( sparse_flt_dbl_vec & datapoint,  flt_dbl_vec &cluster, flt_dbl sqr_sum, flt_dbl sqr_sum_datapoint){
  flt_dbl a_mult_b = dot_prod(datapoint, cluster);
  flt_dbl div = (sqr_sum + sqr_sum_datapoint - a_mult_b);
  if (debug && (div == 0 || a_mult_b/div < 0)){
     logstream(LOG_ERROR) << "divisor is zeo: " << sqr_sum << " " << sqr_sum_datapoint << " " << a_mult_b << " " << std::endl;
     print(datapoint);
     debug_print_vec("cluster", cluster, cluster.size());
     exit(1);
  }
  return 1.0 - a_mult_b/div;
}
예제 #23
0
flt_dbl calc_tanimoto_distance( sparse_flt_dbl_vec & datapoint, sparse_flt_dbl_vec & cluster, flt_dbl sqr_sum, flt_dbl sqr_sum0){ 
  flt_dbl a_mult_b = dot_prod(datapoint , cluster);
  flt_dbl div = (sqr_sum + sqr_sum0 - a_mult_b);
  if (ac.debug && (div == 0 || a_mult_b/div < 0)){
     logstream(LOG_ERROR) << "divisor is zeo: " << sqr_sum<< " " << sqr_sum0 << " " << a_mult_b << " " << std::endl;
     print(datapoint);
     print(cluster);
     exit(1);
  }
  return a_mult_b/div;
}
예제 #24
0
// draw a cylinder
void X3DDisplayDevice::cylinder_noxfrm(float *ta, float *tb, float radius, int filled) {
  if (ta[0] == tb[0] && ta[1] == tb[1] && ta[2] == tb[2]) {
    return;  // we don't serve your kind here
  }

  float height = distance(ta, tb);

  fprintf(outfile, "<Transform translation='%g %g %g' ",
          ta[0], ta[1] + (height / 2.0), ta[2]);

  float rotaxis[3];
  float cylaxdir[3];
  float yaxis[3] = {0.0, 1.0, 0.0};

  vec_sub(cylaxdir, tb, ta);
  vec_normalize(cylaxdir);
  float dp = dot_prod(yaxis, cylaxdir);

  cross_prod(rotaxis, cylaxdir, yaxis);
  vec_normalize(rotaxis);

  // if we have decent rotation vector, use it
  if ((rotaxis[0]*rotaxis[0] + 
      rotaxis[1]*rotaxis[1] + 
      rotaxis[2]*rotaxis[2]) > 0.5) { 
    fprintf(outfile, "center='0.0 %g 0.0' ", -(height / 2.0));
    fprintf(outfile, "rotation='%g %g %g  %g'", 
            rotaxis[0], rotaxis[1], rotaxis[2], -acos(dp));
  } else if (dp < -0.98) {
    // if we have denormalized rotation vector, we can assume it is
    // caused by a cylinder axis that is nearly coaxial with the Y axis.
    // If this is the case, we either perform no rotation in the case of a
    // angle cosine near 1.0, or a 180 degree rotation for a cosine near -1.
    fprintf(outfile, "center='0.0 %g 0.0' ", -(height / 2.0));
    fprintf(outfile, "rotation='0 0 -1 -3.14159'");
  }
  fprintf(outfile, ">\n");  
        
  fprintf(outfile, "  <Shape>\n");
  fprintf(outfile, "  ");
  write_cindexmaterial(colorIndex, materialIndex);

  // draw the cylinder
  fprintf(outfile, "    <Cylinder "
          "bottom='%s' height='%g' radius='%g' side='%s' top='%s' />\n", 
          filled ? "true" : "false",
          height,  
          radius, 
          "true",
          filled ? "true" : "false");

  fprintf(outfile, "  </Shape>\n");
  fprintf(outfile, "</Transform>\n");
}
예제 #25
0
파일: bsvd_coor.cpp 프로젝트: banglh/my_CF
/** compute a missing value based on ALS algorithm */
float bsvd_predict(const vertex_data& user, const vertex_data& movie,
		const float rating, double & prediction, void * extra = NULL) {

	prediction = dot_prod(user.pvec, movie.pvec);
	//truncate prediction to allowed values
//  prediction = std::min((double)prediction, maxval);
//  prediction = std::max((double)prediction, minval);
	//return the squared error
	float err = rating - prediction;
	assert(!std::isnan(err));
	return err * err;
}
예제 #26
0
double normalize_vector(double v[3])  /* returns magnitude */
{
	double mag;

	mag = sqrt(dot_prod(v,v));
	if(mag!=0){
		v[0] /= mag;
		v[1] /= mag;
		v[2] /= mag;
	}
	return(mag);
}
예제 #27
0
파일: triangle.c 프로젝트: gabfou/RT
void			check_triangle(t_item *item, t_pd *s, t_inter *inter, t_thr *f)
{
	t_vec		n;
	t_vec		a;
	FLOAT_SIZE	t;

	n = (prod_vector(item->tr->u, item->tr->v));
	a.x = -dot_prod(n, sub_vec(s->pos, item->tr->p1));
	a.y = dot_prod(n, s->dir);
	if (fabs(a.y) > 0 && (t = a.x / a.y) >= 0)
	{
		n = sub_vec(set_dist_pos(t, s->dir, s->pos), item->tr->p1);
		a.x = dot_prod(n, item->tr->u);
		a.y = dot_prod(n, item->tr->v);
		a.z = (a.y * item->tr->uv - item->tr->vv * a.x) / item->tr->d;
		a.y = (item->tr->uv * a.x - item->tr->uu * a.y) / item->tr->d;
		if (a.z < 0.0 || a.z > 1.0 || a.y < 0.0 || (a.y + a.z) > 1.0)
			return ;
		if (check_t(inter, t, s, item) == 1 && f->impactmod)
			inter->norm = item->tr->n;
	}
	return ;
}
예제 #28
0
파일: triangle.c 프로젝트: gabfou/RT
int				point_triangle(t_vec pos, t_triangle *p)
{
	FLOAT_SIZE	accumilator;
	t_vec		dot;
	t_vec		line1;
	t_vec		line2;

	accumilator = 0;
	line1 = normalizator_ret(sub_vec(p->p1, pos));
	line2 = normalizator_ret(sub_vec(p->p2, pos));
	dot.x = dot_prod(line1, line2);
	line1 = normalizator_ret(sub_vec(p->p2, pos));
	line2 = normalizator_ret(sub_vec(p->p3, pos));
	dot.y = dot_prod(line1, line2);
	line1 = normalizator_ret(sub_vec(p->p3, pos));
	line2 = normalizator_ret(sub_vec(p->p1, pos));
	dot.z = dot_prod(line1, line2);
	accumilator = acos(dot.x) + acos(dot.y) + acos(dot.z);
	if (accumilator < (359.9 * M_PI))
		return (0);
	else
		return (1);
}
예제 #29
0
// Interaction rate function routine 
static void web_rate(void* context, real_t xx, real_t yy, real_t *cxy, real_t *ratesxy)
{
  long int i;
  real_t fac;
  foodweb_t* data = context;
  
  for (i = 0; i<NUM_SPECIES; i++)
    ratesxy[i] = dot_prod(NUM_SPECIES, cxy, acoef[i]);
  
  fac = ONE + ALPHA * xx * yy;
  
  for (i = 0; i < NUM_SPECIES; i++)
    ratesxy[i] = cxy[i] * ( bcoef[i] * fac + ratesxy[i] );  
}
예제 #30
0
파일: opticator.c 프로젝트: gabfou/RT
double			get_schlick(t_pd *pd, t_inter *inter)
{
	double	ro;
	double	cosi;
	double	cost;

	ro = carre(AIR_INCI - GLASS_INCI / AIR_INCI + GLASS_INCI);
	cosi = dot_prod(vec_mult(pd->dir, -1), inter->norm);
	cost = fabs(1 - (carre(AIR_INCI / GLASS_INCI) * (1 - carre(cosi))));
	if (AIR_INCI <= GLASS_INCI)
		return (ro + (1 - ro) * pow(1 - cosi, 5));
	else if (AIR_INCI > GLASS_INCI)
		return (ro + (1 - ro) * pow(1 - cost, 5));
	else
		return (1);
}