// Parametric Bracket by Hasan YILDIZ
// Author: https://makerworld.com/en/@craftsman_live
// License: CC BY-NC-SA 4.0 Attribution-NonCommercial-ShareAlike 4.0 International
//https://https://creativecommons.org/licenses/by-nc-sa/4.0/


Hole_amount=2;
// Distance Between Holes (mm)
 hole_distance=16;//[16:25]
 

 
 module outher_radius() {
union(){
difference(){
cube([23,3,16]);

union(){
translate([11,3,8])
rotate([90,0,0])
cylinder(3,12,12,$fn=100); 
translate([-5,0,0])    
cube([12,3,25]);
translate([0,0,8]) 
cube([23,3,16]);
}}

translate([3,0,0])
rotate([0,0,90])
difference(){
cube([23,3,16]);
union(){
translate([11,3,8])
rotate([90,0,0])
cylinder(3,12,12,$fn=100); 
translate([-5,0,0])    
cube([12,3,25]);
translate([0,0,8]) 
cube([23,3,16]);
}}}}


module inner_chamfer() {
polyhedron(points=[[0,0,0],[15.3,0,0],[0,15.3,0],[15.3,0,0.5], [0,15.3,0.5],[0,0,15.3]],
faces=[[0,1,2],[0,3,1],[0,2,4],[1,3,4,2],[0,5,3],[0,4,5],[3,5,4]],convexity = 1);   
}


difference(){

cube([23,23,hole_distance*Hole_amount]);

union(){ //all extracted features

difference(){  //rounded chamfer
     
 linear_extrude(hole_distance*Hole_amount) {
 polygon([[0,0],[5,0],[0,5]]); }
 
 hull(){
 translate([3,5,-1])
 cylinder(hole_distance*Hole_amount+2,3,3,$fn=50);
 translate([5,3,-1])
 cylinder(hole_distance*Hole_amount+2,3,3,$fn=50);
 }}
 
 
 difference(){  //extraction cube
 
 translate([3,3,0])
 cube([20,20,hole_distance*Hole_amount]);
 
 inner_chamfer();
 translate([0,0,(hole_distance*Hole_amount)])
mirror([0,0,1])
 inner_chamfer();
     
     
 difference(){  //rounded chamfer
     
 linear_extrude(hole_distance*Hole_amount) {
 polygon([[3,3],[7,3],[3,7]]); }
 
 hull(){
 translate([5,7,-1])
 cylinder(hole_distance*Hole_amount+2,2,2,$fn=50);
 translate([7,5,-1])
 cylinder(hole_distance*Hole_amount+2,2,2,$fn=50);
 }}
 
 if(Hole_amount>1){
for(j=[1:Hole_amount-1]) {
translate([0,0,hole_distance*(j)])
union(){
inner_chamfer();
mirror([0,0,1])
inner_chamfer(); }}}
 }
 
 
 for(i=[1:Hole_amount]){ //holes with chamfer
 
 
    
    translate([15,3,(hole_distance/2)+((i-1)*hole_distance)])
    rotate([90,0,0])
    cylinder(3,r=2,$fn=50);
 
    translate([15,3,(hole_distance/2)+((i-1)*hole_distance)])
    rotate([90,0,0])
    cylinder(2,r1=4,r2=2, $fn=50);
        
    translate([0,15,(hole_distance/2)+((i-1)*hole_distance)])
    rotate([0,90,0])
    cylinder(3,r=2,$fn=50);
        
    translate([1,15,(hole_distance/2)+((i-1)*hole_distance)])
    rotate([0,90,0])
    cylinder(2,r1=2,r2=4, $fn=50);
}

outher_radius();

translate([0,0,(hole_distance*Hole_amount)])
mirror([0,0,1])
outher_radius();


}
}