openScad-files-pipes-and-such/pvcpipeGenerator.scad

117 lines
3.1 KiB
OpenSCAD
Raw Permalink Normal View History

2025-01-27 20:13:54 -06:00
// Pipe Fitting Generator
/* [General Settings] */
// Choose fitting type
Fitting_Type = "Coupler"; // [Coupler, Tee, Cross]
// Choose measurement system
Measurement_System = "Metric"; // [Metric, SAE]
// Pipe outer diameter (mm for Metric, inches for SAE)
Pipe_OD = 40; // [10:1:200]
// Wall thickness (mm for Metric, inches for SAE)
Wall_Thickness = 3; // [1:0.5:10]
// Threaded or non-threaded
Threaded = false; // [true, false]
/* [Thread Settings] */
// Thread pitch (mm for Metric, threads per inch for SAE)
Thread_Pitch = 3; // [0.5:0.25:5]
// Thread depth (mm for Metric, inches for SAE)
Thread_Depth = 1; // [0.5:0.25:3]
/* [Hidden] */
$fn = 100;
module pipe_segment(length) {
difference() {
cylinder(h=length, d=Pipe_OD + 2*Wall_Thickness);
translate([0, 0, -0.1])
cylinder(h=length + 0.2, d=Pipe_OD - 2*Wall_Thickness);
}
}
module thread(length) {
pitch = (Measurement_System == "Metric") ? Thread_Pitch : 25.4 / Thread_Pitch;
depth = (Measurement_System == "Metric") ? Thread_Depth : Thread_Depth * 25.4;
difference() {
cylinder(h=length, d=Pipe_OD + 2*Wall_Thickness);
translate([0, 0, -0.1])
cylinder(h=length + 0.2, d=Pipe_OD - 2*Wall_Thickness);
if (Threaded) {
for (i = [0:pitch:length]) {
translate([0, 0, i])
rotate_extrude()
translate([Pipe_OD/2 + Wall_Thickness - depth/2, 0, 0])
circle(d=depth);
}
}
}
}
module coupler() {
length = Pipe_OD + 2*Wall_Thickness;
thread(length);
}
module tee() {
length = Pipe_OD + 2*Wall_Thickness;
branch_length = (Pipe_OD + 2*Wall_Thickness) / 2;
difference() {
union() {
thread(length);
rotate([0, 90, 0])
translate([0, 0, 2*-branch_length])
thread(4*branch_length);
}
// Main pipe hole
translate([0, 0, -length/ - 0.1])
cylinder(h=length + 0.2, d=Pipe_OD - 2*Wall_Thickness);
// Branch hole
rotate([0, 90, 0])
translate([0, 0, -branch_length - 0.1])
cylinder(h=2*branch_length + 0.2, d=Pipe_OD - 2*Wall_Thickness);
}
}
module cross() {
length = Pipe_OD + 2*Wall_Thickness;
difference() {
union() {
// + X-axis branches
rotate([0, 90, 0])
thread(length);
// + Z-axis branches
thread(length);
// - X-axis branches
rotate([0, -90, 0])
thread(length);
rotate([0, 180, 0])
// - Z-axis branches
thread(length);
}
// X-axis hole
rotate([0, 90, 0])
translate([0, 0, -length/2 - 0.1])
cylinder(h=length + 0.2, d=Pipe_OD - 2*Wall_Thickness);
// Z-axis hole
translate([0, 0, -length/2 - 0.1])
cylinder(h=length + 0.2, d=Pipe_OD - 2*Wall_Thickness);
}
}
if (Fitting_Type == "Coupler") {
coupler();
} else if (Fitting_Type == "Tee") {
tee();
} else if (Fitting_Type == "Cross") {
cross();
}