Wednesday, February 16, 2011

OpenSCAD Tip: Round 2 of 3 - Advanced Rounding

After starting with some basic rounding, it is time for advanced rounding. While there are other ways to accomplish the rounds and fillets shown in this tutorial, these techniques are useful in a variety of cases.

The basic idea is that a round can be produced with the integrated volume of a sphere whose center is moving along a path parallel to the edges and tangent to the the two surfaces. It sounds more complicated than it really is.

b = 10;
h = 10;
w = 4;

//Start with an extruded triangle
rotate(a=[90,-90,0])
linear_extrude(height = w, center = true, convexity = 10, twist = 0)
polygon(points=[[0,0],[h,0],[0,b]], paths=[[0,1,2]]);


Starting with an extruded triangle, the top edge can be rounded.



If you try using a cylinder like last time you will find that you need to figure out how high to move the cylinder.

This shows a cross sectional view where you can see where the round must be tangent to the hypotenuse of the triangle.

Next we setup our problem and assign letters to lengths we are interested in.

Now it's time for some trignometry!! Be glad it's not projective geometry.

So if we use 5.17157 for the Z translation of the cylinder the part may or may not be manifold, so it is best to let the computer do the math and use the formula.

pad = 0.1; // Padding to maintain manifold
b = 10;
h = 10;
w = 4;
r = 3; // Radius of round
smooth = 360; // Number of facets of rounding cylinder

z = h - r*h/b - r*pow(pow(h,2)+pow(b,2),0.5)/b;
// x3 = width of cutting block
x3 = r*h/pow(pow(h,2)+pow(b,2),0.5) + r;

translate([0,0,z])
difference() {
translate([-x3/2,0,(h-z)/2])
cube([x3+pad,w+2*pad,h-z],center=true);
translate([-r,0,0])
rotate(a=[0,90,90])
cylinder(w+4*pad,r,r,center=true,$fn=smooth);
}

This is the shape that needs to be removed from the original triangle.
pad = 0.1; // Padding to maintain manifold
b = 10;
h = 10;
w = 4;
r = 3; // Radius of round
smooth = 360; // Number of facets of rounding cylinder

z = h - r*h/b - r*pow(pow(h,2)+pow(b,2),0.5)/b;
x3 = r*h/pow(pow(h,2)+pow(b,2),0.5) + r;

difference() {
rotate(a=[90,-90,0])
linear_extrude(height = w, center = true, convexity = 10, twist = 0)
polygon(points=[[0,0],[h,0],[0,b]], paths=[[0,1,2]]);
translate([0,0,z])
difference() {
translate([-x3/2,0,(h-z)/2])
cube([x3+pad,w+2*pad,h-z],center=true);
translate([-r,0,0])
rotate(a=[0,90,90])
cylinder(w+4*pad,r,r,center=true,$fn=smooth);
}
}


The resulting edge is now properly rounded.

Now let's try something a little different where instead of rounding along a linear path we round along a circular path.

Start with a cup shape.

The inside fillet is then produced by the difference of two toroids.
difference() {
rotate_extrude(convexity=10, $fn = smooth)
translate([cr-ct-r+pad,ct-pad,0])
square(r+pad,r+pad);
rotate_extrude(convexity=10, $fn = smooth)
translate([cr-ct-r,ct+r,0])
circle(r=r,$fn=smooth);
}


This is then unioned with the original cup.

The bottom round is similar to the inner fillet.

This is the result when the bottom round is removed.

This diagram might provided a clearer idea of the process of producing rounded corners shown above.


Next time, in Round 3, we will consider rounding edges like the one shown here. All of the .scad files used can be found on thingiverse. All of our previous OpenSCAD tutorials can be found here.

6 comments:

Anelma said...

If any of this translates to general purpose library code, please add it to MCAD.

Kristen said...

When is Round 3 comin'?

I Heart Robotics said...

I'll try to get Round 3 finished tonight or tomorrow. For some reason, things have been busy here.

I Heart Robotics said...

Round 3 is almost done. Just a little longer.

Kristen said...

Round 3 is never coming : (

Anonymous said...

Round 3 please please please!