Posted by andy.wpg

Help with rounded edge December 09, 2016 05:22PM |
Registered: 5 years ago Posts: 20 |

I have created a couple of OpenSCAD designs for project boxes for

my electronics designs. One creates the back box (standoffs, openings,

lid screw posts, etc) based on a module call with some dimensions in

it.

The other creates the lid for the box, and there are modules for an LCD

window, button and LED holes, etc.

The lid is my problem. It designs a nice lid, except for the top edge.

I would like to round the top edge, but leave the rest square for mating to the

box surfaces. In other words, the outside edge would be a rounded corner

to the top surface. The rest of it is fine as it is in the code presented

below.

I have tried to use hull with spheres, but that didn't work. I'm using hull

now to create the rounded corners as you look at it from the top - those are

fine and match the back box.

Anyone got any idea how I can integrate the rounded edge into the code below?

I would really appreciate any help.

Thanks,

Andy

"I have noticed that even those who assert that everything is predestined and that

we can change nothing about it still look both ways before they cross the street"

-Stephen Hawking

my electronics designs. One creates the back box (standoffs, openings,

lid screw posts, etc) based on a module call with some dimensions in

it.

The other creates the lid for the box, and there are modules for an LCD

window, button and LED holes, etc.

The lid is my problem. It designs a nice lid, except for the top edge.

I would like to round the top edge, but leave the rest square for mating to the

box surfaces. In other words, the outside edge would be a rounded corner

to the top surface. The rest of it is fine as it is in the code presented

below.

I have tried to use hull with spheres, but that didn't work. I'm using hull

now to create the rounded corners as you look at it from the top - those are

fine and match the back box.

Anyone got any idea how I can integrate the rounded edge into the code below?

I would really appreciate any help.

Thanks,

Andy

/* Variable size back box lid. Use the same dimensions as the box you programmed earlier. You do not need to specify height as it will use wall thickness to determine it. Input format: lid(length,width,wall thickness,screw hole diameter); */ $fn=100; //# of facets in curves lid(100,90,3,3); module lid(xdim,ydim,wall,screw) { xdim1 = xdim + (wall*2) + ((screw + 6) * 2); //full box x dimension ydim1 = ydim + (wall*2) + ((screw + 6) * 2); //full box y dimension difference() //screw holes { union() //bottom and top halves of lid { translate([wall+0.2,wall+0.2,0]) roundedrect((xdim1 - (wall*2) - 0.4),(ydim1 - (wall*2) - 0.4),wall-0.2,(wall-1)); //inner lid translate([0,0,wall-0.3]) roundedrect(xdim1,ydim1,wall,(wall-1)); //outer lid } translate([(wall + 3 + (screw / 2)),(wall + 3 + (screw / 2)),0]) cylinder(wall,(screw/2),(screw/2)); //X0, Y0 hole translate([(wall + 3 + (screw / 2)),(wall + 3 + (screw / 2)),wall]) cylinder(wall,screw/2,(screw * 1.5)); //X0 Y0 hole flare translate([(wall + 3 + (screw / 2)),((wall*2) + ydim + screw + 9 + (screw/2)),0]) cylinder(wall,(screw/2),(screw/2)); //X0, Y+ hole translate([(wall + 3 + (screw / 2)),((wall*2) + ydim + screw + 9 + (screw/2)),wall]) cylinder(wall,screw/2,(screw * 1.5)); //X0 Y+ hole flare translate([(wall + xdim + screw + 9 + (screw/2) + 0.1),(wall + 3 + (screw / 2)),0]) cylinder(wall,(screw/2),(screw/2)); //X+, Y0 hole translate([(wall + xdim + screw + 9 + (screw/2) + 0.1),(wall + 3 + (screw / 2)),wall]) cylinder(wall,screw/2,(screw * 1.5)); //X+ Y0 hole flare translate([(wall + xdim + screw + 9 + (screw/2) + 0.1),((wall*2) + ydim + screw + 9 + (screw/2)),0]) cylinder(wall,(screw/2),(screw/2)); //X+, Y+ hole translate([(wall + xdim + screw + 9 + (screw/2) + 0.1),((wall*2) + ydim + screw + 9 + (screw/2)),wall]) cylinder(wall,screw/2,(screw * 1.5)); //X+ Y+ hole flare /* LCD is a module to create a hole for an LCD in the lid. Specify the width (X) and the height (y) and any offest from center required (X and Y). A negative offset takes you closer to zero on that axis. If no offest is required, use zero. Format: LCD(width,height,xoffset,yoffset,xdim1,ydim1,wall); */ lcd(41.5,13.5,-3,20,xdim1,ydim1,wall); /* LCDHoles is the mounting holes for the LCD (if necessary). Specify the X and Y dimensions between hole centers, the offsets used for the LCD window, and the hole diameter. Format: lcdholes(xdim,ydim,xoffset,yoffset,hole diameter,xdim1,ydim1,wall); */ //lcdholes(30.48,17.78,-3,20,3,xdim1,ydim1,wall); /* Holes is a module that creates a single hole, Specify x,y location and the diameter of the hole. Repeat the call as many times as you need. */ holes((xdim1 / 2),35,14,wall); //pushbutton hole holes(30,35,7,wall); //power switch } } module roundedrect(xdim2,ydim2,zdim2,rdim) { hull() { translate([rdim,rdim,0]) cylinder(zdim2,rdim,rdim); //left front translate([rdim,ydim2,0]) cylinder(zdim2,rdim,rdim); //left rear translate([xdim2-rdim,rdim,0]) cylinder(zdim2,rdim,rdim); //right front translate([xdim2-rdim,ydim2,0]) cylinder(zdim2,rdim,rdim); //left rear } } module lcd(xdim2,ydim2,xoffset,yoffset,xtot2,ytot2,wall2) { side = ((xtot2 - xdim2) / 2) + xoffset + wall2; up = ((ytot2 - ydim2) / 2) + yoffset + wall2; translate([side,up,0]) cube([xdim2,ydim2,(wall2 * 2) +1]); } module lcdholes(xdim3,ydim3,xoffset1,yoffset1,hole,xtot1,ytot1,wall1) { side1 = ((xtot1 - xdim3) / 2) + xoffset1; up1 = ((ytot1 - ydim3) / 2) + yoffset1; translate([side1,up1,0]) cylinder(wall1,hole / 2,hole / 2); //X0 Y0 hole translate([side1,up1,wall1]) cylinder(wall1,hole / 2,hole * 1.5); //X0 Y0 hole flare translate([side1,wall1 + up1 + ydim3,0]) cylinder(wall1,hole / 2,hole / 2); //X0 Y+ hole translate([side1,wall1 + up1 + ydim3,wall1]) cylinder(wall1,hole / 2,hole * 1.5); //X0 Y+ hole flare translate([(wall1 + side1 + xdim3),up1,0]) cylinder(wall1,hole / 2,hole / 2); //X+ Y0 hole translate([(wall1 + side1 + xdim3),up1,wall1]) cylinder(wall1,hole / 2,hole * 1.5); //X+ Y0 hole flare translate([(wall1 + side1 + xdim3),wall1 + up1 + ydim3,0]) cylinder(wall1,hole / 2,hole / 2); //X+ Y+ hole translate([(wall1 + side1 + xdim3),wall1 + up1 + ydim3,wall1]) cylinder(wall1,hole / 2,hole * 1.5); //X+ Y+ hole flare } module holes(x2,y2,d2,wall3) { translate([x2,y2,0]) cylinder((wall3 * 2) + 1,(d2 /2),(d2 /2)); }

"I have noticed that even those who assert that everything is predestined and that

we can change nothing about it still look both ways before they cross the street"

-Stephen Hawking

Re: Help with rounded edge December 09, 2016 10:32PM |
Registered: 5 years ago Posts: 775 |

I have used spheres to make the rounded edges with the height increased by the rounded amount, then I have just removed the top by a cube with the height just over the rounded amount to end up with a square edge and rounded sides.

This is some code that was provided to me by a forum member, hope it helps

Lid=true; //set to false if lid not required

screw=true; //set if screw lid

RelieveOverhang=0;

MLen=116; // Cavity length

MWid=60; // Cavity width

MHt=27; // Cavity height

MWall=3.1; // Main box wall thickness

MBase=3.1; // Main box base (front panel) thickness

MRad=MWall; // Radius of box edges

Tol=1; //tolerence

module RoundBox(Len,Wid,Ht,Rad,Wall,Base)

{

difference()

{

RoundCube(Len,Wid,Ht+Rad,Rad);

translate([-Len,-Wid,Ht])

#cube([2*Len,2*Wid,Rad+2]);

translate([0,0,Base])

RoundCube(Len-2*Wall,Wid-2*Wall,Ht+Rad+1,Rad-Wall);

translate([-500,-500,-.1])

cube([1000,1000,Rad]);

}

}

module RoundCube(Len,Wid,Ht,Rad)

{

translate([-Len/2,-Wid/2+Rad,Rad])

cube([Len,Wid-2*Rad,Ht-2*Rad]);

translate([-Len/2+Rad,-Wid/2,Rad])

cube([Len-2*Rad,Wid,Ht-2*Rad]);

hull()

{

translate([-(Len/2-Rad),-(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([-(Len/2-Rad),+(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),-(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),+(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([-(Len/2-Rad),-(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

translate([-(Len/2-Rad),+(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),-(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),+(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

}

}

module Lid(){

translate([0,10+MWid,0])RoundBox(MLen+2*MWall,MWid+2*MWall,MBase+2,MRad,MWall,MBase);

translate([0,10+MWid,4])RoundCube(MLen-Tol,MWid-Tol,MBase+2,0);

}

appjaws - Ormerod 1, core XYUV Duet wifi, duex5

firmware 1.21 Web Server 1.21 Web Interface 1.21

OpenSCAD version 2016.02.09 (git 9950e6a)

slic3r-1.38.5-prusa3d and/or Simplify3D 4.0.0

This is some code that was provided to me by a forum member, hope it helps

Lid=true; //set to false if lid not required

screw=true; //set if screw lid

RelieveOverhang=0;

MLen=116; // Cavity length

MWid=60; // Cavity width

MHt=27; // Cavity height

MWall=3.1; // Main box wall thickness

MBase=3.1; // Main box base (front panel) thickness

MRad=MWall; // Radius of box edges

Tol=1; //tolerence

module RoundBox(Len,Wid,Ht,Rad,Wall,Base)

{

difference()

{

RoundCube(Len,Wid,Ht+Rad,Rad);

translate([-Len,-Wid,Ht])

#cube([2*Len,2*Wid,Rad+2]);

translate([0,0,Base])

RoundCube(Len-2*Wall,Wid-2*Wall,Ht+Rad+1,Rad-Wall);

translate([-500,-500,-.1])

cube([1000,1000,Rad]);

}

}

module RoundCube(Len,Wid,Ht,Rad)

{

translate([-Len/2,-Wid/2+Rad,Rad])

cube([Len,Wid-2*Rad,Ht-2*Rad]);

translate([-Len/2+Rad,-Wid/2,Rad])

cube([Len-2*Rad,Wid,Ht-2*Rad]);

hull()

{

translate([-(Len/2-Rad),-(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([-(Len/2-Rad),+(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),-(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),+(Wid/2-Rad),Rad])

sphere(r=Rad);

translate([-(Len/2-Rad),-(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

translate([-(Len/2-Rad),+(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),-(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

translate([+(Len/2-Rad),+(Wid/2-Rad),Ht-Rad])

sphere(r=Rad);

}

}

module Lid(){

translate([0,10+MWid,0])RoundBox(MLen+2*MWall,MWid+2*MWall,MBase+2,MRad,MWall,MBase);

translate([0,10+MWid,4])RoundCube(MLen-Tol,MWid-Tol,MBase+2,0);

}

appjaws - Ormerod 1, core XYUV Duet wifi, duex5

firmware 1.21 Web Server 1.21 Web Interface 1.21

OpenSCAD version 2016.02.09 (git 9950e6a)

slic3r-1.38.5-prusa3d and/or Simplify3D 4.0.0

Re: Help with rounded edge December 10, 2016 01:41AM |
Registered: 8 years ago Posts: 850 |

I always round my stuf with the minkowski () routine

Only be aware that you need to do*that* first and rework the object later to prevent other faces to be rounded to.

So minkowski the flat cube with a small sphere, (After the merge, it will be bigger 1/2 of the diameter)

Scale down 1/2 of the diameter of the sphere

cut off (difference) a bigger cube of the side that should*not* be rounded

Add all other parts

Thomas

Edited 1 time(s). Last edit at 12/10/2016 01:42AM by Replace.

www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)

Only be aware that you need to do

So minkowski the flat cube with a small sphere, (After the merge, it will be bigger 1/2 of the diameter)

Scale down 1/2 of the diameter of the sphere

cut off (difference) a bigger cube of the side that should

Add all other parts

Thomas

Edited 1 time(s). Last edit at 12/10/2016 01:42AM by Replace.

www.3daybreaker.blogspot.com

Orca V4.4 rebuild to Ramps with Mk8 and E3D, as well as a Rostock Delta Mini and an OLO in backorder :-)

Re: Help with rounded edge December 10, 2016 04:01AM |
Registered: 4 years ago Posts: 556 |

Is this the kind of object you are looking for?

Edited 1 time(s). Last edit at 12/10/2016 04:06AM by enif.

// construct a rectangle with rounded corners but a flat bottom module FlatBottomRoundRect(length,width,height,radius){ // iterate over the 4 corners hull()for(sx=[-1,1])for(sy=[-1,1])scale([sx,sy,1]){ // lower cylindric part if(height>radius)translate([length/2-radius,width/2-radius,0]) cylinder(r=radius,h=height-radius); // upper spheric part intersection(){ // sphere translate([length/2-radius,width/2-radius,height-radius]) sphere(r=radius); // clip shere at bottom plane if(height<2*radius)translate([length/2-radius,width/2-radius,0]) cylinder(r=radius,h=height); } } }

Edited 1 time(s). Last edit at 12/10/2016 04:06AM by enif.

Re: Help with rounded edge December 10, 2016 02:16PM |
Registered: 4 years ago Posts: 904 |

QuoteReplace

So minkowski the flat cube with a small sphere, (After the merge, it will be bigger 1/2 of the diameter)

Scale down 1/2 of the diameter of the sphere

cut off (difference) a bigger cube of the side that shouldnotbe rounded

Add all other parts

If you do the Minkowski with a hemisphere, you won't need to fix up the bottom edges. The vertical edges will still be rounded though. e.g.

minkowski() { cube(50); difference() { sphere($fn=20, 10); translate([-10,-10,-20]) cube(20); } }

Re: Help with rounded edge December 10, 2016 04:30PM |
Registered: 5 years ago Posts: 20 |

Thanks guys! That helped a LOT! Now I have somewhere to start.

BTW, please don't laugh*too* hard at my programming! I'm self-taught and math and I aren't

really the best of friends......but I'm learning!

"I have noticed that even those who assert that everything is predestined and that

we can change nothing about it still look both ways before they cross the street"

-Stephen Hawking

BTW, please don't laugh

really the best of friends......but I'm learning!

"I have noticed that even those who assert that everything is predestined and that

we can change nothing about it still look both ways before they cross the street"

-Stephen Hawking

Sorry, only registered users may post in this forum.