OpenSCAD Modules

From Phormix Wiki
Jump to: navigation, search

These are various modules (functions) for OpenSCAD that can assist in modelling

 

Bevelled Rectangles

These formulas create rectangles which are bevelled along X/Z and extruded on the Y plane

For simplicity, it uses the following variables

  • w = width
  • d = depth
  • h = height (extrusion)
  • r = radius of bevel

Rectangle bevelled on all corners

module beveled_rect(w,d,h,r){
  union() {
  translate([r,r,h/2]) cylinder(r = r, h = h, center = true);
  translate([w-r,r,h/2]) cylinder(r = r, h = h, center = true);
  translate([r,0, 0]) cube([w-(r*2),r,h]);

  translate([r,d-r,h/2]) cylinder(r = r, h = h, center = true);
  translate([w-r,d-r,h/2]) cylinder(r = r, h = h, center = true);
  translate([r,d-r, 0]) cube([w-(r*2),r,h]);
    
  translate([0, r, 0]) cube([w,d-(r*2),h]);
  }
}

Rectangle bevelled on bottom only

module beveled_rect_bot(w,d,h,r){
  union() {
  translate([r,r,h/2]) cylinder(r = r, h = h, center = true);
  translate([w-r,r,h/2]) cylinder(r = r, h = h, center = true);
  translate([r,0, 0]) cube([w-(r*2),r,h]);
   
  translate([0, r, 0]) cube([w,d-r,h]);
  }
}

Rectangle bevelled on top only

module beveled_rect_top(w,d,h,r){
  union() {
  translate([r,d-r,h/2]) cylinder(r = r, h = h, center = true);
  translate([w-r,d-r,h/2]) cylinder(r = r, h = h, center = true);
  translate([r,d-r, 0]) cube([w-(r*2),r,h]);
   
  translate([0, 0, 0]) cube([w,d-r,h]);
  }
}

Rectangle bevelled on left only

module beveled_rect_left(w,d,h,r){
  union() {
  translate([r,r,h/2]) cylinder(r = r, h = h, center = true);
  translate([r,d-r,h/2]) cylinder(r = r, h = h, center = true);
  translate([0,r, 0]) cube([(r*2),d-(r*2),h]);
   
  translate([r, 0, 0]) cube([w-r,d,h]);
  }
}


Rectangle bevelled on right only

module beveled_rect_right(w,d,h,r){
  union() {
  translate([w-r,r,h/2]) cylinder(r = r, h = h, center = true);
  translate([w-r,d-r,h/2]) cylinder(r = r, h = h, center = true);
  translate([w-(r*2),r, 0]) cube([(r*2),d-(r*2),h]);
   
  translate([0, 0, 0]) cube([w-r,d,h]);
  }
}