Ejemplo n.º 1
0
face_t new_tetrahedron()

{
edge_t edges[3];
vertex_t tv0, tv1, tv2, tv3;
vertex_t verts[4];
 face_t tf012, tf132, tf023, tf031;
 face_t tetrahedron;

/* note tv0 = new_vert(0, 0, 0, "v0"); won't work -- ints! yikes */


/* The nice thing about string names is you can represent the topology (like
   name an e01 if it goes from v. 0 to v. 1 and e20 if it goes from 2 to 0.) hmmm */


tv0 = new_vert(0.0, 0.0, 0.0,0);
verts[0] = tv0;
tv1 = new_vert(2.0, 2.0, 0.0,1);
verts[1] = tv1;
tv2 = new_vert(2.0, 0.0, 2.0,2);
verts[2] = tv2;
tv3 = new_vert(0.0, 2.0, 2.0,3);
verts[3] = tv3;

edges[0] = new_edge(tv0, tv1,0);
edges[1] = new_edge(tv1, tv2, 1);
edges[2] = new_edge(tv2, tv0, 2);

tf012 = new_face(edges, 3, 0);

edges[0] = new_edge(tv1, tv3, 3);
edges[1] = new_edge(tv3, tv2, 4);
edges[2] = new_edge(tv2, tv1,5);


tf132 = new_face(edges, 3, 1);


edges[0] = new_edge(tv0, tv2,6);
edges[1] = new_edge(tv2, tv3, 7);
edges[2] = new_edge(tv3, tv0, 8);

tf023 = new_face(edges, 3, 2);

edges[0] = new_edge(tv0, tv3,9);
edges[1] = new_edge(tv3, tv1, 10);
edges[2] = new_edge(tv1, tv0, 11);


 tetrahedron = tf012;
 tf012->next_face = tf132;
 tf132->next_face = tf023;
 tf023->next_face = tf031;
 tf031->next_face = tf012;

return(tetrahedron);

}
Ejemplo n.º 2
0
// Drwa a line
void line(struct window w, struct vert from, struct vert to)
{
	// Copy x and y from vertices
	float x1 = round(from.x);
	float y1 = round(from.y);
	float x2 = round(  to.x);
	float y2 = round(  to.y);

	// Bresenham's line rasterization
	const bool steep = (fabs(y2 - y1) > fabs(x2 - x1));
	if(steep)
	{
		swap(x1, y1);
		swap(x2, y2);
	}

	if(x1 > x2)
	{
		swap(x1, x2);
		swap(y1, y2);
	}

	const float dx = x2 - x1;
	const float dy = fabs(y2 - y1);

	float error = dx / 2.0f;
	const int ystep = (y1 < y2) ? 1 : -1;
	int y = (int)y1;

	const int max_x = (int)x2;

	for(int x = (int)x1; x < max_x; ++x)
	{
		if(steep)
			draw_vert(w, new_vert(y, x), 0);
		else
			draw_vert(w, new_vert(x, y), 0);

		error -= dy;
		if(error < 0)
		{
			y += ystep;
			error += dx;
		}
	}
}
Ejemplo n.º 3
0
polygon *get_healpix_poly(int nside, int hpix)
{
  int nv, nvmax, i, pix_n, pix_e, pix_s, pix_w, ev[1];
  vertices *vert;
  polygon *pixel, *pixelbetter;
  long double verts_vec[12], verts_vec_n[12], verts_vec_e[12], verts_vec_s[12], verts_vec_w[12], dist_n, dist_w, dist_s, dist_e;
  vec center, center_n, center_e, center_s, center_w, vertices_vec[4], vertices_vec_n[4], vertices_vec_e[4], vertices_vec_s[4], vertices_vec_w[4];
  azel *vertices_azel[8], vertices[8];

  for(i=0;i<=7;i++) vertices_azel[i] = &(vertices[i]);

  if (nside == 0) {
     pixel=new_poly(0);
     pixel->weight=1;
     pixel->pixel=0;
     
     return(pixel);
  }

  else {
    healpix_verts(nside, hpix, center, verts_vec);
    
    /* north vertex */
    for(i=0;i<=2;i++) (vertices_vec[0])[i] = verts_vec[i];

    /* east vertex */
    for(i=0;i<=2;i++) (vertices_vec[1])[i] = verts_vec[i+3];

    /* south vertex */
    for(i=0;i<=2;i++) (vertices_vec[2])[i] = verts_vec[i+6];

    /* west vertex */
    for(i=0;i<=2;i++) (vertices_vec[3])[i] = verts_vec[i+9];

    rp_to_azel(vertices_vec[0], vertices_azel[0]);
    rp_to_azel(vertices_vec[3], vertices_azel[2]);
    rp_to_azel(vertices_vec[2], vertices_azel[4]);
    rp_to_azel(vertices_vec[1], vertices_azel[6]);

    pix_n = 4*hpix + 3;
    pix_e = 4*hpix + 1;
    pix_s = 4*hpix;
    pix_w = 4*hpix + 2;

    healpix_verts(nside*2, pix_n, center_n, verts_vec_n);
    healpix_verts(nside*2, pix_e, center_e, verts_vec_e);
    healpix_verts(nside*2, pix_s, center_s, verts_vec_s);
    healpix_verts(nside*2, pix_w, center_w, verts_vec_w);

    /* north vertex of each child pixel */
    for(i=0;i<=2;i++){
      (vertices_vec_n[0])[i] = verts_vec_n[i];
      (vertices_vec_e[0])[i] = verts_vec_e[i];
      (vertices_vec_s[0])[i] = verts_vec_s[i];
      (vertices_vec_w[0])[i] = verts_vec_w[i];
    }

    /* east vertex of each child pixel */
    for(i=0;i<=2;i++){
      (vertices_vec_n[1])[i] = verts_vec_n[i+3];
      (vertices_vec_e[1])[i] = verts_vec_e[i+3];
      (vertices_vec_s[1])[i] = verts_vec_s[i+3];
      (vertices_vec_w[1])[i] = verts_vec_w[i+3];
    }

    /* south vertex of each child pixel */
    for(i=0;i<=2;i++){
      (vertices_vec_n[2])[i] = verts_vec_n[i+6];
      (vertices_vec_e[2])[i] = verts_vec_e[i+6];
      (vertices_vec_s[2])[i] = verts_vec_s[i+6];
      (vertices_vec_w[2])[i] = verts_vec_w[i+6];
    }

    /* west vertex of each child pixel */
    for(i=0;i<=2;i++){
      (vertices_vec_n[3])[i] = verts_vec_n[i+9];
      (vertices_vec_e[3])[i] = verts_vec_e[i+9];
      (vertices_vec_s[3])[i] = verts_vec_s[i+9];
      (vertices_vec_w[3])[i] = verts_vec_w[i+9];
    }
    
    rp_to_azel(vertices_vec_n[3], vertices_azel[1]);
    rp_to_azel(vertices_vec_w[2], vertices_azel[3]);
    rp_to_azel(vertices_vec_s[1], vertices_azel[5]);
    rp_to_azel(vertices_vec_e[0], vertices_azel[7]);

    for(i=0; i<8; i++){
      if(vertices[i].az < 0.) vertices[i].az = vertices[i].az + TWOPI;
      else {};
    }

    for(i=0; i<8; i++){
      if(vertices[i].az >= TWOPI) vertices[i].az = vertices[i].az - TWOPI;
      else {};
    } 

    nv=8; nvmax=8;
    vert=new_vert(nvmax);
    if(!vert){
      fprintf(stderr, "error in get_healpix_poly: failed to allocate memory for 8 vertices\n");
      return(0x0);
    }
    vert->nv=nv; vert->v=&vertices[0];

    pixel=new_poly(4);
    
    if(!pixel){
      fprintf(stderr, "error in get_healpix_poly: failed to allocate memory for polygon of 4 caps\n");
      return(0x0);
    }

    ev[0] = 8;

    edge_to_poly(vert, 2, &ev[0], pixel);
    pixel->id = (long long)hpix;

    pixelbetter=new_poly(5);
    
    if(!pixelbetter){
      fprintf(stderr, "error in get_healpix_poly: failed to allocate memory for polygon of 5 caps\n");
      return(0x0);
    }

    pixelbetter->np = 5;
    pixelbetter->npmax = 5;

    for(i=0; i<=3; i++) {
      pixelbetter->rp[i][0] = pixel->rp[i][0];
      pixelbetter->rp[i][1] = pixel->rp[i][1];
      pixelbetter->rp[i][2] = pixel->rp[i][2];
      pixelbetter->cm[i] = pixel->cm[i];
    }

    pixelbetter->rp[4][0] = center[0]; pixelbetter->rp[4][1] = center[1]; pixelbetter->rp[4][2] = center[2];
    pixelbetter->id = (long long)hpix;

    dist_n = cmrpirpj(center, vertices_vec[0]);
    dist_w = cmrpirpj(center, vertices_vec[3]);
    dist_s = cmrpirpj(center, vertices_vec[2]);
    dist_e = cmrpirpj(center, vertices_vec[1]);

    if(dist_n>=dist_w && dist_n>=dist_s && dist_n>=dist_e){
      pixelbetter->cm[4] = dist_n+0.000001;
    }
    else if(dist_w>=dist_n && dist_w>=dist_s && dist_w>=dist_e){
      pixelbetter->cm[4] = dist_w+0.000001;
    }
    else if(dist_s>=dist_n && dist_s>=dist_w && dist_s>=dist_e){
      pixelbetter->cm[4] = dist_s+0.000001;
    }
    else if(dist_e>=dist_n && dist_e>=dist_s && dist_e>=dist_w){
      pixelbetter->cm[4] = dist_e+0.000001;
    }
    else{
      fprintf(stderr, "error in get_healpix_poly: cannot find correct fifth cap\n");
      return(0x0);
    }


    if(!pixelbetter){
      fprintf(stderr, "error in get_healpix_poly: polygon is NULL.\n");
      return(0x0);
    }

    return(pixelbetter);
  }
}