-- Spur gears, straight teeth ( involute )
-- The involute is not calculated but produced by virtual milling.
z1 = 30 -- Number of teeth for gear 1
z2 = 23 -- Number of teeth for gear 2
m = 0.5 -- Modul (Size of teeths)
B = 5 -- Width
alpha = 20 -- Pressure angle, typ. = 20°
c = 0.167 * m -- Tooth tip clearance, typ. 0.167
autox = true; -- Automatic calculation of the profile shift factor
x1 = 0 -- profile shift factor (will be used for gear 1 if autox = false)
x2 = 0 -- profile shift factor (will be used for gear 1 if autox = false)
-- profile shift factor calculations
if (autox == true) then
--Number of teeth with helical teeth
--TODO: helical teeth not supportet atm
z1e=z1
z2e=z2
--profile shift factor
zg = 2/(sin(alpha)*sin(alpha)) -- Grenzzähnezahl
if (z1e<zg) then
x1 = 1 - z1e / zg
end
if (z2e<zg) then
x2 = 1 - z2e / zg;
end
end
-- Trapezoid tool part for milling the teeth
function tool_trapezoid(m, B, alpha, c, z, x)
p = m * math.pi -- partition p (Distance between two teeth)
i = 0.5 * p/2
j = m/math.tan(math.rad(90-alpha))
k = (m+c)/math.tan(math.rad(90-alpha))
points = {}
indices = {}
table.insert(points,v(0-i-j, 0-m, -B/2-0.1)) --0
table.insert(points,v(0-i+k, 0+m+c, -B/2-0.1)) --1
table.insert(points,v(0+i-k, 0+m+c, -B/2-0.1)) --2
table.insert(points,v(0+i+j, 0-m, -B/2-0.1)) --3
table.insert(points,v(0-i-j, 0-m, B/2+0.1)) --4
table.insert(points,v(0-i+k, 0+m+c, B/2+0.1)) --5
table.insert(points,v(0+i-k, 0+m+c, B/2+0.1)) --6
table.insert(points,v(0+i+j, 0-m, B/2+0.1)) --7
table.insert(indices,v(0,1,2)) --bottom
table.insert(indices,v(2,3,0))
table.insert(indices,v(4,7,5)) --top
table.insert(indices,v(7,6,5))
table.insert(indices,v(0,4,1)) --side1
table.insert(indices,v(4,5,1))
table.insert(indices,v(1,5,2)) --side2
table.insert(indices,v(5,6,2))
table.insert(indices,v(2,6,3)) --side3
table.insert(indices,v(6,7,3))
table.insert(indices,v(3,7,0)) --side4
table.insert(indices,v(7,4,0))
return polyhedron(points,indices)
end
--Tool composed out of 19 trapezoid tool parts
function tool(m, B, alpha, c, z, x)
p = m * math.pi --partition p (Distance between two teeth)
w = tool_trapezoid(m, B, alpha, c, z, x)
w = union {
translate(-9*p,0,0)*w,
translate(-8*p,0,0)*w,
translate(-7*p,0,0)*w,
translate(-6*p,0,0)*w,
translate(-5*p,0,0)*w,
translate(-4*p,0,0)*w,
translate(-3*p,0,0)*w,
translate(-2*p,0,0)*w,
translate(-1*p,0,0)*w,
w,
translate(1*p,0,0)*w,
translate(2*p,0,0)*w,
translate(3*p,0,0)*w,
translate(4*p,0,0)*w,
translate(5*p,0,0)*w,
translate(6*p,0,0)*w,
translate(7*p,0,0)*w,
translate(8*p,0,0)*w,
translate(9*p,0,0)*w
}
return w
end
-- Gear blank ( cylinder )
function gear_blank(r, B)
return translate(0,0,-B/2)*cylinder(r, B)
end
--Milling of the teeth
function gear(m, B, alpha, c, z, x)
d = m * z --Core diameter
V = x * m --profile shift
dk = d + m + V --Tip diameter
r = d/2 -- Radius of the core circle
KU = 2 * math.pi * r --Core circumference
p = m * math.pi --partition p (Distance between two teeth)
toolposition = 0 --X position of the virtual milling tool
z = gear_blank(dk/2+V, B)
w = translate(0,-d/2-V,0)*tool(m, B, alpha, c, z, x)
step_angle= 10 --If you try 0.01 it'll crash the application (IceSL-win32 1.0.4)
for i=0, 359, step_angle
do
toolposition = toolposition + step_angle*KU/360
while (toolposition > p) do
toolposition = toolposition - p
end
z = difference (
rotate(0,0,step_angle)*z,
translate(toolposition,0,0)*w
)
end
--emit(z)
--emit(translate(toolposition,0,0)*w)
return z
end
gear1 = gear(m, B, alpha, c, z1, x1)
gear2 = gear(m, B, alpha, c, z2, x2)
d1 = m * z1
d2 = m * z2
V1 = x1 * m
V2 = x2 * m
wheelbase = d1/2 + V1 + d2/2 + V2
emit(translate(0,-d1/2-V1,0)*rotate(0,0,180+1/2*360/z1)*gear1)
emit(translate(0,d2/2+V2,0)*rotate(0,0,0)*gear2)