Uit Hack42
(+ratchet.scad) |
(+update) |
||
Regel 1: | Regel 1: | ||
==ratchet.scad== | ==ratchet.scad== | ||
− | <pre> | + | {| |
− | module | + | |[[Bestand:Ratchet.png|thumb|left|An example of ratchet(10,6,3,5,7,1)]] |
+ | |- | ||
+ | ||<pre> | ||
+ | module tooth(base, height, tipl, tiph, width) { | ||
difference() { | difference() { | ||
intersection() { | intersection() { | ||
Regel 17: | Regel 20: | ||
module ratchet(diam, nrteeth, height, tipl, tiph, width) { | module ratchet(diam, nrteeth, height, tipl, tiph, width) { | ||
//moves teeth down by this distance | //moves teeth down by this distance | ||
− | down = diam - diam * cos(180/nrteeth); | + | down = 0.01 + (diam - diam * cos(180/nrteeth)); |
//make sure tooth's height is not lower than down movement | //make sure tooth's height is not lower than down movement | ||
− | + | if (height <= down) { | |
− | + | ratchet2(diam, nrteeth, down, tipl, tiph, width, down); | |
} else { | } else { | ||
− | + | ratchet2(diam, nrteeth, height, tipl, tiph, width, down); | |
} | } | ||
− | + | } | |
+ | |||
+ | module ratchet2(diam, nrteeth, height, tipl, tiph, width, down) { | ||
// calculate tooth's base | // calculate tooth's base | ||
base = 2 * sin(180/nrteeth) * diam; | base = 2 * sin(180/nrteeth) * diam; | ||
− | |||
− | |||
union() { | union() { | ||
cylinder(h=width,r=diam); | cylinder(h=width,r=diam); | ||
Regel 34: | Regel 37: | ||
for ( i = [0 : (nrteeth-1)] ) { | for ( i = [0 : (nrteeth-1)] ) { | ||
rotate( i * 360 / nrteeth, [0, 0, 1]) | rotate( i * 360 / nrteeth, [0, 0, 1]) | ||
− | translate([-(0.25*base), (diam-down), 0]) | + | translate([-(0.25*base), (diam-2*down), 0]) // check the .25 |
− | + | tooth(base, height, tipl, tiph, width); | |
} | } | ||
} | } | ||
} | } | ||
− | ratchet(10,6, | + | ratchet(10,6,3,5,7,1); |
</pre> | </pre> | ||
+ | |} |
Versie van 8 sep 2011 22:30
ratchet.scad
module tooth(base, height, tipl, tiph, width) { difference() { intersection() { translate([-(base+tipl)/2,0,0]) cube([base+tipl,height,width], center = false); scale(v=[1,(height/(base+tipl))*2,0]) cylinder(r=(base+tipl)/2,h=width, $fs=0.01); } translate([-(base/2+tipl/2),0,0]) polyhedron( points = [ [0,0,0],[0,0,width],[0,tiph,0],[0,tiph,width],[tipl,0,0],[tipl,0,width] ], triangles = [ [1,3,5],[0,4,2],[0,2,1],[2,3,1],[0,1,4],[4,1,5],[2,4,5],[2,5,3] ]); } } //tooth2(7,7,5,5,1); module ratchet(diam, nrteeth, height, tipl, tiph, width) { //moves teeth down by this distance down = 0.01 + (diam - diam * cos(180/nrteeth)); //make sure tooth's height is not lower than down movement if (height <= down) { ratchet2(diam, nrteeth, down, tipl, tiph, width, down); } else { ratchet2(diam, nrteeth, height, tipl, tiph, width, down); } } module ratchet2(diam, nrteeth, height, tipl, tiph, width, down) { // calculate tooth's base base = 2 * sin(180/nrteeth) * diam; union() { cylinder(h=width,r=diam); //teeth for ( i = [0 : (nrteeth-1)] ) { rotate( i * 360 / nrteeth, [0, 0, 1]) translate([-(0.25*base), (diam-2*down), 0]) // check the .25 tooth(base, height, tipl, tiph, width); } } } ratchet(10,6,3,5,7,1); |