use <threads.scad>

$fn=90;

Delta = 0.01;
Inch = 25.4;
Gesamt_Hoehe = 15;
Kompressor_Nippel = 8;

//intersection() {
  difference() {
    union(){
    
      // Deckel mit Innengewinde
      difference() {
        union() {
          cylinder(d=32, h=Gesamt_Hoehe-1, $fn=90);
          translate([0,0,Gesamt_Hoehe-1]) hull() {
            rotate_extrude() translate([30/2,0]) circle(d=2);
          }
        }
        // Metric Thread 25.75x1
        translate([0,0,-Delta]) 
          metric_thread (diameter=25.75, pitch=1, length=Gesamt_Hoehe-4+2*Delta, internal=true, test=false);
        translate([0,0,Gesamt_Hoehe-4]) 
          cylinder(d=26, h=1);
      }
      
      /*
        Ansatz für Kompressor - Schrader valve: 
        External 8V1 thread: 0.305 in (7.747 mm) x 32 TPI[3] (1⁄32 in or 0.7938 mm pitch) (Tap size: 8v1-32)
        https://en.wikipedia.org/wiki/Schrader_valve
      */
      translate([0,0,Gesamt_Hoehe]) 
        english_thread (diameter=0.305, threads_per_inch=32, length=Kompressor_Nippel/Inch, leadin=1);
      
      // for (i=[0:0.5:8]) translate([0,0,i]) hull() rotate_extrude() translate([(7.747-0.8)/2,0]) circle(d=1);
      // "Rändelung" für mehr Grip
      translate([0,0,7]) for (i=[0:40:360]) rotate([0,0,i]) translate([31/2,0,0]) hull() {
        sphere(d=3, $fn=45);
        translate([0,0,6]) sphere(d=3, $fn=45);
      }
      
      // Ansatz ganz oben wegen Aufbauplatte/Harz/Bottom-Layer
      translate([0,0,Gesamt_Hoehe+Kompressor_Nippel]) cylinder(d1=7, d2=6.5, h=0.5);
    }
    // Innenbohrung
    cylinder(d=3, h=50, $fn=60, center=true);
  }
//  translate([0,50,0]) cube(100, center=true);
//}

// Test, ob das Gewinde passt
*difference() {
  cylinder(d=30, h=4);
  // Metric Thread 25.75x1
  translate([0,0,-Delta]) metric_thread (diameter=25.75, pitch=1, length=6, groove=true);
}
