Parametric screw

master
Vitaliy Filippov 2017-12-14 11:03:37 +00:00
parent 5d5f79725a
commit b303e9978b
1 changed files with 32 additions and 0 deletions

32
screw_gear.scad Normal file
View File

@ -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 ];