Skip to content

Instantly share code, notes, and snippets.

@thehans
Created June 2, 2020 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thehans/ef46860c761f3352c971f70161eca931 to your computer and use it in GitHub Desktop.
Save thehans/ef46860c761f3352c971f70161eca931 to your computer and use it in GitHub Desktop.
// Pipe library demonstrating a concept of chained operations
$fn = 72; // define exact number of fragments in curves
// using $fs instead would cause some mismatched # of edges during tapers
echo(str("For best results, all angles should be multiples of ", 360/$fn, " degrees"));
in = 25.4;
// Example of how to use pipe
// Note that all calls are chained (there's only one semicolon, at the end)
// children are automatically transformed to the end of the "path"
pipe([20,25])
slip_fitting(depth=10, start=true)
elbow()
straight(10)
taper_to([30,35], length=30)
elbow(angle=180, heading=30)
straight(20)
slip_fitting(20);
//sphere(d=35); // we can even terminate the chain with a module that doesn't "know" anything about our pipes
// initializes the pipe size, but draws nothing
module pipe(size=[2,4]) {
$pipe_size = size;
children();
}
module straight(length=10) {
linear_extrude(height=length) difference() {
circle(d=$pipe_size[1]);
circle(d=$pipe_size[0]);
}
translate([0,0,length]) children();
}
// no-operation. This aids in passing data from parent to children
// cals to noop() could also be replaced by let() (experimental), if running a development snapshot.
// Also see https://github.com/openscad/openscad/issues/2104
module noop() children();
module taper_to(size, length=10) {
IR1 = $pipe_size[0]/2;
OR1 = $pipe_size[1]/2;
IR2 = size[0]/2;
OR2 = size[1]/2;
points = [
[IR1, 0], [OR1, 0],
[OR2, length], [IR2, length]
];
rotate_extrude() polygon(points);
translate([0,0,length])
noop($pipe_size=size)
children();
//children($pipe_size=size);
}
module slip_fitting(depth=4, start=false) {
IR1 = $pipe_size[0]/2;
OR1 = $pipe_size[1]/2;
th = OR1 - IR1;
IR2 = IR1 + th;
OR2 = IR2 + th;
th2 = th*sqrt(2);
points = [
[IR1, 0], [OR1, 0], [OR2, th],
[OR2, depth+th2], [IR2, depth+th2],
[IR2, th2], [IR1, th2], [IR1,0]
];
if (start) {
rotate_extrude() translate([0,th2]) mirror([0,1]) polygon(points);
} else {
rotate_extrude() polygon(points);
}
translate([0,0,th2])
children();
}
// R = center radius of elbow
// angle = the angle through which the elbow bends.
// heading = which direction it bend towards
module elbow(R=$pipe_size[1]/2, angle=90, heading=0) {
OR = $pipe_size[1]/2;
if (angle != 0) {
rotate(heading) translate([R+OR,0]) rotate([-90,0,0]) {
rotate_extrude(angle=angle)
translate([-R-OR,0]) difference() {
circle(d=$pipe_size[1]);
circle(d=$pipe_size[0]);
}
}
}
rotate(heading) translate([R+OR,0,0]) rotate([0,angle,0]) translate([-R-OR,0,0]) children();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment