polyhedrons.scad
1 function cat(L1, L2) = [for (i=[0:len(L1)+len(L2)-1]) 2 i < len(L1)? L1[i] : L2[i-len(L1)]] ; 3 4 5 module dish(type = "sphere", sides = 10, length = 10){ 6 7 //TODO length scaling 8 9 function pointyDish(x,y) = (x == 0 || y == 0 || x== sides || y == sides ) ? 0 : abs(5-x) + abs(5-y); 10 11 /* 12 matrix looks like this: 13 [ 14 [0, 0, 0], [0, 1, 0], [0, 2, 0], 15 [1, 0, 0], [1, 1, 0], [1, 2, 0], 16 [2, 0, 0], [2, 1, 0], [2, 2, 0] 17 ] 18 */ 19 // row is how many verts are actually in a row 20 row = sides + 1; 21 22 // first make an x-first matrix of points. (0,0), (1,0) etc 23 matrix = cat([ 24 for ( y = [0 : sides], x = [ 0 : sides ]) [x, y, pointyDish(x,y)] 25 ], [[sides / 2, sides / 2, 0]]); 26 27 echo(matrix); 28 29 echo(matrix[121]); 30 31 echo(len(matrix)); 32 33 translate([sides / 2, sides / 2, 0]) sphere(r=1); 34 35 // then make 2 faces for each set of four points: (0,1,4), (0,4,3) 36 // sides - 1 because we are doing this fromt the bottom left corner and extending up and out 1 vertex 37 // so the rightmost and topmost vertexes are already covered 38 f1 = [ 39 for (y = [0 : sides-1], x = [ 0 : sides-1 ], num = [0, 1]) ( 40 num == 0 ? 41 [(x + row * y), (x + row * y + 1), (x + row * y + 1 + row)] : 42 [(x + row * y), (x + row * y + 1 + row), (x + row * y + row)]) 43 ]; 44 45 f2 = cat(f1, [for (n = [0: sides-1]) [n, n+1, len(matrix) - 1]]); 46 47 faces = cat(f2, [for (n = [len(matrix) - sides-1 : len(matrix)]) [n-1, n, len(matrix) - 1]]); 48 // add 49 50 /* 51 faces needs to start like this: 52 [ 53 [0,1,4,3], 54 [1,2,5,4] 55 ]*/ 56 57 /*index, index + 1, index + 1 + row, index + row*/ 58 59 polyhedron(points = matrix, faces=faces); 60 61 } 62 63 dish();