icosahedron.c
/* we subdivide as follows: for each edge of a triangle face of
 * the icosahedron we find its midpoint. This midpoint is then
 * extended (normalized) to lie on the sphere. From each icosahedron
 * triangle we therefore get 6 vertices on the sphere - 3 original
 * and 3 edge midpoints. These are then joined as indicated to 
 * form 4 new smaller triangles. Thus each original triangle is
 * subdivided into 4.
 * The procedure can be repeated recursively.
 *
 *                  ________
 *                  \  /\  /
 *                   \/__\/
 *                    \  /
 *                     \/
 */
we subdivide as follows: for each edge of a triangle face of
the icosahedron we find its midpoint. This midpoint is then
extended (normalized) to lie on the sphere. From each icosahedron
triangle we therefore get 6 vertices on the sphere - 3 original
and 3 edge midpoints. These are then joined as indicated to
form 4 new smaller triangles. Thus each original triangle is
subdivided into 4.
The procedure can be repeated recursively.


we subdivide as follows : for each edge of a triangle face of the icosahedron we find its midpoint . This midpoint is then extended ( normalized ) to lie on the sphere . From each icosahedron triangle we therefore get 6 vertices on the sphere - 3 original and 3 edge midpoints . These are then joined as indicated to form 4 new smaller triangles . Thus each original triangle is subdivided into 4 . The procedure can be repeated recursively .
void subdivide (float* v1, float* v2, float* v3, int depth){
  GLfloat v12[3], v23[3], v31[3];
  GLint i;
  if (depth == 0){
    drawtriangle(v1, v2, v3);
    return;
  }
  for(i=0; i < 3; i++){
    v12[i] = v1[i] + v2[i];
    v23[i] = v2[i] + v3[i]; 
    v31[i] = v3[i] + v1[i];
  }
  normalize(v12);
  normalize(v23);
  normalize(v31);
  subdivide(v1, v12, v31, depth-1);
  subdivide(v2, v23, v12, depth-1);
  subdivide(v3, v31, v23, depth-1);
  subdivide(v12, v23, v31, depth-1);
}
void subdivide ( float * v1 , float * v2 , float * v3 , int depth ) { GLfloat v12 [ 3 ] , v23 [ 3 ] , v31 [ 3 ] ; GLint i ; if ( depth == 0 ) { drawtriangle ( v1 , v2 , v3 ) ; return ; } for ( i = 0 ; i < 3 ; i ++ ) { v12 [ i ] = v1 [ i ] + v2 [ i ] ; v23 [ i ] = v2 [ i ] + v3 [ i ] ; v31 [ i ] = v3 [ i ] + v1 [ i ] ; } normalize ( v12 ) ; normalize ( v23 ) ; normalize ( v31 ) ; subdivide ( v1 , v12 , v31 , depth - 1 ) ; subdivide ( v2 , v23 , v12 , depth - 1 ) ; subdivide ( v3 , v31 , v23 , depth - 1 ) ; subdivide ( v12 , v23 , v31 , depth - 1 ) ; }
we subdivide as follows: for each edge of a triangle face of
 the icosahedron we find its midpoint.
we subdivide as follows : for each edge of a triangle face of the icosahedron we find its midpoint .