00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
#include <volume_io/internal_volume_io.h>
00016
#include <bicpl/geom.h>
00017
00018
#ifndef lint
00019
static char rcsid[] =
"$Header: /software/source//libraries/bicpl/Geometry/platonics.c,v 1.4 2000/02/06 15:30:16 stever Exp $";
00020
#endif
00021
00022 private void fill_in_indices(
00023
polygons_struct *polygons,
00024
int n_indices,
00025
int indices[] )
00026 {
00027
int ind;
00028
00029
if( polygons->
end_indices[polygons->
n_items-1] != n_indices )
00030 {
00031 handle_internal_error(
"create_unit_(platonic)" );
00032
return;
00033 }
00034
00035 for_less( ind, 0, n_indices )
00036 polygons->
indices[ind] = indices[ind];
00037
00038
compute_polygon_normals( polygons );
00039 }
00040
00041 public void create_unit_tetrahedron(
00042
polygons_struct *polygons )
00043 {
00044 Real x, z, c;
00045
static int indices[] = {
00046 0, 1, 2,
00047 0, 2, 3,
00048 0, 3, 1,
00049 1, 3, 2
00050 };
00051
00052
initialize_polygons_with_size( polygons,
WHITE, NULL, 4, 4, 3 );
00053
00054 x = sqrt( 8.0 ) / 3.0;
00055 z = - 1.0 / 3.0;
00056 c = sqrt( 6.0 ) / 3.0;
00057
00058 fill_Point( polygons->
points[0], 0.0, 0.0, 1.0 );
00059 fill_Point( polygons->
points[1], x, 0.0, z );
00060 fill_Point( polygons->
points[2], -0.5 * x, c, z );
00061 fill_Point( polygons->
points[3], -0.5 * x, -c, z );
00062
00063
fill_in_indices( polygons, SIZEOF_STATIC_ARRAY(indices), indices );
00064 }
00065
00066 public void create_unit_cube(
00067
polygons_struct *polygons )
00068 {
00069 Real d;
00070
static int indices[] = {
00071 0, 1, 3, 2,
00072 4, 6, 7, 5,
00073 0, 4, 5, 1,
00074 2, 3, 7, 6,
00075 0, 2, 6, 4,
00076 1, 5, 7, 3
00077 };
00078
00079
initialize_polygons_with_size( polygons,
WHITE, NULL, 8, 6, 4 );
00080
00081 d = 1.0 / sqrt( 3.0 );
00082
00083 fill_Point( polygons->
points[0], -d, -d, -d );
00084 fill_Point( polygons->
points[1], -d, -d, d );
00085 fill_Point( polygons->
points[2], -d, d, -d );
00086 fill_Point( polygons->
points[3], -d, d, d );
00087 fill_Point( polygons->
points[4], d, -d, -d );
00088 fill_Point( polygons->
points[5], d, -d, d );
00089 fill_Point( polygons->
points[6], d, d, -d );
00090 fill_Point( polygons->
points[7], d, d, d );
00091
00092
fill_in_indices( polygons, SIZEOF_STATIC_ARRAY(indices), indices );
00093 }
00094
00095 public void create_unit_octohedron(
00096
polygons_struct *polygons )
00097 {
00098
static int indices[] = {
00099 0, 3, 4,
00100 0, 4, 2,
00101 0, 2, 5,
00102 0, 5, 3,
00103 1, 3, 5,
00104 1, 5, 2,
00105 1, 2, 4,
00106 1, 4, 3
00107 };
00108
00109
initialize_polygons_with_size( polygons,
WHITE, NULL, 6, 8, 3 );
00110
00111 fill_Point( polygons->
points[0], -1.0, 0.0, 0.0 );
00112 fill_Point( polygons->
points[1], 1.0, 0.0, 0.0 );
00113 fill_Point( polygons->
points[2], 0.0, -1.0, 0.0 );
00114 fill_Point( polygons->
points[3], 0.0, 1.0, 0.0 );
00115 fill_Point( polygons->
points[4], 0.0, 0.0, -1.0 );
00116 fill_Point( polygons->
points[5], 0.0, 0.0, 1.0 );
00117
00118
fill_in_indices( polygons, SIZEOF_STATIC_ARRAY(indices), indices );
00119 }
00120
00121 public void create_unit_icosahedron(
00122
polygons_struct *polygons )
00123 {
00124 Real a, b;
00125
static int indices[] = {
00126 2, 11, 3,
00127 2, 5, 11,
00128 11, 5, 10,
00129 5, 0, 10,
00130 0, 5, 4,
00131 4, 5, 2,
00132 4, 2, 9,
00133 9, 2, 3,
00134 9, 3, 6,
00135 9, 6, 8,
00136 4, 9, 8,
00137 4, 8, 0,
00138 0, 8, 1,
00139 1, 8, 6,
00140 1, 6, 7,
00141 7, 6, 3,
00142 11, 7, 3,
00143 11, 10, 7,
00144 10, 1, 7,
00145 10, 0, 1
00146 };
00147
00148
initialize_polygons_with_size( polygons,
WHITE, NULL, 12, 20, 3 );
00149
00150 a = sqrt( (5.0+sqrt(5.0))/10.0 );
00151 b = sqrt( (5.0-sqrt(5.0))/10.0 );
00152
00153 fill_Point( polygons->
points[0], a, b, 0.0 );
00154 fill_Point( polygons->
points[1], a, -b, 0.0 );
00155 fill_Point( polygons->
points[2], -a, b, 0.0 );
00156 fill_Point( polygons->
points[3], -a, -b, 0.0 );
00157 fill_Point( polygons->
points[4], 0.0, a, b );
00158 fill_Point( polygons->
points[5], 0.0, a, -b );
00159 fill_Point( polygons->
points[6], 0.0, -a, b );
00160 fill_Point( polygons->
points[7], 0.0, -a, -b );
00161 fill_Point( polygons->
points[8], b, 0.0, a );
00162 fill_Point( polygons->
points[9], -b, 0.0, a );
00163 fill_Point( polygons->
points[10], b, 0.0, -a );
00164 fill_Point( polygons->
points[11], -b, 0.0, -a );
00165
00166
fill_in_indices( polygons, SIZEOF_STATIC_ARRAY(indices), indices );
00167 }