├── .gitignore ├── 2Dshapes.scad ├── 3d_triangle.scad ├── README.markdown ├── TODO ├── __init__.py ├── array.scad ├── bearing.scad ├── bitmap ├── README ├── alphabet_block.scad ├── bitmap.scad ├── height_map.scad ├── letter_necklace.scad ├── name_tag.scad └── test_name_tag.scad ├── boxes.scad ├── constants.scad ├── curves.scad ├── fonts.scad ├── gears.scad ├── gridbeam.scad ├── hardware.scad ├── involute_gears.scad ├── layouts.scad ├── lego_compatibility.scad ├── lgpl-2.1.txt ├── libtriangles.scad ├── linear_bearing.scad ├── materials.scad ├── math.scad ├── metric_fastners.scad ├── motors.scad ├── multiply.scad ├── nuts_and_bolts.scad ├── openscad_testing.py ├── openscad_utils.py ├── polyholes.scad ├── profiles.scad ├── regular_shapes.scad ├── screw.scad ├── servos.scad ├── shapes.scad ├── stepper.scad ├── teardrop.scad ├── test_docs.py ├── test_mcad.py ├── transformations.scad ├── triangles.scad ├── trochoids.scad ├── units.scad ├── unregular_shapes.scad └── utilities.scad /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.pyc 3 | .pytest_cache/ 4 | __pycache__/ 5 | -------------------------------------------------------------------------------- /2Dshapes.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenSCAD 2D Shapes Library (www.openscad.org) 3 | * Copyright (C) 2012 Peter Uithoven 4 | * 5 | * License: LGPL 2.1 or later 6 | 7 | * 2D Shapes 8 | * ngon(sides, radius, center=false); 9 | * complexRoundSquare(size,rads1=[0,0], rads2=[0,0], rads3=[0,0], rads4=[0,0], center=true) 10 | * roundedSquare(pos=[10,10],r=2) 11 | * ellipsePart(width,height,numQuarters) 12 | * donutSlice(innerSize,outerSize, start_angle, end_angle) 13 | * pieSlice(size, start_angle, end_angle) //size in radius(es) 14 | * ellipse(width, height) { 15 | */ 16 | 17 | // Examples - (layouts.scad is required for examples) 18 | // example2DShapes(); use ; 19 | 20 | module example2DShapes() { 21 | grid(105,105,true,4) 22 | { 23 | // ellipse 24 | ellipse(50,75); 25 | 26 | // part of ellipse (a number of quarters) 27 | ellipsePart(50,75,3); 28 | ellipsePart(50,75,2); 29 | ellipsePart(50,75,1); 30 | 31 | // complexRoundSquare examples 32 | complexRoundSquare([75,100],[20,10],[20,10],[20,10],[20,10]); 33 | complexRoundSquare([75,100],[0,0],[0,0],[30,50],[20,10]); 34 | complexRoundSquare([50,50],[10,20],[10,20],[10,20],[10,20],false); 35 | complexRoundSquare([100,100]); 36 | complexRoundSquare([100,100],rads1=[20,20],rads3=[20,20]); 37 | 38 | // pie slice 39 | pieSlice(50,0,10); 40 | pieSlice(50,45,190); 41 | pieSlice([50,20],180,270); 42 | 43 | // donut slice 44 | donutSlice(20,50,0,350); 45 | donutSlice(30,50,190,270); 46 | donutSlice([40,22],[50,30],180,270); 47 | donutSlice([50,20],50,180,270); 48 | donutSlice([20,30],[50,40],0,270); 49 | } 50 | } 51 | // end examples ---------------------- 52 | 53 | module complexRoundSquare( 54 | size, // Size 55 | rads1=[0,0], // Top left radius 56 | rads2=[0,0], // Top right radius 57 | rads3=[0,0], // Bottom right radius 58 | rads4=[0,0], // Bottom left radius 59 | center=true // center 60 | ) { 61 | width = size[0]; 62 | height = size[1]; 63 | // %square(size=[width, height],center=true); 64 | x1 = 0-width/2+rads1[0]; 65 | y1 = 0-height/2+rads1[1]; 66 | x2 = width/2-rads2[0]; 67 | y2 = 0-height/2+rads2[1]; 68 | x3 = width/2-rads3[0]; 69 | y3 = height/2-rads3[1]; 70 | x4 = 0-width/2+rads4[0]; 71 | y4 = height/2-rads4[1]; 72 | 73 | scs = 0.1; // straight corner size 74 | 75 | x = (center)? 0: width/2; 76 | y = (center)? 0: height/2; 77 | 78 | translate([x,y,0]) 79 | hull() 80 | { 81 | // top left 82 | if(rads1[0] > 0 && rads1[1] > 0) 83 | translate([x1,y1]) 84 | mirror([1,0]) 85 | ellipsePart(rads1[0]*2,rads1[1]*2,1); 86 | else 87 | translate([x1,y1]) 88 | square(size=[scs, scs]); 89 | 90 | // top right 91 | if(rads2[0] > 0 && rads2[1] > 0) 92 | translate([x2,y2]) 93 | ellipsePart(rads2[0]*2,rads2[1]*2,1); 94 | else 95 | translate([width/2-scs,0-height/2]) 96 | square(size=[scs, scs]); 97 | 98 | // bottom right 99 | if(rads3[0] > 0 && rads3[1] > 0) 100 | translate([x3,y3]) 101 | mirror([0,1]) 102 | ellipsePart(rads3[0]*2,rads3[1]*2,1); 103 | else 104 | translate([width/2-scs,height/2-scs]) 105 | square(size=[scs, scs]); 106 | 107 | // bottom left 108 | if(rads4[0] > 0 && rads4[1] > 0) 109 | translate([x4,y4]) 110 | rotate([0,0,-180]) 111 | ellipsePart(rads4[0]*2,rads4[1]*2,1); 112 | else 113 | #translate([x4,height/2-scs]) 114 | square(size=[scs, scs]); 115 | } 116 | } 117 | 118 | module roundedSquare(pos=[10,10],r=2) { 119 | minkowski() 120 | { 121 | square([pos[0]-r*2,pos[1]-r*2],center=true); 122 | 123 | 124 | circle(r=r); 125 | } 126 | } 127 | 128 | // round shapes 129 | // The orientation might change with the implementation of circle... 130 | module ngon(sides, radius, center=false) { 131 | rotate([0, 0, 360/sides/2]) 132 | circle(r=radius, $fn=sides, center=center); 133 | } 134 | 135 | module ellipsePart(width,height,numQuarters) { 136 | o = 1; //slight overlap to fix a bug 137 | difference() 138 | { 139 | ellipse(width,height); 140 | 141 | if(numQuarters <= 3) 142 | translate([0-width/2-o,0-height/2-o,0]) 143 | square([width/2+o,height/2+o]); 144 | if(numQuarters <= 2) 145 | translate([0-width/2-o,-o,0]) 146 | square([width/2+o,height/2+o*2]); 147 | if(numQuarters < 2) 148 | translate([-o,0,0]) 149 | square([width/2+o*2,height/2+o]); 150 | } 151 | } 152 | 153 | module donutSlice(innerSize,outerSize, start_angle, end_angle) { 154 | difference() 155 | { 156 | pieSlice(outerSize, start_angle, end_angle); 157 | 158 | if(is_list(innerSize) && len(innerSize) > 1) 159 | ellipse(innerSize[0]*2,innerSize[1]*2); 160 | else 161 | circle(innerSize); 162 | } 163 | } 164 | 165 | module pieSlice(size, start_angle, end_angle) { //size in radius(es) 166 | rx = (is_list(size) && len(size) > 1)? size[0] : size; 167 | ry = (is_list(size) && len(size) > 1)? size[1] : size; 168 | trx = rx* sqrt(2) + 1; 169 | try = ry* sqrt(2) + 1; 170 | a0 = (4 * start_angle + 0 * end_angle) / 4; 171 | a1 = (3 * start_angle + 1 * end_angle) / 4; 172 | a2 = (2 * start_angle + 2 * end_angle) / 4; 173 | a3 = (1 * start_angle + 3 * end_angle) / 4; 174 | a4 = (0 * start_angle + 4 * end_angle) / 4; 175 | 176 | if(end_angle > start_angle) 177 | intersection() { 178 | if(is_list(size) && len(size) > 1) 179 | ellipse(rx*2,ry*2); 180 | else 181 | circle(rx); 182 | polygon([ 183 | [0,0], 184 | [trx * cos(a0), try * sin(a0)], 185 | [trx * cos(a1), try * sin(a1)], 186 | [trx * cos(a2), try * sin(a2)], 187 | [trx * cos(a3), try * sin(a3)], 188 | [trx * cos(a4), try * sin(a4)], 189 | [0,0] 190 | ]); 191 | } 192 | } 193 | 194 | module ellipse(width, height) { 195 | scale([1, height/width, 1]) 196 | circle(r=width/2); 197 | } 198 | -------------------------------------------------------------------------------- /3d_triangle.scad: -------------------------------------------------------------------------------- 1 | // Enhancement of OpenSCAD Primitives Solid with Trinagles 2 | // Copyright (C) 2011 Rene BAUMANN, Switzerland 3 | // 4 | // This library is free software; you can redistribute it and/or 5 | // modify it under the terms of the GNU Lesser General Public 6 | // License as published by the Free Software Foundation; either 7 | // version 2.1 of the License, or (at your option) any later version. 8 | // 9 | // This library is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | // Lesser General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU Lesser General Public 15 | // License along with this library; If not, see 16 | // or write to the Free Software Foundation, Inc., 17 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | // ================================================================ 19 | // 20 | // File providing functions and modules to draw 3D - triangles 21 | // created in the X-Y plane with hight h, using various triangle 22 | // specification methods. 23 | // Standard traingle geometrical definition is used. Vertices are named A,B,C, 24 | // side a is opposite vertex A a.s.o. the angle at vertex A is named alpha, 25 | // B(beta), C(gamma). 26 | // 27 | // This SW is a contribution to the Free Software Community doing a marvelous 28 | // job of giving anyone access to knowledge and tools to educate himselfe. 29 | // 30 | // Author: Rene Baumann 31 | // Date: 11.09.2011 32 | // Edition: 0.3 11.09.2011 For review by Marius 33 | // Edition: 0.4 11.11.2011 Ref to GPL2.1 added 34 | // 35 | // -------------------------------------------------------------------------------------- 36 | // 37 | // =========================================== 38 | // 39 | // FUNCTION: 3dtri_sides2coord 40 | // DESCRIPTION: 41 | // Enter triangle sides a,b,c and to get the A,B,C - corner 42 | // co-ordinates. The trinagle's c-side lies on the x-axis 43 | // and A-corner in the co-ordinates center [0,0,0]. Geometry rules 44 | // required that a + b is greater then c. The traingle's vertices are 45 | // computed such that it is located in the X-Y plane, side c is on the 46 | // positive x-axis. 47 | // PARAMETER: 48 | // a : real length of side a 49 | // b : real length of side b 50 | // c : real length of side c 51 | // RETURNS: 52 | // vertices : [Acord,Bcord,Ccord] Array of vertices coordinates 53 | // 54 | // COMMENT: 55 | // vertices = 3dtri_sides2coord (3,4,5); 56 | // vertices[0] : Acord vertex A cordinates the like [x,y,z] 57 | // ------------------------------------------------------------------------------------- 58 | // 59 | function 3dtri_sides2coord (a,b,c) = [ 60 | [0,0,0], 61 | [c,0,0], 62 | [(pow(c,2)+pow(a,2)-pow(b,2))/(2*c),sqrt ( pow(a,2) - 63 | pow((pow(c,2)+pow(a,2)-pow(b,2))/(2*c),2)),0]]; 64 | // 65 | // 66 | // =========================================== 67 | // 68 | // FUNCTION: 3dtri_centerOfGravityCoord 69 | // DESCRIPTION: 70 | // Enter triangle A,B,C - corner coordinates to get the 71 | // triangles Center of Gravity coordinates. It is assumed 72 | // the triangle is parallel to the X-Y plane. The function 73 | // returns always zero for the z-coordinate 74 | // PARAMETER: 75 | // Acord : [x,y,z] Coordinates of vertex A 76 | // Bcord : [x,y,z] Coordinates of vertex B 77 | // Ccord : [x,y,z] Coordinates of vertex C 78 | // RETURNS: 79 | // CG : [x,y,0] Center of gravity coordinate in X-Y-plane 80 | // 81 | // COMMENT: 82 | // vertices = 3dtri_sides2coord (3,4,5); 83 | // cg = 3dtri_centerOfGravityCoord(vertices[0],vertices[1],vertices[2]); 84 | // ------------------------------------------------------------------------------------- 85 | // 86 | function 3dtri_centerOfGravityCoord (Acord,Bcord,Ccord) = [ 87 | (Acord[0]+Bcord[0]+Ccord[0])/3,(Acord[1]+Bcord[1]+Ccord[1])/3,0]; 88 | // 89 | // 90 | // =========================================== 91 | // 92 | // FUNCTION: 3dtri_centerOfcircumcircle 93 | // DESCRIPTION: 94 | // Enter triangle A,B,C - corner coordinates to get the 95 | // circum circle coordinates. It is assumed 96 | // the triangle is parallel to the X-Y plane. The function 97 | // returns always zero for the z-coordinate 98 | // PARAMETER: 99 | // Acord : [x,y,z] Coordinates of vertex A 100 | // Bcord : [x,y,z] Coordinates of vertex B 101 | // Ccord : [x,y,z] Coordinates of vertex C 102 | // RETURNS: 103 | // cc : [x,y,0] Circumcircle center 104 | // 105 | // COMMENT: 106 | // vertices = 3dtri_sides2coord (3,4,5); 107 | // cc = 3dtri_centerOfcircumcircle (vertices[0],vertices[1],vertices[2]); 108 | // ------------------------------------------------------------------------------------- 109 | // 110 | function 3dtri_centerOfcircumcircle (Acord,Bcord,Ccord) = 111 | [0.5*Bcord[0], 112 | 0.5*((pow(Ccord[1],2)+pow(Ccord[0],2)-Bcord[0]*Ccord[0])/Ccord[1]), 113 | 0]; 114 | // 115 | // 116 | // 117 | // =========================================== 118 | // 119 | // FUNCTION: 3dtri_radiusOfcircumcircle 120 | // DESCRIPTION: 121 | // Provides the triangle's radius from circumcircle to the vertices. 122 | // It is assumed the triangle is parallel to the X-Y plane. The function 123 | // returns always zero for the z-coordinate 124 | // PARAMETER: 125 | // Vcord : [x,y,z] Coordinates of a vertex A or B,C 126 | // CCcord : [x,y,z] Coordinates of circumcircle 127 | // r : Radius at vertices if round corner triangle used, 128 | // else enter "0" 129 | // RETURNS: 130 | // cr : Circumcircle radius 131 | // 132 | // COMMENT: Calculate circumcircle radius of trinagle with round vertices having 133 | // radius R = 2 134 | // vertices = 3dtri_sides2coord (3,4,5); 135 | // cc = 3dtri_centerOfcircumcircle (vertices[0],vertices[1],vertices[2]); 136 | // cr = 3dtri_radiusOfcircumcircle (vertices[0],cc,2); 137 | // ------------------------------------------------------------------------------------- 138 | // 139 | function 3dtri_radiusOfcircumcircle (Vcord,CCcord,R) = 140 | sqrt(pow(CCcord[0]-Vcord[0],2)+pow(CCcord[1]-Vcord[1],2))+ R; 141 | // 142 | // 143 | // 144 | // =========================================== 145 | // 146 | // FUNCTION: 3dtri_radiusOfIn_circle 147 | // DESCRIPTION: 148 | // Enter triangle A,B,C - corner coordinates to get the 149 | // in-circle radius. It is assumed the triangle is parallel to the 150 | // X-Y plane. The function always returns zero for the z-coordinate. 151 | // Formula used for inner circle radius: r = 2A /(a+b+c) 152 | // PARAMETER: 153 | // Acord : [x,y,z] Coordinates of vertex A 154 | // Bcord : [x,y,z] Coordinates of vertex B 155 | // Ccord : [x,y,z] Coordinates of vertex C 156 | // 157 | // RETURNS: 158 | // ir : real radius of in-circle 159 | // 160 | // COMMENT: 161 | // vertices = 3dtri_sides2coord (3,4,5); 162 | // ir = 3dtri_radiusOfIn_circle (vertices[0],vertices[1],vertices[2]); 163 | // ------------------------------------------------------------------------------------- 164 | // 165 | function 3dtri_radiusOfIn_circle (Acord,Bcord,Ccord) = 166 | Bcord[0]*Ccord[1]/(Bcord[0]+sqrt(pow(Ccord[0]-Bcord[0],2)+pow(Ccord[1],2))+ 167 | sqrt(pow(Ccord[0],2)+pow(Ccord[1],2))); 168 | // 169 | // 170 | // 171 | // =========================================== 172 | // 173 | // FUNCTION: 3dtri_centerOfIn_circle 174 | // DESCRIPTION: 175 | // Enter triangle A,B,C - corner coordinates to get the 176 | // in-circle coordinates. It is assumed 177 | // the triangle is parallel to the X-Y plane. The function 178 | // returns always zero for the z-coordinate 179 | // PARAMETER: 180 | // Acord : [x,y,z] Coordinates of vertex A 181 | // Bcord : [x,y,z] Coordinates of vertex B 182 | // Ccord : [x,y,z] Coordinates of vertex C 183 | // r : real radius of in-circle 184 | // RETURNS: 185 | // ic : [x,y,0] In-circle center co-ordinates 186 | // 187 | // COMMENT: 188 | // vertices = 3dtri_sides2coord (3,4,5); 189 | // ir = 3dtri_radiusOfIn_circle (vertices[0],vertices[1],vertices[2]); 190 | // ic = 3dtri_centerOfIn_circle (vertices[0],vertices[1],vertices[2],ir); 191 | // ------------------------------------------------------------------------------------- 192 | // 193 | function 3dtri_centerOfIn_circle (Acord,Bcord,Ccord,r) = 194 | [(Bcord[0]+sqrt(pow(Ccord[0]-Bcord[0],2)+pow(Ccord[1],2))+ 195 | sqrt(pow(Ccord[0],2)+pow(Ccord[1],2)))/2-sqrt(pow(Ccord[0]-Bcord[0],2)+pow(Ccord[1],2)),r,0]; 196 | // 197 | // 198 | // ============================================ 199 | // 200 | // MODULE: 3dtri_draw 201 | // DESCRIPTION: 202 | // Draw a standard solid triangle with A,B,C - vertices specified by its 203 | // co-ordinates and height "h", as given by the input parameters. 204 | // PARAMETER: 205 | // Acord : [x,y,z] Coordinates of vertex A 206 | // Bcord : [x,y,z] Coordinates of vertex B 207 | // Ccord : [x,y,z] Coordinates of vertex C 208 | // h : real Height of the triangle 209 | // RETURNS: 210 | // none 211 | // 212 | // COMMENT: 213 | // You might use the result from function 3dtri_sides2coord 214 | // to call module 3dtri_draw ( vertices[0],vertices[1],vertices[2], h) 215 | // ------------------------------------------------------------------------------------- 216 | // 217 | module 3dtri_draw ( Acord, Bcord, Ccord, h) { 218 | polyhedron (points=[Acord,Bcord,Ccord, 219 | Acord+[0,0,h],Bcord+[0,0,h],Ccord+[0,0,h]], 220 | triangles=[ [0,1,2],[0,2,3],[3,2,5], 221 | [3,5,4],[1,5,2],[4,5,1], 222 | [4,1,0],[0,3,4]]); 223 | 224 | }; 225 | // 226 | // 227 | // ============================================== 228 | // 229 | // MODULE: 3dtri_rnd_draw 230 | // DESCRIPTION: 231 | // Draw a round corner triangle with A,B,C - vertices specified by its 232 | // co-ordinates, height h and round vertices having radius "r". 233 | // As specified by the input parameters. 234 | // Please note, the tringles side lenght gets extended by "2 * r", 235 | // and the vertices coordinates define the centers of the 236 | // circles with radius "r". 237 | // PARAMETER: 238 | // Acord : [x,y,z] Coordinates of vertex A 239 | // Bcord : [x,y,z] Coordinates of vertex B 240 | // Ccord : [x,y,z] Coordinates of vertex C 241 | // h : real Height of the triangle 242 | // r : real Radius from vertices coordinates 243 | // RETURNS: 244 | // none 245 | // 246 | // COMMENT: 247 | // You might use the result from function 3dtri_sides2coord 248 | // to call module 3dtri_rnd_draw ( vertices[0],vertices[1],vertices[2], h, r) 249 | // ------------------------------------------------------------------------------------- 250 | // 251 | module 3dtri_rnd_draw ( Acord, Bcord, Ccord, h, r) { 252 | Avect=Ccord-Bcord; // vector pointing from vertex B to vertex C 253 | p0=Acord + [0,-r,0]; 254 | p1=Bcord + [0,-r,0]; 255 | p2=Bcord + [r*Avect[1]/sqrt(pow(Avect[0],2)+pow(Avect[1],2)), 256 | -r*Avect[0]/sqrt(pow(Avect[0],2)+pow(Avect[1],2)) ,0]; 257 | p3=Ccord + [r*Avect[1]/sqrt(pow(Avect[0],2)+pow(Avect[1],2)), 258 | -r*Avect[0]/sqrt(pow(Avect[0],2)+pow(Avect[1],2)) ,0]; 259 | p4=Ccord +[- r*Ccord[1]/sqrt(pow(Ccord[0],2)+pow(Ccord[1],2)), 260 | r*Ccord[0]/sqrt(pow(Ccord[0],2)+pow(Ccord[1],2)) ,0]; 261 | p5=Acord + [- r*Ccord[1]/sqrt(pow(Ccord[0],2)+pow(Ccord[1],2)), 262 | r*Ccord[0]/sqrt(pow(Ccord[0],2)+pow(Ccord[1],2)) ,0]; 263 | bottom_triangles = [[0,1,2],[0,2,3],[0,3,4],[0,4,5]]; 264 | c_side_triangles = [[7,1,0],[0,6,7]]; 265 | a_side_triangles = [[2,8,3],[8,9,3]]; 266 | b_side_triangles = [[4,10,5],[10,11,5]]; 267 | A_edge_triangles = [[0,5,11],[0,11,6]]; 268 | B_edge_triangles = [[1,7,2],[2,7,8]]; 269 | C_edge_triangles = [[3,9,4],[9,10,4]]; 270 | top_triangles = [[11,7,6],[11,8,7],[11,10,8],[8,10,9]]; 271 | union () { 272 | polyhedron (points=[p0,p1,p2,p3,p4,p5, 273 | p0+[0,0,h],p1+[0,0,h],p2+[0,0,h],p3+[0,0,h],p4+[0,0,h],p5+[0,0,h]], 274 | triangles=[ bottom_triangles[0],bottom_triangles[1],bottom_triangles[2],bottom_triangles[3], 275 | A_edge_triangles[0],A_edge_triangles[1], 276 | c_side_triangles[0],c_side_triangles[1], 277 | B_edge_triangles[0],B_edge_triangles[1], 278 | a_side_triangles[0],a_side_triangles[1], 279 | C_edge_triangles[0],C_edge_triangles[1], 280 | b_side_triangles[0],b_side_triangles[1], 281 | top_triangles[0],top_triangles[1],top_triangles[2],top_triangles[3]]); 282 | translate(Acord) cylinder(r1=r,r2=r,h=h,center=false); 283 | translate(Bcord) cylinder(r1=r,r2=r,h=h,center=false); 284 | translate(Ccord) cylinder(r1=r,r2=r,h=h,center=false); 285 | }; 286 | } 287 | // 288 | // ============================================== 289 | // 290 | // Demo Application - copy into new file and uncomment or uncomment here but 291 | // without uncommenting the use <...> statement, then press F6 - Key 292 | // 293 | // use ; 294 | //$fn=50; 295 | // h =4; 296 | // r=2; 297 | // echo ("Draws a right angle triangle with its circumcircle and in-circle"); 298 | // echo ("The calculated co-ordinates and radius are show in this console window"); 299 | // echo ("Geometry rules for a right angle triangle say, that the circumcircle is the"); 300 | // echo ("Thales Circle which center must be in the middle of the triangle's c - side"); 301 | // echo ("==========================================="); 302 | // vertices = 3dtri_sides2coord (30,40,50); 303 | // echo("A = ",vertices[0]," B = ",vertices[1]," C = ",vertices[2]); 304 | // cg = 3dtri_centerOfGravityCoord (vertices[0],vertices[1],vertices[2]); 305 | // echo (" Center of gravity = ",cg); 306 | // cc = 3dtri_centerOfcircumcircle (vertices[0],vertices[1],vertices[2]); 307 | // echo (" Center of circumcircle = ",cc); 308 | // cr = 3dtri_radiusOfcircumcircle (vertices[0],cc,r); 309 | // echo(" Radius of circumcircle ",cr); 310 | // ir = 3dtri_radiusOfIn_circle (vertices[0],vertices[1],vertices[2]); 311 | // echo (" Radius of in-circle = ",ir); 312 | // ic = 3dtri_centerOfIn_circle (vertices[0],vertices[1],vertices[2],ir); 313 | // echo (" Center of in-circle = ",ic); 314 | // translate(cc+[0,0,5*h/2]) difference () { 315 | // cylinder (h=5*h,r1=cr+4,r2=cr+4,center=true); 316 | // cylinder (h=6*h,r1=cr,r2=cr,center=true);} 317 | // difference () { 318 | // union () { 319 | // difference () { 320 | // 3dtri_rnd_draw (vertices[0], vertices[1], vertices[2],5*h,r); 321 | // scale([0.8,0.8,1]) translate([6,2,4*h]) 3dtri_rnd_draw (vertices[0], vertices[1], vertices[2],5*h,r); 322 | // } 323 | // translate (ic+[0,0,5*h]) cylinder(h=10*h,r1=ir+r,r2=ir+r,center=true); 324 | // } 325 | // translate (ic+[0,0,5*h]) cylinder(h=12*h,r1=0.5*ir,r2=0.5*ir,center=true); 326 | // } 327 | 328 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | OpenSCAD MCAD Library 2 | ===================== 3 | 4 | This library contains components commonly used in designing and mocking up 5 | mechanical designs. It is currently unfinished and you can expect some API 6 | changes, however many things are already working. 7 | 8 | This library was created by various authors as named in the individual 9 | files' comments. All the files are licensed under the LGPL 2.1 (see 10 | http://creativecommons.org/licenses/LGPL/2.1/ or the included file 11 | lgpl-2.1.txt), some of them allow distribution under more permissive 12 | terms (as described in the files' comments). 13 | 14 | ## Usage ## 15 | 16 | You can import these files in your scripts with `use `, 17 | where 'filename' is one of the files listed below like 'motors' or 18 | 'servos'. Some files include useful constants which will be available 19 | with `include `, which should be safe to use on all 20 | included files (ie. no top level code should create geometry). (There is 21 | a bug/feature that prevents including constants from files that 22 | "include" other files - see the openscad mailing list archives for more 23 | details. Since the maintainers aren't very responsive, may have to work 24 | around this somehow) 25 | 26 | If you host your project in git, you can do `git submodule add URL PATH` in your 27 | repo to import this library as a git submodule for easy usage. Then you need to do 28 | a `git submodule update --init` after cloning. When you want to update the submodule, 29 | do `cd PATH; git checkout master; git pull`. See `git help submodule` for more info. 30 | 31 | Currently Provided Tools: 32 | 33 | * regular_shapes.scad 34 | - regular polygons, ie. 2D 35 | - regular polyhedrons, ie. 3D 36 | 37 | * involute_gears.scad (http://www.thingiverse.com/thing:3575): 38 | - gear() 39 | - bevel_gear() 40 | - bevel_gear_pair() 41 | 42 | * gears.scad (Old version): 43 | - gear(number_of_teeth, circular_pitch OR diametrial_pitch, pressure_angle OPTIONAL, clearance OPTIONAL) 44 | 45 | * motors.scad: 46 | - stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL) 47 | 48 | Tools (alpha and beta quality): 49 | 50 | * nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes 51 | * bearing.scad: standard/custom bearings 52 | * screw.scad: screws and augers 53 | * materials.scad: color definitions for different materials 54 | * stepper.scad: NEMA standard stepper outlines 55 | * servos.scad: servo outlines 56 | * boxes.scad: box with rounded corners 57 | * triangles.scad: simple triangles 58 | * 3d_triangle.scad: more advanced triangles 59 | 60 | Very generally useful functions and constants: 61 | 62 | * math.scad: general math functions 63 | * constants.scad: mathematical constants 64 | * curves.scad: mathematical functions defining curves 65 | * units.scad: easy metric units 66 | * utilities.scad: geometric funtions and misc. useful stuff 67 | * teardrop.scad (http://www.thingiverse.com/thing:3457): parametric teardrop module 68 | * shapes.scad: DEPRECATED simple shapes by Catarina Mota 69 | * polyholes.scad: holes that should come out well when printed 70 | 71 | Other: 72 | 73 | * alphabet_block.scad 74 | * bitmap.scad 75 | * letter_necklace.scad 76 | * name_tag.scad 77 | * height_map.scad 78 | * trochoids.scad 79 | * libtriangles.scad 80 | * layouts.scad 81 | * transformations.scad 82 | * 2Dshapes.scad 83 | * gridbeam.scad 84 | * fonts.scad 85 | * unregular_shapes.scad 86 | * metric_fastners.scad 87 | * lego_compatibility.scad 88 | * multiply.scad 89 | * hardware.scad 90 | 91 | External utils that generate and process openscad code: 92 | 93 | * openscad_testing.py: testing code, see below 94 | * openscad_utils.py: code for scraping function names etc. 95 | 96 | ## Development ## 97 | 98 | You are welcome to fork this project in github and request pulls. I will try to 99 | accomodate the community as much as possible in this. If for some reason you 100 | want collaborator access, just ask. 101 | 102 | Github is fun (and easy), but I can include code submissions and other 103 | improvements directly, and have already included code from various sources 104 | (thingiverse is great :) 105 | 106 | ### Code style ### 107 | I'd prefer to have all included code nicely indented, at least at the block 108 | level, and no extraneous whitespace. I'm used to indent with four spaces as 109 | opposed to tabs or other mixes of whitespace, but at least try to choose a style 110 | and stick to it. 111 | 112 | ### Testing ### 113 | I've started a minimal testing infrastucture for OpenSCAD code. It's written in 114 | python and uses py.test (might be compatible with Nose also). Just type `py.test` 115 | inside the lib dir in a terminal and you should see a part of the tests passing 116 | and tracebacks for failing tests. It's very simplistic still, but it should test 117 | that no syntax errors occur at least. 118 | 119 | The code is included in openscad_testing.py, and can be imported to be 120 | used in other codebases. 121 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Code that could be integrated: 2 | * http://github.com/l0b0/qr2scad 3 | * http://github.com/l0b0/img2scad 4 | * http://github.com/l0b0/OpenSCAD-Minimizer 5 | * http://www.thingiverse.com/thing:4656 6 | * http://www.thingiverse.com/thing:4758 7 | * http://www.thingiverse.com/thing:6021 8 | * Color library: http://www.thingiverse.com/thing:6717 9 | * http://www.thingiverse.com/thing:6465 10 | 11 | Integrate these better: 12 | * bitmap 13 | 14 | Testing: 15 | * add tests for openscad functions 16 | * motors.scad 17 | * tests for 2D stuff 18 | 19 | Code style: 20 | * motors.scad 21 | * nuts_and_bolts.scad 22 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openscad/MCAD/bd0a7ba3f042bfbced5ca1894b236cea08904e26/__init__.py -------------------------------------------------------------------------------- /array.scad: -------------------------------------------------------------------------------- 1 | // array functions 2 | // by david powell 3 | // licence LGPL V2 or later 4 | // 5 | // this lib provides 2 functions 6 | // Cubic_Array() , and Radial_Array() 7 | // 8 | //Cubic_Array(sx,sy,sz,nx,ny,nz,center){childobject} 9 | // produces a cubic grid of child objects 10 | // sx,sy,sz = spacing for each axis 11 | // nx,ny,nz and number of objects on each axis 12 | // center = true/false on if geometery is centered or not 13 | // 14 | // 15 | //Radial_Array(a,n,r){child object} 16 | // produces a clockwise radial array of child objects rotated around the local z axis 17 | // a= interval angle 18 | // n= number of objects 19 | // r= radius distance 20 | // 21 | // remove // from following line to run test 22 | //Cubic_and_Radial_Array_Test(); 23 | 24 | module Cubic_and_Radial_Array_Test() 25 | { 26 | //center referance point 27 | translate([0,0,0]) 28 | #cube([5,5,5],center=true); 29 | 30 | //cubic array of 5*5*5 objects spaced 10*10*10 center relative 31 | Cubic_Array(10,10,10,5,5,5,center=true) 32 | { 33 | sphere(2.5,$fn=60); 34 | cylinder(h=10,r=.5,center=true); 35 | rotate([90,0,0]) 36 | cylinder(h=10,r=.5,center=true); 37 | rotate([0,90,0]) 38 | cylinder(h=10,r=.5,center=true); 39 | } 40 | 41 | //a linear array allong x can be derived from the cubic array simply 42 | translate([60,0,0]) 43 | Cubic_Array(10,0,0,5,1,1,center=false) 44 | { 45 | cube([5,5,5],center=true); 46 | } 47 | //a linear array allong y can be derived from the cubic array simply 48 | translate([0,60,0]) 49 | Cubic_Array(0,10,0,1,5,1,center=false) 50 | { 51 | cube([5,5,5],center=true); 52 | } 53 | 54 | //a linear array allong z can be derived from the cubic array simply 55 | translate([0,0,60]) 56 | Cubic_Array(0,0,10,1,1,5,center=false) 57 | { 58 | cube([5,5,5],center=true); 59 | } 60 | 61 | //a grid array allong x,y can be derived from the cubic array simply 62 | translate([0,0,-60]) 63 | Cubic_Array(10,10,0,5,5,1,center=true) 64 | { 65 | cube([5,5,5],center=true); 66 | } 67 | 68 | //radial array of 32 objects rotated though 10 degrees 69 | translate([0,0,0]) 70 | Radial_Array(10,32,40) 71 | { 72 | cube([2,4,6],center=true); 73 | } 74 | 75 | // a radial array of linear arrays 76 | 77 | rotate([45,45,45]) 78 | Radial_Array(10,36,40) 79 | { 80 | translate([0,10,0]) 81 | Cubic_Array(0,10,0,1,5,1,center=false) 82 | { 83 | cube([2,3,4],center=true); 84 | cylinder(h=10,r=.5,center=true); 85 | rotate([90,0,0]) 86 | cylinder(h=10,r=.5,center=true); 87 | } 88 | } 89 | 90 | } 91 | 92 | 93 | // main lib modules 94 | module Cubic_Array(sx,sy,sz,nx,ny,nz,center) { 95 | offset = center ? [-(((nx+1)*sx)/2),-(((ny+1)*sy)/2),-(((nz+1)*sz)/2)] : [0,0,0]; 96 | translate(offset) 97 | for(x=[1:nx], y=[1:ny], z=[1:nz]) 98 | translate([x*sx,y*sy,z*sz]) 99 | children(); 100 | } 101 | 102 | // 103 | //Radial_Array(a,n,r){child object} 104 | // produces a clockwise radial array of child objects rotated around the local z axis 105 | // a= interval angle 106 | // n= number of objects 107 | // r= radius distance 108 | // 109 | module Radial_Array(a,n,r){ 110 | for (k=[0:n-1]) 111 | rotate([0,0,-(a*k)]) 112 | translate([0,r,0]) 113 | children(); 114 | } 115 | -------------------------------------------------------------------------------- /bearing.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * Bearing model. 3 | * 4 | * Originally by Hans Häggström, 2010. 5 | * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later 6 | */ 7 | 8 | /* 9 | change list 13/6/2013 10 | added ,604,606,607,628,629,6200,6201,6202,6203,6205,6206 bearing sizes 11 | */ 12 | 13 | include 14 | include 15 | 16 | // Example, uncomment to view 17 | //test_bearing(); 18 | //test_bearing_hole(); 19 | 20 | module test_bearing(){ 21 | bearing(); 22 | bearing(pos=[5*cm, 0,0], angle=[90,0,0]); 23 | bearing(pos=[-2.5*cm, 0,0], model=688); 24 | } 25 | 26 | module test_bearing_hole(){ 27 | difference(){ 28 | cube(size=[30, 30, 7-10*epsilon], center=true); 29 | bearing(outline=true, center=true); 30 | } 31 | } 32 | 33 | BEARING_INNER_DIAMETER = 0; 34 | BEARING_OUTER_DIAMETER = 1; 35 | BEARING_WIDTH = 2; 36 | 37 | // Common bearing names 38 | SkateBearing = 608; 39 | 40 | // Bearing dimensions 41 | // model == XXX ? [inner dia, outer dia, width]: 42 | // http://www.gizmology.net/bearings.htm has some valuable information on that 43 | // https://www.bearingworks.com/bearing-sizes has a very exhaustive table of dimensions 44 | function bearingDimensions(model) = 45 | model == 603 ? [3*mm, 9*mm, 5*mm]: 46 | model == 604 ? [4*mm, 12*mm, 4*mm]: 47 | model == 605 ? [5*mm, 14*mm, 5*mm]: 48 | model == 606 ? [6*mm, 17*mm, 6*mm]: 49 | model == 607 ? [7*mm, 19*mm, 6*mm]: 50 | model == 608 ? [8*mm, 22*mm, 7*mm]: 51 | model == 609 ? [9*mm, 24*mm, 7*mm]: 52 | 53 | model == 623 ? [3*mm, 10*mm, 4*mm]: 54 | model == 624 ? [4*mm, 13*mm, 5*mm]: 55 | model == 625 ? [5*mm, 16*mm, 5*mm]: 56 | model == 626 ? [6*mm, 19*mm, 6*mm]: 57 | model == 627 ? [7*mm, 22*mm, 7*mm]: 58 | model == 628 ? [8*mm, 24*mm, 8*mm]: 59 | model == 629 ? [9*mm, 26*mm, 8*mm]: 60 | 61 | model == 633 ? [3*mm, 13*mm, 5*mm]: 62 | model == 634 ? [4*mm, 16*mm, 5*mm]: 63 | model == 635 ? [5*mm, 19*mm, 6*mm]: 64 | model == 636 ? [6*mm, 22*mm, 7*mm]: 65 | model == 637 ? [7*mm, 26*mm, 9*mm]: 66 | model == 638 ? [8*mm, 28*mm, 9*mm]: 67 | model == 639 ? [9*mm, 30*mm, 10*mm]: 68 | 69 | model == 673 ? [3*mm, 6*mm, 2.5*mm]: 70 | model == 674 ? [4*mm, 7*mm, 2.5*mm]: 71 | model == 675 ? [5*mm, 8*mm, 2.5*mm]: 72 | model == 676 ? [6*mm, 10*mm, 3*mm]: 73 | model == 677 ? [7*mm, 11*mm, 3*mm]: 74 | model == 678 ? [8*mm, 12*mm, 3.5*mm]: 75 | 76 | model == 683 ? [3*mm, 7*mm, 3*mm]: 77 | model == 684 ? [4*mm, 9*mm, 4*mm]: 78 | model == 685 ? [5*mm, 11*mm, 5*mm]: 79 | model == 686 ? [6*mm, 13*mm, 5*mm]: 80 | model == 687 ? [7*mm, 14*mm, 5*mm]: 81 | model == 688 ? [8*mm, 16*mm, 5*mm]: 82 | model == 689 ? [9*mm, 17*mm, 5*mm]: 83 | 84 | model == 692 ? [2*mm, 6*mm, 3*mm]: 85 | model == 693 ? [3*mm, 8*mm, 4*mm]: 86 | model == 694 ? [4*mm, 11*mm, 4*mm]: 87 | model == 695 ? [5*mm, 13*mm, 4*mm]: 88 | model == 696 ? [6*mm, 15*mm, 5*mm]: 89 | model == 697 ? [7*mm, 17*mm, 5*mm]: 90 | model == 698 ? [8*mm, 19*mm, 6*mm]: 91 | model == 699 ? [9*mm, 20*mm, 6*mm]: 92 | 93 | model == 6000 ? [10*mm, 26*mm, 8*mm]: 94 | model == 6001 ? [12*mm, 28*mm, 8*mm]: 95 | model == 6002 ? [15*mm, 32*mm, 9*mm]: 96 | model == 6003 ? [17*mm, 35*mm, 10*mm]: 97 | model == 6004 ? [20*mm, 42*mm, 12*mm]: 98 | model == 6005 ? [25*mm, 47*mm, 12*mm]: 99 | model == 6006 ? [30*mm, 55*mm, 13*mm]: 100 | model == 6007 ? [35*mm, 62*mm, 14*mm]: 101 | model == 6008 ? [40*mm, 68*mm, 15*mm]: 102 | model == 6009 ? [45*mm, 75*mm, 16*mm]: 103 | model == 6010 ? [50*mm, 80*mm, 16*mm]: 104 | model == 6011 ? [55*mm, 90*mm, 18*mm]: 105 | model == 6012 ? [60*mm, 95*mm, 18*mm]: 106 | model == 6013 ? [65*mm, 100*mm, 18*mm]: 107 | model == 6014 ? [70*mm, 110*mm, 20*mm]: 108 | model == 6015 ? [75*mm, 115*mm, 20*mm]: 109 | 110 | model == 6200 ? [10*mm, 30*mm, 9*mm]: 111 | model == 6201 ? [12*mm, 32*mm, 10*mm]: 112 | model == 6202 ? [15*mm, 35*mm, 11*mm]: 113 | model == 6203 ? [17*mm, 40*mm, 12*mm]: 114 | model == 6204 ? [20*mm, 47*mm, 14*mm]: 115 | model == 6205 ? [25*mm, 52*mm, 15*mm]: 116 | model == 6206 ? [30*mm, 62*mm, 16*mm]: 117 | model == 6207 ? [35*mm, 72*mm, 17*mm]: 118 | model == 6208 ? [40*mm, 80*mm, 18*mm]: 119 | model == 6209 ? [45*mm, 85*mm, 19*mm]: 120 | 121 | model == 6300 ? [10*mm, 35*mm, 11*mm]: 122 | model == 6301 ? [12*mm, 37*mm, 12*mm]: 123 | model == 6302 ? [15*mm, 42*mm, 13*mm]: 124 | model == 6303 ? [17*mm, 47*mm, 14*mm]: 125 | model == 6304 ? [20*mm, 52*mm, 15*mm]: 126 | model == 6305 ? [25*mm, 62*mm, 17*mm]: 127 | model == 6306 ? [30*mm, 72*mm, 19*mm]: 128 | model == 6307 ? [35*mm, 80*mm, 21*mm]: 129 | model == 6308 ? [40*mm, 90*mm, 23*mm]: 130 | model == 6309 ? [45*mm, 100*mm, 25*mm]: 131 | model == 6310 ? [50*mm, 110*mm, 27*mm]: 132 | model == 6311 ? [55*mm, 120*mm, 29*mm]: 133 | model == 6312 ? [60*mm, 130*mm, 31*mm]: 134 | model == 6313 ? [65*mm, 140*mm, 33*mm]: 135 | model == 6314 ? [70*mm, 150*mm, 35*mm]: 136 | model == 6315 ? [75*mm, 160*mm, 37*mm]: 137 | 138 | model == 6700 ? [10*mm, 15*mm, 4*mm]: 139 | model == 6701 ? [12*mm, 18*mm, 4*mm]: 140 | 141 | model == 6808 ? [40*mm, 52*mm, 7*mm]: 142 | 143 | model == 6900 ? [10*mm, 22*mm, 6*mm]: 144 | model == 6901 ? [12*mm, 24*mm, 6*mm]: 145 | model == 6902 ? [15*mm, 28*mm, 7*mm]: 146 | model == 6903 ? [17*mm, 30*mm, 7*mm]: 147 | model == 6904 ? [20*mm, 37*mm, 9*mm]: 148 | model == 6905 ? [25*mm, 42*mm, 9*mm]: 149 | 150 | model == "LM12" ? [12*mm, 21*mm, 30*mm]: 151 | 152 | model == "MR52" ? [2*mm, 5*mm, 2.5*mm]: 153 | model == "MR62" ? [2*mm, 6*mm, 2.5*mm]: 154 | model == "MR63" ? [3*mm, 6*mm, 2.5*mm]: 155 | model == "MR72" ? [2*mm, 7*mm, 3*mm]: 156 | model == "MR74" ? [4*mm, 7*mm, 2.5*mm]: 157 | model == "MR83" ? [3*mm, 8*mm, 3*mm]: 158 | model == "MR84" ? [4*mm, 8*mm, 3*mm]: 159 | model == "MR85" ? [5*mm, 8*mm, 2.5*mm]: 160 | model == "MR93" ? [3*mm, 9*mm, 4*mm]: 161 | model == "MR95" ? [5*mm, 9*mm, 3*mm]: 162 | model == "MR104" ? [4*mm, 10*mm, 4*mm]: 163 | model == "MR105" ? [5*mm, 10*mm, 4*mm]: 164 | model == "MR106" ? [6*mm, 10*mm, 3*mm]: 165 | model == "MR115" ? [5*mm, 11*mm, 4*mm]: 166 | model == "MR117" ? [7*mm, 11*mm, 3*mm]: 167 | model == "MR126" ? [6*mm, 12*mm, 4*mm]: 168 | model == "MR128" ? [8*mm, 12*mm, 3.5*mm]: 169 | model == "MR137" ? [7*mm, 13*mm, 4*mm]: 170 | model == "MR148" ? [8*mm, 14*mm, 4*mm]: 171 | model == "MR149" ? [9*mm, 14*mm, 4.5*mm]: 172 | [8*mm, 22*mm, 7*mm]; // this is the default 173 | 174 | 175 | function bearingWidth(model) = bearingDimensions(model)[BEARING_WIDTH]; 176 | function bearingInnerDiameter(model) = bearingDimensions(model)[BEARING_INNER_DIAMETER]; 177 | function bearingOuterDiameter(model) = bearingDimensions(model)[BEARING_OUTER_DIAMETER]; 178 | 179 | module bearing(pos=[0,0,0], angle=[0,0,0], model=SkateBearing, outline=false, 180 | material=Steel, sideMaterial=Brass, center=false) { 181 | // Common bearing names 182 | model = 183 | model == "Skate" ? 608 : 184 | model; 185 | 186 | w = bearingWidth(model); 187 | innerD = outline==false ? bearingInnerDiameter(model) : 0; 188 | outerD = bearingOuterDiameter(model); 189 | 190 | innerRim = innerD + (outerD - innerD) * 0.2; 191 | outerRim = outerD - (outerD - innerD) * 0.2; 192 | midSink = w * 0.1; 193 | newpos = [pos[0], pos[1], center ? pos[2]-(w/2) : pos[2]]; 194 | 195 | translate(newpos) rotate(angle) union() { 196 | color(material) 197 | difference() { 198 | // Basic ring 199 | Ring([0,0,0], outerD, innerD, w, material, material); 200 | 201 | if (outline==false) { 202 | // Side shields 203 | Ring([0,0,-epsilon], outerRim, innerRim, epsilon+midSink, sideMaterial, material); 204 | Ring([0,0,w-midSink], outerRim, innerRim, epsilon+midSink, sideMaterial, material); 205 | } 206 | } 207 | } 208 | 209 | module Ring(pos, od, id, h, material, holeMaterial) { 210 | color(material) { 211 | translate(pos) 212 | difference() { 213 | cylinder(r=od/2, h=h, $fs = 0.01); 214 | color(holeMaterial) 215 | translate([0,0,-10*epsilon]) 216 | cylinder(r=id/2, h=h+20*epsilon, $fs = 0.01); 217 | } 218 | } 219 | } 220 | 221 | } 222 | 223 | 224 | -------------------------------------------------------------------------------- /bitmap/README: -------------------------------------------------------------------------------- 1 | This is an OpenSCAD module that let's you easily (well kinda) create 3D text. I've emulated the Atari 8-Bit fonts A-Z, a-z, 0-9, and most punctuation. You can create them a letter at a time or pass an array of characters. (OpenSCAD doesn't have any real string manipulation) 2 | 3 | It also has a bitmap module that you can use to define your own fonts. It's pretty simple, you pass it an array of numbers, then tell it how many bits per row and it creates cubes (of configurable width and height) in a grid and combines them into a single shape. The number in the array sets the pixel height modifier. So if you set height to 5 and the array value is 2, then the height of that pixel will be 10mm. 4 | 5 | Be careful when defining your own bitmaps in that you can't have two bits only connected diagonally. Otherwise OpenSCAD will say it's not manifold. For instance you can't have: 6 | 7 | 0 0 0 8 | 0 1 0 9 | 0 0 1 10 | 11 | But you can have: 12 | 13 | 0 0 0 14 | 0 1 1 15 | 0 0 1 16 | 17 | For more info see: http://www.thingiverse.com/thing:2054 18 | -------------------------------------------------------------------------------- /bitmap/alphabet_block.scad: -------------------------------------------------------------------------------- 1 | /* 2 | Parametric Alphabet Block 3 | Tony Buser 4 | http://tonybuser.com 5 | http://creativecommons.org/licenses/by/3.0/ 6 | */ 7 | 8 | use 9 | 10 | // change to any letter 11 | letter = "A"; 12 | 13 | union() { 14 | difference() { 15 | cube(size = 20); 16 | translate(v = [2, 2, 17]) { 17 | cube(size = [16, 16, 5]); 18 | } 19 | } 20 | 21 | translate(v = [10, 10, 15]) { 22 | 8bit_char(letter, 2, 5); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /bitmap/bitmap.scad: -------------------------------------------------------------------------------- 1 | /* 2 | Bitmap and 8Bit Font Module 3 | Tony Buser 4 | http://tonybuser.com 5 | http://creativecommons.org/licenses/by/3.0/ 6 | */ 7 | 8 | module bitmap(bitmap, block_size, height, row_size) { 9 | width = block_size * row_size; 10 | bitmap_size = row_size * row_size; 11 | 12 | function loc_x(loc) = floor(loc / row_size) * block_size; 13 | function loc_y(loc) = loc % row_size * block_size; 14 | function loc_z(loc) = (bitmap[loc]*height-height)/2; 15 | 16 | translate(v = [-width/2+block_size/2,-width/2+block_size/2,height/2]) { 17 | for (loc = [0:bitmap_size - 1]) { 18 | if (bitmap[loc] != 0) { 19 | union() { 20 | translate(v = [loc_x(loc), loc_y(loc), loc_z(loc)]) { 21 | cube(size = [block_size, block_size, height * bitmap[loc]], center = true); 22 | } 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | module 8bit_char(char, block_size, height, include_base) { 30 | if (char == "0") { 31 | bitmap([ 32 | 0,0,0,0,0,0,0,0, 33 | 0,0,1,1,1,1,0,0, 34 | 0,1,1,0,0,1,1,0, 35 | 0,1,1,0,1,1,1,0, 36 | 0,1,1,1,1,1,1,0, 37 | 0,1,1,0,0,1,1,0, 38 | 0,0,1,1,1,1,0,0, 39 | 0,0,0,0,0,0,0,0 40 | ], block_size, height, 8); 41 | } else if (char == "1") { 42 | bitmap([ 43 | 0,0,0,0,0,0,0,0, 44 | 0,0,0,1,1,0,0,0, 45 | 0,0,1,1,1,0,0,0, 46 | 0,0,0,1,1,0,0,0, 47 | 0,0,0,1,1,0,0,0, 48 | 0,0,0,1,1,0,0,0, 49 | 0,1,1,1,1,1,1,0, 50 | 0,0,0,0,0,0,0,0 51 | ], block_size, height, 8); 52 | } else if (char == "2") { 53 | bitmap([ 54 | 0,0,0,0,0,0,0,0, 55 | 0,0,1,1,1,1,0,0, 56 | 0,1,1,0,0,1,1,0, 57 | 0,0,0,0,1,1,0,0, 58 | 0,0,0,1,1,0,0,0, 59 | 0,0,1,1,0,0,0,0, 60 | 0,1,1,1,1,1,1,0, 61 | 0,0,0,0,0,0,0,0 62 | ], block_size, height, 8); 63 | } else if (char == "3") { 64 | bitmap([ 65 | 0,0,0,0,0,0,0,0, 66 | 0,1,1,1,1,1,1,0, 67 | 0,0,0,0,1,1,0,0, 68 | 0,0,0,1,1,0,0,0, 69 | 0,0,0,0,1,1,0,0, 70 | 0,1,1,0,0,1,1,0, 71 | 0,0,1,1,1,1,0,0, 72 | 0,0,0,0,0,0,0,0 73 | ], block_size, height, 8); 74 | } else if (char == "4") { 75 | bitmap([ 76 | 0,0,0,0,0,0,0,0, 77 | 0,0,0,0,1,1,0,0, 78 | 0,0,0,1,1,1,0,0, 79 | 0,0,1,1,1,1,0,0, 80 | 0,1,1,0,1,1,0,0, 81 | 0,1,1,1,1,1,1,0, 82 | 0,0,0,0,1,1,0,0, 83 | 0,0,0,0,0,0,0,0 84 | ], block_size, height, 8); 85 | } else if (char == "5") { 86 | bitmap([ 87 | 0,0,0,0,0,0,0,0, 88 | 0,1,1,1,1,1,1,0, 89 | 0,1,1,0,0,0,0,0, 90 | 0,1,1,1,1,1,0,0, 91 | 0,0,0,0,0,1,1,0, 92 | 0,1,1,0,0,1,1,0, 93 | 0,0,1,1,1,1,0,0, 94 | 0,0,0,0,0,0,0,0 95 | ], block_size, height, 8); 96 | } else if (char == "6") { 97 | bitmap([ 98 | 0,0,0,0,0,0,0,0, 99 | 0,0,1,1,1,1,0,0, 100 | 0,1,1,0,0,0,0,0, 101 | 0,1,1,1,1,1,0,0, 102 | 0,1,1,0,0,1,1,0, 103 | 0,1,1,0,0,1,1,0, 104 | 0,0,1,1,1,1,0,0, 105 | 0,0,0,0,0,0,0,0 106 | ], block_size, height, 8); 107 | } else if (char == "7") { 108 | bitmap([ 109 | 0,0,0,0,0,0,0,0, 110 | 0,1,1,1,1,1,1,0, 111 | 0,0,0,0,0,1,1,0, 112 | 0,0,0,0,1,1,0,0, 113 | 0,0,0,1,1,0,0,0, 114 | 0,0,1,1,0,0,0,0, 115 | 0,0,1,1,0,0,0,0, 116 | 0,0,0,0,0,0,0,0 117 | ], block_size, height, 8); 118 | } else if (char == "8") { 119 | bitmap([ 120 | 0,0,0,0,0,0,0,0, 121 | 0,0,1,1,1,1,0,0, 122 | 0,1,1,0,0,1,1,0, 123 | 0,0,1,1,1,1,0,0, 124 | 0,1,1,0,0,1,1,0, 125 | 0,1,1,0,0,1,1,0, 126 | 0,0,1,1,1,1,0,0, 127 | 0,0,0,0,0,0,0,0 128 | ], block_size, height, 8); 129 | } else if (char == "9") { 130 | bitmap([ 131 | 0,0,0,0,0,0,0,0, 132 | 0,0,1,1,1,1,0,0, 133 | 0,1,1,0,0,1,1,0, 134 | 0,0,1,1,1,1,1,0, 135 | 0,0,0,0,0,1,1,0, 136 | 0,0,0,0,1,1,0,0, 137 | 0,0,1,1,1,0,0,0, 138 | 0,0,0,0,0,0,0,0 139 | ], block_size, height, 8); 140 | } else if (char == "A") { 141 | bitmap([ 142 | 0,0,0,0,0,0,0,0, 143 | 0,0,0,1,1,0,0,0, 144 | 0,0,1,1,1,1,0,0, 145 | 0,1,1,0,0,1,1,0, 146 | 0,1,1,0,0,1,1,0, 147 | 0,1,1,1,1,1,1,0, 148 | 0,1,1,0,0,1,1,0, 149 | 0,0,0,0,0,0,0,0 150 | ], block_size, height, 8); 151 | } else if (char == "B") { 152 | bitmap([ 153 | 0,0,0,0,0,0,0,0, 154 | 0,1,1,1,1,1,0,0, 155 | 0,1,1,0,0,1,1,0, 156 | 0,1,1,1,1,1,0,0, 157 | 0,1,1,0,0,1,1,0, 158 | 0,1,1,0,0,1,1,0, 159 | 0,1,1,1,1,1,0,0, 160 | 0,0,0,0,0,0,0,0 161 | ], block_size, height, 8); 162 | } else if (char == "C") { 163 | bitmap([ 164 | 0,0,0,0,0,0,0,0, 165 | 0,0,1,1,1,1,0,0, 166 | 0,1,1,0,0,1,1,0, 167 | 0,1,1,0,0,0,0,0, 168 | 0,1,1,0,0,0,0,0, 169 | 0,1,1,0,0,1,1,0, 170 | 0,0,1,1,1,1,0,0, 171 | 0,0,0,0,0,0,0,0 172 | ], block_size, height, 8); 173 | } else if (char == "D") { 174 | bitmap([ 175 | 0,0,0,0,0,0,0,0, 176 | 0,1,1,1,1,0,0,0, 177 | 0,1,1,0,1,1,0,0, 178 | 0,1,1,0,0,1,1,0, 179 | 0,1,1,0,0,1,1,0, 180 | 0,1,1,0,1,1,0,0, 181 | 0,1,1,1,1,0,0,0, 182 | 0,0,0,0,0,0,0,0 183 | ], block_size, height, 8); 184 | } else if (char == "E") { 185 | bitmap([ 186 | 0,0,0,0,0,0,0,0, 187 | 0,1,1,1,1,1,1,0, 188 | 0,1,1,0,0,0,0,0, 189 | 0,1,1,1,1,1,0,0, 190 | 0,1,1,0,0,0,0,0, 191 | 0,1,1,0,0,0,0,0, 192 | 0,1,1,1,1,1,1,0, 193 | 0,0,0,0,0,0,0,0 194 | ], block_size, height, 8); 195 | } else if (char == "F") { 196 | bitmap([ 197 | 0,0,0,0,0,0,0,0, 198 | 0,1,1,1,1,1,1,0, 199 | 0,1,1,0,0,0,0,0, 200 | 0,1,1,1,1,1,0,0, 201 | 0,1,1,0,0,0,0,0, 202 | 0,1,1,0,0,0,0,0, 203 | 0,1,1,0,0,0,0,0, 204 | 0,0,0,0,0,0,0,0 205 | ], block_size, height, 8); 206 | } else if (char == "G") { 207 | bitmap([ 208 | 0,0,0,0,0,0,0,0, 209 | 0,0,1,1,1,1,1,0, 210 | 0,1,1,0,0,0,0,0, 211 | 0,1,1,0,0,0,0,0, 212 | 0,1,1,0,1,1,1,0, 213 | 0,1,1,0,0,1,1,0, 214 | 0,0,1,1,1,1,1,0, 215 | 0,0,0,0,0,0,0,0 216 | ], block_size, height, 8); 217 | } else if (char == "H") { 218 | bitmap([ 219 | 0,0,0,0,0,0,0,0, 220 | 0,1,1,0,0,1,1,0, 221 | 0,1,1,0,0,1,1,0, 222 | 0,1,1,1,1,1,1,0, 223 | 0,1,1,0,0,1,1,0, 224 | 0,1,1,0,0,1,1,0, 225 | 0,1,1,0,0,1,1,0, 226 | 0,0,0,0,0,0,0,0 227 | ], block_size, height, 8); 228 | } else if (char == "I") { 229 | bitmap([ 230 | 0,0,0,0,0,0,0,0, 231 | 0,1,1,1,1,1,1,0, 232 | 0,0,0,1,1,0,0,0, 233 | 0,0,0,1,1,0,0,0, 234 | 0,0,0,1,1,0,0,0, 235 | 0,0,0,1,1,0,0,0, 236 | 0,1,1,1,1,1,1,0, 237 | 0,0,0,0,0,0,0,0 238 | ], block_size, height, 8); 239 | } else if (char == "J") { 240 | bitmap([ 241 | 0,0,0,0,0,0,0,0, 242 | 0,0,0,0,1,1,1,0, 243 | 0,0,0,0,0,1,1,0, 244 | 0,0,0,0,0,1,1,0, 245 | 0,0,0,0,0,1,1,0, 246 | 0,1,1,0,0,1,1,0, 247 | 0,0,1,1,1,1,0,0, 248 | 0,0,0,0,0,0,0,0 249 | ], block_size, height, 8); 250 | } else if (char == "K") { 251 | bitmap([ 252 | 0,0,0,0,0,0,0,0, 253 | 0,1,1,0,0,1,1,0, 254 | 0,1,1,0,1,1,0,0, 255 | 0,1,1,1,1,0,0,0, 256 | 0,1,1,1,1,0,0,0, 257 | 0,1,1,0,1,1,0,0, 258 | 0,1,1,0,0,1,1,0, 259 | 0,0,0,0,0,0,0,0 260 | ], block_size, height, 8); 261 | } else if (char == "L") { 262 | bitmap([ 263 | 0,0,0,0,0,0,0,0, 264 | 0,1,1,0,0,0,0,0, 265 | 0,1,1,0,0,0,0,0, 266 | 0,1,1,0,0,0,0,0, 267 | 0,1,1,0,0,0,0,0, 268 | 0,1,1,0,0,0,0,0, 269 | 0,1,1,1,1,1,1,0, 270 | 0,0,0,0,0,0,0,0 271 | ], block_size, height, 8); 272 | } else if (char == "M") { 273 | bitmap([ 274 | 0,0,0,0,0,0,0,0, 275 | 0,1,1,0,0,0,1,1, 276 | 0,1,1,1,0,1,1,1, 277 | 0,1,1,1,1,1,1,1, 278 | 0,1,1,0,1,0,1,1, 279 | 0,1,1,0,0,0,1,1, 280 | 0,1,1,0,0,0,1,1, 281 | 0,0,0,0,0,0,0,0 282 | ], block_size, height, 8); 283 | } else if (char == "N") { 284 | bitmap([ 285 | 0,0,0,0,0,0,0,0, 286 | 0,1,1,0,0,1,1,0, 287 | 0,1,1,1,0,1,1,0, 288 | 0,1,1,1,1,1,1,0, 289 | 0,1,1,1,1,1,1,0, 290 | 0,1,1,0,1,1,1,0, 291 | 0,1,1,0,0,1,1,0, 292 | 0,0,0,0,0,0,0,0 293 | ], block_size, height, 8); 294 | } else if (char == "O") { 295 | bitmap([ 296 | 0,0,0,0,0,0,0,0, 297 | 0,0,1,1,1,1,0,0, 298 | 0,1,1,0,0,1,1,0, 299 | 0,1,1,0,0,1,1,0, 300 | 0,1,1,0,0,1,1,0, 301 | 0,1,1,0,0,1,1,0, 302 | 0,0,1,1,1,1,0,0, 303 | 0,0,0,0,0,0,0,0 304 | ], block_size, height, 8); 305 | } else if (char == "P") { 306 | bitmap([ 307 | 0,0,0,0,0,0,0,0, 308 | 0,1,1,1,1,1,0,0, 309 | 0,1,1,0,0,1,1,0, 310 | 0,1,1,0,0,1,1,0, 311 | 0,1,1,1,1,1,0,0, 312 | 0,1,1,0,0,0,0,0, 313 | 0,1,1,0,0,0,0,0, 314 | 0,0,0,0,0,0,0,0 315 | ], block_size, height, 8); 316 | } else if (char == "Q") { 317 | bitmap([ 318 | 0,0,0,0,0,0,0,0, 319 | 0,0,1,1,1,1,0,0, 320 | 0,1,1,0,0,1,1,0, 321 | 0,1,1,0,0,1,1,0, 322 | 0,1,1,0,0,1,1,0, 323 | 0,1,1,1,1,1,0,0, 324 | 0,0,1,1,0,1,1,0, 325 | 0,0,0,0,0,0,0,0 326 | ], block_size, height, 8); 327 | } else if (char == "R") { 328 | bitmap([ 329 | 0,0,0,0,0,0,0,0, 330 | 0,1,1,1,1,1,0,0, 331 | 0,1,1,0,0,1,1,0, 332 | 0,1,1,0,0,1,1,0, 333 | 0,1,1,1,1,1,0,0, 334 | 0,1,1,0,1,1,0,0, 335 | 0,1,1,0,0,1,1,0, 336 | 0,0,0,0,0,0,0,0 337 | ], block_size, height, 8); 338 | } else if (char == "S") { 339 | bitmap([ 340 | 0,0,0,0,0,0,0,0, 341 | 0,0,1,1,1,1,0,0, 342 | 0,1,1,0,0,0,0,0, 343 | 0,0,1,1,1,1,0,0, 344 | 0,0,0,0,0,1,1,0, 345 | 0,0,0,0,0,1,1,0, 346 | 0,0,1,1,1,1,0,0, 347 | 0,0,0,0,0,0,0,0 348 | ], block_size, height, 8); 349 | } else if (char == "T") { 350 | bitmap([ 351 | 0,0,0,0,0,0,0,0, 352 | 0,1,1,1,1,1,1,0, 353 | 0,0,0,1,1,0,0,0, 354 | 0,0,0,1,1,0,0,0, 355 | 0,0,0,1,1,0,0,0, 356 | 0,0,0,1,1,0,0,0, 357 | 0,0,0,1,1,0,0,0, 358 | 0,0,0,0,0,0,0,0 359 | ], block_size, height, 8); 360 | } else if (char == "U") { 361 | bitmap([ 362 | 0,0,0,0,0,0,0,0, 363 | 0,1,1,0,0,1,1,0, 364 | 0,1,1,0,0,1,1,0, 365 | 0,1,1,0,0,1,1,0, 366 | 0,1,1,0,0,1,1,0, 367 | 0,1,1,0,0,1,1,0, 368 | 0,1,1,1,1,1,1,0, 369 | 0,0,0,0,0,0,0,0 370 | ], block_size, height, 8); 371 | } else if (char == "V") { 372 | bitmap([ 373 | 0,0,0,0,0,0,0,0, 374 | 0,1,1,0,0,1,1,0, 375 | 0,1,1,0,0,1,1,0, 376 | 0,1,1,0,0,1,1,0, 377 | 0,1,1,0,0,1,1,0, 378 | 0,0,1,1,1,1,0,0, 379 | 0,0,0,1,1,0,0,0, 380 | 0,0,0,0,0,0,0,0 381 | ], block_size, height, 8); 382 | } else if (char == "W") { 383 | bitmap([ 384 | 0,0,0,0,0,0,0,0, 385 | 0,1,1,0,0,0,1,1, 386 | 0,1,1,0,0,0,1,1, 387 | 0,1,1,0,1,0,1,1, 388 | 0,1,1,1,1,1,1,1, 389 | 0,1,1,1,0,1,1,1, 390 | 0,1,1,0,0,0,1,1, 391 | 0,0,0,0,0,0,0,0 392 | ], block_size, height, 8); 393 | } else if (char == "X") { 394 | bitmap([ 395 | 0,0,0,0,0,0,0,0, 396 | 0,1,1,0,0,1,1,0, 397 | 0,1,1,0,0,1,1,0, 398 | 0,0,1,1,1,1,0,0, 399 | 0,0,1,1,1,1,0,0, 400 | 0,1,1,0,0,1,1,0, 401 | 0,1,1,0,0,1,1,0, 402 | 0,0,0,0,0,0,0,0 403 | ], block_size, height, 8); 404 | } else if (char == "Y") { 405 | bitmap([ 406 | 0,0,0,0,0,0,0,0, 407 | 0,1,1,0,0,1,1,0, 408 | 0,1,1,0,0,1,1,0, 409 | 0,0,1,1,1,1,0,0, 410 | 0,0,0,1,1,0,0,0, 411 | 0,0,0,1,1,0,0,0, 412 | 0,0,0,1,1,0,0,0, 413 | 0,0,0,0,0,0,0,0 414 | ], block_size, height, 8); 415 | } else if (char == "Z") { 416 | bitmap([ 417 | 0,0,0,0,0,0,0,0, 418 | 0,1,1,1,1,1,1,0, 419 | 0,0,0,0,1,1,0,0, 420 | 0,0,0,1,1,0,0,0, 421 | 0,0,1,1,0,0,0,0, 422 | 0,1,1,0,0,0,0,0, 423 | 0,1,1,1,1,1,1,0, 424 | 0,0,0,0,0,0,0,0 425 | ], block_size, height, 8); 426 | } else if (char == "OE") { 427 | bitmap([ 428 | 0,0,1,0,0,1,0,0, 429 | 0,0,0,0,0,0,0,0, 430 | 0,0,1,1,1,1,0,0, 431 | 0,1,1,0,0,1,1,0, 432 | 0,1,1,0,0,1,1,0, 433 | 0,1,1,0,0,1,1,0, 434 | 0,1,1,0,0,1,1,0, 435 | 0,0,1,1,1,1,0,0 436 | ], block_size, height, 8); 437 | } else if (char == "a") { 438 | bitmap([ 439 | 0,0,0,0,0,0,0,0, 440 | 0,0,0,0,0,0,0,0, 441 | 0,0,1,1,1,1,0,0, 442 | 0,0,0,0,0,1,1,0, 443 | 0,0,1,1,1,1,1,0, 444 | 0,1,1,0,0,1,1,0, 445 | 0,0,1,1,1,1,1,0, 446 | 0,0,0,0,0,0,0,0 447 | ], block_size, height, 8); 448 | } else if (char == "b") { 449 | bitmap([ 450 | 0,0,0,0,0,0,0,0, 451 | 0,1,1,0,0,0,0,0, 452 | 0,1,1,0,0,0,0,0, 453 | 0,1,1,1,1,1,0,0, 454 | 0,1,1,0,0,1,1,0, 455 | 0,1,1,0,0,1,1,0, 456 | 0,1,1,1,1,1,0,0, 457 | 0,0,0,0,0,0,0,0 458 | ], block_size, height, 8); 459 | } else if (char == "c") { 460 | bitmap([ 461 | 0,0,0,0,0,0,0,0, 462 | 0,0,0,0,0,0,0,0, 463 | 0,0,1,1,1,1,0,0, 464 | 0,1,1,0,0,0,0,0, 465 | 0,1,1,0,0,0,0,0, 466 | 0,1,1,0,0,0,0,0, 467 | 0,0,1,1,1,1,0,0, 468 | 0,0,0,0,0,0,0,0 469 | ], block_size, height, 8); 470 | } else if (char == "d") { 471 | bitmap([ 472 | 0,0,0,0,0,0,0,0, 473 | 0,0,0,0,0,1,1,0, 474 | 0,0,0,0,0,1,1,0, 475 | 0,0,1,1,1,1,1,0, 476 | 0,1,1,0,0,1,1,0, 477 | 0,1,1,0,0,1,1,0, 478 | 0,0,1,1,1,1,1,0, 479 | 0,0,0,0,0,0,0,0 480 | ], block_size, height, 8); 481 | } else if (char == "e") { 482 | bitmap([ 483 | 0,0,0,0,0,0,0,0, 484 | 0,0,0,0,0,0,0,0, 485 | 0,0,1,1,1,1,0,0, 486 | 0,1,1,0,0,1,1,0, 487 | 0,1,1,1,1,1,1,0, 488 | 0,1,1,0,0,0,0,0, 489 | 0,0,1,1,1,1,0,0, 490 | 0,0,0,0,0,0,0,0 491 | ], block_size, height, 8); 492 | } else if (char == "f") { 493 | bitmap([ 494 | 0,0,0,0,0,0,0,0, 495 | 0,0,0,0,1,1,1,0, 496 | 0,0,0,1,1,0,0,0, 497 | 0,0,1,1,1,1,1,0, 498 | 0,0,0,1,1,0,0,0, 499 | 0,0,0,1,1,0,0,0, 500 | 0,0,0,1,1,0,0,0, 501 | 0,0,0,0,0,0,0,0 502 | ], block_size, height, 8); 503 | } else if (char == "g") { 504 | bitmap([ 505 | 0,0,0,0,0,0,0,0, 506 | 0,0,0,0,0,0,0,0, 507 | 0,0,1,1,1,1,0,0, 508 | 0,1,1,0,0,1,1,0, 509 | 0,1,1,0,0,1,1,0, 510 | 0,0,1,1,1,1,1,0, 511 | 0,0,0,0,0,1,1,0, 512 | 0,1,1,1,1,1,0,0 513 | ], block_size, height, 8); 514 | } else if (char == "h") { 515 | bitmap([ 516 | 0,0,0,0,0,0,0,0, 517 | 0,1,1,0,0,0,0,0, 518 | 0,1,1,0,0,0,0,0, 519 | 0,1,1,1,1,1,0,0, 520 | 0,1,1,0,0,1,1,0, 521 | 0,1,1,0,0,1,1,0, 522 | 0,1,1,0,0,1,1,0, 523 | 0,0,0,0,0,0,0,0 524 | ], block_size, height, 8); 525 | } else if (char == "i") { 526 | bitmap([ 527 | 0,0,0,0,0,0,0,0, 528 | 0,0,0,1,1,0,0,0, 529 | 0,0,0,0,0,0,0,0, 530 | 0,0,1,1,1,0,0,0, 531 | 0,0,0,1,1,0,0,0, 532 | 0,0,0,1,1,0,0,0, 533 | 0,0,1,1,1,1,0,0, 534 | 0,0,0,0,0,0,0,0 535 | ], block_size, height, 8); 536 | } else if (char == "j") { 537 | bitmap([ 538 | 0,0,0,0,0,0,0,0, 539 | 0,0,0,0,0,1,1,0, 540 | 0,0,0,0,0,0,0,0, 541 | 0,0,0,0,0,1,1,0, 542 | 0,0,0,0,0,1,1,0, 543 | 0,0,0,0,0,1,1,0, 544 | 0,0,0,0,0,1,1,0, 545 | 0,0,1,1,1,1,0,0 546 | ], block_size, height, 8); 547 | } else if (char == "k") { 548 | bitmap([ 549 | 0,0,0,0,0,0,0,0, 550 | 0,1,1,0,0,0,0,0, 551 | 0,1,1,0,0,0,0,0, 552 | 0,1,1,0,1,1,0,0, 553 | 0,1,1,1,1,0,0,0, 554 | 0,1,1,0,1,1,0,0, 555 | 0,1,1,0,0,1,1,0, 556 | 0,0,0,0,0,0,0,0 557 | ], block_size, height, 8); 558 | } else if (char == "l") { 559 | bitmap([ 560 | 0,0,0,0,0,0,0,0, 561 | 0,0,1,1,1,0,0,0, 562 | 0,0,0,1,1,0,0,0, 563 | 0,0,0,1,1,0,0,0, 564 | 0,0,0,1,1,0,0,0, 565 | 0,0,0,1,1,0,0,0, 566 | 0,0,1,1,1,1,0,0, 567 | 0,0,0,0,0,0,0,0 568 | ], block_size, height, 8); 569 | } else if (char == "m") { 570 | bitmap([ 571 | 0,0,0,0,0,0,0,0, 572 | 0,0,0,0,0,0,0,0, 573 | 0,1,1,0,0,1,1,0, 574 | 0,1,1,1,1,1,1,1, 575 | 0,1,1,1,1,1,1,1, 576 | 0,1,1,0,1,0,1,1, 577 | 0,1,1,0,0,0,1,1, 578 | 0,0,0,0,0,0,0,0 579 | ], block_size, height, 8); 580 | } else if (char == "n") { 581 | bitmap([ 582 | 0,0,0,0,0,0,0,0, 583 | 0,0,0,0,0,0,0,0, 584 | 0,1,1,1,1,1,0,0, 585 | 0,1,1,0,0,1,1,0, 586 | 0,1,1,0,0,1,1,0, 587 | 0,1,1,0,0,1,1,0, 588 | 0,1,1,0,0,1,1,0, 589 | 0,0,0,0,0,0,0,0 590 | ], block_size, height, 8); 591 | } else if (char == "o") { 592 | bitmap([ 593 | 0,0,0,0,0,0,0,0, 594 | 0,0,0,0,0,0,0,0, 595 | 0,0,1,1,1,1,0,0, 596 | 0,1,1,0,0,1,1,0, 597 | 0,1,1,0,0,1,1,0, 598 | 0,1,1,0,0,1,1,0, 599 | 0,0,1,1,1,1,0,0, 600 | 0,0,0,0,0,0,0,0 601 | ], block_size, height, 8); 602 | } else if (char == "p") { 603 | bitmap([ 604 | 0,0,0,0,0,0,0,0, 605 | 0,0,0,0,0,0,0,0, 606 | 0,1,1,1,1,1,0,0, 607 | 0,1,1,0,0,1,1,0, 608 | 0,1,1,0,0,1,1,0, 609 | 0,1,1,1,1,1,0,0, 610 | 0,1,1,0,0,0,0,0, 611 | 0,1,1,0,0,0,0,0 612 | ], block_size, height, 8); 613 | } else if (char == "q") { 614 | bitmap([ 615 | 0,0,0,0,0,0,0,0, 616 | 0,0,0,0,0,0,0,0, 617 | 0,0,1,1,1,1,1,0, 618 | 0,1,1,0,0,1,1,0, 619 | 0,1,1,0,0,1,1,0, 620 | 0,0,1,1,1,1,1,0, 621 | 0,0,0,0,0,1,1,0, 622 | 0,0,0,0,0,1,1,0 623 | ], block_size, height, 8); 624 | } else if (char == "r") { 625 | bitmap([ 626 | 0,0,0,0,0,0,0,0, 627 | 0,0,0,0,0,0,0,0, 628 | 0,1,1,1,1,1,0,0, 629 | 0,1,1,0,0,1,1,0, 630 | 0,1,1,0,0,0,0,0, 631 | 0,1,1,0,0,0,0,0, 632 | 0,1,1,0,0,0,0,0, 633 | 0,0,0,0,0,0,0,0 634 | ], block_size, height, 8); 635 | } else if (char == "s") { 636 | bitmap([ 637 | 0,0,0,0,0,0,0,0, 638 | 0,0,0,0,0,0,0,0, 639 | 0,0,1,1,1,1,1,0, 640 | 0,1,1,0,0,0,0,0, 641 | 0,0,1,1,1,1,0,0, 642 | 0,0,0,0,0,1,1,0, 643 | 0,1,1,1,1,1,0,0, 644 | 0,0,0,0,0,0,0,0 645 | ], block_size, height, 8); 646 | } else if (char == "t") { 647 | bitmap([ 648 | 0,0,0,0,0,0,0,0, 649 | 0,0,0,1,1,0,0,0, 650 | 0,1,1,1,1,1,1,0, 651 | 0,0,0,1,1,0,0,0, 652 | 0,0,0,1,1,0,0,0, 653 | 0,0,0,1,1,0,0,0, 654 | 0,0,0,0,1,1,1,0, 655 | 0,0,0,0,0,0,0,0 656 | ], block_size, height, 8); 657 | } else if (char == "u") { 658 | bitmap([ 659 | 0,0,0,0,0,0,0,0, 660 | 0,0,0,0,0,0,0,0, 661 | 0,1,1,0,0,1,1,0, 662 | 0,1,1,0,0,1,1,0, 663 | 0,1,1,0,0,1,1,0, 664 | 0,1,1,0,0,1,1,0, 665 | 0,0,1,1,1,1,1,0, 666 | 0,0,0,0,0,0,0,0 667 | ], block_size, height, 8); 668 | } else if (char == "v") { 669 | bitmap([ 670 | 0,0,0,0,0,0,0,0, 671 | 0,0,0,0,0,0,0,0, 672 | 0,1,1,0,0,1,1,0, 673 | 0,1,1,0,0,1,1,0, 674 | 0,1,1,0,0,1,1,0, 675 | 0,0,1,1,1,1,0,0, 676 | 0,0,0,1,1,0,0,0, 677 | 0,0,0,0,0,0,0,0 678 | ], block_size, height, 8); 679 | } else if (char == "w") { 680 | bitmap([ 681 | 0,0,0,0,0,0,0,0, 682 | 0,0,0,0,0,0,0,0, 683 | 0,1,1,0,0,0,1,1, 684 | 0,1,1,0,1,0,1,1, 685 | 0,1,1,1,1,1,1,1, 686 | 0,0,1,1,1,1,1,0, 687 | 0,0,1,1,0,1,1,0, 688 | 0,0,0,0,0,0,0,0 689 | ], block_size, height, 8); 690 | } else if (char == "x") { 691 | bitmap([ 692 | 0,0,0,0,0,0,0,0, 693 | 0,0,0,0,0,0,0,0, 694 | 0,1,1,0,0,1,1,0, 695 | 0,0,1,1,1,1,0,0, 696 | 0,0,0,1,1,0,0,0, 697 | 0,0,1,1,1,1,0,0, 698 | 0,1,1,0,0,1,1,0, 699 | 0,0,0,0,0,0,0,0 700 | ], block_size, height, 8); 701 | } else if (char == "y") { 702 | bitmap([ 703 | 0,0,0,0,0,0,0,0, 704 | 0,0,0,0,0,0,0,0, 705 | 0,1,1,0,0,1,1,0, 706 | 0,1,1,0,0,1,1,0, 707 | 0,1,1,0,0,1,1,0, 708 | 0,0,1,1,1,1,1,0, 709 | 0,0,0,0,1,1,0,0, 710 | 0,1,1,1,1,0,0,0 711 | ], block_size, height, 8); 712 | } else if (char == "z") { 713 | bitmap([ 714 | 0,0,0,0,0,0,0,0, 715 | 0,0,0,0,0,0,0,0, 716 | 0,1,1,1,1,1,1,0, 717 | 0,0,0,0,1,1,0,0, 718 | 0,0,0,1,1,0,0,0, 719 | 0,0,1,1,0,0,0,0, 720 | 0,1,1,1,1,1,1,0, 721 | 0,0,0,0,0,0,0,0 722 | ], block_size, height, 8); 723 | } else if (char == "+") { 724 | bitmap([ 725 | 0,0,0,0,0,0,0,0, 726 | 0,0,0,1,1,0,0,0, 727 | 0,0,0,1,1,0,0,0, 728 | 0,1,1,1,1,1,1,0, 729 | 0,1,1,1,1,1,1,0, 730 | 0,0,0,1,1,0,0,0, 731 | 0,0,0,1,1,0,0,0, 732 | 0,0,0,0,0,0,0,0 733 | ], block_size, height, 8); 734 | } else if (char == "-") { 735 | bitmap([ 736 | 0,0,0,0,0,0,0,0, 737 | 0,0,0,0,0,0,0,0, 738 | 0,0,0,0,0,0,0,0, 739 | 0,1,1,1,1,1,1,0, 740 | 0,1,1,1,1,1,1,0, 741 | 0,0,0,0,0,0,0,0, 742 | 0,0,0,0,0,0,0,0, 743 | 0,0,0,0,0,0,0,0 744 | ], block_size, height, 8); 745 | } else if (char == ":") { 746 | bitmap([ 747 | 0,0,0,0,0,0,0,0, 748 | 0,0,0,0,0,0,0,0, 749 | 0,0,0,1,1,0,0,0, 750 | 0,0,0,1,1,0,0,0, 751 | 0,0,0,0,0,0,0,0, 752 | 0,0,0,1,1,0,0,0, 753 | 0,0,0,1,1,0,0,0, 754 | 0,0,0,0,0,0,0,0 755 | ], block_size, height, 8); 756 | } else if (char == ".") { 757 | bitmap([ 758 | 0,0,0,0,0,0,0,0, 759 | 0,0,0,0,0,0,0,0, 760 | 0,0,0,0,0,0,0,0, 761 | 0,0,0,0,0,0,0,0, 762 | 0,0,0,0,0,0,0,0, 763 | 0,0,0,1,1,0,0,0, 764 | 0,0,0,1,1,0,0,0, 765 | 0,0,0,0,0,0,0,0 766 | ], block_size, height, 8); 767 | } else if (char == ",") { 768 | bitmap([ 769 | 0,0,0,0,0,0,0,0, 770 | 0,0,0,0,0,0,0,0, 771 | 0,0,0,0,0,0,0,0, 772 | 0,0,0,0,0,0,0,0, 773 | 0,0,0,0,0,0,0,0, 774 | 0,0,0,1,1,0,0,0, 775 | 0,0,0,1,1,0,0,0, 776 | 0,0,1,1,0,0,0,0 777 | ], block_size, height, 8); 778 | } else if (char == "?") { 779 | bitmap([ 780 | 0,0,0,0,0,0,0,0, 781 | 0,0,1,1,1,1,0,0, 782 | 0,1,1,0,0,1,1,0, 783 | 0,0,0,0,1,1,0,0, 784 | 0,0,0,1,1,0,0,0, 785 | 0,0,0,0,0,0,0,0, 786 | 0,0,0,1,1,0,0,0, 787 | 0,0,0,0,0,0,0,0 788 | ], block_size, height, 8); 789 | } else if (char == "=") { 790 | bitmap([ 791 | 0,0,0,0,0,0,0,0, 792 | 0,0,0,0,0,0,0,0, 793 | 0,1,1,1,1,1,1,0, 794 | 0,0,0,0,0,0,0,0, 795 | 0,0,0,0,0,0,0,0, 796 | 0,1,1,1,1,1,1,0, 797 | 0,0,0,0,0,0,0,0, 798 | 0,0,0,0,0,0,0,0 799 | ], block_size, height, 8); 800 | } else if (char == "*") { 801 | bitmap([ 802 | 0,0,0,0,0,0,0,0, 803 | 0,1,1,0,0,1,1,0, 804 | 0,0,1,1,1,1,0,0, 805 | 1,1,1,1,1,1,1,1, 806 | 0,0,1,1,1,1,0,0, 807 | 0,1,1,0,0,1,1,0, 808 | 0,0,0,0,0,0,0,0, 809 | 0,0,0,0,0,0,0,0 810 | ], block_size, height, 8); 811 | } else if (char == "!") { 812 | bitmap([ 813 | 0,0,0,0,0,0,0,0, 814 | 0,0,0,1,1,0,0,0, 815 | 0,0,0,1,1,0,0,0, 816 | 0,0,0,1,1,0,0,0, 817 | 0,0,0,1,1,0,0,0, 818 | 0,0,0,0,0,0,0,0, 819 | 0,0,0,1,1,0,0,0, 820 | 0,0,0,0,0,0,0,0 821 | ], block_size, height, 8); 822 | } else if (char == "''") { 823 | bitmap([ 824 | 0,0,0,0,0,0,0,0, 825 | 0,1,1,0,0,1,1,0, 826 | 0,1,1,0,0,1,1,0, 827 | 0,1,1,0,0,1,1,0, 828 | 0,0,0,0,0,0,0,0, 829 | 0,0,0,0,0,0,0,0, 830 | 0,0,0,0,0,0,0,0, 831 | 0,0,0,0,0,0,0,0 832 | ], block_size, height, 8); 833 | } else if (char == "#") { 834 | bitmap([ 835 | 0,0,0,0,0,0,0,0, 836 | 0,1,1,0,0,1,1,0, 837 | 1,1,1,1,1,1,1,1, 838 | 0,1,1,0,0,1,1,0, 839 | 0,1,1,0,0,1,1,0, 840 | 1,1,1,1,1,1,1,1, 841 | 0,1,1,0,0,1,1,0, 842 | 0,0,0,0,0,0,0,0 843 | ], block_size, height, 8); 844 | } else if (char == "$") { 845 | bitmap([ 846 | 0,0,0,1,1,0,0,0, 847 | 0,0,1,1,1,1,1,0, 848 | 0,1,1,0,0,0,0,0, 849 | 0,0,1,1,1,1,0,0, 850 | 0,0,0,0,0,1,1,0, 851 | 0,1,1,1,1,1,0,0, 852 | 0,0,0,1,1,0,0,0, 853 | 0,0,0,0,0,0,0,0 854 | ], block_size, height, 8); 855 | } else if (char == "%") { 856 | bitmap([ 857 | 0,0,0,0,0,0,0,0, 858 | 0,1,1,0,0,1,1,0, 859 | 0,1,1,0,1,1,0,0, 860 | 0,0,1,1,1,0,0,0, 861 | 0,0,1,1,0,0,0,0, 862 | 0,1,1,0,0,1,1,0, 863 | 0,1,0,0,0,1,1,0, 864 | 0,0,0,0,0,0,0,0 865 | ], block_size, height, 8); 866 | } else if (char == "&") { 867 | bitmap([ 868 | 0,0,0,1,1,1,0,0, 869 | 0,0,1,1,0,1,1,0, 870 | 0,0,0,1,1,1,0,0, 871 | 0,0,1,1,1,0,0,0, 872 | 0,1,1,0,1,1,1,1, 873 | 0,1,1,0,1,1,1,0, 874 | 0,0,1,1,1,0,1,1, 875 | 0,0,0,0,0,0,0,0 876 | ], block_size, height, 8); 877 | } else if (char == "@") { 878 | bitmap([ 879 | 0,0,0,0,0,0,0,0, 880 | 0,0,1,1,1,1,0,0, 881 | 0,1,1,0,0,1,1,0, 882 | 0,1,1,0,1,1,1,0, 883 | 0,1,1,0,1,1,1,0, 884 | 0,1,1,0,0,0,0,0, 885 | 0,0,1,1,1,1,1,0, 886 | 0,0,0,0,0,0,0,0 887 | ], block_size, height, 8); 888 | } else if (char == "'") { 889 | bitmap([ 890 | 0,0,0,0,0,0,0,0, 891 | 0,0,0,1,1,0,0,0, 892 | 0,0,0,1,1,0,0,0, 893 | 0,0,0,1,1,0,0,0, 894 | 0,0,0,0,0,0,0,0, 895 | 0,0,0,0,0,0,0,0, 896 | 0,0,0,0,0,0,0,0, 897 | 0,0,0,0,0,0,0,0 898 | ], block_size, height, 8); 899 | } else if (char == "(") { 900 | bitmap([ 901 | 0,0,0,0,0,0,0,0, 902 | 0,0,0,1,1,1,0,0, 903 | 0,0,1,1,1,0,0,0, 904 | 0,0,1,1,0,0,0,0, 905 | 0,0,1,1,0,0,0,0, 906 | 0,0,1,1,1,0,0,0, 907 | 0,0,0,1,1,1,0,0, 908 | 0,0,0,0,0,0,0,0 909 | ], block_size, height, 8); 910 | } else if (char == ")") { 911 | bitmap([ 912 | 0,0,0,0,0,0,0,0, 913 | 0,0,1,1,1,0,0,0, 914 | 0,0,0,1,1,1,0,0, 915 | 0,0,0,0,1,1,0,0, 916 | 0,0,0,0,1,1,0,0, 917 | 0,0,0,1,1,1,0,0, 918 | 0,0,1,1,1,0,0,0, 919 | 0,0,0,0,0,0,0,0 920 | ], block_size, height, 8); 921 | } else if (char == "<") { 922 | bitmap([ 923 | 0,0,0,0,0,1,1,0, 924 | 0,0,0,0,1,1,0,0, 925 | 0,0,0,1,1,0,0,0, 926 | 0,0,1,1,0,0,0,0, 927 | 0,0,0,1,1,0,0,0, 928 | 0,0,0,0,1,1,0,0, 929 | 0,0,0,0,0,1,1,0, 930 | 0,0,0,0,0,0,0,0 931 | ], block_size, height, 8); 932 | } else if (char == ">") { 933 | bitmap([ 934 | 0,1,1,0,0,0,0,0, 935 | 0,0,1,1,0,0,0,0, 936 | 0,0,0,1,1,0,0,0, 937 | 0,0,0,0,1,1,0,0, 938 | 0,0,0,1,1,0,0,0, 939 | 0,0,1,1,0,0,0,0, 940 | 0,1,1,0,0,0,0,0, 941 | 0,0,0,0,0,0,0,0 942 | ], block_size, height, 8); 943 | } else if (char == "[") { 944 | bitmap([ 945 | 0,0,0,0,0,0,0,0, 946 | 0,0,1,1,1,1,0,0, 947 | 0,0,1,1,0,0,0,0, 948 | 0,0,1,1,0,0,0,0, 949 | 0,0,1,1,0,0,0,0, 950 | 0,0,1,1,0,0,0,0, 951 | 0,0,1,1,1,1,0,0, 952 | 0,0,0,0,0,0,0,0 953 | ], block_size, height, 8); 954 | } else if (char == "]") { 955 | bitmap([ 956 | 0,0,0,0,0,0,0,0, 957 | 0,0,1,1,1,1,0,0, 958 | 0,0,0,0,1,1,0,0, 959 | 0,0,0,0,1,1,0,0, 960 | 0,0,0,0,1,1,0,0, 961 | 0,0,0,0,1,1,0,0, 962 | 0,0,1,1,1,1,0,0, 963 | 0,0,0,0,0,0,0,0 964 | ], block_size, height, 8); 965 | } else if (char == "/") { 966 | bitmap([ 967 | 0,0,0,0,0,0,0,0, 968 | 0,0,0,0,0,1,1,0, 969 | 0,0,0,0,1,1,0,0, 970 | 0,0,0,1,1,0,0,0, 971 | 0,0,1,1,0,0,0,0, 972 | 0,1,1,0,0,0,0,0, 973 | 0,1,0,0,0,0,0,0, 974 | 0,0,0,0,0,0,0,0 975 | ], block_size, height, 8); 976 | } else if (char == "\\") { 977 | bitmap([ 978 | 0,0,0,0,0,0,0,0, 979 | 0,1,1,0,0,0,0,0, 980 | 0,0,1,1,0,0,0,0, 981 | 0,0,0,1,1,0,0,0, 982 | 0,0,0,0,1,1,0,0, 983 | 0,0,0,0,0,1,1,0, 984 | 0,0,0,0,0,0,1,0, 985 | 0,0,0,0,0,0,0,0 986 | ], block_size, height, 8); 987 | } else if (char == "_") { 988 | bitmap([ 989 | 0,0,0,0,0,0,0,0, 990 | 0,0,0,0,0,0,0,0, 991 | 0,0,0,0,0,0,0,0, 992 | 0,0,0,0,0,0,0,0, 993 | 0,0,0,0,0,0,0,0, 994 | 0,0,0,0,0,0,0,0, 995 | 0,0,0,0,0,0,0,0, 996 | 1,1,1,1,1,1,1,1 997 | ], block_size, height, 8); 998 | } else if (char == "|") { 999 | bitmap([ 1000 | 0,0,0,1,1,0,0,0, 1001 | 0,0,0,1,1,0,0,0, 1002 | 0,0,0,1,1,0,0,0, 1003 | 0,0,0,1,1,0,0,0, 1004 | 0,0,0,1,1,0,0,0, 1005 | 0,0,0,1,1,0,0,0, 1006 | 0,0,0,1,1,0,0,0, 1007 | 0,0,0,1,1,0,0,0 1008 | ], block_size, height, 8); 1009 | } else { 1010 | echo("Invalid Character: ", char); 1011 | } 1012 | 1013 | } 1014 | 1015 | module 8bit_str(chars, char_count, block_size, height) { 1016 | echo(str("Total Width: ", block_size * 8 * char_count, "mm")); 1017 | union() { 1018 | for (count = [0:char_count-1]) { 1019 | translate(v = [0, count * block_size * 8, 0]) { 1020 | 8bit_char(chars[count], block_size, height); 1021 | } 1022 | } 1023 | } 1024 | } 1025 | 1026 | /* 1027 | 1028 | 1029 | block_size = 5; 1030 | height = 10; 1031 | 1032 | union() { 1033 | translate(v = [0,0,5]) { 1034 | 8bit_char("A", block_size, height); 1035 | 1036 | //bitmap([ 1037 | // 1,1,1,1,1,1,1,1, 1038 | // 1,0,0,1,1,0,0,1, 1039 | // 1,0,1,1,1,1,0,1, 1040 | // 1,1,1,0,0,1,1,1, 1041 | // 1,1,1,0,0,1,1,1, 1042 | // 1,0,1,1,1,1,0,1, 1043 | // 1,0,0,1,1,0,0,1, 1044 | // 1,1,1,1,1,1,1,1 1045 | //], block_size, height, 8); 1046 | 1047 | //bitmap([ 1048 | // 1,1,1,1, 1049 | // 1,0,0,1, 1050 | // 1,0,0,1, 1051 | // 1,1,1,1 1052 | //], block_size, height, 4); 1053 | } 1054 | translate(v = [0,0,5/2]) { 1055 | color([0,0,1,1]) { 1056 | cube(size = [block_size * 8, block_size * 8, 5], center = true); 1057 | } 1058 | } 1059 | } 1060 | 1061 | 1062 | 1063 | chars = ["T","O","N","Y","","B","U","S","E","R"]; 1064 | char_count = 10; 1065 | block_size = 1; 1066 | height = 5; 1067 | 1068 | union() { 1069 | translate(v = [0,-block_size*8*char_count/2+block_size*8/2,5]) { 1070 | 8bit_str(chars, char_count, block_size, height); 1071 | } 1072 | translate(v = [0,0,5/2]) { 1073 | color([0,0,1,1]) { 1074 | cube(size = [block_size * 8, block_size * 8 * char_count, 5], center = true); 1075 | } 1076 | } 1077 | } 1078 | */ 1079 | -------------------------------------------------------------------------------- /bitmap/height_map.scad: -------------------------------------------------------------------------------- 1 | /* 2 | Height Map Example 3 | Tony Buser 4 | http://tonybuser.com 5 | http://creativecommons.org/licenses/by/3.0/ 6 | 7 | Can also dynamically run this by passing an array on the command line: 8 | 9 | /Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD -m make -D bitmap=[2,2,2,0,1,3,2,2,2] -D row_size=3 -s height_map.stl height_map.scad 10 | */ 11 | 12 | use 13 | 14 | block_size = 5; 15 | height = 5; 16 | 17 | row_size = 10; // 10x10 pixels 18 | bitmap = [ 19 | 1,1,0,0,1,1,0,0,1,1, 20 | 1,1,1,1,1,1,1,1,1,1, 21 | 0,1,2,2,1,1,2,2,1,0, 22 | 0,1,2,1,1,1,1,2,1,0, 23 | 1,1,1,1,3,3,1,1,1,1, 24 | 1,1,1,1,3,3,1,1,1,1, 25 | 0,1,2,1,1,1,1,2,1,0, 26 | 0,1,2,2,1,1,2,2,1,0, 27 | 1,1,1,1,1,1,1,1,1,1, 28 | 1,1,0,0,1,1,0,0,1,1 29 | ]; 30 | 31 | bitmap(bitmap, block_size, height, row_size); 32 | -------------------------------------------------------------------------------- /bitmap/letter_necklace.scad: -------------------------------------------------------------------------------- 1 | /* 2 | Parametric letters for for a necklace 3 | Elmo Mäntynen 4 | LGPL 2.1 5 | */ 6 | 7 | use 8 | 9 | // change chars array and char_count 10 | // OpenSCAD has no string or length methods :( 11 | chars = ["M","a","k","e","r","B","o","t"]; 12 | char_count = 8; 13 | 14 | // block size 1 will result in 8mm per letter 15 | block_size = 2; 16 | // height is the Z height of each letter 17 | height = 3; 18 | 19 | //Hole for the necklace 20 | hole_diameter = 5; 21 | 22 | module 8bit_str(chars, char_count, block_size, height) { 23 | echo(str("Total Width: ", block_size * 8 * char_count, "mm")); 24 | union() { 25 | for (count = [0:char_count-1]) { 26 | translate(v = [0, count * block_size * 8, 0]) { 27 | 8bit_char(chars[count], block_size, height); 28 | } 29 | } 30 | } 31 | } 32 | 33 | module letter(char, block_size, height, hole_diameter) { 34 | union() { 35 | translate(v = [0,0, hole_diameter*1.3]) { 36 | 8bit_char(char, block_size, height); 37 | } 38 | translate(v = [0,0,(hole_diameter*1.3)/2]) { 39 | color([0,0,1,1]) { 40 | difference() { 41 | cube(size = [block_size * 8, block_size * 8, hole_diameter+2], center = true); 42 | rotate([90, 0, 0]) cylinder(h = block_size * 8 + 1, r = hole_diameter/2, center = true); 43 | } 44 | } 45 | } 46 | } 47 | } 48 | 49 | matrix = [["O", "L", "E", "N", "S"], 50 | [ "Y", "OE", "N", "Y", "T"]]; 51 | 52 | union() { 53 | for (column = [0:1]) { 54 | for (row = [0:4]) { 55 | translate(v=[column*(block_size*1.1)*8, row*(block_size*1.1)*8, 0]) 56 | letter(matrix[column][row], block_size, height, hole_diameter); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /bitmap/name_tag.scad: -------------------------------------------------------------------------------- 1 | /* 2 | Parametric Name Tag 3 | Tony Buser 4 | http://tonybuser.com 5 | http://creativecommons.org/licenses/by/3.0/ 6 | */ 7 | 8 | use 9 | 10 | /* 11 | chars = chars array 12 | block_size = letter size (block size 1 will result in 8mm per letter) 13 | height = the Z height of each letter in mm 14 | key_ring_hole = (boolean) Append a hole to a keyring, necklace etc. ? 15 | */ 16 | module name_tag(chars = ["R", "E", "P", "R", "A", "P"], 17 | block_size = 2, height = 3, key_ring_hole = true) { 18 | char_count = len(chars); 19 | union() { 20 | translate(v = [0,-block_size*8*char_count/2+block_size*8/2,3]) { 21 | 8bit_str(chars, char_count, block_size, height); 22 | } 23 | translate(v = [0,0,3/2]) { 24 | color([0,0,1,1]) { 25 | cube(size = [block_size * 8, block_size * 8 * char_count, 3], center = true); 26 | } 27 | } 28 | if (key_ring_hole == true){ 29 | translate([0, block_size * 8 * (char_count+1)/2, 3/2]) 30 | difference(){ 31 | cube(size = [block_size * 8, block_size * 8 , 3], center = true); 32 | cube(size = [block_size * 4, block_size * 4 , 5], center = true); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /bitmap/test_name_tag.scad: -------------------------------------------------------------------------------- 1 | include <../bitmap/name_tag.scad>; 2 | 3 | translate([0,0,0]) 4 | name_tag("name_tag"); 5 | 6 | translate([20,0,0]) // 0 + 16/2 + 16/2 + 4 7 | name_tag("NAME_TAG"); 8 | 9 | translate([52,0,0]) // 20 + 16/2 + 40/2 + 4 10 | name_tag("name_tag", block_size=5); 11 | 12 | translate([96,0,0]) // 52 + 40/2 + 40/2 + 4 13 | name_tag("NAME_TAG", block_size=5); 14 | 15 | translate([130,0,0]) // 92 + 40/2 + 16/2 + 4 16 | name_tag("name_tag", height=30); 17 | 18 | translate([150,0,0]) // 130 + 16/2 + 16/2 + 4 19 | name_tag("NAME_TAG", height=30); 20 | -------------------------------------------------------------------------------- /boxes.scad: -------------------------------------------------------------------------------- 1 | // Library: boxes.scad 2 | // Version: 1.0 3 | // Author: Marius Kintel 4 | // Copyright: 2010 5 | // License: 2-clause BSD License (http://opensource.org/licenses/BSD-2-Clause) 6 | 7 | // 8 | // roundedCube([x, y, z], r, sidesonly=true/false, center=true/false); 9 | // roundedCube(x, r, sidesonly=true/false, center=true/false); 10 | 11 | // EXAMPLE USAGE: 12 | // roundedCube([20, 30, 40], 5, true, true); 13 | 14 | // Only for backwards compatibility with existing scripts, (always centered, radius instead of consistent "r" naming. 15 | module roundedBox(size, radius, sidesonly) 16 | { 17 | echo("WARNING: roundedBox(size, radius, sidesonly) is deprecated, use roundedCube(size, r, sidesonly, center)"); 18 | roundedCube(size, radius, sidesonly, true); 19 | } 20 | 21 | // New implementation 22 | module roundedCube(size, r, sidesonly, center) { 23 | s = is_list(size) ? size : [size,size,size]; 24 | translate(center ? -s/2 : [0,0,0]) { 25 | if (sidesonly) { 26 | hull() { 27 | translate([ r, r]) cylinder(r=r, h=s[2]); 28 | translate([ r,s[1]-r]) cylinder(r=r, h=s[2]); 29 | translate([s[0]-r, r]) cylinder(r=r, h=s[2]); 30 | translate([s[0]-r,s[1]-r]) cylinder(r=r, h=s[2]); 31 | } 32 | } 33 | else { 34 | hull() { 35 | translate([ r, r, r]) sphere(r=r); 36 | translate([ r, r,s[2]-r]) sphere(r=r); 37 | translate([ r,s[1]-r, r]) sphere(r=r); 38 | translate([ r,s[1]-r,s[2]-r]) sphere(r=r); 39 | translate([s[0]-r, r, r]) sphere(r=r); 40 | translate([s[0]-r, r,s[2]-r]) sphere(r=r); 41 | translate([s[0]-r,s[1]-r, r]) sphere(r=r); 42 | translate([s[0]-r,s[1]-r,s[2]-r]) sphere(r=r); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /constants.scad: -------------------------------------------------------------------------------- 1 | // MIT license 2 | // Author: Elmo Mäntynen 3 | 4 | TAU = 6.2831853071; //2*PI, see http://tauday.com/ 5 | PI = TAU/2; 6 | 7 | // translates a imperial measurement in inches to meters 8 | mm_per_inch = 25.4; 9 | 10 | -------------------------------------------------------------------------------- /curves.scad: -------------------------------------------------------------------------------- 1 | // Parametric curves, to be used as paths 2 | // Licensed under the MIT license. 3 | // © 2010 by Elmo Mäntynen 4 | use 5 | include 6 | 7 | 8 | 9 | /* A circular helix of radius a and pitch 2πb is described by the following parametrisation: 10 | x(t) = a*cos(t), 11 | y(t) = a*sin(t), 12 | z(t) = b*t 13 | */ 14 | 15 | 16 | function b(pitch) = pitch/(TAU); 17 | function t(pitch, z) = z/b(pitch); 18 | 19 | function helix_curve(pitch, radius, z) = 20 | [radius*cos(deg(t(pitch, z))), radius*sin(deg(t(pitch, z))), z]; 21 | 22 | -------------------------------------------------------------------------------- /gears.scad: -------------------------------------------------------------------------------- 1 | // Copyright 2010 D1plo1d 2 | // LGPL 2.1 3 | 4 | 5 | //test_involute_curve(); 6 | //test_gears(); 7 | //demo_3d_gears(); 8 | 9 | // Geometry Sources: 10 | // http://www.cartertools.com/involute.html 11 | // gears.py (inkscape extension: /usr/share/inkscape/extensions/gears.py) 12 | // Usage: 13 | // Diametral pitch: Number of teeth per unit length. 14 | // Circular pitch: Length of the arc from one tooth to the next 15 | // Clearance: Radial distance between top of tooth on one gear to bottom of gap on another. 16 | 17 | function pitch_circular2diameter(number_of_teeth,circular_pitch) = number_of_teeth * circular_pitch / 180; 18 | function pitch_diametral2diameter(number_of_teeth,diametral_pitch) = number_of_teeth / diametral_pitch; 19 | 20 | module gear(number_of_teeth, 21 | circular_pitch=false, diametral_pitch=false, 22 | pressure_angle=20, clearance = 0, 23 | verbose=false) 24 | { 25 | if(verbose) { 26 | echo("gear arguments:"); 27 | echo(str(" number_of_teeth: ", number_of_teeth)); 28 | echo(str(" circular_pitch: ", circular_pitch)); 29 | echo(str(" diametral_pitch: ", diametral_pitch)); 30 | echo(str(" pressure_angle: ", pressure_angle)); 31 | echo(str(" clearance: ", clearance)); 32 | } 33 | if (circular_pitch==false && diametral_pitch==false) echo("MCAD ERROR: gear module needs either a diametral_pitch or circular_pitch"); 34 | if(verbose) echo("gear calculations:"); 35 | 36 | //Convert diametrial pitch to our native circular pitch 37 | circular_pitch = (circular_pitch!=false?circular_pitch:180/diametral_pitch); 38 | 39 | // Pitch diameter: Diameter of pitch circle. 40 | pitch_diameter = pitch_circular2diameter(number_of_teeth,circular_pitch); 41 | if(verbose) echo (str(" pitch_diameter: ", pitch_diameter)); 42 | pitch_radius = pitch_diameter/2; 43 | 44 | // Base Circle 45 | base_diameter = pitch_diameter*cos(pressure_angle); 46 | if(verbose) echo (str(" base_diameter: ", base_diameter)); 47 | base_radius = base_diameter/2; 48 | 49 | // Diametrial pitch: Number of teeth per unit length. 50 | pitch_diametrial = number_of_teeth / pitch_diameter; 51 | if(verbose) echo (str(" pitch_diametrial: ", pitch_diametrial)); 52 | 53 | // Addendum: Radial distance from pitch circle to outside circle. 54 | addendum = 1/pitch_diametrial; 55 | if(verbose) echo (str(" addendum: ", addendum)); 56 | 57 | //Outer Circle 58 | outer_radius = pitch_radius+addendum; 59 | outer_diameter = outer_radius*2; 60 | if(verbose) echo (str(" outer_diameter: ", outer_diameter)); 61 | 62 | // Dedendum: Radial distance from pitch circle to root diameter 63 | dedendum = addendum + clearance; 64 | if(verbose) echo (str(" dedendum: ", dedendum)); 65 | 66 | // Root diameter: Diameter of bottom of tooth spaces. 67 | root_radius = pitch_radius-dedendum; 68 | root_diameter = root_radius * 2; 69 | if(verbose) echo (str(" root_diameter: ", root_diameter)); 70 | 71 | half_thick_angle = 360 / (4 * number_of_teeth); 72 | if(verbose) echo (str(" half_thick_angle: ", half_thick_angle)); 73 | 74 | union() 75 | { 76 | rotate(half_thick_angle) circle($fn=number_of_teeth*2, r=root_radius*1.001); 77 | 78 | for (i= [1:number_of_teeth]) 79 | //for (i = [0]) 80 | { 81 | rotate([0,0,i*360/number_of_teeth]) 82 | { 83 | involute_gear_tooth( 84 | pitch_radius = pitch_radius, 85 | root_radius = root_radius, 86 | base_radius = base_radius, 87 | outer_radius = outer_radius, 88 | half_thick_angle = half_thick_angle); 89 | } 90 | } 91 | } 92 | } 93 | 94 | 95 | module involute_gear_tooth( 96 | pitch_radius, 97 | root_radius, 98 | base_radius, 99 | outer_radius, 100 | half_thick_angle 101 | ) 102 | { 103 | pitch_to_base_angle = involute_intersect_angle( base_radius, pitch_radius ); 104 | 105 | outer_to_base_angle = involute_intersect_angle( base_radius, outer_radius ); 106 | 107 | base1 = 0 - pitch_to_base_angle - half_thick_angle; 108 | pitch1 = 0 - half_thick_angle; 109 | outer1 = outer_to_base_angle - pitch_to_base_angle - half_thick_angle; 110 | 111 | b1 = polar_to_cartesian([ base1, base_radius ]); 112 | p1 = polar_to_cartesian([ pitch1, pitch_radius ]); 113 | o1 = polar_to_cartesian([ outer1, outer_radius ]); 114 | 115 | b2 = polar_to_cartesian([ -base1, base_radius ]); 116 | p2 = polar_to_cartesian([ -pitch1, pitch_radius ]); 117 | o2 = polar_to_cartesian([ -outer1, outer_radius ]); 118 | 119 | // ( root_radius > base_radius variables ) 120 | pitch_to_root_angle = pitch_to_base_angle - involute_intersect_angle(base_radius, root_radius ); 121 | root1 = pitch1 - pitch_to_root_angle; 122 | root2 = -pitch1 + pitch_to_root_angle; 123 | r1_t = polar_to_cartesian([ root1, root_radius ]); 124 | r2_t = polar_to_cartesian([ -root1, root_radius ]); 125 | 126 | // ( else ) 127 | r1_f = polar_to_cartesian([ base1, root_radius ]); 128 | r2_f = polar_to_cartesian([ -base1, root_radius ]); 129 | 130 | if (root_radius > base_radius) 131 | { 132 | //echo("true"); 133 | polygon( points = [ 134 | r1_t,p1,o1,o2,p2,r2_t 135 | ], convexity = 3); 136 | } 137 | else 138 | { 139 | polygon( points = [ 140 | r1_f, b1,p1,o1,o2,p2,b2,r2_f 141 | ], convexity = 3); 142 | } 143 | 144 | } 145 | 146 | // Mathematical Functions 147 | //=============== 148 | 149 | // Finds the angle of the involute about the base radius at the given distance (radius) from it's center. 150 | //source: http://www.mathhelpforum.com/math-help/geometry/136011-circle-involute-solving-y-any-given-x.html 151 | 152 | function involute_intersect_angle(base_radius, radius) = sqrt( pow(radius/base_radius,2) - 1); 153 | 154 | 155 | 156 | // Polar coord [angle, radius] to cartesian coord [x,y] 157 | 158 | function polar_to_cartesian(polar) = [ 159 | polar[1]*cos(polar[0]), 160 | polar[1]*sin(polar[0]) 161 | ]; 162 | 163 | 164 | // Test Cases 165 | //=============== 166 | 167 | module test_gears() 168 | { 169 | gear(number_of_teeth=51,circular_pitch=200); 170 | translate([0, 50])gear(number_of_teeth=17,circular_pitch=200); 171 | translate([-50,0]) gear(number_of_teeth=17,diametral_pitch=1); 172 | } 173 | 174 | module demo_3d_gears() 175 | { 176 | //double helical gear 177 | translate([50,0]) 178 | { 179 | linear_extrude(height = 10, center = true, convexity = 10, twist = -45) 180 | gear(number_of_teeth=17,diametral_pitch=1); 181 | translate([0,0,10]) 182 | rotate([0,180,180/17]) 183 | linear_extrude(height = 10, center = true, convexity = 10, twist = 45) 184 | gear(number_of_teeth=17,diametral_pitch=1); 185 | } 186 | 187 | //spur gear 188 | translate([0,-50]) linear_extrude(height = 10, center = true, convexity = 10, twist = 0) 189 | gear(number_of_teeth=17,diametral_pitch=1); 190 | 191 | } 192 | 193 | module test_involute_curve() 194 | { 195 | for (i=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) 196 | { 197 | translate(polar_to_cartesian([involute_intersect_angle( 0.1,i) , i ])) circle($fn=15, r=0.5); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /gridbeam.scad: -------------------------------------------------------------------------------- 1 | /********************************* 2 | * OpenSCAD GridBeam Library * 3 | * (c) Timothy Schmidt 2013 * 4 | * http://www.github.com/gridbeam * 5 | * License: LGPL 2.1 or later * 6 | *********************************/ 7 | 8 | /* Todo: 9 | - implement "dxf" mode 10 | - implement hole cutout pattern - interference based on hole size, compatible with two sizes above and below the currently set size. 11 | */ 12 | 13 | // zBeam(segments) - create a vertical gridbeam strut 'segments' long 14 | // xBeam(segments) - create a horizontal gridbeam strut along the X axis 15 | // yBeam(segments) - create a horizontal gridbeam strut along the Y axis 16 | // zBolt(segments) - create a bolt 'segments' in length 17 | // xBolt(segments) 18 | // yBolt(segments) 19 | // topShelf(width, depth, corners) - create a shelf suitable for use in gridbeam structures width and depth in 'segments', corners == 1 notches corners 20 | // bottomShelf(width, depth, corners) - like topShelf, but aligns shelf to underside of beams 21 | // backBoard(width, height, corners) - create a backing board suitable for use in gridbeam structures width and height in 'segments', corners == 1 notches corners 22 | // frontBoard(width, height, corners) - like backBoard, but aligns board to front side of beams 23 | // translateBeam([x, y, z]) - translate gridbeam struts or shelves in X, Y, or Z axes in units 'segments' 24 | 25 | // To render the DXF file from the command line: 26 | // openscad -x connector.dxf -D'mode="dxf"' connector.scad 27 | mode = "model"; 28 | //mode = "dxf"; 29 | 30 | include 31 | 32 | beam_width = inch * 1.5; 33 | beam_hole_diameter = inch * 5/16; 34 | beam_hole_radius = beam_hole_diameter / 2; 35 | beam_is_hollow = 1; 36 | beam_wall_thickness = inch * 1/8; 37 | beam_shelf_thickness = inch * 1/4; 38 | 39 | module zBeam(segments) { 40 | if (mode == "model") { 41 | difference() { 42 | cube([beam_width, beam_width, beam_width * segments]); 43 | for(i = [0 : segments - 1]) { 44 | translate([beam_width / 2, beam_width + 1, beam_width * i + beam_width / 2]) 45 | rotate([90,0,0]) 46 | cylinder(r=beam_hole_radius, h=beam_width + 2); 47 | 48 | translate([-1, beam_width / 2, beam_width * i + beam_width / 2]) 49 | rotate([0,90,0]) 50 | cylinder(r=beam_hole_radius, h=beam_width + 2); 51 | } 52 | if (beam_is_hollow == 1) { 53 | translate([beam_wall_thickness, beam_wall_thickness, -1]) 54 | cube([beam_width - beam_wall_thickness * 2, beam_width - beam_wall_thickness * 2, beam_width * segments + 2]); 55 | } 56 | } 57 | } 58 | 59 | if (mode == "dxf") { 60 | 61 | } 62 | } 63 | 64 | module xBeam(segments) { 65 | if (mode == "model") { 66 | translate([0,0,beam_width]) 67 | rotate([0,90,0]) 68 | zBeam(segments); 69 | } 70 | 71 | if (mode == "dxf") { 72 | 73 | } 74 | } 75 | 76 | module yBeam(segments) { 77 | if (mode == "model") { 78 | translate([0,0,beam_width]) 79 | rotate([-90,0,0]) 80 | zBeam(segments); 81 | } 82 | 83 | if (mode == "dxf") { 84 | 85 | } 86 | } 87 | 88 | module zBolt(segments) { 89 | if (mode == "model") { 90 | 91 | } 92 | 93 | if (mode == "dxf") { 94 | 95 | } 96 | } 97 | 98 | module xBolt(segments) { 99 | if (mode == "model") { 100 | } 101 | 102 | if (mode == "dxf") { 103 | 104 | } 105 | } 106 | 107 | module yBolt(segments) { 108 | if (mode == "model") { 109 | } 110 | 111 | if (mode == "dxf") { 112 | 113 | } 114 | } 115 | 116 | module translateBeam(v) translate(v * beam_width) children([0 : $children - 1]); 117 | 118 | module topShelf(width, depth, corners) { 119 | if (mode == "model") { 120 | difference() { 121 | cube([width * beam_width, depth * beam_width, beam_shelf_thickness]); 122 | 123 | if (corners == 1) { 124 | translate([-1, -1, -1]) 125 | cube([beam_width + 2, beam_width + 2, beam_shelf_thickness + 2]); 126 | translate([-1, (depth - 1) * beam_width, -1]) 127 | cube([beam_width + 2, beam_width + 2, beam_shelf_thickness + 2]); 128 | translate([(width - 1) * beam_width, -1, -1]) 129 | cube([beam_width + 2, beam_width + 2, beam_shelf_thickness + 2]); 130 | translate([(width - 1) * beam_width, (depth - 1) * beam_width, -1]) 131 | cube([beam_width + 2, beam_width + 2, beam_shelf_thickness + 2]); 132 | } 133 | } 134 | } 135 | 136 | if (mode == "dxf") { 137 | 138 | } 139 | } 140 | 141 | module bottomShelf(width, depth, corners) { 142 | if (mode == "model") { 143 | translate([0,0,-beam_shelf_thickness]) 144 | topShelf(width, depth, corners); 145 | } 146 | 147 | if (mode == "dxf") { 148 | 149 | } 150 | } 151 | 152 | module backBoard(width, height, corners) { 153 | if (mode == "model") { 154 | translate([beam_width, 0, 0]) 155 | difference() { 156 | cube([beam_shelf_thickness, width * beam_width, height * beam_width]); 157 | 158 | if (corners == 1) { 159 | translate([-1, -1, -1]) 160 | cube([beam_shelf_thickness + 2, beam_width + 2, beam_width + 2]); 161 | translate([-1, -1, (height - 1) * beam_width]) 162 | cube([beam_shelf_thickness + 2, beam_width + 2, beam_width + 2]); 163 | translate([-1, (width - 1) * beam_width, -1]) 164 | cube([beam_shelf_thickness + 2, beam_width + 2, beam_width + 2]); 165 | translate([-1, (width - 1) * beam_width, (height - 1) * beam_width]) 166 | cube([beam_shelf_thickness + 2, beam_width + 2, beam_width + 2]); 167 | } 168 | } 169 | } 170 | 171 | if (mode == "dxf") { 172 | 173 | } 174 | } 175 | 176 | module frontBoard(width, height, corners) { 177 | if (mode == "model") { 178 | translate([-beam_width - beam_shelf_thickness, 0, 0]) 179 | backBoard(width, height, corners); 180 | } 181 | 182 | if (mode == "dxf") { 183 | 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /hardware.scad: -------------------------------------------------------------------------------- 1 | // License: LGPL 2.1 2 | 3 | rodsize = 6; //threaded/smooth rod diameter in mm 4 | xaxis = 182.5; //width of base in mm 5 | yaxis = 266.5; //length of base in mm 6 | 7 | 8 | screwsize = 3; //bearing bore/screw diameter in mm 9 | bearingsize = 10; //outer diameter of bearings in mm 10 | bearingwidth = 4; //width of bearings in mm 11 | 12 | 13 | rodpitch = rodsize / 6; 14 | rodnutsize = 0.8 * rodsize; 15 | rodnutdiameter = 1.9 * rodsize; 16 | rodwashersize = 0.2 * rodsize; 17 | rodwasherdiameter = 2 * rodsize; 18 | screwpitch = screwsize / 6; 19 | nutsize = 0.8 * screwsize; 20 | nutdiameter = 1.9 * screwsize; 21 | washersize = 0.2 * screwsize; 22 | washerdiameter = 2 * screwsize; 23 | partthick = 2 * rodsize; 24 | vertexrodspace = 2 * rodsize; 25 | 26 | 27 | c = [0.3, 0.3, 0.3]; 28 | rodendoffset = rodnutsize + rodwashersize * 2 + partthick / 2; 29 | vertexoffset = vertexrodspace + rodendoffset; 30 | 31 | 32 | renderrodthreads = false; 33 | renderscrewthreads = false; 34 | fn = 36; 35 | 36 | 37 | 38 | module rod(length, threaded) if (threaded && renderrodthreads) { 39 | linear_extrude(height = length, center = true, convexity = 10, twist = -360 * length / rodpitch, $fn = fn) 40 | translate([rodsize * 0.1 / 2, 0, 0]) 41 | circle(r = rodsize * 0.9 / 2, $fn = fn); 42 | } else cylinder(h = length, r = rodsize / 2, center = true, $fn = fn); 43 | 44 | 45 | module screw(length, nutpos, washer, bearingpos = -1) union(){ 46 | translate([0, 0, -length / 2]) if (renderscrewthreads) { 47 | linear_extrude(height = length, center = true, convexity = 10, twist = -360 * length / screwpitch, $fn = fn) 48 | translate([screwsize * 0.1 / 2, 0, 0]) 49 | circle(r = screwsize * 0.9 / 2, $fn = fn); 50 | } else cylinder(h = length, r = screwsize / 2, center = true, $fn = fn); 51 | render() difference() { 52 | translate([0, 0, screwsize / 2]) cylinder(h = screwsize, r = screwsize, center = true, $fn = fn); 53 | translate([0, 0, screwsize]) cylinder(h = screwsize, r = screwsize / 2, center = true, $fn = 6); 54 | } 55 | if (washer > 0 && nutpos > 0) { 56 | washer(nutpos); 57 | nut(nutpos + washersize); 58 | } else if (nutpos > 0) nut(nutpos); 59 | if (bearingpos >= 0) bearing(bearingpos); 60 | } 61 | 62 | 63 | module bearing(position) render() translate([0, 0, -position - bearingwidth / 2]) union() { 64 | difference() { 65 | cylinder(h = bearingwidth, r = bearingsize / 2, center = true, $fn = fn); 66 | cylinder(h = bearingwidth * 2, r = bearingsize / 2 - 1, center = true, $fn = fn); 67 | } 68 | difference() { 69 | cylinder(h = bearingwidth - 0.5, r = bearingsize / 2 - 0.5, center = true, $fn = fn); 70 | cylinder(h = bearingwidth * 2, r = screwsize / 2 + 0.5, center = true, $fn = fn); 71 | } 72 | difference() { 73 | cylinder(h = bearingwidth, r = screwsize / 2 + 1, center = true, $fn = fn); 74 | cylinder(h = bearingwidth + 0.1, r = screwsize / 2, center = true, $fn = fn); 75 | } 76 | } 77 | 78 | 79 | module nut(position, washer) render() translate([0, 0, -position - nutsize / 2]) { 80 | intersection() { 81 | scale([1, 1, 0.5]) sphere(r = 1.05 * screwsize, center = true); 82 | difference() { 83 | cylinder (h = nutsize, r = nutdiameter / 2, center = true, $fn = 6); 84 | cylinder(r = screwsize / 2, h = nutsize + 0.1, center = true, $fn = fn); 85 | } 86 | } 87 | if (washer > 0) washer(0); 88 | } 89 | 90 | 91 | module washer(position) render() translate ([0, 0, -position - washersize / 2]) difference() { 92 | cylinder(r = washerdiameter / 2, h = washersize, center = true, $fn = fn); 93 | cylinder(r = screwsize / 2, h = washersize + 0.1, center = true, $fn = fn); 94 | } 95 | 96 | module rodnut(position, washer) render() translate([0, 0, position]) { 97 | intersection() { 98 | scale([1, 1, 0.5]) sphere(r = 1.05 * rodsize, center = true); 99 | difference() { 100 | cylinder (h = rodnutsize, r = rodnutdiameter / 2, center = true, $fn = 6); 101 | rod(rodnutsize + 0.1); 102 | } 103 | } 104 | if (washer == 1 || washer == 4) rodwasher(((position > 0) ? -1 : 1) * (rodnutsize + rodwashersize) / 2); 105 | if (washer == 2 || washer == 4) rodwasher(((position > 0) ? 1 : -1) * (rodnutsize + rodwashersize) / 2); 106 | } 107 | 108 | 109 | module rodwasher(position) render() translate ([0, 0, position]) difference() { 110 | cylinder(r = rodwasherdiameter / 2, h = rodwashersize, center = true, $fn = fn); 111 | rod(rodwashersize + 0.1); 112 | } 113 | 114 | 115 | rod(20); 116 | translate([rodsize * 2.5, 0, 0]) rod(20, true); 117 | translate([rodsize * 5, 0, 0]) screw(10, true); 118 | translate([rodsize * 7.5, 0, 0]) bearing(); 119 | translate([rodsize * 10, 0, 0]) rodnut(); 120 | translate([rodsize * 12.5, 0, 0]) rodwasher(); 121 | translate([rodsize * 15, 0, 0]) nut(); 122 | translate([rodsize * 17.5, 0, 0]) washer(); -------------------------------------------------------------------------------- /layouts.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenSCAD Layout Library (www.openscad.org) 3 | * Copyright (C) 2012 Peter Uithoven 4 | * 5 | * License: LGPL 2.1 or later 6 | */ 7 | 8 | //list(iHeight); 9 | //grid(iWidth,iHeight,inYDir = true,limit=3) 10 | 11 | // Examples: 12 | /*list(15) 13 | { 14 | square([25,10]); 15 | square([25,10]); 16 | square([25,10]); 17 | square([25,10]); 18 | square([25,10]); 19 | }*/ 20 | /*grid(30,15,false,2) 21 | { 22 | square([25,10]); 23 | square([25,10]); 24 | square([25,10]); 25 | square([25,10]); 26 | square([25,10]); 27 | }*/ 28 | 29 | //---------------------- 30 | 31 | module list(iHeight) 32 | { 33 | for (i = [0 : $children-1]) 34 | translate([0,i*iHeight]) children(i); 35 | } 36 | module grid(iWidth,iHeight,inYDir = true,limit=3) 37 | { 38 | for (i = [0 : $children-1]) 39 | { 40 | translate([(inYDir)? (iWidth)*(i%limit) : (iWidth)*floor(i/limit), 41 | (inYDir)? (iHeight)*floor(i/limit) : (iHeight)*(i%limit)]) 42 | children(i); 43 | } 44 | } -------------------------------------------------------------------------------- /lego_compatibility.scad: -------------------------------------------------------------------------------- 1 | // This file is placed under the public domain 2 | 3 | // from: http://www.thingiverse.com/thing:9512 4 | // Author: nefercheprure 5 | 6 | // Examples: 7 | // standard LEGO 2x1 tile has no pin 8 | // block(1,2,1/3,reinforcement=false,flat_top=true); 9 | // standard LEGO 2x1 flat has pin 10 | // block(1,2,1/3,reinforcement=true); 11 | // standard LEGO 2x1 brick has pin 12 | // block(1,2,1,reinforcement=true); 13 | // standard LEGO 2x1 brick without pin 14 | // block(1,2,1,reinforcement=false); 15 | // standard LEGO 2x1x5 brick has no pin and has hollow knobs 16 | // block(1,2,5,reinforcement=false,hollow_knob=true); 17 | 18 | 19 | knob_diameter=4.8; //knobs on top of blocks 20 | knob_height=2; 21 | knob_spacing=8.0; 22 | wall_thickness=1.45; 23 | roof_thickness=1.05; 24 | block_height=9.5; 25 | pin_diameter=3; //pin for bottom blocks with width or length of 1 26 | post_diameter=6.5; 27 | reinforcing_width=1.5; 28 | axle_spline_width=2.0; 29 | axle_diameter=5; 30 | cylinder_precision=0.5; 31 | 32 | /* EXAMPLES: 33 | 34 | block(2,1,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true); 35 | 36 | translate([50,-10,0]) 37 | block(1,2,1/3,axle_hole=false,circular_hole=true,reinforcement=false,hollow_knob=true,flat_top=true); 38 | 39 | translate([10,0,0]) 40 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=true); 41 | translate([30,0,0]) 42 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=false,flat_top=false); 43 | translate([50,0,0]) 44 | block(2,2,1/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false); 45 | translate([0,20,0]) 46 | block(3,2,2/3,axle_hole=false,circular_hole=true,reinforcement=true,hollow_knob=true,flat_top=false); 47 | translate([20,20,0]) 48 | block(3,2,1,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false); 49 | translate([40,20,0]) 50 | block(3,2,1/3,axle_hole=false,circular_hole=false,reinforcement=false,hollow_knob=false,flat_top=false); 51 | translate([0,-10,0]) 52 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=false,flat_top=false); 53 | translate([0,-20,0]) 54 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=false); 55 | translate([0,-30,0]) 56 | block(1,5,1/3,axle_hole=true,circular_hole=false,reinforcement=true,hollow_knob=true,flat_top=true); 57 | //*/ 58 | 59 | module block(width,length,height,axle_hole=false,reinforcement=false, hollow_knob=false, flat_top=false, circular_hole=false, solid_bottom=true, center=false) { 60 | overall_length=(length-1)*knob_spacing+knob_diameter+wall_thickness*2; 61 | overall_width=(width-1)*knob_spacing+knob_diameter+wall_thickness*2; 62 | center= center==true ? 1 : 0; 63 | translate(center*[-overall_length/2, -overall_width/2, 0]) 64 | union() { 65 | difference() { 66 | union() { 67 | // body: 68 | cube([overall_length,overall_width,height*block_height]); 69 | // knobs: 70 | if (flat_top != true) 71 | translate([knob_diameter/2+wall_thickness,knob_diameter/2+wall_thickness,0]) 72 | for (ycount=[0:width-1]) 73 | for (xcount=[0:length-1]) { 74 | translate([xcount*knob_spacing,ycount*knob_spacing,0]) 75 | difference() { 76 | cylinder(r=knob_diameter/2,h=block_height*height+knob_height,$fs=cylinder_precision); 77 | if (hollow_knob==true) 78 | translate([0,0,-roof_thickness]) 79 | cylinder(r=pin_diameter/2,h=block_height*height+knob_height+2*roof_thickness,$fs=cylinder_precision); 80 | } 81 | } 82 | } 83 | // hollow bottom: 84 | if (solid_bottom == false) 85 | translate([wall_thickness,wall_thickness,-roof_thickness]) cube([overall_length-wall_thickness*2,overall_width-wall_thickness*2,block_height*height]); 86 | // flat_top -> groove around bottom 87 | if (flat_top == true) { 88 | translate([-wall_thickness/2,-wall_thickness*2/3,-wall_thickness/2]) 89 | cube([overall_length+wall_thickness,wall_thickness,wall_thickness]); 90 | translate([-wall_thickness/2,overall_width-wall_thickness/3,-wall_thickness/2]) 91 | cube([overall_length+wall_thickness,wall_thickness,wall_thickness]); 92 | 93 | translate([-wall_thickness*2/3,-wall_thickness/2,-wall_thickness/2]) 94 | cube([wall_thickness,overall_width+wall_thickness,wall_thickness]); 95 | translate([overall_length-wall_thickness/3,0,-wall_thickness/2]) 96 | cube([wall_thickness,overall_width+wall_thickness,wall_thickness]); 97 | } 98 | if (axle_hole==true) 99 | if (width>1 && length>1) for (ycount=[1:width-1]) 100 | for (xcount=[1:length-1]) 101 | translate([xcount*knob_spacing,ycount*knob_spacing,roof_thickness]) axle(height); 102 | if (circular_hole==true) 103 | if (width>1 && length>1) for (ycount=[1:width-1]) 104 | for (xcount=[1:length-1]) 105 | translate([xcount*knob_spacing,ycount*knob_spacing,roof_thickness]) 106 | cylinder(r=knob_diameter/2, h=height*block_height+roof_thickness/4,$fs=cylinder_precision); 107 | } 108 | 109 | if (reinforcement==true && width>1 && length>1) 110 | difference() { 111 | for (ycount=[1:width-1]) 112 | for (xcount=[1:length-1]) 113 | translate([xcount*knob_spacing,ycount*knob_spacing,0]) reinforcement(height); 114 | for (ycount=[1:width-1]) 115 | for (xcount=[1:length-1]) 116 | translate([xcount*knob_spacing,ycount*knob_spacing,-roof_thickness/2]) cylinder(r=knob_diameter/2, h=height*block_height+roof_thickness, $fs=cylinder_precision); 117 | } 118 | // posts: 119 | if (solid_bottom == false) 120 | if (width>1 && length>1) for (ycount=[1:width-1]) 121 | for (xcount=[1:length-1]) 122 | translate([xcount*knob_spacing,ycount*knob_spacing,0]) post(height); 123 | 124 | if (reinforcement == true && width==1 && length!=1) 125 | for (xcount=[1:length-1]) 126 | translate([xcount*knob_spacing,overall_width/2,0]) cylinder(r=pin_diameter/2,h=block_height*height,$fs=cylinder_precision); 127 | 128 | if (reinforcement == true && length==1 && width!=1) 129 | for (ycount=[1:width-1]) 130 | translate([overall_length/2,ycount*knob_spacing,0]) cylinder(r=pin_diameter/2,h=block_height*height,$fs=cylinder_precision); 131 | } 132 | } 133 | 134 | module post(height) { 135 | difference() { 136 | cylinder(r=post_diameter/2, h=height*block_height-roof_thickness/2,$fs=cylinder_precision); 137 | translate([0,0,-roof_thickness/2]) 138 | cylinder(r=knob_diameter/2, h=height*block_height+roof_thickness/4,$fs=cylinder_precision); 139 | } 140 | } 141 | 142 | module reinforcement(height) { 143 | union() { 144 | translate([0,0,height*block_height/2]) union() { 145 | cube([reinforcing_width,knob_spacing+knob_diameter+wall_thickness/2,height*block_height],center=true); 146 | rotate(v=[0,0,1],a=90) cube([reinforcing_width,knob_spacing+knob_diameter+wall_thickness/2,height*block_height], center=true); 147 | } 148 | } 149 | } 150 | 151 | module axle(height) { 152 | translate([0,0,height*block_height/2]) union() { 153 | cube([axle_diameter,axle_spline_width,height*block_height],center=true); 154 | cube([axle_spline_width,axle_diameter,height*block_height],center=true); 155 | } 156 | } 157 | 158 | -------------------------------------------------------------------------------- /lgpl-2.1.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | -------------------------------------------------------------------------------- /libtriangles.scad: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2013 Alex Davies 2 | //License: LGPL 2.1 or later 3 | //todo, make library work with negative lengths by adding triangles to the inside of every surface. basicaly copy and paste the current triangles set and reverse the first and last digit of every triangle. In 4 character traingles switcht the middle ones around as well. Not sure if that' actually useful though. 4 | 5 | module rightpyramid(rightpyramidx, rightpyramidy, rightpyramidz) { 6 | polyhedron ( points = [[0,0,0], 7 | [rightpyramidx, 0, 0], 8 | [0, rightpyramidy, 0], 9 | [rightpyramidx, rightpyramidy, 0], 10 | [rightpyramidx/2, rightpyramidy, rightpyramidz]], 11 | 12 | triangles = [[0,1,2],[2,1,3],[4,1,0],[3,1,4],[2,3,4],[0,2,4]]); 13 | 14 | } 15 | 16 | module cornerpyramid(cornerpyramidx, cornerpyramidy, cornerpyramidz) { 17 | polyhedron ( points = [[0,0,0], 18 | [cornerpyramidx, 0, 0], 19 | [0, cornerpyramidy, 0], 20 | [cornerpyramidx, cornerpyramidy, 0], 21 | [0, cornerpyramidy, cornerpyramidz]], 22 | 23 | triangles = [[0,1,2],[2,1,3],[4,1,0],[3,1,4],[2,3,4],[0,2,4]]); 24 | 25 | } 26 | 27 | module eqlpyramid(eqlpyramidx, eqlpyramidy, eqlpyramidz) { 28 | polyhedron ( points = [[0,0,0], 29 | [eqlpyramidx, 0, 0], 30 | [0, eqlpyramidy, 0], 31 | [eqlpyramidx, eqlpyramidy, 0], 32 | [eqlpyramidx/2, eqlpyramidy/2, eqlpyramidz]], 33 | 34 | triangles = [[0,1,2],[2,1,3],[4,1,0],[3,1,4],[2,3,4],[0,2,4]]); 35 | 36 | } 37 | 38 | 39 | module rightprism(rightprismx,rightprismy,rightprismz){ 40 | polyhedron ( points = [[0,0,0], 41 | [rightprismx,0,0], 42 | [rightprismx,rightprismy,0], 43 | [0,rightprismy,0], 44 | [0,rightprismy,rightprismz], 45 | [0,0,rightprismz]], 46 | triangles = [[0,1,2,3],[5,1,0],[5,4,2,1],[4,3,2],[0,3,4,5]]); 47 | } 48 | 49 | 50 | 51 | module eqlprism(rightprismx,rightprismy,rightprismz){ 52 | polyhedron ( points = [[0,0,0], 53 | [rightprismx,0,0], 54 | [rightprismx,rightprismy,0], 55 | [0,rightprismy,0], 56 | [rightprismx/2,rightprismy,rightprismz], 57 | [rightprismx/2,0,rightprismz]], 58 | triangles = [[0,1,2,3],[5,1,0],[5,4,2,1],[4,3,2],[0,3,4,5]]); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /linear_bearing.scad: -------------------------------------------------------------------------------- 1 | //By Glen Chung, 2013. 2 | //Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later 3 | 4 | include 5 | include 6 | 7 | LINEAR_BEARING_dr = 0; //Inscribed circle 8 | LINEAR_BEARING_D = 1; //Outer diameter 9 | LINEAR_BEARING_L = 2; //Length 10 | LINEAR_BEARING_B = 3; //Outer locking groove B 11 | LINEAR_BEARING_D1 = 4; //Outer locking groove D1 12 | LINEAR_BEARING_W = 5; //W 13 | 14 | 15 | // Common bearing names 16 | LinearBearing = "LM8UU"; 17 | 18 | // Linear Bearing dimensions 19 | // model == "XXXXX" ? [ dr, D, L, B, D1, W]: 20 | function linearBearingDimensions(model) = 21 | model == "LM3UU" ? [ 3*mm, 7*mm, 10*mm, 0.0*mm, 0.0*mm, 0.00*mm]: 22 | model == "LM4UU" ? [ 4*mm, 8*mm, 12*mm, 0.0*mm, 0.0*mm, 0.00*mm]: 23 | model == "LM5UU" ? [ 5*mm, 10*mm, 15*mm, 10.2*mm, 9.6*mm, 1.10*mm]: 24 | model == "LM6UU" ? [ 6*mm, 12*mm, 19*mm, 13.5*mm, 11.5*mm, 1.10*mm]: 25 | model == "LM8SUU" ? [ 8*mm, 15*mm, 17*mm, 11.5*mm, 14.3*mm, 1.10*mm]: 26 | model == "LM10UU" ? [ 10*mm, 19*mm, 29*mm, 22.0*mm, 18.0*mm, 1.30*mm]: 27 | model == "LM12UU" ? [ 12*mm, 21*mm, 30*mm, 23.0*mm, 20.0*mm, 1.30*mm]: 28 | model == "LM13UU" ? [ 13*mm, 23*mm, 32*mm, 23.0*mm, 22.0*mm, 1.30*mm]: 29 | model == "LM16UU" ? [ 16*mm, 28*mm, 37*mm, 26.5*mm, 27.0*mm, 1.60*mm]: 30 | model == "LM20UU" ? [ 20*mm, 32*mm, 42*mm, 30.5*mm, 30.5*mm, 1.60*mm]: 31 | model == "LM25UU" ? [ 25*mm, 40*mm, 59*mm, 41.0*mm, 38.0*mm, 1.85*mm]: 32 | model == "LM30UU" ? [ 30*mm, 45*mm, 64*mm, 44.5*mm, 43.0*mm, 1.85*mm]: 33 | model == "LM35UU" ? [ 35*mm, 52*mm, 70*mm, 49.5*mm, 49.0*mm, 2.10*mm]: 34 | model == "LM40UU" ? [ 40*mm, 60*mm, 80*mm, 60.5*mm, 57.0*mm, 2.10*mm]: 35 | model == "LM50UU" ? [ 50*mm, 80*mm, 100*mm, 74.0*mm, 76.5*mm, 2.60*mm]: 36 | model == "LM60UU" ? [ 60*mm, 90*mm, 110*mm, 85.0*mm, 86.5*mm, 3.15*mm]: 37 | model == "LM80UU" ? [ 80*mm, 120*mm, 140*mm, 105.5*mm, 116.0*mm, 4.15*mm]: 38 | model == "LM100UU" ? [100*mm, 150*mm, 150*mm, 125.5*mm, 145.0*mm, 4.15*mm]: 39 | /*model == "LM8UU" ?*/ [ 8*mm, 15*mm, 24*mm, 17.5*mm, 14.3*mm, 1.10*mm]; 40 | 41 | 42 | function linearBearing_dr(model) = linearBearingDimensions(model)[LINEAR_BEARING_dr]; 43 | function linearBearing_D(model) = linearBearingDimensions(model)[LINEAR_BEARING_D]; 44 | function linearBearing_L(model) = linearBearingDimensions(model)[LINEAR_BEARING_L]; 45 | function linearBearing_B(model) = linearBearingDimensions(model)[LINEAR_BEARING_B]; 46 | function linearBearing_D1(model) = linearBearingDimensions(model)[LINEAR_BEARING_D1]; 47 | function linearBearing_W(model) = linearBearingDimensions(model)[LINEAR_BEARING_W]; 48 | 49 | module linearBearing(pos=[0,0,0], angle=[0,0,0], model=LinearBearing, 50 | material=Steel, sideMaterial=BlackPaint) { 51 | dr = linearBearing_dr(model); 52 | D = linearBearing_D(model); 53 | L = linearBearing_L(model); 54 | B = linearBearing_B(model); 55 | D1 = linearBearing_D1(model); 56 | W = linearBearing_W(model); 57 | 58 | innerRim = dr + (D - dr) * 0.2; 59 | outerRim = D - (D - dr) * 0.2; 60 | midSink = W/4; 61 | 62 | translate(pos) rotate(angle) union() { 63 | color(material) 64 | difference() { 65 | // Basic ring 66 | Ring([0,0,0], D, dr, L, material, material); 67 | 68 | if(W) { 69 | // Side shields 70 | Ring([0,0,-epsilon], outerRim, innerRim, L*epsilon+midSink, sideMaterial, material); 71 | Ring([0,0,L-midSink-epsilon], outerRim, innerRim, L*epsilon+midSink, sideMaterial, material); 72 | //Outer locking groove 73 | Ring([0,0,(L-B)/2], D+epsilon, outerRim+W/2, W, material, material); 74 | Ring([0,0,L-(L-B)/2], D+epsilon, outerRim+W/2, W, material, material); 75 | } 76 | } 77 | if(W) 78 | Ring([0,0,midSink], D-L*epsilon, dr+L*epsilon, L-midSink*2, sideMaterial, sideMaterial); 79 | } 80 | 81 | module Ring(pos, od, id, h, material, holeMaterial) { 82 | color(material) { 83 | translate(pos) 84 | difference() { 85 | cylinder(r=od/2, h=h, $fn = 100); 86 | color(holeMaterial) 87 | translate([0,0,-10*epsilon]) 88 | cylinder(r=id/2, h=h+20*epsilon, $fn = 100); 89 | } 90 | } 91 | } 92 | 93 | } 94 | 95 | 96 | //examples 97 | //linearBearing(model="LM8UU"); 98 | //linearBearing(model="LM10UU"); 99 | -------------------------------------------------------------------------------- /materials.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * Material colors. 3 | * 4 | * Originally by Hans Häggström, 2010. 5 | * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later 6 | */ 7 | 8 | // Material colors 9 | Oak = [0.65, 0.5, 0.4]; 10 | Pine = [0.85, 0.7, 0.45]; 11 | Birch = [0.9, 0.8, 0.6]; 12 | FiberBoard = [0.7, 0.67, 0.6]; 13 | BlackPaint = [0.2, 0.2, 0.2]; 14 | Iron = [0.36, 0.33, 0.33]; 15 | Steel = [0.65, 0.67, 0.72]; 16 | Stainless = [0.45, 0.43, 0.5]; 17 | Aluminum = [0.77, 0.77, 0.8]; 18 | Brass = [0.88, 0.78, 0.5]; 19 | Transparent = [1, 1, 1, 0.2]; 20 | 21 | // Example, uncomment to view 22 | //color_demo(); 23 | 24 | module color_demo(){ 25 | // Wood 26 | colorTest(Oak, 0, 0); 27 | colorTest(Pine, 1, 0); 28 | colorTest(Birch, 2, 0); 29 | 30 | // Metals 31 | colorTest(Iron, 0, 1); 32 | colorTest(Steel, 1, 1); 33 | colorTest(Stainless, 2, 1); 34 | colorTest(Aluminum, 3, 1); 35 | 36 | // Mixboards 37 | colorTest(FiberBoard, 0, 2); 38 | 39 | // Paints 40 | colorTest(BlackPaint, 0, 3); 41 | } 42 | 43 | module colorTest(col, row=0, c=0) { 44 | color(col) translate([row * 30,c*30,0]) sphere(r=10); 45 | } 46 | -------------------------------------------------------------------------------- /math.scad: -------------------------------------------------------------------------------- 1 | // MIT license 2 | 3 | include 4 | 5 | function deg(angle) = 360*angle/TAU; 6 | 7 | -------------------------------------------------------------------------------- /metric_fastners.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenSCAD Metric Fastners Library (www.openscad.org) 3 | * Copyright (C) 2010-2011 Giles Bathgate 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, 8 | * LGPL version 2.1, or (at your option) any later version of the GPL. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | */ 20 | 21 | $fn=50; 22 | apply_chamfer=true; 23 | 24 | module cap_bolt(dia,len) 25 | { 26 | e=1.5*dia; 27 | h1=1.25*dia; 28 | cylinder(r=dia/2,h=len); 29 | translate([0,0,-h1]) cylinder(r=e/2,h=h1); 30 | } 31 | 32 | module csk_bolt(dia,len) 33 | { 34 | h1=0.6*dia; 35 | h2=len-h1; 36 | cylinder(r=dia/2,h=h2); 37 | cylinder(r1=dia,r2=dia/2,h=h1); 38 | } 39 | 40 | module washer(dia) 41 | { 42 | t=0.1*dia; 43 | difference() 44 | { 45 | cylinder(r=dia,h=t); 46 | translate([0,0,-t/2])cylinder(r=dia/2,h=t*2); 47 | } 48 | } 49 | 50 | module flat_nut(dia) 51 | { 52 | m=0.8*dia; 53 | e=1.8*dia; 54 | c=0.2*dia; 55 | difference() 56 | { 57 | cylinder(r=e/2,h=m,$fn=6); 58 | translate([0,0,-m/2])cylinder(r=dia/2,h=m*2); 59 | if(apply_chamfer) 60 | translate([0,0,c])cylinder_chamfer(e/2,c); 61 | } 62 | } 63 | 64 | module bolt(dia,len) 65 | { 66 | e=1.8*dia; 67 | k=0.7*dia; 68 | c=0.2*dia; 69 | difference() 70 | { 71 | cylinder(r=e/2,h=k,$fn=6); 72 | if(apply_chamfer) 73 | translate([0,0,c])cylinder_chamfer(e/2,c); 74 | } 75 | 76 | cylinder(r=dia/2,h=len); 77 | 78 | } 79 | 80 | module cylinder_chamfer(r1,r2) 81 | { 82 | t=r1-r2; 83 | p=r2*2; 84 | rotate_extrude() 85 | difference() 86 | { 87 | translate([t,-p])square([p,p]); 88 | translate([t,0])circle(r2); 89 | } 90 | } 91 | 92 | module chamfer(len,r) 93 | { 94 | p=r*2; 95 | linear_extrude(height=len) 96 | difference() 97 | { 98 | square([p,p]); 99 | circle(r); 100 | } 101 | } 102 | 103 | union() 104 | { 105 | //csk_bolt(3,14); 106 | //washer(3); 107 | //flat_nut(3); 108 | //bolt(4,14); 109 | //cylinder_chamfer(8,1); 110 | //chamfer(10,2); 111 | } 112 | -------------------------------------------------------------------------------- /motors.scad: -------------------------------------------------------------------------------- 1 | // Copyright 2010 D1plo1d 2 | 3 | // This library is dual licensed under the GPL 3.0 and the GNU Lesser General Public License as per http://creativecommons.org/licenses/LGPL/2.1/ . 4 | 5 | include 6 | 7 | 8 | //generates a motor mount for the specified nema standard #. 9 | module stepper_motor_mount(nema_standard,slide_distance=0, mochup=true, tolerance=0) { 10 | //dimensions from: 11 | // http://www.numberfactory.com/NEMA%20Motor%20Dimensions.htm 12 | if (nema_standard == 17) 13 | { 14 | _stepper_motor_mount( 15 | motor_shaft_diameter = 0.1968*mm_per_inch, 16 | motor_shaft_length = 0.945*mm_per_inch, 17 | pilot_diameter = 0.866*mm_per_inch, 18 | pilot_length = 0.80*mm_per_inch, 19 | mounting_bolt_circle = 1.725*mm_per_inch, 20 | bolt_hole_size = 3.5, 21 | bolt_hole_distance = 1.220*mm_per_inch, 22 | slide_distance = slide_distance, 23 | mochup = mochup, 24 | tolerance=tolerance); 25 | } 26 | if (nema_standard == 23) 27 | { 28 | _stepper_motor_mount( 29 | motor_shaft_diameter = 0.250*mm_per_inch, 30 | motor_shaft_length = 0.81*mm_per_inch, 31 | pilot_diameter = 1.500*mm_per_inch, 32 | pilot_length = 0.062*mm_per_inch, 33 | mounting_bolt_circle = 2.625*mm_per_inch, 34 | bolt_hole_size = 0.195*mm_per_inch, 35 | bolt_hole_distance = 1.856*mm_per_inch, 36 | slide_distance = slide_distance, 37 | mochup = mochup, 38 | tolerance=tolerance); 39 | } 40 | 41 | } 42 | 43 | 44 | //inner mehod for creating a stepper motor mount of any dimensions 45 | module _stepper_motor_mount( 46 | motor_shaft_diameter, 47 | motor_shaft_length, 48 | pilot_diameter, 49 | pilot_length, 50 | mounting_bolt_circle, 51 | bolt_hole_size, 52 | bolt_hole_distance, 53 | slide_distance = 0, 54 | motor_length = 40, //arbitray - not standardized 55 | mochup, 56 | tolerance = 0 57 | ) 58 | { 59 | union() 60 | { 61 | // == centered mount points == 62 | //mounting circle inset 63 | translate([0,slide_distance/2,0]) circle(r = pilot_diameter/2 + tolerance); 64 | square([pilot_diameter,slide_distance],center=true); 65 | translate([0,-slide_distance/2,0]) circle(r = pilot_diameter/2 + tolerance); 66 | 67 | //todo: motor shaft hole 68 | 69 | //mounting screw holes 70 | for (x = [-1,1]) 71 | { 72 | for (y = [-1,1]) 73 | { 74 | translate([x*bolt_hole_distance/2,y*bolt_hole_distance/2,0]) 75 | { 76 | translate([0,slide_distance/2,0]) circle(bolt_hole_size/2 + tolerance); 77 | translate([0,-slide_distance/2,0]) circle(bolt_hole_size/2 + tolerance); 78 | square([bolt_hole_size+2*tolerance,slide_distance],center=true); 79 | } 80 | } 81 | } 82 | // == motor mock-up == 83 | //motor box 84 | if (mochup == true) 85 | { 86 | %translate([0,0,-5]) cylinder(h = 5, r = pilot_diameter/2); 87 | %translate(v=[0,0,-motor_length/2]) 88 | { 89 | cube(size=[bolt_hole_distance+bolt_hole_size+5,bolt_hole_distance+bolt_hole_size+5,motor_length], center = true); 90 | } 91 | //shaft 92 | %translate(v=[0,0,-(motor_length-motor_shaft_length-2)/2]) 93 | { 94 | %cylinder(r=motor_shaft_diameter/2,h=motor_length+motor_shaft_length--1, center = true); 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /multiply.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * Multiplication along certain curves 3 | * 4 | * Copyright by Elmo Mäntynen, 2012. 5 | * Licenced under LGPL2 or later 6 | */ 7 | 8 | include 9 | 10 | use 11 | 12 | // Copy everything $no of times around an $axis, spread over $angle 13 | // If $strict==true or $angle==360, then spacing will leave an empty at $angle, 14 | // otherwise, $no will be distributed so first is at 0deg, last copy at $angle degrees 15 | // NOTE: $axis works (rotates around that axis), but pass parameter as lower case string 16 | // eg: "x", "y", or "z". Alternatively, use units.scad vector definitions: X, Y, Z 17 | module spin(no, angle=360, axis=Z, strict=false){ 18 | divisor = (strict || angle==360) ? no : no-1; 19 | for (i = [0:no-1]) 20 | rotate(normalized_axis(axis)*angle*i/divisor) 21 | children(); 22 | } 23 | 24 | // Make a copy of children by rotating around $axis by 180 degrees 25 | module duplicate(axis=Z) spin(no=2, axis=axis) children(); 26 | 27 | // Make $no copies along the $axis, separated by $separation 28 | module linear_multiply(no, separation, axis=Z) 29 | for (i = [0:no-1]) 30 | translate(i*separation*normalized_axis(axis)) children(); 31 | -------------------------------------------------------------------------------- /nuts_and_bolts.scad: -------------------------------------------------------------------------------- 1 | // Copyright 2010 D1plo1d 2 | 3 | // This library is dual licensed under the GPL 3.0 and the GNU Lesser General Public License as per http://creativecommons.org/licenses/LGPL/2.1/ . 4 | 5 | //testNutsAndBolts(); 6 | 7 | module SKIPtestNutsAndBolts() 8 | { 9 | $fn = 360; 10 | translate([0,15])nutHole(3, proj=2); 11 | boltHole(3, length= 30, proj=2); 12 | } 13 | 14 | MM = "mm"; 15 | INCH = "inch"; //Not yet supported 16 | 17 | //Based on: http://www.roymech.co.uk/Useful_Tables/Screws/Hex_Screws.htm 18 | METRIC_NUT_AC_WIDTHS = 19 | [ 20 | -1, //0 index is not used but reduces computation 21 | -1, 22 | 4.38,//m2 23 | 6.40,//m3 24 | 8.10,//m4 25 | 9.20,//m5 26 | 11.50,//m6 27 | -1, 28 | 15.00,//m8 29 | -1, 30 | 19.60,//m10 31 | -1, 32 | 22.10,//m12 33 | -1, 34 | -1, 35 | -1, 36 | 27.70,//m16 37 | -1, 38 | -1, 39 | -1, 40 | 34.60,//m20 41 | -1, 42 | -1, 43 | -1, 44 | 41.60,//m24 45 | -1, 46 | -1, 47 | -1, 48 | -1, 49 | -1, 50 | 53.1,//m30 51 | -1, 52 | -1, 53 | -1, 54 | -1, 55 | -1, 56 | 63.5//m36 57 | ]; 58 | METRIC_NUT_THICKNESS = 59 | [ 60 | -1, //0 index is not used but reduces computation 61 | -1, 62 | 1.6,//m2 63 | 2.40,//m3 64 | 3.20,//m4 65 | 4.00,//m5 66 | 5.00,//m6 67 | -1, 68 | 6.50,//m8 69 | -1, 70 | 8.00,//m10 71 | -1, 72 | 10.00,//m12 73 | -1, 74 | -1, 75 | -1, 76 | 13.00,//m16 77 | -1, 78 | -1, 79 | -1, 80 | 16.00//m20 81 | -1, 82 | -1, 83 | -1, 84 | 19.00,//m24 85 | -1, 86 | -1, 87 | -1, 88 | -1, 89 | -1, 90 | 24.00,//m30 91 | -1, 92 | -1, 93 | -1, 94 | -1, 95 | -1, 96 | 29.00//m36 97 | ]; 98 | 99 | COARSE_THREAD_METRIC_BOLT_MAJOR_DIAMETERS = 100 | [//based on max values 101 | -1, //0 index is not used but reduces computation 102 | -1, 103 | 1.6,//m2 104 | 2.98,//m3 105 | 3.978,//m4 106 | 4.976,//m5 107 | 5.974,//m6 108 | -1, 109 | 7.972,//m8 110 | -1, 111 | 9.968,//m10 112 | -1, 113 | 11.966,//m12 114 | -1, 115 | -1, 116 | -1, 117 | 15.962,//m16 118 | -1, 119 | -1, 120 | -1, 121 | 19.958,//m20 122 | -1, 123 | -1, 124 | -1, 125 | 23.952,//m24 126 | -1, 127 | -1, 128 | -1, 129 | -1, 130 | -1, 131 | 29.947,//m30 132 | -1, 133 | -1, 134 | -1, 135 | -1, 136 | -1, 137 | 35.940//m36 138 | ]; 139 | 140 | // Deprecated, but kept around for people who use the wrong spelling. 141 | COURSE_METRIC_BOLT_MAJOR_THREAD_DIAMETERS = COARSE_THREAD_METRIC_BOLT_MAJOR_DIAMETERS; 142 | 143 | //Based on: http://www.roymech.co.uk/Useful_Tables/Screws/cap_screws.htm 144 | METRIC_BOLT_CAP_DIAMETERS = 145 | [ 146 | -1, //0 index is not used but reduces computation 147 | -1, 148 | 3.8, 149 | 5.50,//m3 150 | 7.00,//m4 151 | 8.50,//m5 152 | 10.00,//m6 153 | -1, 154 | 13.00,//m8 155 | -1, 156 | 16.00,//m10 157 | -1, 158 | 18.00,//m12 159 | -1, 160 | -1, 161 | -1, 162 | 24.00,//m16 163 | -1, 164 | -1, 165 | -1, 166 | 30.00//m20 167 | -1, 168 | -1, 169 | -1, 170 | 36.00,//m24 171 | -1, 172 | -1, 173 | -1, 174 | -1, 175 | -1, 176 | 45.00,//m30 177 | -1, 178 | -1, 179 | -1, 180 | -1, 181 | -1, 182 | 54.00//m36 183 | ]; 184 | 185 | module nutHole(size, units=MM, tolerance = +0.0001, proj = -1) 186 | { 187 | //takes a metric screw/nut size and looksup nut dimensions 188 | radius = METRIC_NUT_AC_WIDTHS[size]/2+tolerance; 189 | height = METRIC_NUT_THICKNESS[size]+tolerance; 190 | if (proj == -1) 191 | { 192 | cylinder(r= radius, h=height, $fn = 6, center=[0,0]); 193 | } 194 | if (proj == 1) 195 | { 196 | circle(r= radius, $fn = 6); 197 | } 198 | if (proj == 2) 199 | { 200 | translate([-radius/2, 0]) 201 | square([radius*2, height]); 202 | } 203 | } 204 | 205 | module boltHole(size, units=MM, length, tolerance = +0.0001, proj = -1) 206 | { 207 | radius = COARSE_THREAD_METRIC_BOLT_MAJOR_DIAMETERS[size]/2+tolerance; 208 | capHeight = size+tolerance; 209 | capRadius = METRIC_BOLT_CAP_DIAMETERS[size]/2+tolerance; 210 | 211 | if (proj == -1) 212 | { 213 | translate([0, 0, -capHeight]) 214 | cylinder(r= capRadius, h=capHeight); 215 | cylinder(r = radius, h = length); 216 | } 217 | if (proj == 1) 218 | { 219 | circle(r = radius); 220 | } 221 | if (proj == 2) 222 | { 223 | translate([-capRadius/2, -capHeight]) 224 | square([capRadius*2, capHeight]); 225 | square([radius*2, length]); 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /openscad_testing.py: -------------------------------------------------------------------------------- 1 | import py 2 | import os.path 3 | from openscad_utils import * 4 | 5 | 6 | temppath = py.test.ensuretemp('MCAD') 7 | 8 | def pytest_generate_tests(metafunc): 9 | if "modpath" in metafunc.funcargnames: 10 | args1 = [] 11 | args2 = [] 12 | for fpath, modnames in collect_test_modules().items(): 13 | basename = os.path.splitext(os.path.split(str(fpath))[1])[0] 14 | if "modname" in metafunc.funcargnames: 15 | for modname in modnames: 16 | args2.append([fpath, modname]) 17 | else: 18 | args1.append(fpath) 19 | 20 | if "modname" in metafunc.funcargnames: 21 | metafunc.parametrize(["modpath", "modname"], args2) 22 | else: 23 | metafunc.parametrize("modpath", args1) 24 | 25 | def test_module_compile(modname, modpath): 26 | tempname = modpath.basename + '-' + modname + '.scad' 27 | fpath = temppath.join(tempname) 28 | stlpath = temppath.join(tempname + ".stl") 29 | f = fpath.open('w') 30 | code = """ 31 | //generated testfile 32 | use <%s> 33 | 34 | %s(); 35 | """ % (modpath, modname) 36 | print(code) 37 | f.write(code) 38 | f.flush() 39 | output = call_openscad(path=fpath, stlpath=stlpath, timeout=60) 40 | print(output) 41 | assert output[0] is 0 42 | for s in ("warning", "error"): 43 | assert s not in output[2].strip().lower().decode("utf-8") 44 | assert len(stlpath.readlines()) > 2 45 | 46 | def test_file_compile(modpath): 47 | stlpath = temppath.join(modpath.basename + "-test.stl") 48 | output = call_openscad(path=modpath, stlpath=stlpath) 49 | print(output) 50 | assert output[0] is 0 51 | for s in ("warning", "error"): 52 | assert s not in output[2].strip().lower().decode("utf-8") 53 | assert len(stlpath.readlines()) == 2 54 | -------------------------------------------------------------------------------- /openscad_utils.py: -------------------------------------------------------------------------------- 1 | import py, re, os, signal, time, subprocess, sys 2 | from subprocess import Popen, PIPE 3 | 4 | mod_re = (r"\bmodule\s+(", r")\s*\(\s*") 5 | func_re = (r"\bfunction\s+(", r")\s*\(") 6 | 7 | def extract_definitions(fpath, name_re=r"\w+", def_re=""): 8 | regex = name_re.join(def_re) 9 | matcher = re.compile(regex) 10 | return (m.group(1) for m in matcher.finditer(fpath.read())) 11 | 12 | def extract_mod_names(fpath, name_re=r"\w+"): 13 | return extract_definitions(fpath, name_re=name_re, def_re=mod_re) 14 | 15 | def extract_func_names(fpath, name_re=r"\w+"): 16 | return extract_definitions(fpath, name_re=name_re, def_re=func_re) 17 | 18 | def collect_test_modules(dirpath=None): 19 | dirpath = dirpath or py.path.local("./") 20 | print("Collecting openscad test module names") 21 | 22 | test_files = {} 23 | for fpath in dirpath.visit('*.scad'): 24 | #print(fpath) 25 | modules = extract_mod_names(fpath, r"test\w*") 26 | #functions = extract_func_names(fpath, r"test\w*") 27 | test_files[fpath] = modules 28 | return test_files 29 | 30 | class Timeout(Exception): pass 31 | 32 | def call_openscad(path, stlpath, timeout=5): 33 | if sys.platform == 'darwin': exe = 'OpenSCAD.app/Contents/MacOS/OpenSCAD' 34 | else: exe = 'openscad' 35 | command = [exe, '-o', str(stlpath), str(path)] 36 | print(command) 37 | if timeout: 38 | try: 39 | proc = Popen(command, 40 | stdout=PIPE, stderr=PIPE, close_fds=True) 41 | calltime = time.time() 42 | time.sleep(0.05) 43 | #print(calltime) 44 | while True: 45 | if proc.poll() is not None: 46 | break 47 | time.sleep(0.5) 48 | #print(time.time()) 49 | if time.time() > calltime + timeout: 50 | raise Timeout() 51 | finally: 52 | try: 53 | proc.terminate() 54 | proc.kill() 55 | except OSError: 56 | pass 57 | 58 | return (proc.returncode,) + proc.communicate() 59 | else: 60 | output = subprocess.getstatusoutput(" ".join(command)).decode("utf-8") 61 | return output + ('', '') 62 | 63 | def parse_output(text): 64 | pass 65 | -------------------------------------------------------------------------------- /polyholes.scad: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Nophead (of RepRap fame) 2 | // This file is licensed under the terms of Creative Commons Attribution 3.0 Unported. 3 | 4 | // Using this holes should come out approximately right when printed 5 | module polyhole(h, d=0, r=0, center=false) { 6 | _r = (r == 0 ? d / 2 : r); 7 | _d = (d == 0 ? r * 2 : d); 8 | 9 | n = max(round(2 * _d),3); 10 | 11 | rotate([0,0,180]) 12 | cylinder(h = h, r = (_d / 2) / cos (180 / n), $fn = n, center=center); 13 | } 14 | 15 | module test_polyhole(){ 16 | difference() { 17 | cube(size = [100,27,3]); 18 | union() { 19 | for(i = [1:10]) { 20 | translate([(i * i + i)/2 + 3 * i , 8,-1]) 21 | polyhole(h = 5, d = i); 22 | 23 | let(d = i + 0.5) 24 | translate([(d * d + d)/2 + 3 * d, 19,-1]) 25 | polyhole(h = 5, d = d); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /profiles.scad: -------------------------------------------------------------------------------- 1 | // ============================================== 2 | // Miscellaneous profiles (aluminum etc) 3 | // By Vitaly Mankevich / contraptor.org, (c) 2012 4 | // LGPL 2.1 5 | // ============================================== 6 | // 7 | // PROFILES (DIMENSIONLESS UNLESS SPECIFIED) 8 | // ----------------------------------------- 9 | // profile_angle_equal(1, 1/8); 10 | // profile_angle_unequal(1, 1/2, 1/16); 11 | // profile_square_tube(1.5, 1/8); 12 | // profile_rect_tube(1.5, 2, 1/8); 13 | // profile_channel(1.5, 1, 1/8); 14 | // 15 | // profile_8020_fractional_1010(); // inches 16 | // profile_misumi_metric_2020(); // millimeters 17 | // profile_makerbeam(); // millimeters 18 | // 19 | // EXTRUDED PROFILES 20 | // ----------------- 21 | // linear_extrude (height = 3.5) profile_square_tube(1.5, 1/8); 22 | // 23 | 24 | $fn = 24; 25 | 26 | module profile_angle_equal(side, wall) { 27 | difference () { 28 | square (side); 29 | translate([wall, wall, 0]) square (side - wall); 30 | } 31 | } 32 | 33 | module profile_angle_unequal(side_x, side_y, wall) { 34 | difference () { 35 | square ([side_x, side_y]); 36 | translate ([wall, wall, 0]) square ([side_x - wall, side_y - wall]); 37 | } 38 | } 39 | 40 | module profile_square_tube(side, wall) { 41 | difference () { 42 | square (side, center = true); 43 | square (side-wall*2, center = true); 44 | } 45 | } 46 | 47 | module profile_rect_tube(side_x, side_y, wall) { 48 | difference () { 49 | square ([side_x, side_y], center = true); 50 | square ([side_x - wall*2, side_y - wall*2], center = true); 51 | } 52 | } 53 | 54 | module profile_channel(base, side, wall) { 55 | translate ([0, side/2, 0]) difference () { 56 | square ([base, side], center = true); 57 | translate ([0, wall/2, 0]) square ([base - wall*2, side - wall], center = true); 58 | } 59 | } 60 | 61 | module profile_tslot_generic (pitch, slot, lip, web, core, hole) { 62 | // pitch = side width, slot = slot width, lip = thickness of the lip, web = thickness of the web, core = side of the center square, hole = center hole diameter 63 | difference () { 64 | union() { 65 | difference () { 66 | square (pitch, center=true); 67 | square (pitch - lip*2, center=true); 68 | square ([pitch, slot], center=true); 69 | square ([slot, pitch], center=true); 70 | } 71 | rotate ([0, 0, 45]) square ([pitch*1.15, web], center=true); 72 | rotate ([0, 0, -45]) square ([pitch*1.15, web], center=true); 73 | square (core, center=true); 74 | } 75 | circle (hole/2); 76 | } 77 | } 78 | 79 | module profile_8020_fractional_1010 () { 80 | profile_tslot_generic (pitch = 1, slot = 0.26, lip = 0.1, web = 0.13, core = 0.45, hole = 0.28); 81 | } 82 | 83 | module profile_misumi_metric_2020 () { 84 | profile_tslot_generic (pitch = 20, slot = 5.2, lip = 2, web = 2.6, core = 9, hole = 5.6); 85 | } 86 | 87 | module profile_makerbeam () { 88 | profile_tslot_generic (pitch = 10, slot = 2.5, lip = 1, web = 2, core = 1, hole = 0); 89 | } 90 | -------------------------------------------------------------------------------- /regular_shapes.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenSCAD Shapes Library (www.openscad.org) 3 | * Copyright (C) 2010-2011 Giles Bathgate, Elmo Mäntynen 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, 8 | * LGPL version 2.1, or (at your option) any later version of the GPL. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | */ 20 | 21 | // 2D regular shapes 22 | 23 | module triangle(radius) 24 | { 25 | o=radius/2; //equivalent to radius*sin(30) 26 | a=radius*sqrt(3)/2; //equivalent to radius*cos(30) 27 | polygon(points=[[-a,-o],[0,radius],[a,-o]],paths=[[0,1,2]]); 28 | } 29 | 30 | module reg_polygon(sides, radius) { 31 | echo(" 32 | DEPRECATED: function 'reg_polygon' is now deprecated 33 | please use 'regular_polygon' instead"); 34 | 35 | regular_polygon(sides, radius); 36 | } 37 | 38 | module regular_polygon(sides, radius) 39 | { 40 | function dia(r) = sqrt(pow(r*2,2)/2); //sqrt((r*2^2)/2) if only we had an exponention op 41 | if(sides<2) square([radius,0]); 42 | if(sides==3) triangle(radius); 43 | if(sides==4) square([dia(radius),dia(radius)],center=true); 44 | if(sides>4) { 45 | angles=[ for (i = [0:sides-1]) i*(360/sides) ]; 46 | coords=[ for (th=angles) [radius*cos(th), radius*sin(th)] ]; 47 | polygon(coords); 48 | } 49 | } 50 | 51 | module pentagon(radius) 52 | { 53 | regular_polygon(5,radius); 54 | } 55 | 56 | module hexagon(radius, diameter, across_flats) 57 | { 58 | r = across_flats ? across_flats/2/cos(30) : diameter ? diameter/2 : radius; 59 | regular_polygon(6,r); 60 | } 61 | 62 | module heptagon(radius) 63 | { 64 | regular_polygon(7,radius); 65 | } 66 | 67 | module octagon(radius) 68 | { 69 | regular_polygon(8,radius); 70 | } 71 | 72 | module nonagon(radius) 73 | { 74 | regular_polygon(9,radius); 75 | } 76 | 77 | module decagon(radius) 78 | { 79 | regular_polygon(10,radius); 80 | } 81 | 82 | module hendecagon(radius) 83 | { 84 | regular_polygon(11,radius); 85 | } 86 | 87 | module dodecagon(radius) 88 | { 89 | regular_polygon(12,radius); 90 | } 91 | 92 | module ring(inside_diameter, thickness){ 93 | difference(){ 94 | circle(r=(inside_diameter+thickness*2)/2); 95 | circle(r=inside_diameter/2); 96 | } 97 | } 98 | 99 | module ellipse(width, height) { 100 | scale([1, height/width, 1]) circle(r=width/2); 101 | } 102 | 103 | // The ratio of length and width is about 1.39 for a real egg 104 | module egg_outline(width, length){ 105 | translate([0, width/2, 0]) union(){ 106 | rotate([0, 0, 180]) difference(){ 107 | ellipse(width, 2*length-width); 108 | translate([-length/2, 0, 0]) square(length); 109 | } 110 | circle(r=width/2); 111 | } 112 | } 113 | 114 | //3D regular shapes 115 | 116 | module cone(height, radius, center = false) 117 | { 118 | cylinder(height, radius, 0, center); 119 | } 120 | 121 | module oval_prism(height, rx, ry, center = false) 122 | { 123 | scale([1, rx/ry, 1]) cylinder(h=height, r=ry, center=center); 124 | } 125 | 126 | module oval_tube(height, rx, ry, wall, center = false) 127 | { 128 | difference() { 129 | scale([1, ry/rx, 1]) cylinder(h=height, r=rx, center=center); 130 | translate([0,0,-height/2]) scale([(rx-wall)/rx, (ry-wall)/rx, 2]) cylinder(h=height, r=rx, center=center); 131 | } 132 | } 133 | 134 | module cylinder_tube(height, radius, wall, center = false) 135 | { 136 | tubify(radius,wall) 137 | cylinder(h=height, r=radius, center=center); 138 | } 139 | 140 | //Tubifies any regular prism 141 | module tubify(radius,wall) 142 | { 143 | difference() 144 | { 145 | children(0); 146 | translate([0, 0, -0.1]) scale([(radius-wall)/radius, (radius-wall)/radius, 2]) children(0); 147 | } 148 | } 149 | 150 | module triangle_prism(height,radius) 151 | { 152 | linear_extrude(height=height) triangle(radius); 153 | } 154 | 155 | module triangle_tube(height,radius,wall) 156 | { 157 | tubify(radius,wall) triangle_prism(height,radius); 158 | } 159 | 160 | module pentagon_prism(height,radius) 161 | { 162 | linear_extrude(height=height) pentagon(radius); 163 | } 164 | 165 | module pentagon_tube(height,radius,wall) 166 | { 167 | tubify(radius,wall) pentagon_prism(height,radius); 168 | } 169 | 170 | module hexagon_prism(height, radius, across_flats) 171 | { 172 | linear_extrude(height=height) 173 | hexagon(radius=radius, across_flats=across_flats); 174 | } 175 | 176 | module hexagon_tube(height,radius,wall) 177 | { 178 | tubify(radius,wall) hexagon_prism(height,radius); 179 | } 180 | 181 | module heptagon_prism(height,radius) 182 | { 183 | linear_extrude(height=height) heptagon(radius); 184 | } 185 | 186 | module heptagon_tube(height,radius,wall) 187 | { 188 | tubify(radius,wall) heptagon_prism(height,radius); 189 | } 190 | 191 | module octagon_prism(height,radius) 192 | { 193 | linear_extrude(height=height) octagon(radius); 194 | } 195 | 196 | module octagon_tube(height,radius,wall) 197 | { 198 | tubify(radius,wall) octagon_prism(height,radius); 199 | } 200 | 201 | module nonagon_prism(height,radius) 202 | { 203 | linear_extrude(height=height) nonagon(radius); 204 | } 205 | 206 | module decagon_prism(height,radius) 207 | { 208 | linear_extrude(height=height) decagon(radius); 209 | } 210 | 211 | module hendecagon_prism(height,radius) 212 | { 213 | linear_extrude(height=height) hendecagon(radius); 214 | } 215 | 216 | module dodecagon_prism(height,radius) 217 | { 218 | linear_extrude(height=height) dodecagon(radius); 219 | } 220 | 221 | module torus(outerRadius, innerRadius) 222 | { 223 | r=(outerRadius-innerRadius)/2; 224 | rotate_extrude() translate([innerRadius+r,0,0]) circle(r); 225 | } 226 | 227 | module torus2(r1, r2) 228 | { 229 | rotate_extrude() translate([r1,0,0]) circle(r2); 230 | } 231 | 232 | module oval_torus(inner_radius, thickness=[0, 0]) 233 | { 234 | rotate_extrude() translate([inner_radius+thickness[0]/2,0,0]) ellipse(width=thickness[0], height=thickness[1]); 235 | } 236 | 237 | 238 | module triangle_pyramid(radius) 239 | { 240 | o=radius/2; //equivalent to radius*sin(30) 241 | a=radius*sqrt(3)/2; //equivalent to radius*cos(30) 242 | polyhedron(points=[[-a,-o,-o],[a,-o,-o],[0,radius,-o],[0,0,radius]],triangles=[[0,1,2],[1,2,3],[0,1,3],[0,2,3]]); 243 | } 244 | 245 | module square_pyramid(base_x, base_y,height) 246 | { 247 | w=base_x/2; 248 | h=base_y/2; 249 | polyhedron(points=[[-w,-h,0],[-w,h,0],[w,h,0],[w,-h,0],[0,0,height]],triangles=[[0,3,2,1], [0,1,4], [1,2,4], [2,3,4], [3,0,4]]); 250 | } 251 | 252 | module egg(width, length){ 253 | rotate_extrude() 254 | difference(){ 255 | egg_outline(width, length); 256 | translate([-length, 0, 0]) cube(2*length, center=true); 257 | } 258 | } 259 | 260 | // Tests: 261 | 262 | test_square_pyramid(){square_pyramid(10, 20, 30);} 263 | -------------------------------------------------------------------------------- /screw.scad: -------------------------------------------------------------------------------- 1 | // Parametric screw-like things (ball screws, augers) 2 | // License: GNU LGPL 2.1 or later. 3 | // © 2010 by Elmo Mäntynen 4 | 5 | include 6 | 7 | /* common screw parameter 8 | length 9 | pitch = length/rotations: the distance between the turns of the thread 10 | outside_diameter 11 | inner_diameter: thickness of the shaft 12 | */ 13 | 14 | //Uncomment to see examples 15 | //test_auger(); 16 | //test_ball_groove(); 17 | //test_ball_groove2(); 18 | //test_ball_screw(); 19 | 20 | module helix(pitch, length, slices=500){ 21 | rotations = length/pitch; 22 | linear_extrude(height=length, center=false, convexity=10, twist=360*rotations, slices=slices, $fn=100) 23 | children(); 24 | } 25 | 26 | module auger(pitch, length, outside_radius, inner_radius, taper_ratio = 0.25) { 27 | union(){ 28 | helix(pitch, length) 29 | polygon(points=[[0,inner_radius],[outside_radius,(inner_radius * taper_ratio)],[outside_radius,(inner_radius * -1 * taper_ratio)],[0,(-1 * inner_radius)]], paths=[[0,1,2,3]]); 30 | cylinder(h=length, r=inner_radius); 31 | } 32 | } 33 | 34 | module test_auger(){translate([50, 0, 0]) auger(40, 80, 25, 5);} 35 | 36 | 37 | module ball_groove(pitch, length, diameter, ball_radius=10) { 38 | helix(pitch, length, slices=100) 39 | translate([diameter, 0, 0]) 40 | circle(r = ball_radius); 41 | } 42 | 43 | module test_ball_groove(){ translate([0, 300, 0]) ball_groove(100, 300, 10);} 44 | 45 | module ball_groove2(pitch, length, diameter, ball_radius, slices=200){ 46 | rotations = length/pitch; 47 | radius=diameter/2; 48 | offset = length/slices; 49 | union(){ 50 | for (i = [0:slices]) { 51 | let (z = i*offset){ 52 | translate(helix_curve(pitch, radius, z)) sphere(ball_radius, $fa=5, $fs=1); 53 | } 54 | } 55 | } 56 | } 57 | 58 | module test_ball_groove2(){translate([0, 0, 0]) ball_groove2(100, 300, 100, 10);} 59 | 60 | module ball_screw(pitch, length, bearing_radius=2) { 61 | 62 | } 63 | 64 | module test_ball_screw(){} 65 | -------------------------------------------------------------------------------- /servos.scad: -------------------------------------------------------------------------------- 1 | /** 2 | * Servo outline library 3 | * 4 | * Authors: 5 | * - Eero 'rambo' af Heurlin 2010- 6 | * 7 | * License: LGPL 2.1 8 | */ 9 | 10 | use 11 | 12 | /** 13 | * TowerPro SG90 servo 14 | * 15 | * @param vector position The position vector 16 | * @param vector rotation The rotation vector 17 | * @param boolean screws If defined then "screws" will be added and when the module is differenced() from something if will have holes for the screws 18 | * @param boolean cables If defined then "cables" output will be added and when the module is differenced() from something if will have holes for the cables output 19 | * @param number axle_length If defined this will draw a red indicator for the main axle 20 | */ 21 | module towerprosg90(position=undef, rotation=undef, screws = 0, axle_length = 0, cables=0) 22 | { 23 | translate(position) rotate(rotation) { 24 | difference(){ 25 | union() 26 | { 27 | translate([-5.9,-11.8/2,0]) cube([22.5,11.8,22.7]); 28 | translate([0,0,22.7-0.1]){ 29 | cylinder(d=11.8,h=4+0.1); 30 | hull(){ 31 | translate([8.8-5/2,0,0]) cylinder(d=5,h=4+0.1); 32 | cylinder(d=5,h=4+0.1); 33 | } 34 | translate([0,0,4]) cylinder(d=4.6,h=3.2); 35 | } 36 | translate([-4.7-5.9,-11.8/2,15.9]) cube([22.5+4.7*2, 11.8, 2.5]); 37 | } 38 | //screw holes 39 | translate([-2.3-5.9,0,15.9+1.25]) cylinder(d=2,h=5, center=true); 40 | translate([-2.3-5.9-2,0,15.9+1.25]) cube([3,1.3,5], center=true); 41 | translate([2.3+22.5-5.9,0,15.9+1.25]) cylinder(d=2,h=5, center=true); 42 | translate([2.3+22.5-5.9+2,0,15.9+1.25]) cube([3,1.3,5], center=true); 43 | } 44 | if (axle_length > 0) { 45 | color("red", 0.3) translate([0,0,29.9/2]) cylinder(r=1, h=29.9+axle_length, center=true); 46 | } 47 | if (cables > 0) color("red", 0.3) translate([-12.4,-1.8,4.5]) cube([10,3.6,1.2]); 48 | if(screws > 0) color("red", 0.3) { 49 | translate([-2.3-5.9,0,15.9+1.25]) cylinder(d=2,h=10, center=true); 50 | translate([2.3+22.5-5.9,0,15.9+1.25]) cylinder(d=2,h=10, center=true); 51 | } 52 | } 53 | 54 | } 55 | 56 | /** 57 | * Align DS420 digital servo 58 | * 59 | * @param vector position The position vector 60 | * @param vector rotation The rotation vector 61 | * @param boolean screws If defined then "screws" will be added and when the module is differenced() from something if will have holes for the screws 62 | * @param number axle_lenght If defined this will draw "backgound" indicator for the main axle 63 | */ 64 | module alignds420(position, rotation, screws = 0, axle_lenght = 0) 65 | { 66 | translate(position) 67 | { 68 | rotate(rotation) 69 | { 70 | union() 71 | { 72 | // Main axle 73 | translate([0,0,17]) 74 | { 75 | cylinder(r=6, h=8, $fn=30); 76 | cylinder(r=2.5, h=10.5, $fn=20); 77 | } 78 | // Box and ears 79 | translate([-6,-6,0]) 80 | { 81 | cube([12, 22.8,19.5], false); 82 | translate([0,-5, 17]) 83 | { 84 | cube([12, 7, 2.5]); 85 | } 86 | translate([0, 20.8, 17]) 87 | { 88 | cube([12, 7, 2.5]); 89 | } 90 | } 91 | if (screws > 0) 92 | { 93 | translate([0,(-10.2 + 1.8),11.5]) 94 | { 95 | # cylinder(r=1.8/2, h=6, $fn=6); 96 | } 97 | translate([0,(21.0 - 1.8),11.5]) 98 | { 99 | # cylinder(r=1.8/2, h=6, $fn=6); 100 | } 101 | 102 | } 103 | // The large slope 104 | translate([-6,0,19]) 105 | { 106 | rotate([90,0,90]) 107 | { 108 | triangle(4, 18, 12); 109 | } 110 | } 111 | 112 | /** 113 | * This seems to get too complex fast 114 | // Small additional axes 115 | translate([0,6,17]) 116 | { 117 | cylinder(r=2.5, h=6, $fn=10); 118 | cylinder(r=1.25, h=8, $fn=10); 119 | } 120 | // Small slope 121 | difference() 122 | { 123 | translate([-6,-6,19.0]) 124 | { 125 | cube([12,6.5,4]); 126 | } 127 | translate([7,-7,24.0]) 128 | { 129 | rotate([-90,0,90]) 130 | { 131 | triangle(3, 8, 14); 132 | } 133 | } 134 | 135 | } 136 | */ 137 | // So we render a cube instead of the small slope on a cube 138 | translate([-6,-6,19.0]) 139 | { 140 | cube([12,6.5,4]); 141 | } 142 | } 143 | if (axle_lenght > 0) 144 | { 145 | % cylinder(r=0.9, h=axle_lenght, center=true, $fn=8); 146 | } 147 | } 148 | } 149 | } 150 | 151 | /** 152 | * Futaba S3003 servo 153 | * 154 | * @param vector position The position vector 155 | * @param vector rotation The rotation vector 156 | */ 157 | module futabas3003(position, rotation) 158 | { 159 | translate(position) 160 | { 161 | rotate(rotation) 162 | { 163 | union() 164 | { 165 | // Box and ears 166 | translate([0,0,0]) 167 | { 168 | cube([20.1, 39.9, 36.1], false); 169 | translate([1.1, -7.6, 26.6]) 170 | { 171 | difference() { 172 | cube([18, 7.6, 2.5]); 173 | translate([4, 3.5, 0]) cylinder(100, 2); 174 | translate([14, 3.5, 0]) cylinder(100, 2); 175 | } 176 | } 177 | 178 | translate([1.1, 39.9, 26.6]) 179 | { 180 | difference() { 181 | cube([18, 7.6, 2.5]); 182 | translate([4, 4.5, 0]) cylinder(100, 2); 183 | translate([14, 4.5, 0]) cylinder(100, 2); 184 | } 185 | } 186 | } 187 | 188 | // Main axle 189 | translate([10, 30, 36.1]) 190 | { 191 | cylinder(r=6, h=0.4, $fn=30); 192 | cylinder(r=2.5, h=4.9, $fn=20); 193 | } 194 | } 195 | } 196 | } 197 | } 198 | 199 | // Tests: 200 | module test_alignds420(){alignds420(screws=1);} 201 | -------------------------------------------------------------------------------- /shapes.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * OpenSCAD Shapes Library (www.openscad.org) 3 | * Copyright (C) 2009 Catarina Mota 4 | * Copyright (C) 2010 Elmo Mäntynen 5 | * 6 | * License: LGPL 2.1 or later 7 | */ 8 | 9 | include 10 | 11 | /* 12 | 2D Shapes 13 | ngon(sides, radius, center=false); 14 | 15 | 3D Shapes 16 | box(width, height, depth); 17 | roundedBox(width, height, depth, radius); 18 | cone(height, radius); 19 | ellipticalCylinder(width, height, depth); 20 | ellipsoid(width, height); 21 | tube(height, radius, wall, center = false); 22 | tube2(height, ID, OD, center = false); 23 | ovalTube(width, height, depth, wall, center = false); 24 | hexagon(height, depth); 25 | octagon(height, depth); 26 | dodecagon(height, depth); 27 | hexagram(height, depth); 28 | 29 | rightTriangle(adjacent, opposite, depth); 30 | equiTriangle(side, depth); 31 | 12ptStar(height, depth); 32 | */ 33 | 34 | //---------------------- 35 | 36 | echo_deprecated_shapes_library(); 37 | 38 | module echo_deprecated_shapes_library() { 39 | echo(" 40 | DEPRECATED: 'shapes' library is now deprecated 41 | please use 'regular_shapes' instead"); 42 | } 43 | 44 | // size is a vector [w, h, d] 45 | module box(width, height, depth) { 46 | echo_deprecated_shapes_library(); 47 | cube([width, height, depth], true); 48 | } 49 | 50 | // size is a vector [w, h, d] 51 | module roundedBox(width, height, depth, radius) { 52 | echo_deprecated_shapes_library(); 53 | size=[width, height, depth]; 54 | cube(size - [2*radius,0,0], true); 55 | cube(size - [0,2*radius,0], true); 56 | for (x = [radius-size[0]/2, -radius+size[0]/2], 57 | y = [radius-size[1]/2, -radius+size[1]/2]) { 58 | translate([x,y,0]) cylinder(r=radius, h=size[2], center=true); 59 | } 60 | } 61 | 62 | module cone(height, radius, center = false) { 63 | echo_deprecated_shapes_library(); 64 | cylinder(height, radius, 0, center); 65 | } 66 | 67 | module ellipticalCylinder(w,h, height, center = false) { 68 | echo_deprecated_shapes_library(); 69 | scale([1, h/w, 1]) cylinder(h=height, r=w, center=center); 70 | } 71 | 72 | module ellipsoid(w, h, center = false) { 73 | echo_deprecated_shapes_library(); 74 | scale([1, h/w, 1]) sphere(r=w/2, center=center); 75 | } 76 | 77 | // wall is wall thickness 78 | module tube(height, radius, wall, center = false) { 79 | echo_deprecated_shapes_library(); 80 | linear_extrude (height = height, center = center) { 81 | difference() { 82 | circle(r = radius); 83 | circle(r = radius - wall); 84 | } 85 | } 86 | difference() { 87 | cylinder(h=height, r=radius, center=center); 88 | translate([0,0,-epsilon]) 89 | cylinder(h=height+2*epsilon, r=radius-wall, center=center); 90 | } 91 | } 92 | 93 | module tube2(height, ID, OD, center = false) { 94 | tube(height = height, center = center, radius = OD / 2, wall = (OD - ID)/2); 95 | } 96 | 97 | // wall is wall thickness 98 | module ovalTube(height, rx, ry, wall, center = false) { 99 | echo_deprecated_shapes_library(); 100 | difference() { 101 | scale([1, ry/rx, 1]) cylinder(h=height, r=rx, center=center); 102 | scale([(rx-wall)/rx, (ry-wall)/rx, 1]) cylinder(h=height, r=rx, center=center); 103 | } 104 | } 105 | 106 | // size is the XY plane size, height in Z 107 | module hexagon(size, height) { 108 | echo_deprecated_shapes_library(); 109 | boxWidth = size/1.75; 110 | for (r = [-60, 0, 60]) 111 | rotate([0,0,r]) 112 | cube([boxWidth, size, height], true); 113 | } 114 | 115 | // size is the XY plane size, height in Z 116 | module octagon(size, height) { 117 | echo_deprecated_shapes_library(); 118 | intersection() { 119 | cube([size, size, height], true); 120 | rotate([0,0,45]) 121 | cube([size, size, height], true); 122 | } 123 | } 124 | 125 | // size is the XY plane size, height in Z 126 | module dodecagon(size, height) { 127 | echo_deprecated_shapes_library(); 128 | intersection() { 129 | hexagon(size, height); 130 | rotate([0,0,90]) hexagon(size, height); 131 | } 132 | } 133 | 134 | // size is the XY plane size, height in Z 135 | module hexagram(size, height) { 136 | echo_deprecated_shapes_library(); 137 | boxWidth=size/1.75; 138 | for (v = [[0,1],[0,-1],[1,-1]]) { 139 | intersection() { 140 | rotate([0,0,60*v[0]]) cube([size, boxWidth, height], true); 141 | rotate([0,0,60*v[1]]) cube([size, boxWidth, height], true); 142 | } 143 | } 144 | } 145 | 146 | module rightTriangle(adjacent, opposite, height) { 147 | echo_deprecated_shapes_library(); 148 | difference() { 149 | translate([-adjacent/2,opposite/2,0]) 150 | cube([adjacent, opposite, height], true); 151 | translate([-adjacent,0,0]) { 152 | rotate([0,0,atan(opposite/adjacent)]) 153 | dislocateBox(adjacent*2, opposite, height+2); 154 | } 155 | } 156 | } 157 | 158 | module equiTriangle(side, height) { 159 | echo_deprecated_shapes_library(); 160 | difference() { 161 | translate([-side/2,side/2,0]) cube([side, side, height], true); 162 | rotate([0,0,30]) dislocateBox(side*2, side, height); 163 | translate([-side,0,0]) { 164 | rotate([0,0,60]) dislocateBox(side*2, side, height); 165 | } 166 | } 167 | } 168 | 169 | module 12ptStar(size, height) { 170 | echo_deprecated_shapes_library(); 171 | starNum = 3; 172 | starAngle = 90/starNum; 173 | for (s = [1:starNum]) { 174 | rotate([0, 0, s*starAngle]) cube([size, size, height], true); 175 | } 176 | } 177 | 178 | //----------------------- 179 | //MOVES THE ROTATION AXIS OF A BOX FROM ITS CENTER TO THE BOTTOM LEFT CORNER 180 | module dislocateBox(w, h, d) { 181 | translate([0,0,-d/2]) cube([w,h,d]); 182 | } 183 | -------------------------------------------------------------------------------- /stepper.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * A nema standard stepper motor module. 3 | * 4 | * Originally by Hans Häggström, 2010. 5 | * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later 6 | */ 7 | 8 | include 9 | include 10 | 11 | 12 | // Demo, uncomment to show: 13 | //nema_demo(); 14 | 15 | module nema_demo(){ 16 | for (size = [NemaShort, NemaMedium, NemaLong]) { 17 | translate([-100,size*100,0]) motor(Nema34, size, dualAxis=true); 18 | translate([0,size*100,0]) motor(Nema23, size, dualAxis=true); 19 | translate([100,size*100,0]) motor(Nema17, size, dualAxis=true); 20 | translate([200,size*100,0]) motor(Nema14, size, dualAxis=true); 21 | translate([300,size*100,0]) motor(Nema11, size, dualAxis=true); 22 | translate([400,size*100,0]) motor(Nema08, size, dualAxis=true); 23 | } 24 | } 25 | 26 | 27 | // Parameters: 28 | NemaModel = 0; 29 | NemaLengthShort = 1; 30 | NemaLengthMedium = 2; 31 | NemaLengthLong = 3; 32 | NemaSideSize = 4; 33 | NemaDistanceBetweenMountingHoles = 5; 34 | NemaMountingHoleDiameter = 6; 35 | NemaMountingHoleDepth = 7; 36 | NemaMountingHoleLip = 8; 37 | NemaMountingHoleCutoutRadius = 9; 38 | NemaEdgeRoundingRadius = 10; 39 | NemaRoundExtrusionDiameter = 11; 40 | NemaRoundExtrusionHeight = 12; 41 | NemaAxleDiameter = 13; 42 | NemaFrontAxleLength = 14; 43 | NemaBackAxleLength = 15; 44 | NemaAxleFlatDepth = 16; 45 | NemaAxleFlatLengthFront = 17; 46 | NemaAxleFlatLengthBack = 18; 47 | 48 | NemaA = 1; 49 | NemaB = 2; 50 | NemaC = 3; 51 | 52 | NemaShort = NemaA; 53 | NemaMedium = NemaB; 54 | NemaLong = NemaC; 55 | 56 | // TODO: The small motors seem to be a bit too long, I picked the size specs from all over the place, is there some canonical reference? 57 | Nema08 = [ 58 | [NemaModel, 8], 59 | [NemaLengthShort, 33*mm], 60 | [NemaLengthMedium, 43*mm], 61 | [NemaLengthLong, 43*mm], 62 | [NemaSideSize, 20*mm], 63 | [NemaDistanceBetweenMountingHoles, 15.4*mm], 64 | [NemaMountingHoleDiameter, 2*mm], 65 | [NemaMountingHoleDepth, 1.75*mm], 66 | [NemaMountingHoleLip, -1*mm], 67 | [NemaMountingHoleCutoutRadius, 0*mm], 68 | [NemaEdgeRoundingRadius, 2*mm], 69 | [NemaRoundExtrusionDiameter, 16*mm], 70 | [NemaRoundExtrusionHeight, 1.5*mm], 71 | [NemaAxleDiameter, 4*mm], 72 | [NemaFrontAxleLength, 13.5*mm], 73 | [NemaBackAxleLength, 9.9*mm], 74 | [NemaAxleFlatDepth, -1*mm], 75 | [NemaAxleFlatLengthFront, 0*mm], 76 | [NemaAxleFlatLengthBack, 0*mm] 77 | ]; 78 | 79 | Nema11 = [ 80 | [NemaModel, 11], 81 | [NemaLengthShort, 32*mm], 82 | [NemaLengthMedium, 40*mm], 83 | [NemaLengthLong, 52*mm], 84 | [NemaSideSize, 28*mm], 85 | [NemaDistanceBetweenMountingHoles, 23*mm], 86 | [NemaMountingHoleDiameter, 2.5*mm], 87 | [NemaMountingHoleDepth, 2*mm], 88 | [NemaMountingHoleLip, -1*mm], 89 | [NemaMountingHoleCutoutRadius, 0*mm], 90 | [NemaEdgeRoundingRadius, 2.5*mm], 91 | [NemaRoundExtrusionDiameter, 22*mm], 92 | [NemaRoundExtrusionHeight, 1.8*mm], 93 | [NemaAxleDiameter, 5*mm], 94 | [NemaFrontAxleLength, 13.7*mm], 95 | [NemaBackAxleLength, 10*mm], 96 | [NemaAxleFlatDepth, 0.5*mm], 97 | [NemaAxleFlatLengthFront, 10*mm], 98 | [NemaAxleFlatLengthBack, 9*mm] 99 | ]; 100 | 101 | Nema14 = [ 102 | [NemaModel, 14], 103 | [NemaLengthShort, 26*mm], 104 | [NemaLengthMedium, 28*mm], 105 | [NemaLengthLong, 34*mm], 106 | [NemaSideSize, 35.3*mm], 107 | [NemaDistanceBetweenMountingHoles, 26*mm], 108 | [NemaMountingHoleDiameter, 3*mm], 109 | [NemaMountingHoleDepth, 3.5*mm], 110 | [NemaMountingHoleLip, -1*mm], 111 | [NemaMountingHoleCutoutRadius, 0*mm], 112 | [NemaEdgeRoundingRadius, 5*mm], 113 | [NemaRoundExtrusionDiameter, 22*mm], 114 | [NemaRoundExtrusionHeight, 1.9*mm], 115 | [NemaAxleDiameter, 5*mm], 116 | [NemaFrontAxleLength, 18*mm], 117 | [NemaBackAxleLength, 10*mm], 118 | [NemaAxleFlatDepth, 0.5*mm], 119 | [NemaAxleFlatLengthFront, 15*mm], 120 | [NemaAxleFlatLengthBack, 9*mm] 121 | ]; 122 | 123 | Nema17 = [ 124 | [NemaModel, 17], 125 | [NemaLengthShort, 33*mm], 126 | [NemaLengthMedium, 39*mm], 127 | [NemaLengthLong, 47*mm], 128 | [NemaSideSize, 42.20*mm], 129 | [NemaDistanceBetweenMountingHoles, 31.04*mm], 130 | [NemaMountingHoleDiameter, 4*mm], 131 | [NemaMountingHoleDepth, 4.5*mm], 132 | [NemaMountingHoleLip, -1*mm], 133 | [NemaMountingHoleCutoutRadius, 0*mm], 134 | [NemaEdgeRoundingRadius, 7*mm], 135 | [NemaRoundExtrusionDiameter, 22*mm], 136 | [NemaRoundExtrusionHeight, 1.9*mm], 137 | [NemaAxleDiameter, 5*mm], 138 | [NemaFrontAxleLength, 18*mm], 139 | [NemaBackAxleLength, 15*mm], 140 | [NemaAxleFlatDepth, 0.5*mm], 141 | [NemaAxleFlatLengthFront, 15*mm], 142 | [NemaAxleFlatLengthBack, 14*mm] 143 | ]; 144 | 145 | Nema23 = [ 146 | [NemaModel, 23], 147 | [NemaLengthShort, 39*mm], 148 | [NemaLengthMedium, 54*mm], 149 | [NemaLengthLong, 76*mm], 150 | [NemaSideSize, 56.4*mm], 151 | [NemaDistanceBetweenMountingHoles, 47.14*mm], 152 | [NemaMountingHoleDiameter, 4.75*mm], 153 | [NemaMountingHoleDepth, 5*mm], 154 | [NemaMountingHoleLip, 4.95*mm], 155 | [NemaMountingHoleCutoutRadius, 9.5*mm], 156 | [NemaEdgeRoundingRadius, 2.5*mm], 157 | [NemaRoundExtrusionDiameter, 38.10*mm], 158 | [NemaRoundExtrusionHeight, 1.52*mm], 159 | [NemaAxleDiameter, 6.36*mm], 160 | [NemaFrontAxleLength, 18.80*mm], 161 | [NemaBackAxleLength, 15.60*mm], 162 | [NemaAxleFlatDepth, 0.5*mm], 163 | [NemaAxleFlatLengthFront, 16*mm], 164 | [NemaAxleFlatLengthBack, 14*mm] 165 | ]; 166 | 167 | Nema34 = [ 168 | [NemaModel, 34], 169 | [NemaLengthShort, 66*mm], 170 | [NemaLengthMedium, 96*mm], 171 | [NemaLengthLong, 126*mm], 172 | [NemaSideSize, 85*mm], 173 | [NemaDistanceBetweenMountingHoles, 69.58*mm], 174 | [NemaMountingHoleDiameter, 6.5*mm], 175 | [NemaMountingHoleDepth, 5.5*mm], 176 | [NemaMountingHoleLip, 5*mm], 177 | [NemaMountingHoleCutoutRadius, 17*mm], 178 | [NemaEdgeRoundingRadius, 3*mm], 179 | [NemaRoundExtrusionDiameter, 73.03*mm], 180 | [NemaRoundExtrusionHeight, 1.9*mm], 181 | [NemaAxleDiameter, 0.5*inch], 182 | [NemaFrontAxleLength, 37*mm], 183 | [NemaBackAxleLength, 34*mm], 184 | [NemaAxleFlatDepth, 1.20*mm], 185 | [NemaAxleFlatLengthFront, 25*mm], 186 | [NemaAxleFlatLengthBack, 25*mm] 187 | ]; 188 | 189 | 190 | 191 | function motorWidth(model=Nema23) = lookup(NemaSideSize, model); 192 | function motorLength(model=Nema23, size=NemaMedium) = lookup(size, model); 193 | 194 | 195 | module motor(model=Nema23, size=NemaMedium, dualAxis=false, pos=[0,0,0], orientation = [0,0,0]) { 196 | 197 | length = lookup(size, model); 198 | 199 | echo(str(" Motor: Nema",lookup(NemaModel, model),", length= ",length,"mm, dual axis=",dualAxis)); 200 | 201 | stepperBlack = BlackPaint; 202 | stepperAluminum = Aluminum; 203 | 204 | side = lookup(NemaSideSize, model); 205 | 206 | cutR = lookup(NemaMountingHoleCutoutRadius, model); 207 | lip = lookup(NemaMountingHoleLip, model); 208 | holeDepth = lookup(NemaMountingHoleDepth, model); 209 | 210 | axleLengthFront = lookup(NemaFrontAxleLength, model); 211 | axleLengthBack = lookup(NemaBackAxleLength, model); 212 | axleRadius = lookup(NemaAxleDiameter, model) * 0.5; 213 | 214 | extrSize = lookup(NemaRoundExtrusionHeight, model); 215 | extrRad = lookup(NemaRoundExtrusionDiameter, model) * 0.5; 216 | 217 | holeDist = lookup(NemaDistanceBetweenMountingHoles, model) * 0.5; 218 | holeRadius = lookup(NemaMountingHoleDiameter, model) * 0.5; 219 | 220 | mid = side / 2; 221 | 222 | roundR = lookup(NemaEdgeRoundingRadius, model); 223 | 224 | axleFlatDepth = lookup(NemaAxleFlatDepth, model); 225 | axleFlatLengthFront = lookup(NemaAxleFlatLengthFront, model); 226 | axleFlatLengthBack = lookup(NemaAxleFlatLengthBack, model); 227 | 228 | color(stepperBlack){ 229 | translate(pos) rotate(orientation) { 230 | translate([-mid, -mid, 0]) 231 | difference() { 232 | cube(size=[side, side, length + extrSize]); 233 | 234 | // Corner cutouts 235 | if (lip > 0) { 236 | translate([0, 0, lip]) cylinder(h=length, r=cutR); 237 | translate([side, 0, lip]) cylinder(h=length, r=cutR); 238 | translate([0, side, lip]) cylinder(h=length, r=cutR); 239 | translate([side, side, lip]) cylinder(h=length, r=cutR); 240 | 241 | } 242 | 243 | // Rounded edges 244 | if (roundR > 0) { 245 | translate([mid+mid, mid+mid, length/2]) 246 | rotate([0,0,45]) 247 | cube(size=[roundR, roundR*2, 4+length + extrSize+2], center=true); 248 | translate([mid-(mid), mid+(mid), length/2]) 249 | rotate([0,0,45]) 250 | cube(size=[roundR*2, roundR, 4+length + extrSize+2], center=true); 251 | translate([mid+mid, mid-mid, length/2]) 252 | rotate([0,0,45]) 253 | cube(size=[roundR*2, roundR, 4+length + extrSize+2], center=true); 254 | translate([mid-mid, mid-mid, length/2]) 255 | rotate([0,0,45]) 256 | cube(size=[roundR, roundR*2, 4+length + extrSize+2], center=true); 257 | 258 | } 259 | 260 | // Bolt holes 261 | color(stepperAluminum, $fs=holeRadius/8) { 262 | translate([mid+holeDist,mid+holeDist,-1*mm]) cylinder(h=holeDepth+1*mm+extrSize, r=holeRadius); 263 | translate([mid-holeDist,mid+holeDist,-1*mm]) cylinder(h=holeDepth+1*mm+extrSize, r=holeRadius); 264 | translate([mid+holeDist,mid-holeDist,-1*mm]) cylinder(h=holeDepth+1*mm+extrSize, r=holeRadius); 265 | translate([mid-holeDist,mid-holeDist,-1*mm]) cylinder(h=holeDepth+1*mm+extrSize, r=holeRadius); 266 | 267 | } 268 | 269 | // Grinded flat 270 | color(stepperAluminum) { 271 | difference() { 272 | translate([-1*mm, -1*mm, -1*mm]) 273 | cube(size=[side+2*mm, side+2*mm, extrSize + 1*mm]); 274 | translate([side/2, side/2, -1*mm]) 275 | cylinder(h=extrSize + 1*mm, r=extrRad); 276 | } 277 | } 278 | 279 | } 280 | 281 | // Axle 282 | translate([0, 0, extrSize-axleLengthFront]) color(stepperAluminum) 283 | difference() { 284 | 285 | cylinder(h=axleLengthFront + 1*mm , r=axleRadius, $fs=axleRadius/10); 286 | 287 | // Flat 288 | if (axleFlatDepth > 0) 289 | translate([axleRadius - axleFlatDepth,-5*mm,-extrSize*mm -(axleLengthFront-axleFlatLengthFront)] ) cube(size=[5*mm, 10*mm, axleLengthFront]); 290 | } 291 | 292 | if (dualAxis) { 293 | translate([0, 0, length+extrSize]) color(stepperAluminum) 294 | difference() { 295 | 296 | cylinder(h=axleLengthBack + 0*mm, r=axleRadius, $fs=axleRadius/10); 297 | 298 | // Flat 299 | if (axleFlatDepth > 0) 300 | translate([axleRadius - axleFlatDepth,-5*mm,(axleLengthBack-axleFlatLengthBack)]) cube(size=[5*mm, 10*mm, axleLengthBack]); 301 | } 302 | 303 | } 304 | 305 | } 306 | } 307 | } 308 | 309 | module roundedBox(size, edgeRadius) { 310 | cube(size); 311 | 312 | } 313 | 314 | -------------------------------------------------------------------------------- /teardrop.scad: -------------------------------------------------------------------------------- 1 | /* From http://www.thingiverse.com/thing:3457 2 | © 2010 whosawhatsis 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | 19 | /* 20 | This script generates a teardrop shape at the appropriate angle to prevent overhangs greater than 45 degrees. The angle is in degrees, and is a rotation around the Y axis. You can then rotate around Z to point it in any direction. Rotation around X or Y will cause the angle to be wrong. 21 | */ 22 | 23 | module teardrop(radius, length, angle) { 24 | rotate([0, angle, 0]) union() { 25 | linear_extrude(height = length, center = true, convexity = radius, twist = 0) 26 | circle(r = radius, $fn = 30); 27 | linear_extrude(height = length, center = true, convexity = radius, twist = 0) 28 | projection(cut = false) rotate([0, -angle, 0]) translate([0, 0, radius * sin(45) * 1.5]) cylinder(h = radius * sin(45), r1 = radius * sin(45), r2 = 0, center = true, $fn = 30); 29 | } 30 | 31 | //I worked this portion out when a bug was causing the projection above to take FOREVER to calculate. It works as a replacement, and I figured I'd leave it here just in case. 32 | /* 33 | #polygon(points = [[radius * cos(-angle / 2), radius * sin(-angle / 2), 0],[radius * cos(-angle / 2), radius * -sin(-angle / 2), 0],[(sin(-angle - 45) + cos(-angle - 45)) * radius, 0, 0]], paths = [[0, 1, 2]]); 34 | #polygon(points = [[radius * -cos(-angle / 2), radius * sin(-angle / 2), 0],[radius * -cos(-angle / 2), radius * -sin(-angle / 2), 0],[(sin(-angle - 45) + cos(-angle - 45)) * radius, 0, 0]], paths = [[0, 1, 2]]); 35 | #polygon(points = [[radius * sin(-angle / 2), radius * cos(-angle / 2), 0],[radius * sin(-angle / 2), radius * -cos(-angle / 2), 0],[(sin(-angle - 45) + cos(-angle - 45)) * radius, 0, 0]], paths = [[0, 1, 2]]); 36 | */ 37 | } 38 | 39 | /* 40 | * Simple intersection method to implement a flat/truncated teardrop 41 | */ 42 | module flat_teardrop(radius, length, angle) { 43 | intersection() { 44 | rotate([0, angle, 0]) { 45 | cube(size=[radius * 2, radius * 2, length], center=true); 46 | } 47 | teardrop(radius, length, angle); 48 | } 49 | } 50 | 51 | module test_teardrop(){ 52 | translate([0, -15, 0]) teardrop(5, 20, 90); 53 | translate([0, 0, 0]) teardrop(5, 20, 60); 54 | translate([0, 15, 0]) teardrop(5, 20, 45); 55 | } 56 | 57 | //test_teardrop(); 58 | -------------------------------------------------------------------------------- /test_docs.py: -------------------------------------------------------------------------------- 1 | import py 2 | import os.path 3 | 4 | dirpath = py.path.local("./") 5 | 6 | def pytest_generate_tests(metafunc): 7 | names = [] 8 | if "filename" in metafunc.funcargnames: 9 | for fpath in dirpath.visit('*.scad'): 10 | names.append(fpath.basename) 11 | for fpath in dirpath.visit('*.py'): 12 | name = fpath.basename 13 | if not (name.startswith('test_') or name.startswith('_')): 14 | names.append(name) 15 | metafunc.parametrize("filename", names) 16 | 17 | def test_README(filename): 18 | README = dirpath.join('README.markdown').read() 19 | 20 | assert filename in README 21 | -------------------------------------------------------------------------------- /test_mcad.py: -------------------------------------------------------------------------------- 1 | from openscad_testing import * 2 | -------------------------------------------------------------------------------- /transformations.scad: -------------------------------------------------------------------------------- 1 | // License: GNU LGPL 2.1 or later. 2 | // © 2010 by Elmo Mäntynen 3 | 4 | module local_scale(v, reference=[0, 0, 0]) { 5 | translate(-reference) scale(v) translate(reference) children(); 6 | } 7 | -------------------------------------------------------------------------------- /triangles.scad: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple triangles library 3 | * 4 | * Authors: 5 | * - Eero 'rambo' af Heurlin 2010- 6 | * 7 | * License: LGPL 2.1 8 | */ 9 | 10 | 11 | /** 12 | * Standard right-angled triangle 13 | * 14 | * @param number o_len Length of the opposite side 15 | * @param number a_len Length of the adjacent side 16 | * @param number depth How wide/deep the triangle is in the 3rd dimension 17 | * @param boolean center Whether to center the triangle on the origin 18 | * @todo a better way ? 19 | */ 20 | module triangle(o_len, a_len, depth, center=false) 21 | { 22 | centroid = center ? [-a_len/3, -o_len/3, -depth/2] : [0, 0, 0]; 23 | translate(centroid) linear_extrude(height=depth) 24 | { 25 | polygon(points=[[0,0],[a_len,0],[0,o_len]], paths=[[0,1,2]]); 26 | } 27 | } 28 | 29 | /** 30 | * Standard right-angled triangle (tangent version) 31 | * 32 | * @param number tan_angle Angle of adjacent to hypotenuse (ie tangent) 33 | * @param number a_len Length of the adjacent side 34 | * @param number depth How wide/deep the triangle is in the 3rd dimension 35 | * @param boolean center Whether to center the triangle on the origin 36 | */ 37 | module a_triangle(tan_angle, a_len, depth, center=false) 38 | { 39 | triangle(tan(tan_angle) * a_len, a_len, depth, center); 40 | } 41 | 42 | // Tests: 43 | module test_triangle() { triangle(5, 5, 5); } 44 | module test_a_triangle() { a_triangle(45, 5, 5); } 45 | module test_triangles() 46 | { 47 | // Generate a bunch of triangles by sizes 48 | for (i = [1:10]) 49 | { 50 | translate([i*7, -30, i*7]) 51 | { 52 | triangle(i*5, sqrt(i*5+pow(i,2)), 5); 53 | } 54 | } 55 | 56 | // Generate a bunch of triangles by angle 57 | for (i = [1:85/5]) 58 | { 59 | translate([i*7, 22, i*7]) 60 | { 61 | a_triangle(i*5, 10, 5); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /trochoids.scad: -------------------------------------------------------------------------------- 1 | //=========================================== 2 | // Public Domain Epi- and Hypo- trochoids in OpenSCAD 3 | // version 1.0 4 | // by Matt Moses, 2011, mmoses152@gmail.com 5 | // http://www.thingiverse.com/thing:8067 6 | // 7 | // This file is public domain. Use it for any purpose, including commercial 8 | // applications. Attribution would be nice, but is not required. There is 9 | // no warranty of any kind, including its correctness, usefulness, or safety. 10 | // 11 | // An EPITROCHOID is a curve traced by a point 12 | // fixed at a distance "d" 13 | // to the center of a circle of radius "r" 14 | // as the circle rolls 15 | // outside another circle of radius "R". 16 | // 17 | // An HYPOTROCHOID is a curve traced by a point 18 | // fixed at a distance "d" 19 | // to the center of a circle of radius "r" 20 | // as the circle rolls 21 | // inside another circle of radius "R". 22 | // 23 | // An EPICYCLOID is an epitrochoid with d = r. 24 | // 25 | // An HYPOCYCLOID is an hypotrochoid with d = r. 26 | // 27 | // See http://en.wikipedia.org/wiki/Epitrochoid 28 | // and http://en.wikipedia.org/wiki/Hypotrochoid 29 | // 30 | // Beware the polar forms of the equations on Wikipedia... 31 | // They are correct, but theta is measured to the center of the small disk!! 32 | //=========================================== 33 | 34 | // There are several different methods for extruding. The best are probably 35 | // the ones using linear extrude. 36 | 37 | 38 | //=========================================== 39 | // Demo - draws one of each, plus some little wheels and sticks. 40 | // 41 | // Fun stuff to try: 42 | // Animate, try FPS = 5 and Steps = 200 43 | // R = 2, r = 1, d = 0.2 44 | // R = 4, r = 1, d = 1 45 | // R = 2, r = 1, d = 0.5 46 | // 47 | // What happens when you make d > r ?? 48 | // What happens when d < 0 ?? 49 | // What happens when r < 0 ?? 50 | // 51 | //=========================================== 52 | 53 | $fn = 30; 54 | 55 | thickness = 2; 56 | R = 4; 57 | r = 1; 58 | d = 1; 59 | n = 60; // number of wedge segments 60 | 61 | alpha = 360*$t; 62 | 63 | color([0, 0, 1]) 64 | translate([0, 0, -0.5]) 65 | cylinder(h = 1, r= R, center = true); 66 | 67 | color([0, 1, 0]) 68 | epitrochoid(R,r,d,n,thickness); 69 | 70 | color([1, 0, 0]) 71 | translate([ (R+r)*cos(alpha) , (R+r)*sin(alpha), -0.5]) { 72 | rotate([0, 0, alpha + R/r*alpha]) { 73 | cylinder(h = 1, r = r, center = true); 74 | translate([-d, 0, 1.5]) { 75 | cylinder(h = 2.2, r = 0.1, center = true); 76 | } 77 | } 78 | } 79 | 80 | 81 | translate([2*(abs(R) + abs(r) + abs(d)), 0, 0]){ 82 | color([0, 0, 1]) 83 | translate([0, 0, -0.5]) 84 | difference() { 85 | cylinder(h = 1, r = 1.1*R, center = true); 86 | cylinder(h = 1.1, r= R, center = true); 87 | } 88 | 89 | color([0, 1, 0]) 90 | hypotrochoid(R,r,d,n,thickness); 91 | 92 | color([1, 0, 0]) 93 | translate([ (R-r)*cos(alpha) , (R-r)*sin(alpha), -0.5]) { 94 | rotate([0, 0, alpha - R/r*alpha]) { 95 | cylinder(h = 1, r = r, center = true); 96 | translate([d, 0, 1.5]) { 97 | cylinder(h = 2.2, r = 0.1, center = true); 98 | } 99 | } 100 | } 101 | } 102 | 103 | // This just makes a twisted hypotrochoid 104 | translate([0,14, 0]) 105 | hypotrochoidLinear(4, 1, 1, 40, 40, 10, 30); 106 | 107 | // End of Demo Section 108 | //=========================================== 109 | 110 | 111 | //=========================================== 112 | // Epitrochoid 113 | // 114 | module epitrochoid(R, r, d, n, thickness) { 115 | dth = 360/n; 116 | for ( i = [0:n-1] ) { 117 | polyhedron(points = [[0,0,0], 118 | [(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), 0], 119 | [(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), 0], 120 | [0,0,thickness], 121 | [(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), thickness], 122 | [(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), thickness]], 123 | triangles = [[0, 2, 1], 124 | [0, 1, 3], 125 | [3, 1, 4], 126 | [3, 4, 5], 127 | [0, 3, 2], 128 | [2, 3, 5], 129 | [1, 2, 4], 130 | [2, 5, 4]]); 131 | } 132 | } 133 | //=========================================== 134 | 135 | 136 | //=========================================== 137 | // Hypotrochoid 138 | // 139 | module hypotrochoid(R, r, d, n, thickness) { 140 | dth = 360/n; 141 | for ( i = [0:n-1] ) { 142 | polyhedron(points = [[0,0,0], 143 | [(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), 0], 144 | [(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), 0], 145 | [0,0,thickness], 146 | [(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), thickness], 147 | [(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), thickness]], 148 | triangles = [[0, 2, 1], 149 | [0, 1, 3], 150 | [3, 1, 4], 151 | [3, 4, 5], 152 | [0, 3, 2], 153 | [2, 3, 5], 154 | [1, 2, 4], 155 | [2, 5, 4]]); 156 | } 157 | } 158 | //=========================================== 159 | 160 | 161 | //=========================================== 162 | // Epitrochoid Wedge with Bore 163 | // 164 | module epitrochoidWBore(R, r, d, n, p, thickness, rb) { 165 | dth = 360/n; 166 | union() { 167 | for ( i = [0:p-1] ) { 168 | polyhedron(points = [[rb*cos(dth*i), rb*sin(dth*i),0], 169 | [(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), 0], 170 | [(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), 0], 171 | [rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), 0], 172 | [rb*cos(dth*i), rb*sin(dth*i), thickness], 173 | [(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i), thickness], 174 | [(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1)), thickness], 175 | [rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), thickness]], 176 | triangles = [[0, 1, 4], [4, 1, 5], 177 | [1, 2, 5], [5, 2, 6], 178 | [2, 3, 7], [7, 6, 2], 179 | [3, 0, 4], [4, 7, 3], 180 | [4, 5, 7], [7, 5, 6], 181 | [0, 3, 1], [1, 3, 2]]); 182 | } 183 | } 184 | } 185 | //=========================================== 186 | 187 | 188 | //=========================================== 189 | // Epitrochoid Wedge with Bore, Linear Extrude 190 | // 191 | module epitrochoidWBoreLinear(R, r, d, n, p, thickness, rb, twist) { 192 | dth = 360/n; 193 | linear_extrude(height = thickness, convexity = 10, twist = twist) { 194 | union() { 195 | for ( i = [0:p-1] ) { 196 | polygon(points = [[rb*cos(dth*i), rb*sin(dth*i)], 197 | [(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i)], 198 | [(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1))], 199 | [rb*cos(dth*(i+1)), rb*sin(dth*(i+1))]], 200 | paths = [[0, 1, 2, 3]], convexity = 10); 201 | } 202 | } 203 | } 204 | } 205 | //=========================================== 206 | 207 | 208 | //=========================================== 209 | // Epitrochoid Wedge, Linear Extrude 210 | // 211 | module epitrochoidLinear(R, r, d, n, p, thickness, twist) { 212 | dth = 360/n; 213 | linear_extrude(height = thickness, convexity = 10, twist = twist) { 214 | union() { 215 | for ( i = [0:p-1] ) { 216 | polygon(points = [[0, 0], 217 | [(R+r)*cos(dth*i) - d*cos((R+r)/r*dth*i), (R+r)*sin(dth*i) - d*sin((R+r)/r*dth*i)], 218 | [(R+r)*cos(dth*(i+1)) - d*cos((R+r)/r*dth*(i+1)), (R+r)*sin(dth*(i+1)) - d*sin((R+r)/r*dth*(i+1))]], 219 | paths = [[0, 1, 2]], convexity = 10); 220 | } 221 | } 222 | } 223 | } 224 | //=========================================== 225 | 226 | 227 | //=========================================== 228 | // Hypotrochoid Wedge with Bore 229 | // 230 | module hypotrochoidWBore(R, r, d, n, p, thickness, rb) { 231 | dth = 360/n; 232 | union() { 233 | for ( i = [0:p-1] ) { 234 | polyhedron(points = [[rb*cos(dth*i), rb*sin(dth*i),0], 235 | [(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), 0], 236 | [(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), 0], 237 | [rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), 0], 238 | [rb*cos(dth*i), rb*sin(dth*i), thickness], 239 | [(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i), thickness], 240 | [(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1)), thickness], 241 | [rb*cos(dth*(i+1)), rb*sin(dth*(i+1)), thickness]], 242 | triangles = [[0, 1, 4], [4, 1, 5], 243 | [1, 2, 5], [5, 2, 6], 244 | [2, 3, 7], [7, 6, 2], 245 | [3, 0, 4], [4, 7, 3], 246 | [4, 5, 7], [7, 5, 6], 247 | [0, 3, 1], [1, 3, 2]]); 248 | } 249 | } 250 | } 251 | //=========================================== 252 | 253 | 254 | //=========================================== 255 | // Hypotrochoid Wedge with Bore, Linear Extrude 256 | // 257 | module hypotrochoidWBoreLinear(R, r, d, n, p, thickness, rb, twist) { 258 | dth = 360/n; 259 | linear_extrude(height = thickness, convexity = 10, twist = twist) { 260 | union() { 261 | for ( i = [0:p-1] ) { 262 | polygon(points = [[rb*cos(dth*i), rb*sin(dth*i)], 263 | [(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i)], 264 | [(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1))], 265 | [rb*cos(dth*(i+1)), rb*sin(dth*(i+1))]], 266 | paths = [[0, 1, 2, 3]], convexity = 10); 267 | } 268 | } 269 | } 270 | } 271 | //=========================================== 272 | 273 | 274 | //=========================================== 275 | // Hypotrochoid Wedge, Linear Extrude 276 | // 277 | module hypotrochoidLinear(R, r, d, n, p, thickness, twist) { 278 | dth = 360/n; 279 | linear_extrude(height = thickness, convexity = 10, twist = twist) { 280 | union() { 281 | for ( i = [0:p-1] ) { 282 | polygon(points = [[0, 0], 283 | [(R-r)*cos(dth*i) + d*cos((R-r)/r*dth*i), (R-r)*sin(dth*i) - d*sin((R-r)/r*dth*i)], 284 | [(R-r)*cos(dth*(i+1)) + d*cos((R-r)/r*dth*(i+1)), (R-r)*sin(dth*(i+1)) - d*sin((R-r)/r*dth*(i+1))]], 285 | paths = [[0, 1, 2]], convexity = 10); 286 | } 287 | } 288 | } 289 | } 290 | //=========================================== 291 | -------------------------------------------------------------------------------- /units.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * Basic units. 3 | * 4 | * Originally by Hans Häggström, 2010. 5 | * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later 6 | */ 7 | 8 | 9 | mm = 1; 10 | cm = 10 * mm; 11 | dm = 100 * mm; 12 | m = 1000 * mm; 13 | 14 | inch = 25.4 * mm; 15 | 16 | X = [1, 0, 0]; 17 | Y = [0, 1, 0]; 18 | Z = [0, 0, 1]; 19 | 20 | M3 = 3*mm; 21 | M4 = 4*mm; 22 | M5 = 5*mm; 23 | M6 = 6*mm; 24 | M8 = 8*mm; 25 | 26 | 27 | // When a small distance is needed to overlap shapes for boolean cutting, etc. 28 | epsilon = 0.01*mm; 29 | 30 | -------------------------------------------------------------------------------- /unregular_shapes.scad: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Elmo Mäntynen 2 | // LGPL 2.1 3 | 4 | // Give a list of 4+4 points (check order) to form an 8 point polyhedron 5 | module connect_squares(points){ 6 | polyhedron(points=points, 7 | triangles=[[0,1,2], [3,0,2], [7,6,5], [7,5,4], // Given polygons 8 | [0,4,1], [4,5,1], [1,5,2], [2,5,6], // Connecting 9 | [2,6,3], [3,6,7], [3,4,0], [3,7,4]]);// sides 10 | } 11 | -------------------------------------------------------------------------------- /utilities.scad: -------------------------------------------------------------------------------- 1 | /* 2 | * Utility functions. 3 | * 4 | * Originally by Hans Häggström, 2010. 5 | * Dual licenced under Creative Commons Attribution-Share Alike 3.0 and LGPL2 or later 6 | */ 7 | 8 | include 9 | 10 | function distance(a, b) = sqrt( (a[0] - b[0])*(a[0] - b[0]) + 11 | (a[1] - b[1])*(a[1] - b[1]) + 12 | (a[2] - b[2])*(a[2] - b[2]) ); 13 | 14 | function length2(a) = sqrt( a[0]*a[0] + a[1]*a[1] ); 15 | 16 | function normalized(a) = a / (max(distance([0,0,0], a), 0.00001)); 17 | 18 | function normalized_axis(a) = a == "x" ? [1, 0, 0]: 19 | a == "y" ? [0, 1, 0]: 20 | a == "z" ? [0, 0, 1]: normalized(a); 21 | 22 | function angleOfNormalizedVector(n) = [0, -atan2(n[2], length2([n[0], n[1]])), atan2(n[1], n[0]) ]; 23 | 24 | function angle(v) = angleOfNormalizedVector(normalized(v)); 25 | 26 | function angleBetweenTwoPoints(a, b) = angle(normalized(b-a)); 27 | 28 | 29 | CENTER = 0; 30 | LEFT = -0.5; 31 | RIGHT = 0.5; 32 | TOP = 0.5; 33 | BOTTOM = -0.5; 34 | 35 | FlatCap =0; 36 | ExtendedCap =0.5; 37 | CutCap =-0.5; 38 | 39 | 40 | module fromTo(from=[0,0,0], to=[1*m,0,0], size=[1*cm, 1*cm], align=[CENTER, CENTER], material=[0.5, 0.5, 0.5], name="", endExtras=[0,0], endCaps=[FlatCap, FlatCap], rotation=[0,0,0], printString=true) { 41 | 42 | angle = angleBetweenTwoPoints(from, to); 43 | length = distance(from, to) + endCaps[0]*size[0] + endCaps[1]*size[0] + endExtras[0] + endExtras[1]; 44 | 45 | if (length > 0) { 46 | if (printString) echo(str(" " ,name, " ", size[0], "mm x ", size[1], "mm, length ",length,"mm")); 47 | 48 | color(material) 49 | translate(from) 50 | rotate(angle) 51 | translate( [ -endCaps[0]*size[0] - endExtras[0], size[0]*(-0.5-align[0]), size[1]*(-0.5+align[1]) ] ) 52 | rotate(rotation) 53 | scale([length, size[0], size[1]]) children(); 54 | } 55 | } 56 | 57 | module part(name) { 58 | echo(""); 59 | echo(str(name, ":")); 60 | } 61 | --------------------------------------------------------------------------------