/*
* Simple thread polygon library
* Copyright (C) 2019, 2021 Alicia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
module thread(points, subdiv=20)
{
lpoints=[for(i=[0:1/subdiv:len(points)-1/subdiv])(points[i]*(1-(i%1))+points[(i+1)%len(points)]*(i%1))];
points2=[for(i=[0:len(lpoints)-1])[sin(360*i/len(lpoints))*lpoints[i], cos(360*i/len(lpoints))*lpoints[i]]];
echo(points2);
polygon(points2);
}
module thread2(points, subdiv=20)
{
lpoints=[for(i=[0:len(points)-1])([ // Position along one rotation, from 0.0 to 1.0
i,
points[i][1]
])];
rpoints=[for(i=[0:len(points)-1])([ // Radiuses
i,
points[i][0]
])];
points2=[for(i=[0:1/subdiv:len(lpoints)-1])[sin(360*lookup(i, lpoints))*lookup(i, rpoints), cos(360*lookup(i, lpoints))*lookup(i, rpoints)]];
polygon(points2);
}
// Simple thread, just a list of radiuses to make up the thread profile
linear_extrude(10, twist=-600)
thread([4,4,5,5,4,4,5,5]);
// Advanced thread, a list of two sets of values, the first being the radius just like the simple thread, the latter being the position along the profile ranging from 0.0 to 1.0
translate([12,0,0])linear_extrude(10, twist=-500)
thread2([[4, 0],
[4, 1/6],
[6, 2/6],
[6, 3/6],
[4, 3/6],
[4, 4/6],
[6, 5/6],
[6, 1]]);