diff --git a/screw_gear.scad b/screw_gear.scad new file mode 100644 index 0000000..49040b3 --- /dev/null +++ b/screw_gear.scad @@ -0,0 +1,32 @@ +screw_gear(8, 4, 2, 8, 18, 32); + +module screw_gear(outer_radius, inner_radius, thickness, thread_length, precision, total_length) +{ + linear_extrude(height=total_length, twist=360*total_length/thread_length, slices=360) + polygon( + points = screw_crosssection(outer_radius, inner_radius, thickness, thread_length, precision), + paths = [ range((precision+8)*2) ] + ); +} + +function screw_crosssection(outer_radius, inner_radius, thickness, thread_length, precision) = + concat( + [ for (x=[1 : 8]) polar(outer_radius, thickness*360/thread_length*x/8) ], + [ for (x=[1 : precision]) + polar( + outer_radius-(outer_radius-inner_radius)*x/precision, + thickness*360/thread_length + x/precision*(180-(thickness*360/thread_length)) + ) + ], + [ for (x=[1 : 8]) polar(inner_radius, 180 + thickness*360/thread_length*x/8) ], + [ for (x=[1 : precision]) + polar( + inner_radius+(outer_radius-inner_radius)*x/precision, + 180 + thickness*360/thread_length + x/precision*(180-(thickness*360/thread_length)) + ) + ] + ); + +function polar(r,theta) = r*[sin(theta), cos(theta)]; // convert polar to cartesian coordinates + +function range(n) = [ for(x = [0 : n-1]) x ];