$fn = $preview? 32 : 72;

module stepper_103H5205(){
  body_length = 33;
  body_width = 42;
  shaft_length = 24;
  shaft_diameter = 5;
  flange_thickness = 1.5;
  flange_diameter = 22;
  hole_seperation = 31;
  hole_bore = 3;
  hole_depth = 4;
  corner_radius = 5;
  connector_height = 7;
  connector_width = 27;
  connector_depth = 11;
  connector_offset = 20;

  // body;
  color("dimgray")
  difference(){
  rotate([180,0,0])
    body(length=body_length, width=body_width, corner_radius = corner_radius);
    // remove screws
    rotate([180,0,0]) translate([0,0,-1]) four_cylinder(hole_seperation/2,hole_depth+1,hole_bore/2);
  }
  // flange
  color("silver") translate([0,0,-1]) cylinder(h=flange_thickness+1,d=flange_diameter);
  // shaft
  color("lightcyan")cylinder(h=shaft_length,d=shaft_diameter);
  color("snow")translate([body_width/2-1,-connector_width/2,-connector_offset-connector_depth]) cube([connector_height+1,connector_width,connector_depth]);
}

module body(length, width, corner_radius){
  distance = (width/2-corner_radius);
  hull(){
    four_cylinder(distance,length,corner_radius);
  }
}

module four_cylinder(distance,height,radius){
  for (i = [0:3]){
    rotate([0,0,90*i]) translate([distance,distance,0]) cylinder(h=height,r=radius);
  }
}

rotate([0,0,90]) stepper_103H5205();
translate([0,0,0.2]) stepper_103H5205_bracket();

module stepper_103H5205_mount() {
  body_width = 43;
  flange_diameter = 22;
  hole_seperation = 31;
  hole_bore = 4;
  hole_depth = 4;
  corner_radius = 5;
  bracket_thickness = 4;

  difference(){
  hull(){
    body(length=bracket_thickness, width=body_width, corner_radius = corner_radius);
    }
    translate([0,0,-0.5]) four_cylinder(hole_seperation/2,bracket_thickness+1,hole_bore/2);
    translate([0,0,-0.5]) cylinder(h=bracket_thickness+1,d=flange_diameter+1);
  }
}

module stepper_103H5205_bracket() {
  body_width = 43;
  flange_diameter = 22;
  hole_seperation = 31;
  hole_bore = 4;
  hole_depth = 4;
  corner_radius = 5;
  bracket_thickness = 4;

  difference(){
  hull(){
    body(length=bracket_thickness, width=body_width, corner_radius = corner_radius);
    translate([body_width/2-5,0,bracket_thickness/2])
    cube([10,body_width,bracket_thickness],center=true);
    }
    translate([0,0,-0.5]) four_cylinder(hole_seperation/2,bracket_thickness+1,hole_bore/2);
    translate([0,0,-0.5]) cylinder(h=bracket_thickness+1,d=flange_diameter+1);
  }
  mount_side(body_width, bracket_thickness);
  mirror([0,1,0])
  mount_side(body_width, bracket_thickness);
  translate([body_width/2, -(body_width/2+bracket_thickness) ,-body_width*0.7+bracket_thickness])
  cube([bracket_thickness,bracket_thickness*2+body_width,body_width*0.7]);
}

module mount_side(body_width, bracket_thickness) {
  translate([body_width/2 - body_width *0.7, body_width/2, bracket_thickness- body_width *0.7])
  difference(){
  cube([body_width*0.7,bracket_thickness,body_width*0.7]);
  rotate([90,0,0])
  cylinder(h=bracket_thickness*2.5,r=body_width*0.7-bracket_thickness,center=true);
  }
}
    

  
    


