/** A parameterized drain cover. Stan Seibert April 25, 2010 Consists of two parts: A flat plate with a grid of square holes and a hollow sleeve that fits inside the pipe to secure the cover. The grid of holes is automatically scaled to fit inside the inner diameter of the sleeve. You should set the sleeve outer diameter to be slightly less than the inner diameter of your drain pipe. Now you won't lose your toothpaste caps anymore! */ /**** Model parameters ****/ plate_diameter = 100; plate_thickness = 1.5; sleeve_outer_diameter = 77; sleeve_wall_thickness = 1.5; sleeve_depth = 15; square_hole_spacing = 3.0; square_hole_size = 4.0; /**** Begin construction here ****/ /* How large of a square grid of square holes is required to cover the inner diameter of the sleeve? Must allow for a square_hole_spacing on each side. We will cut off the diagonal squares that extend past the sleeve inner diameter later during construction. */ hole_stride = square_hole_size + square_hole_spacing; sleeve_inner_diameter = sleeve_outer_diameter - 2 * sleeve_wall_thickness; grid_size = floor( (sleeve_inner_diameter + square_hole_size/2 - square_hole_spacing) / hole_stride); grid_origin_offset = -( square_hole_size * grid_size + square_hole_spacing * (grid_size - 1) ) / 2; echo("Using a square ", grid_size, "by", grid_size, "grid to cover the drain pipe."); union() { /** Top plate **/ difference() { cylinder(h=plate_thickness, r=plate_diameter/2); /** Hole grid **/ intersection() { cylinder(h=plate_thickness+sleeve_depth, r=sleeve_inner_diameter/2-sleeve_wall_thickness); union() { for (i=[0:grid_size-1]) { for (j=[0:grid_size-1]) { assign(x = grid_origin_offset + i * hole_stride, y = grid_origin_offset + j * hole_stride) { translate(v=[x, y,-0.5]) { cube(size=[square_hole_size, square_hole_size, plate_thickness+1]); } } } } } } } /** Sleeve **/ difference() { cylinder(h=plate_thickness+sleeve_depth, r=sleeve_outer_diameter/2); /* cut out inner diameter */ translate(v=[0,0,-0.5]) { cylinder(h=plate_thickness+sleeve_depth+1, r=sleeve_outer_diameter/2 - sleeve_wall_thickness); } } }