$fn = 150; number_of_pens = 8; pen_radius = 8; pen_length = 115; side_height = 40; circle_spacing = 3; wall_offset_y = 13; wall_offset_x = 10; circle_offset_y = 0; height = (number_of_pens*pen_radius*2)+(number_of_pens+1)*circle_spacing; width = (2*pen_radius); width_circle_spacing = 1; d = wall_offset_y - 3; p = 5; k = height/2; h = (d^2 - (height/2 - p)^2)/(2*d); R = sqrt(pow(h,2)+pow((height/2)-p,2)); echo(R); echo(h); difference(){ group(){ linear_extrude(height) group(){ difference() { translate([-12,0]) square([12,10]); rotate([0,0,-45]) translate([-16,-11]) square([20,10]); } translate([0,4]) square([3,1]); translate([0,10]) square([3,1]); translate([3,10]) square([1,3]); translate([3,2]) square([1,3]); translate([-pen_length-wall_offset_x,10]) square([pen_length+wall_offset_x,3]); //inner wall translate([-pen_length-wall_offset_x,0]) square([3,wall_offset_y+width+3+width_circle_spacing*2]); //bottom translate([-pen_length-wall_offset_x,wall_offset_y+width+width_circle_spacing*2]) square([pen_length+3,3]); //outer wall translate([-wall_offset_x,12]) square([3,width+3+width_circle_spacing*2]); }; translate([-pen_length+3-wall_offset_x,13,0]) cube([side_height,width+width_circle_spacing*2,3]); translate([-pen_length+3-wall_offset_x,13,height-circle_spacing]) cube([side_height,width+width_circle_spacing*2,3]); } for(i = [1:1:number_of_pens]) { position = pen_radius+circle_spacing+((i-1)*circle_spacing)+((i-1)*pen_radius*2); translate([-5-wall_offset_x, +wall_offset_y+width_circle_spacing+circle_offset_y+pen_radius, position]) rotate([0,90,0]) cylinder(10, pen_radius, pen_radius); } translate([-pen_length-wall_offset_x,h,height/2]) rotate([0,90,0]) cylinder(h = 10, r = R); }