Skip to content

Instantly share code, notes, and snippets.

@Dianoga
Forked from ednisley/Vacuum Hose Fittings.scad
Last active July 19, 2021 21:26
Show Gist options
  • Save Dianoga/46055af9678bcdb74aaa09066518e675 to your computer and use it in GitHub Desktop.
Save Dianoga/46055af9678bcdb74aaa09066518e675 to your computer and use it in GitHub Desktop.
Pipe Adapter
/* [General] */
// Transition length in mm
transition_length = 10;
// Number of sections in cylinder (more = more circular)
circle_sections = 360;
// Used for debugging
show_real_part = true;
/* [Side 1] */
// Desired OD in mm
from_od = 115;
// Desired wall thickness in mm
from_wall_thickness = 6;
// Desired length in mm
from_length = 20;
// Is the taper inside the cylinder?
from_taper_inside = true;
// Desired taper length in mm
from_taper_length = 10;
/* [Side 2] */
// Desired OD in mm
to_od = 112;
// Desired wall thickness in mm
to_wall_thickness = 6;
// Desired length in mm
to_length = 20;
// Is the taper inside the cylinder?
to_taper_inside = true;
// Desired taper length in mm
to_taper_length = 10;
/* [Hidden] */
cleanup = 0.1;
from_id = from_od - from_wall_thickness*2;
to_id = to_od - to_wall_thickness*2;
$fn = circle_sections;
module taper(start, finish, length, inside, od, z=0) {
echo(str("start = ", start, " finish = ", finish, " length = ", length, " inside = ", inside, " od = ", od, " z = ", z));
color("blue") {
if (inside) {
cylinder(d1=start, d2=finish, h=length);
} else {
difference() {
translate([0, 0, z]) cylinder(d=od, h=length);
translate([0, 0, z - cleanup]) cylinder(d1=start, d2=finish, h=length + cleanup*2);
}
}
}
}
if (show_real_part) {
difference() {
// Outside
union() {
from_taper_start = from_od - from_wall_thickness;
from_taper_finish = from_taper_inside ? from_id : from_od;
taper(from_taper_start, from_taper_finish, from_taper_length, !from_taper_inside, od=from_od, z=0);
translate([0, 0, (from_taper_length)]) cylinder(d=from_od, h=(from_length - from_taper_length)); // From side
translate([0, 0, (from_length)]) cylinder(d1=from_od, d2=to_od, h=(transition_length)); // Transition
translate([0, 0, (from_length + transition_length)]) cylinder(d=to_od, h=(to_length - to_taper_length)); // To side
to_taper_z = from_length + transition_length + to_length - to_taper_length;
to_taper_start = to_taper_inside ? to_id : to_od;
to_taper_finish = to_od - to_wall_thickness;
taper(to_taper_start, to_taper_finish, to_taper_length, !to_taper_inside, od=to_od, z=to_taper_z);
}
// Inside
union() {
translate([0, 0, -cleanup]) cylinder(d=from_id, h=(from_length + cleanup)); // From side
translate([0, 0, (from_length - cleanup)]) cylinder(d1=from_id, d2=to_id, h=(transition_length + cleanup*2)); // Transition
translate([0, 0, (from_length + transition_length - cleanup)]) cylinder(d=to_id, h=(to_length + cleanup*2)); // To side
}
}
} else {
color("red"){
start = 100;
finish = 106;
length = 10;
od = 112;
z = 40;
difference() {
translate([0, 0, z]) cylinder(d=od, h=length);
translate([0, 0, z - cleanup]) cylinder(d1=start, d2=finish, h=length + cleanup*2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment