discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Curved groove gets wrong depth

B
Bananapeel
Wed, Oct 5, 2016 9:16 AM

I'm trying to make a groove in a bend, but I can't get it to have an even
depth. It gets shallower in the middle. Any ideas?

Code:

$fn=100;

function first(list) = list[0];
function tail(list) = [for (i=[1:len(list)-1]) list[i]];
function snd(list) = list[1];

module bend_2d(thickness, inner_radius, angle=90 /* 1->180 */) {
inner_r = inner_radius;
outer_r = inner_r + thickness;

angle_real = abs(angle);
invert = angle < 0;
mirror_vec_y = invert ? 1 : 0;
translate_y = invert ? thickness : 0;

translate([0, translate_y, 0]) // negative bends
  mirror([0, mirror_vec_y, 0]) //

  translate([0, outer_r])
    difference() {
        circle(outer_r);
        
        circle(inner_r);
        
        rotate(angle_real-90)
          square(outer_r);
        
        translate([-outer_r, -outer_r])
            square([outer_r, outer_r*2]);
        
        if (angle_real < 90)
            square(outer_r);
    }

}

/*
Make bent sheet metal

The bend list contains bend points and angles
as [length, angle]. The length refers to the length
of unbent metal before the bend.

The last angle can be undef, in which case no bend is produced.

Draws a 2d profile that must be extruded.

*/
module sheet_metal_2d(thickness, inner_radius, bend_list) {
task = first(bend_list);
straight = first(task);
angle = snd(task);

if (len(bend_list) > 1) {
  outer_radius = inner_radius + thickness;
               /* distance of bend */    /* distance due to straight

part rotation */
angle_abs    = abs(angle);

  // parameters for positive angles (around outside radius)
  pos_bend_width  = cos(angle_abs+270)*outer_radius;
  pos_bend_height = sin(angle_abs+270)*outer_radius + outer_radius;

  // parameters for negative angles (around inside radius, mirrored)
  inv_bend_width  = cos(90-angle_abs)*inner_radius;
  inv_bend_height = sin(90-angle_abs)*inner_radius - inner_radius;
  
  invert = angle < 0;
  bend_width  = invert ? inv_bend_width  : pos_bend_width;
  bend_height = invert ? inv_bend_height : pos_bend_height;
  
  translate([bend_width, bend_height]) // to angle end
    translate([straight, 0]) // to straight end
      rotate(angle)
        sheet_metal_2d(thickness, inner_radius, tail(bend_list));

} // endif

square([straight, thickness]);
if (angle != undef) {
    translate([straight, 0])
      bend_2d(thickness, inner_radius, angle);
}

}

/*
//bend_2d(3, 7, 60);
//bend_2d(3, 10, -70);

*sheet_metal_2d(1, 10, [ [20, -120],  [30, 30] ]);
*linear_extrude(100)
sheet_metal_2d(5, 10, [ [40, 30],  [60, -90], [10, -90], [40, -30], [60]
]);
*/

case = [ [200, 90], [200,90], [200, undef] ];
d = 2;
case_groove = [  [200-d, 90], [200-d*2,90], [200-d, undef] ];

difference() {
linear_extrude(135)
sheet_metal_2d(3, 10, case);

translate([0, d, 5])
linear_extrude(2) sheet_metal_2d(3, 10, case_groove);
}

--
View this message in context: http://forum.openscad.org/Curved-groove-gets-wrong-depth-tp18537.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

I'm trying to make a groove in a bend, but I can't get it to have an even depth. It gets shallower in the middle. Any ideas? Code: $fn=100; function first(list) = list[0]; function tail(list) = [for (i=[1:len(list)-1]) list[i]]; function snd(list) = list[1]; module bend_2d(thickness, inner_radius, angle=90 /* 1->180 */) { inner_r = inner_radius; outer_r = inner_r + thickness; angle_real = abs(angle); invert = angle < 0; mirror_vec_y = invert ? 1 : 0; translate_y = invert ? thickness : 0; translate([0, translate_y, 0]) // negative bends mirror([0, mirror_vec_y, 0]) // translate([0, outer_r]) difference() { circle(outer_r); circle(inner_r); rotate(angle_real-90) square(outer_r); translate([-outer_r, -outer_r]) square([outer_r, outer_r*2]); if (angle_real < 90) square(outer_r); } } /* Make bent sheet metal The bend list contains bend points and angles as [length, angle]. The length refers to the length of unbent metal before the bend. The last angle can be undef, in which case no bend is produced. Draws a 2d profile that must be extruded. */ module sheet_metal_2d(thickness, inner_radius, bend_list) { task = first(bend_list); straight = first(task); angle = snd(task); if (len(bend_list) > 1) { outer_radius = inner_radius + thickness; /* distance of bend */ /* distance due to straight part rotation */ angle_abs = abs(angle); // parameters for positive angles (around outside radius) pos_bend_width = cos(angle_abs+270)*outer_radius; pos_bend_height = sin(angle_abs+270)*outer_radius + outer_radius; // parameters for negative angles (around inside radius, mirrored) inv_bend_width = cos(90-angle_abs)*inner_radius; inv_bend_height = sin(90-angle_abs)*inner_radius - inner_radius; invert = angle < 0; bend_width = invert ? inv_bend_width : pos_bend_width; bend_height = invert ? inv_bend_height : pos_bend_height; translate([bend_width, bend_height]) // to angle end translate([straight, 0]) // to straight end rotate(angle) sheet_metal_2d(thickness, inner_radius, tail(bend_list)); } // endif square([straight, thickness]); if (angle != undef) { translate([straight, 0]) bend_2d(thickness, inner_radius, angle); } } /* //bend_2d(3, 7, 60); //bend_2d(3, 10, -70); *sheet_metal_2d(1, 10, [ [20, -120], [30, 30] ]); *linear_extrude(100) sheet_metal_2d(5, 10, [ [40, 30], [60, -90], [10, -90], [40, -30], [60] ]); */ case = [ [200, 90], [200,90], [200, undef] ]; d = 2; case_groove = [ [200-d, 90], [200-d*2,90], [200-d, undef] ]; difference() { linear_extrude(135) sheet_metal_2d(3, 10, case); translate([0, d, 5]) linear_extrude(2) sheet_metal_2d(3, 10, case_groove); } -- View this message in context: http://forum.openscad.org/Curved-groove-gets-wrong-depth-tp18537.html Sent from the OpenSCAD mailing list archive at Nabble.com.
NH
nop head
Wed, Oct 5, 2016 9:53 AM

I think that instead of reducing the lengths of the groove you should just
reduce the bend radius by d instead.

I.e.

translate([0, d, 5])
linear_extrude(2) sheet_metal_2d(3, 10 - d, case);

You also need to set the convexity in the linear extrudes.

On 5 October 2016 at 10:16, Bananapeel lunatica.xiaoyu@gmail.com wrote:

I'm trying to make a groove in a bend, but I can't get it to have an even
depth. It gets shallower in the middle. Any ideas?

Code:

$fn=100;

function first(list) = list[0];
function tail(list) = [for (i=[1:len(list)-1]) list[i]];
function snd(list) = list[1];

module bend_2d(thickness, inner_radius, angle=90 /* 1->180 */) {
inner_r = inner_radius;
outer_r = inner_r + thickness;

 angle_real = abs(angle);
 invert = angle < 0;
 mirror_vec_y = invert ? 1 : 0;
 translate_y = invert ? thickness : 0;

 translate([0, translate_y, 0]) // negative bends
   mirror([0, mirror_vec_y, 0]) //

   translate([0, outer_r])
     difference() {
         circle(outer_r);

         circle(inner_r);

         rotate(angle_real-90)
           square(outer_r);

         translate([-outer_r, -outer_r])
             square([outer_r, outer_r*2]);

         if (angle_real < 90)
             square(outer_r);
     }

}

/*
Make bent sheet metal

 The bend list contains bend points and angles
 as [length, angle]. The length refers to the length
 of unbent metal before the bend.

 The last angle can be undef, in which case no bend is produced.

 Draws a 2d profile that must be extruded.

*/
module sheet_metal_2d(thickness, inner_radius, bend_list) {
task = first(bend_list);
straight = first(task);
angle = snd(task);

 if (len(bend_list) > 1) {
   outer_radius = inner_radius + thickness;
                /* distance of bend */    /* distance due to straight

part rotation */
angle_abs    = abs(angle);

   // parameters for positive angles (around outside radius)
   pos_bend_width  = cos(angle_abs+270)*outer_radius;
   pos_bend_height = sin(angle_abs+270)*outer_radius + outer_radius;

   // parameters for negative angles (around inside radius, mirrored)
   inv_bend_width  = cos(90-angle_abs)*inner_radius;
   inv_bend_height = sin(90-angle_abs)*inner_radius - inner_radius;

   invert = angle < 0;
   bend_width  = invert ? inv_bend_width  : pos_bend_width;
   bend_height = invert ? inv_bend_height : pos_bend_height;

   translate([bend_width, bend_height]) // to angle end
     translate([straight, 0]) // to straight end
       rotate(angle)
         sheet_metal_2d(thickness, inner_radius, tail(bend_list));

 } // endif

 square([straight, thickness]);
 if (angle != undef) {
     translate([straight, 0])
       bend_2d(thickness, inner_radius, angle);
 }

}

/*
//bend_2d(3, 7, 60);
//bend_2d(3, 10, -70);

*sheet_metal_2d(1, 10, [ [20, -120],  [30, 30] ]);
*linear_extrude(100)
sheet_metal_2d(5, 10, [ [40, 30],  [60, -90], [10, -90], [40, -30],
[60]
]);
*/

case = [ [200, 90], [200,90], [200, undef] ];
d = 2;
case_groove = [  [200-d, 90], [200-d*2,90], [200-d, undef] ];

difference() {
linear_extrude(135)
sheet_metal_2d(3, 10, case);

translate([0, d, 5])
linear_extrude(2) sheet_metal_2d(3, 10, case_groove);
}

--
View this message in context: http://forum.openscad.org/
Curved-groove-gets-wrong-depth-tp18537.html
Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I think that instead of reducing the lengths of the groove you should just reduce the bend radius by d instead. I.e. translate([0, d, 5]) linear_extrude(2) sheet_metal_2d(3, 10 - d, case); You also need to set the convexity in the linear extrudes. On 5 October 2016 at 10:16, Bananapeel <lunatica.xiaoyu@gmail.com> wrote: > I'm trying to make a groove in a bend, but I can't get it to have an even > depth. It gets shallower in the middle. Any ideas? > > Code: > > $fn=100; > > function first(list) = list[0]; > function tail(list) = [for (i=[1:len(list)-1]) list[i]]; > function snd(list) = list[1]; > > module bend_2d(thickness, inner_radius, angle=90 /* 1->180 */) { > inner_r = inner_radius; > outer_r = inner_r + thickness; > > angle_real = abs(angle); > invert = angle < 0; > mirror_vec_y = invert ? 1 : 0; > translate_y = invert ? thickness : 0; > > translate([0, translate_y, 0]) // negative bends > mirror([0, mirror_vec_y, 0]) // > > translate([0, outer_r]) > difference() { > circle(outer_r); > > circle(inner_r); > > rotate(angle_real-90) > square(outer_r); > > translate([-outer_r, -outer_r]) > square([outer_r, outer_r*2]); > > if (angle_real < 90) > square(outer_r); > } > } > > /* > Make bent sheet metal > > The bend list contains bend points and angles > as [length, angle]. The length refers to the length > of unbent metal before the bend. > > The last angle can be undef, in which case no bend is produced. > > Draws a 2d profile that must be extruded. > */ > module sheet_metal_2d(thickness, inner_radius, bend_list) { > task = first(bend_list); > straight = first(task); > angle = snd(task); > > if (len(bend_list) > 1) { > outer_radius = inner_radius + thickness; > /* distance of bend */ /* distance due to straight > part rotation */ > angle_abs = abs(angle); > > // parameters for positive angles (around outside radius) > pos_bend_width = cos(angle_abs+270)*outer_radius; > pos_bend_height = sin(angle_abs+270)*outer_radius + outer_radius; > > // parameters for negative angles (around inside radius, mirrored) > inv_bend_width = cos(90-angle_abs)*inner_radius; > inv_bend_height = sin(90-angle_abs)*inner_radius - inner_radius; > > invert = angle < 0; > bend_width = invert ? inv_bend_width : pos_bend_width; > bend_height = invert ? inv_bend_height : pos_bend_height; > > translate([bend_width, bend_height]) // to angle end > translate([straight, 0]) // to straight end > rotate(angle) > sheet_metal_2d(thickness, inner_radius, tail(bend_list)); > > } // endif > > square([straight, thickness]); > if (angle != undef) { > translate([straight, 0]) > bend_2d(thickness, inner_radius, angle); > } > > } > > /* > //bend_2d(3, 7, 60); > //bend_2d(3, 10, -70); > > *sheet_metal_2d(1, 10, [ [20, -120], [30, 30] ]); > *linear_extrude(100) > sheet_metal_2d(5, 10, [ [40, 30], [60, -90], [10, -90], [40, -30], > [60] > ]); > */ > > case = [ [200, 90], [200,90], [200, undef] ]; > d = 2; > case_groove = [ [200-d, 90], [200-d*2,90], [200-d, undef] ]; > > difference() { > linear_extrude(135) > sheet_metal_2d(3, 10, case); > > translate([0, d, 5]) > linear_extrude(2) sheet_metal_2d(3, 10, case_groove); > } > > > > > -- > View this message in context: http://forum.openscad.org/ > Curved-groove-gets-wrong-depth-tp18537.html > Sent from the OpenSCAD mailing list archive at Nabble.com. > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
arnholm@arnholm.org
Wed, Oct 5, 2016 10:56 AM

On 2016-10-05 11:16, Bananapeel wrote:

I'm trying to make a groove in a bend, but I can't get it to have an
even
depth. It gets shallower in the middle. Any ideas?

I did not study your code in all detail, it seemed complex to me.
Below you have another approach that creates something almost similar to
your code (the parameter values may be off). In this version the groove
depth is constant in the "bend".

$fn=100;

module rounded_square(width=10,height=10,radius=1)
{
hull() {
for(iy=[-1:2:1]) {
for(ix=[-1:2:1]) {

translate([ix*(width-radius),iy*(height-radius)])circle(radius);
}
}
}
}

module box(dx=10,dy=10,dz=10,th=1,inner_r=3)
{
linear_extrude(dz,convexity=10)
difference() {
rounded_square(dx+th,dy+th,inner_r+th);
rounded_square(dx,dy,inner_r);
}
}

width        = 200;
height        = width/2;
thickness    =  3;
inner_radius  = 10;
d            = 1.5;

difference()
{
box(dx=width,dy=height,dz=135,th=thickness,inner_r=inner_radius);

union() {
    translate([0,0,thickness])
    linear_extrude(thickness,convexity=10)
    rounded_square(width+d,height+d,radius=inner_radius+d);
    translate([-250,0,0])cube([500,500,500],center=true);
}

}

Carsten Arnholm

On 2016-10-05 11:16, Bananapeel wrote: > I'm trying to make a groove in a bend, but I can't get it to have an > even > depth. It gets shallower in the middle. Any ideas? I did not study your code in all detail, it seemed complex to me. Below you have another approach that creates something almost similar to your code (the parameter values may be off). In this version the groove depth is constant in the "bend". $fn=100; module rounded_square(width=10,height=10,radius=1) { hull() { for(iy=[-1:2:1]) { for(ix=[-1:2:1]) { translate([ix*(width-radius),iy*(height-radius)])circle(radius); } } } } module box(dx=10,dy=10,dz=10,th=1,inner_r=3) { linear_extrude(dz,convexity=10) difference() { rounded_square(dx+th,dy+th,inner_r+th); rounded_square(dx,dy,inner_r); } } width = 200; height = width/2; thickness = 3; inner_radius = 10; d = 1.5; difference() { box(dx=width,dy=height,dz=135,th=thickness,inner_r=inner_radius); union() { translate([0,0,thickness]) linear_extrude(thickness,convexity=10) rounded_square(width+d,height+d,radius=inner_radius+d); translate([-250,0,0])cube([500,500,500],center=true); } } Carsten Arnholm
B
Bananapeel
Wed, Oct 5, 2016 2:01 PM

Thanks, reducing the bend radius did the trick.

--
View this message in context: http://forum.openscad.org/Curved-groove-gets-wrong-depth-tp18537p18540.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thanks, reducing the bend radius did the trick. -- View this message in context: http://forum.openscad.org/Curved-groove-gets-wrong-depth-tp18537p18540.html Sent from the OpenSCAD mailing list archive at Nabble.com.