Skip to content

Instantly share code, notes, and snippets.

@prozacgod
Last active April 14, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prozacgod/0c7b04b82262e8afea8842d76aad3d65 to your computer and use it in GitHub Desktop.
Save prozacgod/0c7b04b82262e8afea8842d76aad3d65 to your computer and use it in GitHub Desktop.
Parametric Windowed Tubing for 3d Printed Cooling loop (OpenJSCAD)
// title : OpenJSCAD.org Logo
// author : Prozacgod
// license : MIT License
// revision : 0.001
// file : jscad
// This was inspired by https://www.youtube.com/watch?v=LDk4XcMztf0
// I figured a parametric version of a tube planner would be nice, started with 90 turns
// you can define things such as window count, inner diameter outter diameter and the radius of the turn
//
// all measurements are in MM - you'll probably have to tell your slicer when you import the STL
const curveRadius = 80;
const outerDiameter = 20;
const innerDiameter = 16;
const windowHeight = 3;
const windowCount = 4;
const separatorWidth = 4;
const endLengthA = 40;
const endLengthB = 40;
// increase this when you're satisfied
const resolution = 32;
// Future Use - Define tubing path
// this defines the straigh line path, that you need your tubing to take
// the algorithm will put cuves in where necessary
const path = [
["+y", 40], // go up 40mm
["+"]
]
// internal use variables
const outerRadius = outerDiameter / 2;
const innerRadius = innerDiameter / 2;
const halfWindowHeight = windowHeight / 2;
const windowHeightFudge = halfWindowHeight * .2;
const halfFudge = windowHeightFudge / 2;
function curveCutoutTool() {
const ang = Math.sin(windowHeight / curveRadius) * 180/Math.PI;
const lr_tube = union(
rotate(
[0,0,-ang],
translate(
[curveRadius, 0, 0],
cylinder({r: halfWindowHeight + windowHeightFudge, h: outerRadius + 20, center:true})
)
),
rotate(
[0,0,+ang],
translate(
[curveRadius, 0, 0],
cylinder({r: halfWindowHeight + windowHeightFudge, h: outerRadius + 20, center:true})
)
)
);
const verticalCutter = difference(
difference(
cylinder({center: true, r: curveRadius + (halfWindowHeight + windowHeightFudge), h: outerDiameter*2 }),
cylinder({center: true, r: curveRadius - (halfWindowHeight + windowHeightFudge), h: outerDiameter*2 })
),
lr_tube,
// these last elements are all copy/pasted cubes to block out the rest of the tool quick dirty..
rotate(
[0, 0, 0],
translate(
[curveRadius/2, curveRadius/2 + windowHeight * 2.5, 0],
cube({
center: true,
size:[curveRadius + outerDiameter, curveRadius + outerDiameter, outerDiameter + 20]
})
)
),
rotate(
[0, 180, 0],
translate(
[curveRadius/2, curveRadius/2 + windowHeight * 2.5, 0],
cube({
center: true,
size:[curveRadius + outerDiameter, curveRadius + outerDiameter, outerDiameter + 20]
})
)
),
rotate(
[0, 0, 180],
translate(
[curveRadius/2, curveRadius/2 + windowHeight * 2.5, 0],
cube({
center: true,
size:[curveRadius + outerDiameter, curveRadius + outerDiameter, outerDiameter + 20]
})
)
),
rotate(
[0, 180, 180],
translate(
[curveRadius/2, curveRadius/2 + windowHeight * 2.5, 0],
cube({
center: true,
size:[curveRadius + outerDiameter, curveRadius + outerDiameter, outerDiameter + 20]
})
)
),
translate(
[-curveRadius, 0, 0],
cube({
center: true,
size:[curveRadius + outerDiameter, curveRadius + outerDiameter, outerDiameter + 20]
})
)
)
let horizCutter = difference(
cube({
size: [windowHeight, windowHeight * 2, outerDiameter * 2],
center: true
}),
translate([0,-windowHeight,0],
cylinder({
center: true,
r: halfWindowHeight,
h: outerDiameter * 2
})
),
translate([0,windowHeight,0],
cylinder({
center: true,
r: halfWindowHeight,
h: outerDiameter * 2
})
)
)
horizCutter = rotate([0,90,0], horizCutter);
horizCutter = translate([curveRadius,0,0], horizCutter);
return union(
verticalCutter,
horizCutter
);
}
function curveCutout() {
const windowSpliter = cube({size: 10});
const ang = 90/windowCount;
const dividers = [];
function pushDivider(a) {
dividers.push(
translate([0, 0, outerDiameter],
rotate([0,0,-a],
curveCutoutTool()
)
)
);
}
pushDivider(0);
pushDivider(90);
for (var i = 1; i < windowCount; i++) {
pushDivider(ang * i);
}
const dividerUnion = union(dividers);
const topBottomWindowCutout = difference(
cylinder({center: true, r: curveRadius + (windowHeight/2), h: outerDiameter * 2}),
cylinder({center: true, r: curveRadius - (windowHeight/2), h: outerDiameter * 2})
);
return (
difference(
union(
topBottomWindowCutout,
translate(
[0, 0, 0],
cylinder({center: true, r: curveRadius + outerDiameter, h : windowHeight})
)
),
translate(
[0, 0, -outerDiameter],
union(
cube(
{size: [
curveRadius + outerDiameter,
separatorWidth * 2,
outerDiameter * 2
]}
),
translate([-separatorWidth * 2,0,0],
rotate(
[0,0,-90],
cube(
{size: [
curveRadius + outerDiameter,
separatorWidth * 2,
outerDiameter * 2
]}
)
)),
dividerUnion
)
)
)
);
}
function curve() {
return difference(
torus({
ri: outerDiameter/2,
ro: curveRadius,
fni: resolution,
fno: resolution * 2,
}),
translate([
-curveRadius - outerRadius - 1,
0,
-outerRadius
], cube({
size: [
curveRadius * 2 + outerDiameter + 2,
curveRadius + outerDiameter,
outerDiameter + 1]
})), translate([
-curveRadius - outerRadius - 1,
-curveRadius - outerRadius - 1,
-outerRadius
], cube({
size: [
curveRadius + outerRadius + 1,
curveRadius + outerRadius + 1,
outerDiameter + 1]
})), torus({
ri: innerDiameter/2,
ro: curveRadius,
fni: resolution,
fno: resolution* 2,
})
)
}
function pipeA() {
return translate([
curveRadius, 0, 0
],
rotate(
[90,0,180],
difference(
cylinder({
r: outerRadius, h: endLengthA}
))
)
);
}
function main () {
return union(
pipeA(),
difference(
curve(),
curveCutout()
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment