openscad - Placing depressions in octagonal shape - Stack Overflow

admin2025-04-22  5

I am new to Openscad so bear with me. As part of a larger model, I have created an octagon with a circle cut out of the middle. I want to create a depressed circle in middle of each side of the octagon with a diameter of 11mm and depth of 6mm. Unfortunately, I have no idea how to do this. Can someone please point me in the right direction? A snippet of my code is below:

$fn = 150; // Smoothness for round parts
outer_diameter = 103; // Outer diameter of the hose connection
inner_diameter = 100;  // Inner diameter (to fit hose)
adapter_height = 50;  // Height of the adapter
lip_height = 25                                 ;       // Height of the lip for magnetic connection
lip_width = 40;        // Thickness of the lip

// Octagonal Magnetic Lip
module magnetic_lip() {
    difference() {
        // Outer lip with octagonal shape
        linear_extrude(height=lip_height)
            offset(delta=lip_width, chamfer=false)
                circle(d=inner_diameter, $fn=8); // Octagon shape
        
        // Inner lip hole
        translate([0, 0, -1])
            cylinder(h=lip_height + 2, d=outer_diameter);
        
    }
}


// Complete Assembly
module hose_adapter() {
    union() {
        magnetic_lip();
    }
}

// Render the adapter
hose_adapter();

I am new to Openscad so bear with me. As part of a larger model, I have created an octagon with a circle cut out of the middle. I want to create a depressed circle in middle of each side of the octagon with a diameter of 11mm and depth of 6mm. Unfortunately, I have no idea how to do this. Can someone please point me in the right direction? A snippet of my code is below:

$fn = 150; // Smoothness for round parts
outer_diameter = 103; // Outer diameter of the hose connection
inner_diameter = 100;  // Inner diameter (to fit hose)
adapter_height = 50;  // Height of the adapter
lip_height = 25                                 ;       // Height of the lip for magnetic connection
lip_width = 40;        // Thickness of the lip

// Octagonal Magnetic Lip
module magnetic_lip() {
    difference() {
        // Outer lip with octagonal shape
        linear_extrude(height=lip_height)
            offset(delta=lip_width, chamfer=false)
                circle(d=inner_diameter, $fn=8); // Octagon shape
        
        // Inner lip hole
        translate([0, 0, -1])
            cylinder(h=lip_height + 2, d=outer_diameter);
        
    }
}


// Complete Assembly
module hose_adapter() {
    union() {
        magnetic_lip();
    }
}

// Render the adapter
hose_adapter();
Share Improve this question asked Jan 21 at 14:37 M BeckerM Becker 731 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

With the help of ChatGPT (it can write Openscad code!), I got the following using the code below:

$fn = 150; // Smoothness for round parts
outer_diameter = 103; // Outer diameter of the hose connection
inner_diameter = 100; // Inner diameter (to fit hose)
adapter_height = 50;  // Height of the adapter
lip_height = 25;      // Height of the lip for magnetic connection
lip_width = 40;       // Thickness of the lip

hole_diameter = 12.5;   // Diameter of the holes
hole_depth = 4;       // Depth of the holes
num_holes = 8;        // Number of holes

// Octagonal Magnetic Lip
module magnetic_lip() {
    difference() {
        // Outer lip with octagonal shape
        linear_extrude(height=lip_height)
            offset(delta=lip_width, chamfer=false)
                circle(d=inner_diameter, $fn=8); // Octagon shape
        
        // Inner lip hole
        translate([0, 0, -1])
            cylinder(h=lip_height + 2, d=outer_diameter);
        
        // Drill holes on the top horizontal surface, centered between inner circle and outer edge
        for (i = [0 : 360 / num_holes : 360 - (360 / num_holes)]) {
            rotate([0, 0, i]) {
                // Calculate midpoint radius between inner circle and outer edge of the octagon
                radius_midpoint = (inner_diameter / 2 + (inner_diameter / 2 + lip_width)) / 2;

                translate([radius_midpoint, 0, lip_height]) {
                    cylinder(h=hole_depth, d=hole_diameter, center=true);
                }
            }
        }
    }
}

// Complete Assembly
module hose_adapter() {
    union() {
        magnetic_lip();
    }
}

// Render the adapter
hose_adapter();
转载请注明原文地址:http://anycun.com/QandA/1745304142a90622.html