Permalink
Browse files

commit Giles' regular shapes and metric fasteners

  • Loading branch information...
1 parent 32fdce5 commit d53660d3b321b4e8c42e54b6f339e85cb82acf2e @timschmidt timschmidt committed Jan 18, 2011
Showing with 299 additions and 0 deletions.
  1. +111 −0 metric_fastners.scad
  2. +188 −0 regular_shapes.scad
View
@@ -0,0 +1,111 @@
+/*
+ * OpenSCAD Metric Fastners Library (www.openscad.org)
+ * Copyright (C) 2010-2011 Giles Bathgate
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License,
+ * LGPL version 2.1, or (at your option) any later version of the GPL.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+*/
+
+$fn=50;
+apply_chamfer=true;
+
+module cap_bolt(dia,len)
+{
+ e=1.5*dia;
+ h1=1.25*dia;
+ cylinder(r=dia/2,h=len);
+ translate([0,0,-h1]) cylinder(r=e/2,h=h1);
+}
+
+module csk_bolt(dia,len)
+{
+ h1=0.6*dia;
+ h2=len-h1;
+ cylinder(r=dia/2,h=h2);
+ cylinder(r1=dia,r2=dia/2,h=h1);
+}
+
+module washer(dia)
+{
+ t=0.1*dia;
+ difference()
+ {
+ cylinder(r=dia,h=t);
+ translate([0,0,-t/2])cylinder(r=dia/2,h=t*2);
+ }
+}
+
+module flat_nut(dia)
+{
+ m=0.8*dia;
+ e=1.8*dia;
+ c=0.2*dia;
+ difference()
+ {
+ cylinder(r=e/2,h=m,$fn=6);
+ translate([0,0,-m/2])cylinder(r=dia/2,h=m*2);
+ if(apply_chamfer)
+ translate([0,0,c])cylinder_chamfer(e/2,c);
+ }
+}
+
+module bolt(dia,len)
+{
+ e=1.8*dia;
+ k=0.7*dia;
+ c=0.2*dia;
+ difference()
+ {
+ cylinder(r=e/2,h=k,$fn=6);
+ if(apply_chamfer)
+ translate([0,0,c])cylinder_chamfer(e/2,c);
+ }
+
+ cylinder(r=dia/2,h=len);
+
+}
+
+module cylinder_chamfer(r1,r2)
+{
+ t=r1-r2;
+ p=r2*2;
+ rotate_extrude()
+ difference()
+ {
+ translate([t,-p])square([p,p]);
+ translate([t,0])circle(r2);
+ }
+}
+
+module chamfer(len,r)
+{
+ p=r*2;
+ linear_extrude(height=len)
+ difference()
+ {
+ square([p,p]);
+ circle(r);
+ }
+}
+
+union()
+{
+//csk_bolt(3,14);
+//washer(3);
+//flat_nut(3);
+//bolt(4,14);
+//cylinder_chamfer(8,1);
+//chamfer(5,1);
+}
View
@@ -0,0 +1,188 @@
+/*
+ * OpenSCAD Shapes Library (www.openscad.org)
+ * Copyright (C) 2010-2011 Giles Bathgate
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License,
+ * LGPL version 2.1, or (at your option) any later version of the GPL.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+*/
+
+// 2D regular shapes
+
+module triangle(radius)
+{
+ o=radius/2; //equivalent to radius*sin(30)
+ a=radius*sqrt(3)/2; //equivalent to radius*cos(30)
+ polygon(points=[[-a,-o],[0,radius],[a,-o]],paths=[[0,1,2]]);
+}
+
+module reg_polygon(sides,radius)
+{
+ function dia(r) = sqrt(pow(r*2,2)/2); //sqrt(r*2^2/2) if only we had an exponention op
+ if(sides<2) square([radius,0]);
+ if(sides==3) triangle(radius);
+ if(sides==4) square([dia(radius),dia(radius)],center=true);
+ if(sides>4) circle(r=radius,$fn=sides);
+}
+
+module pentagon(radius)
+{
+ reg_polygon(5,radius);
+}
+
+module hexagon(radius)
+{
+ reg_polygon(6,radius);
+}
+
+module heptagon(radius)
+{
+ reg_polygon(7,radius);
+}
+
+module octagon(radius)
+{
+ reg_polygon(8,radius);
+}
+
+module nonagon(radius)
+{
+ reg_polygon(9,radius);
+}
+
+module decagon(radius)
+{
+ reg_polygon(10,radius);
+}
+
+module hendecagon(radius)
+{
+ reg_polygon(11,radius);
+}
+
+module dodecagon(radius)
+{
+ reg_polygon(12,radius);
+}
+
+//3D regular shapes
+
+module cone(height, radius, center = false)
+{
+ cylinder(height, radius, 0, center);
+}
+
+module oval_prism(height, rx, ry, center = false)
+{
+ scale([1, rx/ry, 1]) cylinder(h=height, r=ry, center=center);
+}
+
+module oval_tube(height, rx, ry, wall, center = false)
+{
+ difference() {
+ scale([1, ry/rx, 1]) cylinder(h=height, r=rx, center=center);
+ translate([0,0,-height/2]) scale([(rx-wall)/rx, (ry-wall)/rx, 2]) cylinder(h=height, r=rx, center=center);
+ }
+}
+
+module cylinder_tube(height, radius, wall, center = false)
+{
+ tubify(radius,wall)
+ cylinder(h=height, r=radius, center=center);
+}
+
+//Tubifies any regular prism
+module tubify(radius,wall)
+{
+ difference()
+ {
+ child(0);
+ translate([0, 0, -0.1]) scale([(radius-wall)/radius, (radius-wall)/radius, 2]) child(0);
+ }
+}
+
+module triangle_prism(height,radius)
+{
+ linear_extrude(height=height) triangle(radius);
+}
+
+module triangle_tube(height,radius,wall)
+{
+ tubify(radius,wall) triangle_prism(height,radius);
+}
+
+module pentagon_prism(height,radius)
+{
+ linear_extrude(height=height) pentagon(radius);
+}
+
+module pentagon_tube(height,radius,wall)
+{
+ tubify(radius,wall) pentagon_prism(height,radius);
+}
+
+module hexagon_prism(height,radius)
+{
+ linear_extrude(height=height) hexagon(radius);
+}
+
+module heptagon_prism(height,radius)
+{
+ linear_extrude(height=height) heptagon(radius);
+}
+
+module octagon_prism(height,radius)
+{
+ linear_extrude(height=height) octagon(radius);
+}
+
+module nonagon_prism(height,radius)
+{
+ linear_extrude(height=height) nonagon(radius);
+}
+
+module decagon_prism(height,radius)
+{
+ linear_extrude(height=height) decagon(radius);
+}
+
+module hendecagon_prism(height,radius)
+{
+ linear_extrude(height=height) hendecagon(radius);
+}
+
+module dodecagon_prism(height,radius)
+{
+ linear_extrude(height=height) dodecagon(radius);
+}
+
+module torus(outerRadius, innerRadius)
+{
+ r=(outerRadius-innerRadius)/2;
+ rotate_extrude() translate([innerRadius+r,0,0]) circle(r);
+}
+
+module triangle_pyramid(radius)
+{
+ o=radius/2; //equivalent to radius*sin(30)
+ a=radius*sqrt(3)/2; //equivalent to radius*cos(30)
+ 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]]);
+}
+
+module square_pyramid(width,height,depth)
+{
+ w=width/2;
+ h=height/2;
+ polyhedron(points=[[-w,-h,0],[-w,h,0],[w,h,0],[w,-h,0],[0,0,depth]],triangles=[[0,1,2],[0,1,4],[0,1,3],[0,2,3]]);
+}

0 comments on commit d53660d

Please sign in to comment.