Created
December 30, 2018 17:41
-
-
Save patmandenver/8c6e30bb3775398e39020bb2557f06e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Patrick Bailey (iqless.com) | |
// Date: 12/11/2018 | |
// | |
// Notes: This code makes a link of chains | |
// The chains have text on them | |
// Either Numbers or you can populate a text | |
// Array | |
// | |
// Code for Archemedian Spiral copied from | |
// Openscad code for thing 28405 | |
// https://www.thingiverse.com/thing:28405 | |
// | |
// See Thing post | |
// https://www.thingiverse.com/thing:3284739 | |
// | |
// 2018-12-11 : Original Code | |
// 2018-12-15 : Tweaked the code to better handle | |
// Smaller diameters | |
// 2018-12-30 : Added variables rotate_chain, num_one, and | |
// num_two to make it more scriptable | |
//---------------------------------------- | |
$fn=100; | |
l = 60; //Length of Link (Max L = 2xh) | |
h = 45; //Width of Link | |
d = 12; //Diameter of Link | |
//ro = 60; | |
r0 = 35*pow((l/h),2); // Initial radius of spiral | |
// Higher Number means spiral | |
// Starts further away from radius | |
// You may need to start further away | |
// ... Too close and the initial | |
// angle is too much | |
// And may cause links to | |
// "Fuse" when printed | |
pitch = 60; // Increase of radius per turn | |
//Extra variable for house | |
rotate_chain = 195; | |
num_one = 1; | |
num_two = 5; | |
textArray = createNumbers(num_one, num_two); //Creates array of Numbers to print on Chain Link | |
//textArray = ["Your", "Text", "Here", "iQless.com"]; | |
// If you want just a text array | |
spiral_chain(textArray,l,h,d,r0,pitch); | |
module spiral_chain(textArray,l,h,d,r0,pitch) { | |
spacing=l/2 + (sqrt(d)*10)/10; | |
//Nudge the even numbered links slightly | |
//This nudge reduces as i increases as you need | |
//It less as the spiral angle becomes less | |
evenNudge = 2*d/7; | |
rotate([0,0,rotate_chain]){ | |
for (i=[0:len(textArray) - 1]) { | |
angle1 = inv_arch_len(spacing*i,r0,pitch); | |
angle2 = inv_arch_len(spacing*(i+1),r0,pitch); | |
p1 = arch_spiral(angle1,pitch); | |
p2 = arch_spiral(angle2,pitch); | |
//Translate distance out to spiral | |
translate(p1) { | |
//Rotate link to match curve of spiral | |
rotate([0,0,atan2(p2[1]-p1[1],p2[0]-p1[0])]) { | |
//Nudge Further along spiral | |
//so links hook correctly | |
//(Tweak spacing variable) | |
translate([spacing/2,0,0]) { | |
if (i % 2 == 0){ | |
createSingleChain(l, h, d, textArray[i]); | |
} | |
else { | |
rotate([0,0,180]){ | |
translate([0,-evenNudge/sqrt(i+1),0]){ | |
createSingleChain(l, h, d, textArray[i]); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
module createSingleChain(l, h, d, myText) { | |
fontSize = d/2; //Divide by a bigger number | |
//to reduce font size | |
myFont="Bauhaus 93:style=Regular"; //Change this | |
//to use different font | |
//from menu click on | |
//Help -> Font List | |
translate([0,-d/4,h/2 - d/16]){ | |
rotate([-45, 0, 0]){ | |
difference() { | |
union(){ | |
createQuarterChain(l,h,d); | |
mirror([1,0,0]){ | |
createQuarterChain(l,h,d); | |
} | |
mirror([0,0,1]){ | |
createQuarterChain(l,h,d); | |
mirror([1,0,0]){ | |
createQuarterChain(l,h,d); | |
} | |
} | |
} | |
//Begin FONT section | |
translate([0,d/8,-h/2 + d/4]){ | |
rotate([90,0,0]){ | |
linear_extrude(d/8){ | |
text(myText, fontSize, | |
halign="center", | |
font=myFont); | |
} | |
} | |
} | |
//End Font Section | |
} | |
} | |
} | |
} | |
// Point on archimedes spiral at angle given pitch a (mm/turn). | |
function arch_spiral(angle,a) = | |
[a*angle/360*cos(angle), | |
a*angle/360*sin(angle),0]; | |
module createQuarterChain(l, h, d) { | |
//Bottom of chain | |
y0 = 0; | |
y1 = d/4; | |
y2 = (3 * d)/4; | |
y3 = d; | |
x0 = y0; | |
x1 = y1; | |
x2 = y2; | |
x3 = y3; | |
linkPoints = [ | |
//First Lower Octogon | |
[x1,y0], //0 | |
[x2,y0], //1 | |
[x3,y1], //2 | |
[x3,y2], //3 | |
[x2,y3], //4 | |
[x1,y3], //5 | |
[x0,y2], //6 | |
[x0,y1], //7 | |
]; | |
translate([-l/2,0,-h/2]){ | |
difference(){ | |
translate([0, 0, d]){ | |
rotate([0, 90, 0]){ | |
linear_extrude(l/2) { | |
polygon(linkPoints); | |
} | |
} | |
} | |
translate([(17*l)/80, 0, 0]){ | |
rotate([0, 22.5, 0]){ | |
translate([-d, 0, -2*d]){ | |
linear_extrude([0, 0, 2*d]){ | |
polygon([[x0-l, y0], [x3, y0], | |
[x3,y3], [x0-l,y3]]); | |
} | |
} | |
} | |
} | |
} | |
//START Angle Section | |
difference(){ | |
difference(){ | |
translate([(17*l)/80, 0, 0]){ | |
rotate([0, -45, 0]){ | |
translate([0, 0, -(17*l)/160]){ | |
linear_extrude(h) { | |
polygon(linkPoints); | |
} | |
} | |
} | |
} | |
translate([(17*l)/80, 0, 0]){ | |
rotate([0, 22.5, 0]){ | |
translate([-d, 0, -2*d]){ | |
linear_extrude([0, 0, 2*d]){ | |
polygon([[x0+l, y0],[x3, y0], | |
[x3,y3],[x0+l,y3]]); | |
} | |
} | |
} | |
} | |
} | |
translate([0, 0, (17*l)/80]){ | |
rotate([0, 67.5, 0]){ | |
translate([-d, 0, -d]){ | |
linear_extrude([0, 0, 4*d]){ | |
polygon([[x0-l, y0-10],[x3, y0-10], | |
[x3,y3+10],[x0-l,y3+10]]); | |
} | |
rotate([0,180,180]){ | |
translate([0,x0-x3,0]){ | |
linear_extrude([0, 0, -2*d]){ | |
polygon([[x0-l, y0-10],[x3, y0-10], | |
[x3,y3+10],[x0-l,y3+10]]); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
//END Angle Section | |
//START Vertical Section | |
difference(){ | |
linear_extrude(h/2) { | |
polygon(linkPoints); | |
} | |
translate([0, 0, (17*l)/80]){ | |
rotate([0, 67.5, 0]){ | |
translate([0, 0, -2*d]){ | |
linear_extrude([0, 0, 2*d]){ | |
polygon([[x0, y0],[x3+100, y0], | |
[x3+100,y3],[x0,y3]]); | |
} | |
} | |
} | |
} | |
} | |
//END Vertical Section | |
} | |
} | |
//Creates a number list, as strings, from start to end | |
function createNumbers(start, end) = | |
(start >= end) | |
? [ str(end) ] | |
: concat([str(start)], | |
createNumbers(start+1, end)); | |
// Copied from Openscad code for thing 28405 | |
// Approximate angle of archimedes spiral of | |
// length len (mm) from radius r0, given pitch a (mm/turn). | |
function inv_arch_len(len,r0,a) = | |
180/3.1416*sqrt( | |
len*2/(a/2/3.1416) | |
+(r0*2*3.1416/a)*(r0*2*3.1416/a)); | |
// Copied from Openscad code for thing 28405 | |
// Point on archimedes spiral at angle given | |
// pitch a (mm/turn). | |
function arch_spiral(angle,a) = | |
[a*angle/360*cos(angle),a*angle/360*sin(angle),0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment