//parameters
d16 = 16.4; // nozzle outer diameter, plane xz
d13 = 13; // nozzle inner diameter, plane xz
d2 = 2; // filament tunnel diameter, plane xz
l275 = 26.7+.5; // nozzle holder hole width
d015 = 1.5; // nozzle holder screw hole diam. , plane xz
d3 = 3.3; // motor bolts holes, plane xy
d6 = 6.5; // countersink motor holes dia 6 for M3 bolt head, plane xy
d3cm = 3; // carriage mount holes, plane yz
d6cm = 6; // countersink carr. holes dia 6 for M3 bolt head, plane yz


// nozzle mount cavity
module nozzleHole(){
	union(){
	translate([0,0,-.75]) cylinder(r=d16/2, h=4, $fn=60);
	cylinder(r=d13/2, h=12, $fn=50);
	translate([0,0,13-5.75]) cylinder(r=d16/2, h=5.75, $fn=60);
	cylinder(r=d2/2, h=30, $fn=15);
	translate([-d16/2,0,-.75])cube([d16,15,4]);
	translate([-d13/2,0,0])cube([d13,15,12]);
	translate([-d16/2,0,13-5.75])cube([d16,15,5.75]);
	translate([-l275/2,0,1.5]) cube([l275,15,7.5]);
	translate([10,-5-2,5.25]) rotate([-90,0,0]) cylinder(r=d015/2, h=6, $fn=10);
	translate([-10,-5-2,5.25]) rotate([-90,0,0]) cylinder(r=d015/2, h=6, $fn=10);
	translate([-d16/2,0,2.5]) rotate([0,0,45]) translate([0,-5,0]) cube([3,5,6]);
	translate([d16/2,0,2.5]) rotate([0,0,-45]) translate([-3,-5,0]) cube([3,5,6]);
	}
}


difference(){
	union(){


		// basic L-body
		linear_extrude(height=60)
		polygon(points=[[0,-8.6],[6,-8.6],[12,0],[51,0],[51,9.7],[6,9.7],[6,54.5],[0,54.5],[0,-8.6]],paths=[[0,1,2,3,4,5,6,7,8]]);


		// front mass
		difference(){
			hull(){
				translate([47,17.1171,0]) cylinder(r=4, h=25, $fn=50);
				translate([30.4751,18,0]) cylinder(r=6, h=25, $fn=50);
				translate([5,8.7,0]) cube([51-5,1,25]);
				translate([5,8.7,0]) cube([1,24-8.7,25]);
			}
			translate([29,31,22.5]) cylinder(r=24/2, h=3, $fn=70);
		}


		// radius mass X L-body
		translate([5,23,0])
		difference(){
			cube([5,5,25]);
			translate([5,5,-1]) cylinder(r=4, h=27, $fn=40);
		}


		// upper brackett
		hull(){
			translate([16,41.5,0]) cylinder(r=3, h=6.8, $fn=40);
			translate([16,51.5,0]) cylinder(r=3, h=6.8, $fn=40);
			translate([5,38.5,0]) cube([1,16,6.8]);
		}


		// tooth
		translate([0,0,6]){
			difference(){
				difference(){
				translate([22,23,0]) cube([7.5,6,14.5]);
				translate([29.3481,31.1711,-1]) cylinder(r=5.15, h=16.5, $fn=40);
				translate([18.8993,31.5647,-1]) cylinder(r=6.5, h=16.5, $fn=40);
				}
			translate([21,23,0]) rotate([45,0,0]) translate([0,0,-5]) cube([10,10,5]);
			translate([21,23,14.5]) rotate([-30,0,0]) cube([10,10,5]);
			}
		}
	} //union


	// nozzle mount cavity
	translate([25,0,13.2]) rotate([-90,0,0]) nozzleHole();


	// motor holes
	translate([43.5,15.5,-1]){
		hull(){
		cylinder(r=d6/2+.1, h=4, $fn=20);
		translate([1.5,0,0])cylinder(r=d6/2+.1, h=4, $fn=20);
		}
		hull(){
		cylinder(r=d3/2+.1, h=30, $fn=20);
		translate([1.5,0,0]) cylinder(r=d3/2+.1, h=30, $fn=20);
		}
	}

	translate([12.5,15.5,-1]){
		hull(){
		cylinder(r=d6/2+.1, h=4, $fn=20);
		translate([1.5,0,0])cylinder(r=d6/2+.1, h=4, $fn=20);
		}
		hull(){
		cylinder(r=d3/2+.1, h=30, $fn=20);
		translate([1.5,0,0]) cylinder(r=d3/2+.1, h=30, $fn=20);
		}
	}

	translate([12.5,46.5,-1]){
		hull(){
		cylinder(r=d6/2+.1, h=4, $fn=20);
		translate([1.5,0,0])cylinder(r=d6/2+.1, h=4, $fn=20);
		}
		hull(){
		cylinder(r=d3/2+.1, h=30, $fn=20);
		translate([1.5,0,0]) cylinder(r=d3/2+.1, h=30, $fn=20);
		}
	}


	// ribs under motor
	translate([0,7,31]){
		translate([6,0,0]) cube([6.5,3,30]);
		translate([14.5,0,0]) cube([14,3,30]);
		translate([30.5,0,0]) cube([14,3,30]);
		translate([46.5,0,0]) cube([6,3,30]);
	}


	// chamfers
	translate([-1,54.5,25]) rotate([11,0,0]) cube([10,10,40]);
	translate([-1,0,0]) rotate([18.24,0,0]) translate([0,-10,0]) cube([20,10,30]);
	
	// X-carriage mount holes
	translate([7,14.7,28.5]) rotate([0,-90,0]){
		cylinder(r=d6cm/2, h=3, $fn=20);
		cylinder(r=d3cm/2, h=10, $fn=20);
	}
	
	translate([7,14.7,28.5+24]) rotate([0,-90,0]){
		cylinder(r=d6cm/2, h=3, $fn=20);
		cylinder(r=d3cm/2, h=10, $fn=20);
	}

	// holder mount holes
	translate([52,7,12.5]) rotate([0,-90,0])cylinder(r=2.5/2, h=7, $fn=20);
	translate([52,3.5,37]) rotate([0,-90,0])cylinder(r=2.5/2, h=7, $fn=20);
	translate([52,3.5,54]) rotate([0,-90,0])cylinder(r=2.5/2, h=7, $fn=20);

} //difference

//support
/* uncomment when needed
translate([43.5+.75,15.5,1.5]){
	cube([d6+.5,.7,3],center=true);
	translate([1,0,0]) cube([.7,d6-1,3],center=true);
	translate([-1,0,0]) cube([.7,d6-1,3],center=true);
}
	
translate([12.5+.75,15.5,1.5]){
	cube([d6+.5,.7,3],center=true);
	translate([1,0,0]) cube([.7,d6-1,3],center=true);
	translate([-1,0,0]) cube([.7,d6-1,3],center=true);
}

translate([12.5+.75,46.5,1.5]){
	cube([d6+.5,.7,3],center=true);
	translate([1,0,0]) cube([.7,d6-1,3],center=true);
	translate([-1,0,0]) cube([.7,d6-1,3],center=true);
}

translate([25+10.5,5.3,13.2/2]) cube([5,.7,13.2], center=true);
translate([25-10.5,5.3,13.2/2]) cube([5,.7,13.2], center=true);

translate([25-2.5,5.3,13]) cube([.7,4,26], center=true);
translate([25+2.5,5.3,13]) cube([.7,4,26], center=true);
translate([25,5.3,8.5]) cube([6,.7,17], center=true);
*/
