// User Configurable Dimensions inlet_outer_diameter = 40; // mm inlet_inner_diameter = 35; // mm (This is the taper start width) elbow_length = 70; // mm (Length of the straight section) width_at_elbow = 32.1; // mm (Target width at elbow) wall_thickness = 3; // mm (Base wall thickness) // Geometry Generation inlet_len = 10; taper_len = inlet_len; // Calculate Inner Radius at various points // Point 0 (y=0): 32.1mm width (0.16) // Point 1 (y=10): 30mm width (0.15) // Point 2 (y=70): 32.1mm width (0.16) r_in_0 = width_at_elbow / 2; r_in_end = 30 / 2; r_in_70 = width_at_elbow / 2; // Calculate Outer Radius (add wall thickness) // Start: 35mm ID -> 32.1mm width. Wall is 2.9mm. r_out_0 = inlet_outer_diameter / 2; r_out_end = (30 + wall_thickness) / 2; // Inner is 30, Wall is 3 -> Outer is 33mm // Create a function to get the Radius at any given distance 'y' function get_radius(y) = (y <= inlet_len) ? linear_interpolate(0, inlet_len, r_in_0, r_in_end, y) : linear_interpolate(inlet_len, elbow_length, r_in_end, r_in_70, y); function get_outer_radius(y) = get_radius(y) + wall_thickness; // Syntax Error Here /* //old code // Generate points for the profile profile_points = [ [0, r_out_0] ]; for (y = [0.1 : 0.5 : inlet_len]) profile_points = concat(profile_points, [[y, get_radius(y)]]); for (y = [inlet_len : 0.5 : elbow_length]) profile_points = concat(profile_points, [[y, get_radius(y)]]); */ // revised code // Generate points for the profile profile_points = [ [0, r_out_0], for (y = [0.1 : 0.5 : inlet_len]) [y, get_radius(y)], for (y = [inlet_len : 0.5 : elbow_length]) [y, get_radius(y)] ]; // --- SECTION E: The Main Shape Generator --- module create_adapter() { // Inlet (Bottom) polygon(profile_points); // Elbow (Top) // We need to rotate the profile so the bottom (inlet) points down and top points right. // Let's define a pivot point at the end of the inlet. pivot_x = inlet_len; pivot_y = get_radius(inlet_len); // The radius at the bend point // Create a new set of points for the elbow section // We offset the elbow section so its origin (0,0) is at the pivot elbow_points = [ for (i = [0:1:len(profile_points)-1]) [profile_points[i][0] - pivot_x, profile_points[i][1] - pivot_y] ]; // Rotate the elbow rotate([0, 0, 90]) { translate([0, 0, -elbow_radius]) { polygon(elbow_points); } } // Extrude to make it a tube // We need to create a closed loop for extrusion. // The polygon is just the top half. We need to mirror it for the bottom. // Actually, for `linear_extrude`, we should define a closed shape. // The top points are [x, y]. The bottom points are [x, -y]. // Another Syntax Error Here /* //old code closed_shape = concat( for (p = profile_points) [p[0], -p[1]], profile_points ); */ //revised code closed_shape = concat( [ for (p = profile_points) [p[0], -p[1]] ], profile_points ); linear_extrude(height = 50) { polygon(closed_shape); } } function linear_interpolate(y0, y1, r0, r1, y) = r0 + (r1 - r0) * (y - y0) / (y1 - y0); create_adapter();