00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/Models/Solids.h"
00026 #include "Teddy/Models/Vertex.h"
00027 #include "Teddy/SysSupport/StdMaths.h"
00028
00029
00030 namespace Teddy {
00031 namespace Models {
00032
00033
00034 static const double sq2 = sqrt( 2.0 );
00035 static const double sq3 = sqrt( 3.0 );
00036 static const double sq5 = sqrt( 5.0 );
00037
00038
00039 Cube::Cube( double r )
00040 :Model("Cube")
00041 {
00042 Vertex *p[8];
00043 p[0] = new Vertex(-r / sq3, r / sq3, r / sq3);
00044 p[1] = new Vertex( r / sq3, r / sq3, r / sq3);
00045 p[2] = new Vertex( r / sq3, -r / sq3, r / sq3);
00046 p[3] = new Vertex(-r / sq3, -r / sq3, r / sq3);
00047 p[4] = new Vertex(-r / sq3, r / sq3, -r / sq3);
00048 p[5] = new Vertex( r / sq3, r / sq3, -r / sq3);
00049 p[6] = new Vertex( r / sq3, -r / sq3, -r / sq3);
00050 p[7] = new Vertex(-r / sq3, -r / sq3, -r / sq3);
00051
00052 addQuad( p[0], p[1], p[2], p[3] );
00053 addQuad( p[0], p[3], p[7], p[4] );
00054 addQuad( p[0], p[4], p[5], p[1] );
00055 addQuad( p[6], p[7], p[4], p[5] );
00056 addQuad( p[6], p[5], p[1], p[2] );
00057 addQuad( p[6], p[2], p[3], p[7] );
00058 setupClipRadius();
00059 }
00060
00061
00062 Cuboctahedron::Cuboctahedron( double r )
00063 :Model("Cuboctahedron")
00064 {
00065 Vertex *p[12];
00066
00067 p[ 0] = new Vertex( 0, r, 0 );
00068 p[ 1] = new Vertex( r / 2, r / 2, r * sq2 / 2 );
00069 p[ 2] = new Vertex( r / 2, r / 2, -r * sq2 / 2 );
00070 p[ 3] = new Vertex( r, 0, 0 );
00071 p[ 4] = new Vertex( r / 2, -r / 2, r * sq2 / 2 );
00072 p[ 5] = new Vertex( r / 2, -r / 2, -r * sq2 / 2 );
00073 p[ 6] = new Vertex( 0, -r, 0 );
00074 p[ 7] = new Vertex( -r / 2, -r / 2, r * sq2 / 2 );
00075 p[ 8] = new Vertex( -r / 2, -r / 2, -r * sq2 / 2 );
00076 p[ 9] = new Vertex( -r, 0, 0 );
00077 p[10] = new Vertex( -r / 2, r / 2, r * sq2 / 2 );
00078 p[11] = new Vertex( -r / 2, r / 2, -r * sq2 / 2 );
00079
00080
00081 addQuad( p[ 1], p[4], p[ 7], p[10] );
00082 addQuad( p[ 4], p[3], p[ 5], p[ 6] );
00083 addQuad( p[ 1], p[3], p[ 2], p[ 0] );
00084 addQuad( p[ 2], p[5], p[ 8], p[11] );
00085 addQuad( p[10], p[9], p[11], p[ 0] );
00086 addQuad( p[ 7], p[6], p[ 8], p[ 9] );
00087
00088
00089 addTri( p[ 0], p[1], p[10] );
00090 addTri( p[ 3], p[4], p[ 1] );
00091 addTri( p[ 4], p[6], p[ 7] );
00092 addTri( p[10], p[7], p[ 9] );
00093 addTri( p[ 0], p[2], p[11] );
00094 addTri( p[ 3], p[5], p[ 2] );
00095 addTri( p[ 5], p[6], p[ 8] );
00096 addTri( p[11], p[8], p[ 9] );
00097
00098 setupClipRadius();
00099 }
00100
00101
00102 Dodecahedron::Dodecahedron( double r )
00103 :Model("Dodecahedron")
00104 {
00105 double a = 2.0 / (sq3 + sq3 * sq5);
00106 double b = 1.0 / (3.0 * a);
00107
00108 Vertex *p[20];
00109 p[ 0] = new Vertex( r / sq3, r / sq3, r / sq3);
00110 p[ 1] = new Vertex( r / sq3, r / sq3, -r / sq3);
00111 p[ 2] = new Vertex( r / sq3, -r / sq3, r / sq3);
00112 p[ 3] = new Vertex( r / sq3, -r / sq3, -r / sq3);
00113 p[ 4] = new Vertex(-r / sq3, r / sq3, r / sq3);
00114 p[ 5] = new Vertex(-r / sq3, r / sq3, -r / sq3);
00115 p[ 6] = new Vertex(-r / sq3, -r / sq3, r / sq3);
00116 p[ 7] = new Vertex(-r / sq3, -r / sq3, -r / sq3);
00117 p[ 8] = new Vertex( 0, r * a, r * b);
00118 p[ 9] = new Vertex( 0, r * a, -r * b);
00119 p[10] = new Vertex( 0, -r * a, r * b);
00120 p[11] = new Vertex( 0, -r * a, -r * b);
00121 p[12] = new Vertex( r * a, r * b, 0);
00122 p[13] = new Vertex( r * a, -r * b, 0);
00123 p[14] = new Vertex(-r * a, r * b, 0);
00124 p[15] = new Vertex(-r * a, -r * b, 0);
00125 p[16] = new Vertex( r * b, 0, r * a);
00126 p[17] = new Vertex( r * b, 0, -r * a);
00127 p[18] = new Vertex(-r * b, 0, r * a);
00128 p[19] = new Vertex(-r * b, 0, -r * a);
00129
00130 addPenta( p[10], p[ 8], p[4], p[18], p[6] );
00131 addPenta( p[10], p[ 8], p[0], p[16], p[2] );
00132 addPenta( p[11], p[ 9], p[1], p[17], p[3] );
00133 addPenta( p[ 9], p[11], p[7], p[19], p[5] );
00134 addPenta( p[17], p[16], p[2], p[13], p[3] );
00135 addPenta( p[17], p[16], p[0], p[12], p[1] );
00136 addPenta( p[19], p[18], p[6], p[15], p[7] );
00137 addPenta( p[19], p[18], p[4], p[14], p[5] );
00138 addPenta( p[12], p[14], p[4], p[ 8], p[0] );
00139 addPenta( p[12], p[14], p[5], p[ 9], p[1] );
00140 addPenta( p[13], p[15], p[6], p[10], p[2] );
00141 addPenta( p[13], p[15], p[7], p[11], p[3] );
00142
00143 setupClipRadius();
00144 }
00145
00146
00147 Icosahedron::Icosahedron( double r )
00148 :Model("Icosahedron")
00149 {
00150 double a = 2.0 / (1.0 + sq5);
00151 double b = sqrt((3.0 + sq5) / (1.0 + sq5));
00152 a /= b;
00153
00154 Vertex *p[12];
00155 p[ 0] = new Vertex( 0, r * a, r / b );
00156 p[ 1] = new Vertex( 0, r * a, -r / b );
00157 p[ 2] = new Vertex( 0, -r * a, r / b );
00158 p[ 3] = new Vertex( 0, -r * a, -r / b );
00159 p[ 4] = new Vertex( r * a, r / b, 0 );
00160 p[ 5] = new Vertex( r * a, -r / b, 0 );
00161 p[ 6] = new Vertex( -r * a, r / b, 0 );
00162 p[ 7] = new Vertex( -r * a, -r / b, 0 );
00163 p[ 8] = new Vertex( r / b, 0, r * a );
00164 p[ 9] = new Vertex( r / b, 0, -r * a );
00165 p[10] = new Vertex( -r / b, 0, r * a );
00166 p[11] = new Vertex( -r / b, 0, -r * a );
00167
00168
00169 addTri( p[1], p[ 4], p[ 6]);
00170 addTri( p[0], p[ 6], p[ 4]);
00171 addTri( p[0], p[ 2], p[10]);
00172 addTri( p[0], p[ 8], p[ 2]);
00173 addTri( p[1], p[ 3], p[ 9]);
00174 addTri( p[1], p[11], p[ 3]);
00175 addTri( p[2], p[ 5], p[ 7]);
00176 addTri( p[3], p[ 7], p[ 5]);
00177 addTri( p[6], p[10], p[11]);
00178 addTri( p[7], p[11], p[10]);
00179 addTri( p[4], p[ 9], p[ 8]);
00180 addTri( p[5], p[ 8], p[ 9]);
00181 addTri( p[0], p[10], p[ 6]);
00182 addTri( p[0], p[ 4], p[ 8]);
00183 addTri( p[1], p[ 6], p[11]);
00184 addTri( p[1], p[ 9], p[ 4]);
00185 addTri( p[3], p[11], p[ 7]);
00186 addTri( p[3], p[ 5], p[ 9]);
00187 addTri( p[2], p[ 7], p[10]);
00188 addTri( p[2], p[ 8], p[ 5]);
00189
00190 setupClipRadius();
00191 }
00192
00193
00194 Octahedron::Octahedron( double r )
00195 :Model("Octahedron")
00196 {
00197 Vertex *p[6];
00198 p[0] = new Vertex( 0, r, 0);
00199 p[1] = new Vertex( 0, -r, 0);
00200 p[2] = new Vertex(-r, 0, 0);
00201 p[3] = new Vertex( 0, 0, -r);
00202 p[4] = new Vertex( r, 0, 0);
00203 p[5] = new Vertex( 0, 0, r);
00204
00205 addTri( p[0], p[2], p[3] );
00206 addTri( p[0], p[3], p[4] );
00207 addTri( p[0], p[4], p[5] );
00208 addTri( p[0], p[5], p[2] );
00209 addTri( p[1], p[2], p[3] );
00210 addTri( p[1], p[3], p[4] );
00211 addTri( p[1], p[4], p[5] );
00212 addTri( p[1], p[5], p[2] );
00213
00214 setupClipRadius();
00215 }
00216
00217
00218 Tetrahedron::Tetrahedron( const double r )
00219 :Model("Tetrahedron")
00220 {
00221 Vertex *p[4];
00222 p[0] = new Vertex( 0, r, 0 );
00223 p[1] = new Vertex( 0, -r / 3.0, r * 2.0 * sq2 / 3.0 );
00224 p[2] = new Vertex(-r * sq3 * sq2 / 3.0, -r / 3.0, -r * sq2 / 3.0 );
00225 p[3] = new Vertex( r * sq3 * sq2 / 3.0, -r / 3.0, -r * sq2 / 3.0 );
00226
00227 addTri( p[0], p[1], p[2] );
00228 addTri( p[0], p[1], p[3] );
00229 addTri( p[0], p[2], p[3] );
00230 addTri( p[1], p[2], p[3] );
00231
00232 setupClipRadius();
00233 }
00234
00235
00236 TruncatedCube::TruncatedCube( double r )
00237 :Model("TruncatedCube")
00238 {
00239 double a = (1.0 + sq2) / (2.0 * sqrt(5.0 / 2.0 + sq2));
00240 double b = 1.0 / (2.0 * sqrt(5.0 / 2.0 + sq2));
00241
00242 Vertex *p[24];
00243 p[ 0] = new Vertex( r * b, r * a, r * a);
00244 p[ 1] = new Vertex( r * a, r * b, r * a);
00245 p[ 2] = new Vertex( r * a, -r * b, r * a);
00246 p[ 3] = new Vertex( r * b, -r * a, r * a);
00247 p[ 4] = new Vertex(-r * b, -r * a, r * a);
00248 p[ 5] = new Vertex(-r * a, -r * b, r * a);
00249 p[ 6] = new Vertex(-r * a, r * b, r * a);
00250 p[ 7] = new Vertex(-r * b, r * a, r * a);
00251 p[ 8] = new Vertex( r * a, r * a, r * b);
00252 p[ 9] = new Vertex( r * a, -r * a, r * b);
00253 p[10] = new Vertex(-r * a, -r * a, r * b);
00254 p[11] = new Vertex(-r * a, r * a, r * b);
00255 p[12] = new Vertex( r * a, r * a, -r * b);
00256 p[13] = new Vertex( r * a, -r * a, -r * b);
00257 p[14] = new Vertex(-r * a, -r * a, -r * b);
00258 p[15] = new Vertex(-r * a, r * a, -r * b);
00259 p[16] = new Vertex( r * b, r * a, -r * a);
00260 p[17] = new Vertex( r * a, r * b, -r * a);
00261 p[18] = new Vertex( r * a, -r * b, -r * a);
00262 p[19] = new Vertex( r * b, -r * a, -r * a);
00263 p[20] = new Vertex(-r * b, -r * a, -r * a);
00264 p[21] = new Vertex(-r * a, -r * b, -r * a);
00265 p[22] = new Vertex(-r * a, r * b, -r * a);
00266 p[23] = new Vertex(-r * b, r * a, -r * a);
00267
00268
00269 addTri( p[ 0], p[ 1], p[ 8] );
00270 addTri( p[ 2], p[ 3], p[ 9] );
00271 addTri( p[ 4], p[ 5], p[10] );
00272 addTri( p[ 6], p[ 7], p[11] );
00273 addTri( p[16], p[17], p[12] );
00274 addTri( p[18], p[19], p[13] );
00275 addTri( p[20], p[21], p[14] );
00276 addTri( p[22], p[23], p[15] );
00277
00278
00279 addOcta( p[ 0], p[ 1], p[ 2], p[ 3], p[ 4], p[ 5], p[ 6], p[ 7] );
00280 addOcta( p[ 1], p[ 2], p[ 9], p[13], p[18], p[17], p[12], p[ 8] );
00281 addOcta( p[ 3], p[ 4], p[10], p[14], p[20], p[19], p[13], p[ 9] );
00282 addOcta( p[ 5], p[ 6], p[11], p[15], p[22], p[21], p[14], p[10] );
00283 addOcta( p[ 7], p[ 0], p[ 8], p[12], p[16], p[23], p[15], p[11] );
00284 addOcta( p[16], p[17], p[18], p[19], p[20], p[21], p[22], p[23] );
00285
00286 setupClipRadius();
00287 }
00288
00289
00290 TruncatedCuboctahedron::TruncatedCuboctahedron( double r )
00291 :Model("TruncatedCuboctahedron")
00292 {
00293 Vertex *p[24];
00294 p[ 0] = new Vertex(-r / (sq2 * sq3), r / (sq2 * sq3), r * sq2 / sq3 );
00295 p[ 1] = new Vertex( r / (sq2 * sq3), r / (sq2 * sq3), r * sq2 / sq3 );
00296 p[ 2] = new Vertex( r / (sq2 * sq3), -r / (sq2 * sq3), r * sq2 / sq3 );
00297 p[ 3] = new Vertex(-r / (sq2 * sq3), -r / (sq2 * sq3), r * sq2 / sq3 );
00298 p[ 4] = new Vertex(-r / (sq2 * sq3), r * sq2 / sq3 , r / (sq2 * sq3));
00299 p[ 5] = new Vertex(-r / (sq2 * sq3), r * sq2 / sq3 , -r / (sq2 * sq3));
00300 p[ 6] = new Vertex( r / (sq2 * sq3), r * sq2 / sq3 , -r / (sq2 * sq3));
00301 p[ 7] = new Vertex( r / (sq2 * sq3), r * sq2 / sq3 , r / (sq2 * sq3));
00302 p[ 8] = new Vertex( r * sq2 / sq3 , r / (sq2 * sq3), r / (sq2 * sq3));
00303 p[ 9] = new Vertex( r * sq2 / sq3 , r / (sq2 * sq3), -r / (sq2 * sq3));
00304 p[10] = new Vertex( r * sq2 / sq3 , -r / (sq2 * sq3), -r / (sq2 * sq3));
00305 p[11] = new Vertex( r * sq2 / sq3 , -r / (sq2 * sq3), r / (sq2 * sq3));
00306 p[12] = new Vertex( r / (sq2 * sq3), r / (sq2 * sq3), r / (sq2 * sq3));
00307 p[13] = new Vertex( r / (sq2 * sq3), r / (sq2 * sq3), -r / (sq2 * sq3));
00308 p[14] = new Vertex(-r / (sq2 * sq3), r / (sq2 * sq3), -r / (sq2 * sq3));
00309 p[15] = new Vertex(-r / (sq2 * sq3), r / (sq2 * sq3), r / (sq2 * sq3));
00310 p[16] = new Vertex(-r * sq2 / sq3 , -r / (sq2 * sq3), r / (sq2 * sq3));
00311 p[17] = new Vertex(-r * sq2 / sq3 , -r / (sq2 * sq3), -r / (sq2 * sq3));
00312 p[18] = new Vertex(-r * sq2 / sq3 , r / (sq2 * sq3), -r / (sq2 * sq3));
00313 p[19] = new Vertex(-r * sq2 / sq3 , r / (sq2 * sq3), r / (sq2 * sq3));
00314 p[20] = new Vertex(-r / (sq2 * sq3), r / (sq2 * sq3), -r * sq2 / sq3 );
00315 p[21] = new Vertex( r / (sq2 * sq3), r / (sq2 * sq3), -r * sq2 / sq3 );
00316 p[22] = new Vertex( r / (sq2 * sq3), -r / (sq2 * sq3), -r * sq2 / sq3 );
00317 p[23] = new Vertex(-r / (sq2 * sq3), -r / (sq2 * sq3), -r * sq2 / sq3 );
00318
00319 addTri( p[ 0], p[19], p[ 4] );
00320 addTri( p[ 1], p[ 7], p[ 8] );
00321 addTri( p[ 2], p[11], p[12] );
00322 addTri( p[ 3], p[15], p[16] );
00323 addTri( p[20], p[ 5], p[18] );
00324 addTri( p[21], p[ 9], p[ 6] );
00325 addTri( p[22], p[13], p[10] );
00326 addTri( p[23], p[17], p[14] );
00327
00328
00329 addQuad( p[ 0], p[ 1], p[ 2], p[ 3] );
00330 addQuad( p[ 4], p[ 5], p[ 6], p[ 7] );
00331 addQuad( p[ 8], p[ 9], p[10], p[11] );
00332 addQuad( p[12], p[13], p[14], p[15] );
00333 addQuad( p[16], p[17], p[18], p[19] );
00334 addQuad( p[20], p[21], p[22], p[23] );
00335
00336
00337 addQuad( p[ 0], p[ 4], p[ 7], p[ 1] );
00338 addQuad( p[ 1], p[ 8], p[11], p[ 2] );
00339 addQuad( p[ 2], p[12], p[15], p[ 3] );
00340 addQuad( p[ 3], p[16], p[19], p[ 0] );
00341 addQuad( p[20], p[ 5], p[ 6], p[21] );
00342 addQuad( p[21], p[ 9], p[10], p[22] );
00343 addQuad( p[22], p[13], p[14], p[23] );
00344 addQuad( p[23], p[17], p[18], p[20] );
00345
00346 setupClipRadius();
00347 }
00348
00349
00350 TruncatedOctahedron::TruncatedOctahedron( double r )
00351 :Model("TruncatedOctahedron")
00352 {
00353 Vertex *p[24];
00354 p[ 0] = new Vertex( 0, r / sq5, r * 2 / sq5);
00355 p[ 1] = new Vertex( r / sq5, 0, r * 2 / sq5);
00356 p[ 2] = new Vertex( 0, -r / sq5, r * 2 / sq5);
00357 p[ 3] = new Vertex( -r / sq5, 0, r * 2 / sq5);
00358 p[ 4] = new Vertex( 0, r * 2 / sq5, r / sq5);
00359 p[ 5] = new Vertex( -r / sq5, r * 2 / sq5, 0);
00360 p[ 6] = new Vertex( 0, r * 2 / sq5, -r / sq5);
00361 p[ 7] = new Vertex( r / sq5, r * 2 / sq5, 0);
00362 p[ 8] = new Vertex( r * 2 / sq5, 0, r / sq5);
00363 p[ 9] = new Vertex( r * 2 / sq5, r / sq5, 0);
00364 p[10] = new Vertex( r * 2 / sq5, 0, -r / sq5);
00365 p[11] = new Vertex( r * 2 / sq5, -r / sq5, 0);
00366 p[12] = new Vertex( 0, -r * 2 / sq5, r / sq5);
00367 p[13] = new Vertex( r / sq5, -r * 2 / sq5, 0);
00368 p[14] = new Vertex( 0, -r * 2 / sq5, -r / sq5);
00369 p[15] = new Vertex( -r / sq5, -r * 2 / sq5, 0);
00370 p[16] = new Vertex(-r * 2 / sq5, 0, r / sq5);
00371 p[17] = new Vertex(-r * 2 / sq5, -r / sq5, 0);
00372 p[18] = new Vertex(-r * 2 / sq5, 0, -r / sq5);
00373 p[19] = new Vertex(-r * 2 / sq5, r / sq5, 0);
00374 p[20] = new Vertex( 0, r / sq5, -r * 2 / sq5);
00375 p[21] = new Vertex( r / sq5, 0, -r * 2 / sq5);
00376 p[22] = new Vertex( 0, -r / sq5, -r * 2 / sq5);
00377 p[23] = new Vertex( -r / sq5, 0, -r * 2 / sq5);
00378
00379
00380 addQuad( p[ 0], p[ 1], p[ 2], p[ 3] );
00381 addQuad( p[ 4], p[ 5], p[ 6], p[ 7] );
00382 addQuad( p[ 8], p[ 9], p[10], p[11] );
00383 addQuad( p[12], p[13], p[14], p[15] );
00384 addQuad( p[16], p[17], p[18], p[19] );
00385 addQuad( p[20], p[21], p[22], p[23] );
00386
00387 addHexa( p[ 0], p[ 4], p[ 7], p[ 9], p[ 8], p[ 1] );
00388 addHexa( p[ 1], p[ 8], p[11], p[13], p[12], p[ 2] );
00389 addHexa( p[ 2], p[12], p[15], p[17], p[16], p[ 3] );
00390 addHexa( p[ 3], p[16], p[19], p[ 5], p[ 4], p[ 0] );
00391 addHexa( p[20], p[ 6], p[ 7], p[ 9], p[10], p[21] );
00392 addHexa( p[21], p[10], p[11], p[13], p[14], p[22] );
00393 addHexa( p[22], p[14], p[15], p[17], p[18], p[23] );
00394 addHexa( p[23], p[18], p[19], p[ 5], p[ 6], p[20] );
00395
00396 setupClipRadius();
00397 }
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410 };
00411 };
00412