[OpenSCAD] Routine to make holes (for weight/material saving)

luckycharms openscad at shenkin.org
Wed Apr 11 08:31:22 EDT 2018


Hi all,

New openSCAD user here.  I'm building a little platform upon which to mount
sensors on a drone, so would like to carve out holes in the platform (a flat
cube) in order to save weight.  I'm wondering if there might be some
routines out there that would do this for me in a configurable way?  See
image and code below.

Any thoughts greatly appreciated!

Thanks,
Alex


<http://forum.openscad.org/file/t2222/2018-04-11_13_29_18-OpenSCAD_-_DLS_GPS_platform.png> 

code:

$fn = 30;


// from https://www.thingiverse.com/thing:9347
module roundedRect(size, radius)
{
	x = size[0];
	y = size[1];
	z = size[2];

	linear_extrude(height=z)
	hull()
	{
		// place 4 circles in the corners, with the given radius
		translate([(-x/2)+radius, (-y/2)+radius, 0])
		circle(r=radius);

		translate([(x/2)-radius, (-y/2)+radius, 0])
		circle(r=radius);

		translate([(-x/2) + radius, (y/2)-radius, 0])
		circle(r=radius);

		translate([(x/2)-radius, (y/2)-radius, 0])
		circle(r=radius);
	}

}

// from
https://github.com/dannystaple/OpenSCAD-Parts-Library/blob/master/prism.scad
//Draw a prism based on a right angled triangle
//l - length of prism
//w - width of triangle
//h - height of triangle
module prism(l, w, h) {
       polyhedron(points=[
               [0,0,h],           // 0    front top corner
               [0,0,0],[w,0,0],   // 1, 2 front left & right bottom corners
               [0,l,h],           // 3    back top corner
               [0,l,0],[w,l,0]    // 4, 5 back left & right bottom corners
       ], faces=[ // points for all faces must be ordered clockwise when
looking in
               [0,2,1],    // top face
               [3,4,5],    // base face
               [0,1,4,3],  // h face
               [1,2,5,4],  // w face
               [0,3,5,2],  // hypotenuse face
       ]);
}

*prism(10,5,5);

attach_thickness = 3;
attach_width = 15;
attach_length = 16;
attach_hole = 3.5/2;
hole_pos = [attach_width/2, 9, 0];
attach_tri_height = 1.5;
attach_sep = 2.8;
attach_base_border = 5;

base_thick = 3;

module attachment_leg(width, length, thick, hole_rad, tri_height, hole_pos){
	difference() {

	union(){
	cube([width, length - width/2, thick]);
	translate([width/2, length - width/2, 0]) cylinder(h = thick, r = width/2);
	// triangle at base of leg
	// adding 0.1 so they will extend into the base in the attachment_legs
module
	translate([0, (thick + attach_sep)/2, thick/2]) rotate([0,45,270])
		prism(width, (thick + attach_sep)/sqrt(2) + 0.1, (thick +
attach_sep)/sqrt(2) + 0.1); 
	}

	// screw hole
	translate(hole_pos) scale([1,1,2.5]) cylinder(h = thick, r = hole_rad,
center = true);

	}
}

*attachment_leg(attach_width, attach_length, attach_thickness, attach_hole,
attach_tri_height, hole_pos);


module attachment_legs(width, length, thick, hole_rad, tri_height,
hole_pos){
	attachment_leg(width, length, thick, hole_rad, tri_height, hole_pos);
	translate([0, 0, attach_thickness + attach_sep]) attachment_leg(width,
length, thick, hole_rad, tri_height, hole_pos);
	
	// base for legs
	legs_base_width = width + attach_base_border*2;
	legs_base_len = thick*2 + attach_sep*2 + attach_base_border*2;
	rotate([90,0,0]) translate([width/2 - legs_base_width/2, thick +
attach_sep/2 - legs_base_len/2])
		cube([legs_base_width, legs_base_len, base_thick]);
}


*attachment_legs(attach_width, attach_length, attach_thickness, attach_hole,
attach_tri_height, hole_pos);



module DLS_holes(thick) {
	dist = 40;
	rad = 2.5;
	
	cylinder(h = thick * 3, r = rad, center = true);
	translate([40, 0, 0]) cylinder(h = thick * 3, r = rad, center = true);
}

*DLS_holes(attach_thickness);


module baseplate(width, length, thick, radius) {
	difference() {
	translate([width/2, length/2, 0]) roundedRect([width,length,thick], 5);
	translate([(width - 40)/2, 6, 0]) DLS_holes(thick);
	}
}

baseplate(55, 120, 3, 5);
translate([(attach_thickness*2 + attach_sep)/2 + 55/2, 10, 0])
rotate([270,0,90])
attachment_legs(attach_width, attach_length, attach_thickness, attach_hole,
attach_tri_height, hole_pos);






--
Sent from: http://forum.openscad.org/



More information about the Discuss mailing list