3dprint/screw_gear.scad

33 lines
1.3 KiB
OpenSCAD
Raw Normal View History

2017-12-14 14:03:37 +03:00
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 ];