[OpenSCAD] Curved groove gets wrong depth

Bananapeel lunatica.xiaoyu at gmail.com
Wed Oct 5 05:16:42 EDT 2016


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.




More information about the Discuss mailing list