Refactore code: global and geometry variables now more clear, stacking function easier to read

This commit is contained in:
2025-04-22 20:24:44 +02:00
parent b34b941fef
commit d31d0044a3
2 changed files with 59 additions and 88 deletions
-88
View File
@@ -1,88 +0,0 @@
// Inlet variables
inlet_length = 250; // 100.5 raggio grande, 200mm lunghezza
inlet_radius = 200;
inlet_throat_radius = 100;
inlet_thickness = 0.25;
inlet_segments = 30; // Number of stacked layers (higher = smoother)
inlet_curve_factor = 2; // Controls how aggressively the walls curve
module inlet() {
difference() {
union() {
for (i = [0:inlet_segments-1]) {
h = inlet_length / inlet_segments;
t = i / (inlet_segments-1);
// Apply power function for curvature
r1 = inlet_throat_radius + (inlet_radius - inlet_throat_radius) * pow(t, inlet_curve_factor);
r2 = inlet_throat_radius + (inlet_radius - inlet_throat_radius) * pow((i+1) / (inlet_segments-1), inlet_curve_factor);
translate([0, 0, i * h])
cylinder(h = h, r1 = r1, r2 = r2, $fn = 75);
}
}
// Inner subtraction (to maintain thickness)
union() {
for (i = [0:inlet_segments-1]) {
h = inlet_length / inlet_segments;
t = i / (inlet_segments-1);
r1 = (inlet_throat_radius + (inlet_radius - inlet_throat_radius) * pow(t, inlet_curve_factor)) - inlet_thickness;
r2 = (inlet_throat_radius + (inlet_radius - inlet_throat_radius) * pow((i+1) / (inlet_segments-1), inlet_curve_factor)) - inlet_thickness;
translate([0, 0, i * h])
cylinder(h = h, r1 = r1, r2 = r2, $fn = 75);
}
}
}
}
// Rotate for correct orientation
rotate([0, -90, 0]) inlet();
// Outlet variables
outlet_length = 350;
outlet_radius = 165;
outlet_throat_radius = 100;
outlet_thickness = 0.25;
outlet_segments = 20; // Number of stacked layers (higher = smoother)
outlet_curve_factor = 1.5; // Controls how aggressively the walls curve
module outlet() {
difference() {
union() {
for (i = [0:outlet_segments-1]) {
h = outlet_length / outlet_segments;
t = i / (outlet_segments-1);
// Apply power function for curvature
r1 = outlet_throat_radius + (outlet_radius - outlet_throat_radius) * pow(t, outlet_curve_factor);
r2 = outlet_throat_radius + (outlet_radius - outlet_throat_radius) * pow((i+1) / (outlet_segments-1), outlet_curve_factor);
translate([0, 0, i * h])
cylinder(h = h, r1 = r1, r2 = r2, $fn = 75);
}
}
// Inner subtraction (to maintain thickness)
union() {
for (i = [0:outlet_segments-1]) {
h = outlet_length / outlet_segments;
t = i / (outlet_segments-1);
r1 = (outlet_throat_radius + (outlet_radius - outlet_throat_radius) * pow(t, outlet_curve_factor)) - outlet_thickness;
r2 = (outlet_throat_radius + (outlet_radius - outlet_throat_radius) * pow((i+1) / (outlet_segments-1), outlet_curve_factor)) - outlet_thickness;
translate([0, 0, i * h])
cylinder(h = h, r1 = r1, r2 = r2, $fn = 75);
}
}
}
}
// Rotate for correct orientation
rotate([0, 90, 0]) outlet();
+59
View File
@@ -0,0 +1,59 @@
// ======== Global Parameters ======== //
$fn = 75;
inlet_segments = 60;
outlet_segments = 20;
// ======== Venturi Geometry ======== //
inlet_length = 250;
outlet_length = 350;
inlet_radius = 300;
throat_radius = 80;
outlet_radius = 110;
wall_thickness = 5;
inlet_curve_factor = 2;
outlet_curve_factor = 1.5;
// ======== Stacking Function ======== //
module stacked_shell(length, r_end, thickness, segments, curve_factor, is_outer = true) {
for (i = [0:segments - 1]) {
h = length / segments;
t0 = i / (segments - 1);
t1 = (i + 1) / (segments - 1);
r1 = throat_radius + (r_end - throat_radius) * pow(t0, curve_factor);
r2 = throat_radius + (r_end - throat_radius) * pow(t1, curve_factor);
if (!is_outer) {
r1 = r1 - thickness;
r2 = r2 - thickness;
}
translate([0, 0, i * h])
cylinder(h = h, r1 = r1, r2 = r2);
}
}
// ======== Inlet Module ======== //
module inlet() {
difference() {
union()
stacked_shell(inlet_length, inlet_radius, wall_thickness, inlet_segments, inlet_curve_factor, true);
union()
stacked_shell(inlet_length, inlet_radius, wall_thickness, inlet_segments, inlet_curve_factor, false);
}
}
rotate([0, -90, 0]) inlet();
// ======== Outlet Module ======== //
module outlet() {
difference() {
union()
stacked_shell(outlet_length, outlet_radius, wall_thickness, outlet_segments, outlet_curve_factor, true);
union()
stacked_shell(outlet_length, outlet_radius, wall_thickness, outlet_segments, outlet_curve_factor, false);
}
}
rotate([0, 90, 0]) outlet();