Exemplo n.º 1
0
void test_sphere_intersection_point(void){

   struct ray r = create_ray(create_point(0,0,0),create_vector(1.3,0,0));
   struct sphere s = create_sphere(create_point(2.5,0,0),1.2);
   struct maybe_point test = sphere_intersection_point(r,s);
   checkit_double(test.p.x,1.3);
   checkit_double(test.p.y,0);
   checkit_double(test.p.z,0);
   checkit_int(test.isPoint,1);
   
   struct ray r2 = create_ray(create_point(-2.4,-2.9,-4.4),create_vector(-1,0,0));
   struct sphere s2 = create_sphere(create_point(2.3,5.7,8.2),1);
   struct maybe_point test2 = sphere_intersection_point(r2,s2);
   checkit_int(test2.isPoint,0);
   
   
   struct ray r3 = create_ray(create_point(-4.3,0,4.7),create_vector(3.5,0,0));
   struct sphere s3 = create_sphere(create_point(2.1,0,0),4.7);
   struct maybe_point test3 = sphere_intersection_point(r3,s3);
   checkit_int(test3.isPoint,1); 
   

   struct ray r4 = create_ray(create_point(1.2,-5.4,4.2),create_vector(1.1,1.2,1.3));
   struct sphere s4 = create_sphere(create_point(4.7,6.4,2.2),13.5);
   struct maybe_point test4 = sphere_intersection_point(r4,s4);
   checkit_double(test4.p.x,9.871860);
   checkit_double(test4.p.y,4.060210);
   checkit_double(test4.p.z,14.448561);
   checkit_int(test4.isPoint,1);
}
Exemplo n.º 2
0
int find_intersection_points(struct sphere spheres[], int num_spheres, struct ray r,
   struct sphere hit_spheres[], struct point intersection_points[]){
   int hit = 0;
   for(int i =0; i<num_spheres; i++){
      struct maybe_point point = sphere_intersection_point(r, spheres[i]);
      
      if(point.isPoint ==1){
         hit_spheres[hit] = spheres[i];
         intersection_points[hit] = point.p;
         hit++;
      }
   }
   return hit;
}
int find_intersection_points(struct sphere spheres[], int num_spheres, struct ray r, struct sphere hit_spheres [], struct point intersection_points[])
{
    int i;
    int position = 0;
    struct maybe_point maypoint;
    for (i = 0; i < num_spheres; i++)
    {
        maypoint = sphere_intersection_point(r, spheres[i]);
        if (maypoint.isPoint == 1)
        {
            hit_spheres[position] = spheres[i];
            intersection_points[position++] = maypoint.p;
        }
    }
    return position;
}
Exemplo n.º 4
0
int find_intersection_points(struct sphere spheres[], int num_spheres, struct ray r, struct sphere hit_spheres[],struct point intersection_points[])
{
   int i;
   int counter;
   for(i=0,counter=0;i<num_spheres;i++)
   {
      struct maybe_point mp = sphere_intersection_point(r,spheres[i]);
      if( mp.isPoint==1)
      {
        hit_spheres[counter]=spheres[i];
        intersection_points[counter]=mp.p; 
        counter++;
      }
   }
   return counter;

}