Rounding the edge of a hole? September 25, 2019 04:58PM |
Registered: 9 years ago Posts: 893 |

This is a simplified extract from something I'm designing:

This results in a cube with an oval hole through it (see attachment)

What I would like to do is to put a nice rounded edge around the hole at both ends. The trouble is, I don't know where to start! I would appreciate it if someone could give me some suggested techniques, helpful hints, etc. I'm not expecting anyone to actually do the work - just give me a clue about how to do it!

Note - this is something I've often wanted to do, but shied away from due to a lack of knowledge.

TIA,

David

Edited 2 time(s). Last edit at 09/25/2019 05:02PM by David J.

bodyWidth = 25; bodyHeight = 15; slotWidth = 6; slotHeight = 10; $fn = 50; module slot() { rotate( [-90, -90, 0] ) union() { cylinder(d = slotWidth, h = bodyWidth + 2); translate( [0, -slotWidth/2, 0] ) cube( [bodyHeight - slotHeight, slotWidth, bodyWidth + 2] ); translate( [bodyHeight - slotHeight, 0, 0] ) cylinder(d = slotWidth, h = bodyWidth + 2); } } difference() { cube(bodyWidth); translate( [bodyWidth/2, -1, bodyWidth/2] ) #slot(); }

This results in a cube with an oval hole through it (see attachment)

What I would like to do is to put a nice rounded edge around the hole at both ends. The trouble is, I don't know where to start! I would appreciate it if someone could give me some suggested techniques, helpful hints, etc. I'm not expecting anyone to actually do the work - just give me a clue about how to do it!

Note - this is something I've often wanted to do, but shied away from due to a lack of knowledge.

TIA,

David

Edited 2 time(s). Last edit at 09/25/2019 05:02PM by David J.

Re: Rounding the edge of a hole? September 25, 2019 10:53PM |
AdminRegistered: 13 years ago Posts: 6,982 |

I presume you want this chamfer removed from the cube not the slot.

That is a rounded chamfer, and is very annoying do in openscad. (This is one of openscads biggest issues in my view)

You need to apply the chamfer to each component part, ie two cylinders and the square.

What I do is a 45 degree chamfer. Ie create some 90 degree cones at each end and remove how much you want

Do the same on the straight parts with a 45 degree rotated cube.

This is much easier to print, you don't get overhangs over 45 degrees.

Edited 4 time(s). Last edit at 09/26/2019 05:14AM by Dust.

That is a rounded chamfer, and is very annoying do in openscad. (This is one of openscads biggest issues in my view)

You need to apply the chamfer to each component part, ie two cylinders and the square.

What I do is a 45 degree chamfer. Ie create some 90 degree cones at each end and remove how much you want

Do the same on the straight parts with a 45 degree rotated cube.

This is much easier to print, you don't get overhangs over 45 degrees.

Edited 4 time(s). Last edit at 09/26/2019 05:14AM by Dust.

Re: Rounding the edge of a hole? September 26, 2019 12:29AM |
AdminRegistered: 13 years ago Posts: 6,982 |

But if you insist on rounded chamfers. Here is a cylinder for cut out with round chamfer (I just wrote this)

Edited 3 time(s). Last edit at 09/26/2019 12:50AM by Dust.

module Chamfered_Cylinder(CylinderDiameter,CylinderHeight,ChamferRadius,ChamferFacits) { difference () { union() { //Central Cyclinder cylinder(d=CylinderDiameter,h=CylinderHeight); //Bottom Chamfer cylinder translate ([0,0,0]) cylinder(d=CylinderDiameter+ChamferRadius,h=ChamferRadius/2); //Top Chamfer cylinder translate ([0,0,CylinderHeight-ChamferRadius/2]) cylinder(d=CylinderDiameter+ChamferRadius,h=ChamferRadius/2); } //Generate Bottom chamfer for (i = [0:1:ChamferFacits-1]) { rotate([90,0,i*360/ChamferFacits+90]) translate([CylinderDiameter/2+ChamferRadius/2,ChamferRadius/2,-ChamferRadius/2]) cylinder(d=ChamferRadius, h=ChamferRadius); } //generate Top chamfer for (i = [0:1:ChamferFacits-1]) { rotate([90,0,i*360/ChamferFacits+90]) translate([CylinderDiameter/2+ChamferRadius/2,CylinderHeight-ChamferRadius/2,-ChamferRadius/2]) cylinder(d=ChamferRadius, h=ChamferRadius); } } } CylinderDiameter = 15; CylinderHeight = 40; ChamferRadius = 5; ChamferFacits = 50; //Its best to have the cylinder facits and the Chamfer facits the same value. $fn=ChamferFacits; //Extra cylinder on bottom to appease the scad gods translate ([0,0,-ChamferRadius]) cylinder(d=CylinderDiameter+ChamferRadius,h=ChamferRadius); //Extra cylinder on top to appease the scad gods translate ([0,0,CylinderHeight]) cylinder(d=CylinderDiameter+ChamferRadius,h=ChamferRadius); //The Cylinder with chamfer Chamfered_Cylinder(CylinderDiameter,CylinderHeight,ChamferRadius,ChamferFacits);

Edited 3 time(s). Last edit at 09/26/2019 12:50AM by Dust.

Re: Rounding the edge of a hole? September 26, 2019 12:52AM |
Registered: 9 years ago Posts: 978 |

If you can live with the outside edges of the cube being rounded, then Minkowski is the answer. However, this is very slow operation. Put **minkowski() {... sphere(1); }** around your main block.

minkowski() { difference() { cube(bodyWidth); translate( [bodyWidth/2, -1, bodyWidth/2] ) slot(); } sphere(1); }

Re: Rounding the edge of a hole? September 26, 2019 04:24AM |
Registered: 9 years ago Posts: 893 |

Hmm - I need to study your answers! Especially that code example...

I hadn't thought about using minkowski when the object has the slots - in the real project I had applied it to the body prior to 'cutting' the slots. I shall have to try that out. However it means re-arranging my code as I have included screw holes in the same part as the slots (not a major crisis).

My other random thought last night was about making the slot itself a better shape - making the cube and two cylinders with 'fat ends' so that a difference with a larger object results in a rounded exit. I suspect that's what the code example is doing, but I'll confirm that later today...

Thanks for all your help - I'll see how it works out.

I hadn't thought about using minkowski when the object has the slots - in the real project I had applied it to the body prior to 'cutting' the slots. I shall have to try that out. However it means re-arranging my code as I have included screw holes in the same part as the slots (not a major crisis).

My other random thought last night was about making the slot itself a better shape - making the cube and two cylinders with 'fat ends' so that a difference with a larger object results in a rounded exit. I suspect that's what the code example is doing, but I'll confirm that later today...

Thanks for all your help - I'll see how it works out.

Re: Rounding the edge of a hole? September 26, 2019 08:06AM |
Registered: 9 years ago Posts: 893 |

Right - I tried using minkowski... life is too short... and all of my dimensions were screwed up (as expected); it would be a PITA to make size adjustments to compensate. So, good idea, but too painful.

I've been trying to develop my own idea, and here's how far I've got:

UPDATE 1: I've just look at the code written by 'Dust' - mine follows a similar technique. I didn't copy yours, honest!

UPDATE 2: Dust's approach is better than mine...

Obviously it doesn't yet achieve my original objective, but it's a start. I won't show the code just yet as it's messy and horrible, but I do plan to make it into a library so I'll put it up here for review when it's in decent shape (and when I'm not too ashamed to show it in public!).

Cheers,

David

Edited 2 time(s). Last edit at 09/26/2019 08:16AM by David J.

I've been trying to develop my own idea, and here's how far I've got:

UPDATE 1: I've just look at the code written by 'Dust' - mine follows a similar technique. I didn't copy yours, honest!

UPDATE 2: Dust's approach is better than mine...

Obviously it doesn't yet achieve my original objective, but it's a start. I won't show the code just yet as it's messy and horrible, but I do plan to make it into a library so I'll put it up here for review when it's in decent shape (and when I'm not too ashamed to show it in public!).

Cheers,

David

Edited 2 time(s). Last edit at 09/26/2019 08:16AM by David J.

Re: Rounding the edge of a hole? September 26, 2019 08:51AM |
AdminRegistered: 13 years ago Posts: 6,982 |

Re: Rounding the edge of a hole? September 26, 2019 10:36AM |
Registered: 9 years ago Posts: 893 |

Re: Rounding the edge of a hole? September 26, 2019 11:49AM |
Registered: 9 years ago Posts: 590 |

Interesting problem...

Here my approach, which is a bit different. Instead of subtracting cylinders to get the chamfer, I construct the cylinder in slices:

The module*chamfercyl()* takes as parameters the radius *r* and height *h* of the cylinder and in addition the chamfer radii *b* for bottom and *t* for top, where a positive chamfer radius goes to the outside and a negative to the inside of the main cylinder. The *slices* parameter gives the number of slices for rounding the chamfer. The optional *offset* array can be used to generate a convex hull at the slice level (cannot be done at the object level because the final object is not convex if outside chamfering is used). In David's object I use the offsets to make a slot instead of a round hole. Finally, the parameter *eps* can be used to add a tiny overlap of the slices.

Here some more simple examples to show the basic working of the module*chamfercyl()*:

Here my approach, which is a bit different. Instead of subtracting cylinders to get the chamfer, I construct the cylinder in slices:

// chamfercyl - create a cylinder with round chamfered ends module chamfercyl( r, // cylinder radius h, // cylinder height b=0, // bottom chamfer radius (=0 none, >0 outside, <0 inside) t=0, // top chamfer radius (=0 none, >0 outside, <0 inside) offset=[[0,0]], // optional offsets in X and Y to create // convex hulls at slice level slices=10, // number of slices used for chamfering eps=0.01, // tiny overlap of slices ){ astep=90/slices; hull()for(o = offset) translate([o[0],o[1],abs(b)-eps])cylinder(r=r,h=h-abs(b)-abs(t)+2*eps); if(b)for(a=[0:astep:89.999])hull()for(o = offset) translate([o[0],o[1],abs(b)-abs(b)*sin(a+astep)-eps]) cylinder(r2=r+(1-cos(a))*b,r1=r+(1-cos(a+astep))*b,h=(sin(a+astep)-sin(a))*abs(b)+2*eps); if(t)for(a=[0:astep:89.999])hull()for(o = offset) translate([o[0],o[1],h-abs(t)+abs(t)*sin(a)-eps]) cylinder(r1=r+(1-cos(a))*t,r2=r+(1-cos(a+astep))*t,h=(sin(a+astep)-sin(a))*abs(t)+2*eps); } // now build David's example, the cube with the chamfered hole (viewed from below to make things easy...) $fn=36; difference(){ translate([-12.5,-12.5,0])cube(25); chamfercyl(3,25,3,3,[[-2,0],[2,0]]); }

The module

Here some more simple examples to show the basic working of the module

translate([-60,0,0])chamfercyl(10,50,0,12); translate([-30,0,0])chamfercyl(10,50,-3,-6); translate([0,0,0])chamfercyl(10,50,7,-3); translate([30,0,0])chamfercyl(10,50,-9,2); translate([60,0,0])chamfercyl(10,50,4,4);gives the following cylinders:

Re: Rounding the edge of a hole? September 26, 2019 12:34PM |
AdminRegistered: 13 years ago Posts: 6,982 |

Re: Rounding the edge of a hole? September 26, 2019 12:53PM |
Registered: 9 years ago Posts: 590 |

Re: Rounding the edge of a hole? September 26, 2019 02:58PM |
Registered: 9 years ago Posts: 978 |

QuoteDavid J

Right - I tried using minkowski... life is too short... and all of my dimensions were screwed up (as expected); it would be a PITA to make size adjustments to compensate. So, good idea, but too painful.

Right... I'd forgotten that Minkowski with a sphere moves the surface by the radius of the sphere. For sphere of radius 1, you need to subtract 1 from each of your width and height variables.

Re: Rounding the edge of a hole? September 26, 2019 03:43PM |
Registered: 9 years ago Posts: 893 |

Quotefrankvdh

QuoteDavid J

Right - I tried using minkowski... life is too short... and all of my dimensions were screwed up (as expected); it would be a PITA to make size adjustments to compensate. So, good idea, but too painful.

Right... I'd forgotten that Minkowski with a sphere moves the surface by the radius of the sphere. For sphere of radius 1, you need to subtract 1 from each of your width and height variables.

Correct - and it's not a significant problem if you're dealing with the external measurements of a solid. However, both sides of the holes are also reduced by the radius of the sphere - the calculations just get too complicated. But really the compilation time is the major issue when you have more than 1 hole in the object.

Re: Rounding the edge of a hole? September 26, 2019 03:48PM |
Registered: 9 years ago Posts: 893 |

Wow, that's tough to read!

Clever though... I think. I'll have to get studying.

Edited 2 time(s). Last edit at 09/26/2019 04:03PM by David J.

Clever though... I think. I'll have to get studying.

Quoteenif

Interesting problem...

Here my approach, which is a bit different. Instead of subtracting cylinders to get the chamfer, I construct the cylinder in slices:

-- snip for brevity ---

Edited 2 time(s). Last edit at 09/26/2019 04:03PM by David J.

Re: Rounding the edge of a hole? September 29, 2019 04:06AM |
Registered: 9 years ago Posts: 893 |

Well, enif's code works very nicely - here's what I did with it:

Desk cable organiser

Enif - have a look at what I did with your code, and let me know if you're happy with what I've done. Also, if you want a more detailed credit in the code and on Thingiverse then please PM me with your details.

Many thanks to all,

David

Desk cable organiser

Enif - have a look at what I did with your code, and let me know if you're happy with what I've done. Also, if you want a more detailed credit in the code and on Thingiverse then please PM me with your details.

Many thanks to all,

David

Re: Rounding the edge of a hole? September 29, 2019 06:28AM |
Registered: 9 years ago Posts: 590 |

Re: Rounding the edge of a hole? September 29, 2019 08:13AM |
Registered: 9 years ago Posts: 893 |

Re: Rounding the edge of a hole? February 03, 2020 11:45PM |
Registered: 10 years ago Posts: 39 |

Here's a filleted cylinder tool like enif's, but should run faster:

As an easter egg, if you also pass in $fn=4, you'll get a filletted square prism.

module fillet_cylinder( r, // cylinder radius h, // cylinder height b=0, // bottom chamfer radius (=0 none, >0 outside, <0 inside) t=0, // top chamfer radius (=0 none, >0 outside, <0 inside, deg=10 // degrees per rib of fillet ) rotate_extrude() polygon(concat([[0,h],[0,0]], [for(a=[0:deg:90]) [r-b*(sin(a)-1), abs(b)*(1-cos(a))]], //bottom fillet [for(a=[90:-deg:0]) [r-t*(sin(a)-1), h-abs(t)*(1-cos(a))]])); //top fillet

As an easter egg, if you also pass in $fn=4, you'll get a filletted square prism.

Re: Rounding the edge of a hole? November 11, 2020 06:35AM |
Registered: 3 years ago Posts: 1 |

Re: Rounding the edge of a hole? April 28, 2022 03:41AM |
Registered: 1 year ago Posts: 2 |

Looks like a nice solution to a serious headache problem in openscad, until I tried creating a pin from a filleted cylinder with rounded tip and flared base. Then in a "for" loop to create a sideways elongated tab from it, to be used in a difference from a cube. This is a very standard locating pin style as used in injection molding machines.

I had to force a quit on openscad after maybe 30 minutes of doing nothing and then it started to affect the rest of the computer.

I take your word for it that it is faster then minkowski (which I avoid like the plague for being too slow to be useful) but IMHO this is still not useful either. My code was only 17 lines long! (which I had not saved before the crash)

I might try something else later, for which I got the idea looking at your solution. Split the pin I try to make in 3 parts, base, center and tip.

base is a large cylinder with a torus taken off it so it creates the bottom flare. center is just a cylinder, top is just a sphere.

Now translate to the length of the tab I need to make, and hull each of the three parts separately. Then put them in a module and use them to difference out from a cube.....need to try this to see if it will be just as slow.

So I still love Openscad to bits, but until something works better then these solutions my designs will resemble an mine-craft landscape, mostly anyway. Thanks to chamfer.scad though, just takes the sharp edges off this problem a little ;-)

I had to force a quit on openscad after maybe 30 minutes of doing nothing and then it started to affect the rest of the computer.

I take your word for it that it is faster then minkowski (which I avoid like the plague for being too slow to be useful) but IMHO this is still not useful either. My code was only 17 lines long! (which I had not saved before the crash)

I might try something else later, for which I got the idea looking at your solution. Split the pin I try to make in 3 parts, base, center and tip.

base is a large cylinder with a torus taken off it so it creates the bottom flare. center is just a cylinder, top is just a sphere.

Now translate to the length of the tab I need to make, and hull each of the three parts separately. Then put them in a module and use them to difference out from a cube.....need to try this to see if it will be just as slow.

So I still love Openscad to bits, but until something works better then these solutions my designs will resemble an mine-craft landscape, mostly anyway. Thanks to chamfer.scad though, just takes the sharp edges off this problem a little ;-)

Re: Rounding the edge of a hole? April 28, 2022 04:55AM |
Registered: 1 year ago Posts: 2 |

As mentioned earlier, I said I would have to try my suggestion. Still not fast but I feel way faster then minkowsky on any day.

Just a pig to rewrite all these modules in subroutines to be applied in different parts of the design, and again, if you have many it will be slow, but probably faster then minkowsky. Where the previous solution crashed on my pc, this reviewed in about 1 minute.

$fn=64;

based=40;

baseh=10;

bodyd=20;

bodyh=10;

trans=50;

//calling parts

for(a=[0:1:trans])

translate([a,0,0])pin_base();

hull(){

pin_body();

translate([trans,0,0])pin_body();

}

hull(){

pin_top();

translate([trans,0,0])pin_top();

}

//base

module torus_cut(){

rotate_extrude(angle=360) translate([based/2, 0, 0])circle(baseh);

}

module pin_base(){

difference(){

cylinder(h=baseh,d=based,center=true);

translate([0,0,baseh/2])torus_cut();

}

}

//body

module pin_body(){

translate([0,0,baseh/2+bodyh/2])cylinder(h=baseh,d=bodyd,center=true);

}

//top

module pin_top(){

translate([0,0,baseh/2+bodyh])sphere(d=bodyd);

}

Just a pig to rewrite all these modules in subroutines to be applied in different parts of the design, and again, if you have many it will be slow, but probably faster then minkowsky. Where the previous solution crashed on my pc, this reviewed in about 1 minute.

$fn=64;

based=40;

baseh=10;

bodyd=20;

bodyh=10;

trans=50;

//calling parts

for(a=[0:1:trans])

translate([a,0,0])pin_base();

hull(){

pin_body();

translate([trans,0,0])pin_body();

}

hull(){

pin_top();

translate([trans,0,0])pin_top();

}

//base

module torus_cut(){

rotate_extrude(angle=360) translate([based/2, 0, 0])circle(baseh);

}

module pin_base(){

difference(){

cylinder(h=baseh,d=based,center=true);

translate([0,0,baseh/2])torus_cut();

}

}

//body

module pin_body(){

translate([0,0,baseh/2+bodyh/2])cylinder(h=baseh,d=bodyd,center=true);

}

//top

module pin_top(){

translate([0,0,baseh/2+bodyh])sphere(d=bodyd);

}

Re: Rounding the edge of a hole? April 08, 2023 09:40PM |
Registered: 10 months ago Posts: 26 |

Another approach is to use Torleif Ceder's very handy unionRound() module, available on his github page.

It allows you to join any two arbitrary objects with a radius fillet.

In this case I join two cylinders using unionRound() and then subtract this from a cube. Easy to extend for the oval'ed slot case.

module unionRound(r, detail = 8) {

epsilon = 1e-6;

children(0);

children(1);

step = 90 / detail;

for (i = [0: detail-1]) {

{

x = r - sin(i * step ) * r;

y = r - cos(i * step ) * r;

xi = r - sin((i * step + step) ) * r;

yi = r - cos((i * step + step) ) * r;

color(rands(0, 1, 3, i))

hull() {

intersection() {

// shell(epsilon)

clad(x) children(0);

// shell(epsilon)

clad(y) children(1);

}

intersection() {

// shell(epsilon)

clad(xi) children(0);

// shell(epsilon)

clad(yi) children(1);

}

}

}

}

}

// unionRound helper expand by r

module clad(r) {

minkowski() {

children();

// icosphere(r,2);

isosphere(r,70);

}

}

// unionRound helper

module shell(r) {

difference() {

clad(r) children();

children();

}

}

/*

// The following is a sphere with some equidistant properties.

// Not strictly necessary

Kogan, Jonathan (2017) "A New Computationally Efficient Method for Spacing n Points on a Sphere," Rose-Hulman Undergraduate Mathematics Journal: Vol. 18 : Iss. 2 , Article 5.

Available at: [scholar.rose-hulman.edu] */

function sphericalcoordinate(x,y)= [cos(x )*cos(y ), sin(x )*cos(y ), sin(y )];

function Nn,x)=

let(toDeg=57.2958,PI=acos(-1)/toDeg,

start=(-1.+1./(n-1.)),increment=(2.-2./(n-1.))/(n-1.) )

[ for (j= [0:n-1])let (s=start+j*increment )

sphericalcoordinate( s*x*toDeg, PI/2.* sign(s)*(1.-sqrt(1.-abs(s)))*toDeg)];

function generatepoints(n)= Nn,0.1+1.2*n);

module isosphere(r,detail){

a= generatepoints(detail);

scale(r)hull()polyhedron(a,[[for(i=[0:len(a)-1])i]]);

}

$fn=60;

difference()

{

cube([20,20,10],center=true);

unionRound(4, detail = 10)

{

translate([0,0,10])

cylinder(h=10,d=20,center=true);

cylinder(h=20,d=5,center=true);

}

}

It allows you to join any two arbitrary objects with a radius fillet.

In this case I join two cylinders using unionRound() and then subtract this from a cube. Easy to extend for the oval'ed slot case.

module unionRound(r, detail = 8) {

epsilon = 1e-6;

children(0);

children(1);

step = 90 / detail;

for (i = [0: detail-1]) {

{

x = r - sin(i * step ) * r;

y = r - cos(i * step ) * r;

xi = r - sin((i * step + step) ) * r;

yi = r - cos((i * step + step) ) * r;

color(rands(0, 1, 3, i))

hull() {

intersection() {

// shell(epsilon)

clad(x) children(0);

// shell(epsilon)

clad(y) children(1);

}

intersection() {

// shell(epsilon)

clad(xi) children(0);

// shell(epsilon)

clad(yi) children(1);

}

}

}

}

}

// unionRound helper expand by r

module clad(r) {

minkowski() {

children();

// icosphere(r,2);

isosphere(r,70);

}

}

// unionRound helper

module shell(r) {

difference() {

clad(r) children();

children();

}

}

/*

// The following is a sphere with some equidistant properties.

// Not strictly necessary

Kogan, Jonathan (2017) "A New Computationally Efficient Method for Spacing n Points on a Sphere," Rose-Hulman Undergraduate Mathematics Journal: Vol. 18 : Iss. 2 , Article 5.

Available at: [scholar.rose-hulman.edu] */

function sphericalcoordinate(x,y)= [cos(x )*cos(y ), sin(x )*cos(y ), sin(y )];

function Nn,x)=

let(toDeg=57.2958,PI=acos(-1)/toDeg,

start=(-1.+1./(n-1.)),increment=(2.-2./(n-1.))/(n-1.) )

[ for (j= [0:n-1])let (s=start+j*increment )

sphericalcoordinate( s*x*toDeg, PI/2.* sign(s)*(1.-sqrt(1.-abs(s)))*toDeg)];

function generatepoints(n)= Nn,0.1+1.2*n);

module isosphere(r,detail){

a= generatepoints(detail);

scale(r)hull()polyhedron(a,[[for(i=[0:len(a)-1])i]]);

}

$fn=60;

difference()

{

cube([20,20,10],center=true);

unionRound(4, detail = 10)

{

translate([0,0,10])

cylinder(h=10,d=20,center=true);

cylinder(h=20,d=5,center=true);

}

}

Sorry, only registered users may post in this forum.