// Link with ends for ball inserts
// (c) Vitaliy Filippov 2014, license: CC-BY-SA 4.0

$fn=50;
length=9; // 9 stud, like LEGO Black Link 9 (32293)

difference() {
  union() {
    ball_end_p();
    translate([-3, 0, 0]) cube(size=[6, (length-1)*8, 2.5]);
    translate([0, (length-1)*8, 0]) ball_end_p();
  }
  ball_end_n();
  translate([0, (length-1)*8, 0]) ball_end_n();
}

module ball_end() {
  difference() {
    ball_end_p();
    ball_end_n();
  }
}

module ball_end_p() {
  union() {
    translate([0, 0, 1.7+3.2+1-4]) difference() { sphere(r=4); translate([-5, -5, -6]) cube(size=[10,10,5]); }
    cylinder(r=4, h=2);
  }
}

module ball_end_n() {
  translate([0, 0, 1.7]) sphere(r=3.05);
  translate([0, 0, -0.1]) cylinder(r=2.9, h=2);
}
