// Brilliant cut diamond (57 faces)
// Inspired by thing:50915 by takuya, but rewritten to be more correct
// (original script produces incorrect results with diameter != 20)
// (c) Vitaliy Filippov 2014, license: CC-BY-SA 4.0

// Diamond_size_d
dd=40;

// Diamond_height_ratio
hr=0.615;

// Cut angles.
// FIXME: Crown angles are in fact dependent - one of them isn't a true
// parameter (it's just matched by hand here) and should be calculated from the other two.
// cag4 should be calculated from cag3 and cag5 if trying to resemble real cutting process...

pag1=42.45; // Pavillion_angle1
pag2=40.75; // Pavillion_angle2
cag3=40.16; // Crown_angle3
cag4=34.5;  // Crown_angle4
cag5=24.6;  // Crown_angle5 [was 23.45 in original script?!]

dh=dd*hr; // Diamond height

difference() {

translate([0,0,-dd*0.431]) cylinder(h=dh,r=dd/2,$fn=48);

union() {
  for (i = [0 : 16-1]) {
    rotate([0,0,360/16*i])
      translate([dd/2,0,0])
      rotate([0,90-pag1,0])
      translate([0, -dd/4, -dd])
      cube(size=[dd/2,dd/2,1.1*dd], center=false);
  }
}
union() {
  for (i = [0 : 8-1]) {
    rotate([0,0,360/8*i+11.25])
      translate([dd/2 + /*compensation for elliptical cut*/dd/2*(1-cos(360/32))*tan(90-pag1),0,0])
      rotate([0,90-pag2,0])
      translate([0, -dd/4, -dd])
      cube(size=[dd/2,dd/2,1.1*dd], center=false);
  }
}
union() {
  for (i = [0 : 16-1]) {
    rotate([0,0,360/16*i])
      translate([dd/2,0,0])
      rotate([0,-90+cag3,0])
      translate([0, -dd/4, -0])
      cube(size=[dd/2,dd/2,dd], center=false);
  }
}
union() {
  for (i = [0 : 8-1]) {
    rotate([0,0,360/8*i+11.25])
      translate([dd/2,0,dd/2*(1-cos(360/32))*tan(cag3)])
      rotate([0,-90+cag4,0])
      translate([0, -dd/4, -dd/2])
      cube(size=[dd/2,dd/2,dd], center=false);
  }
}
union() {
  for (i = [0 : 8-1] ) {
    rotate([0,0,360/8*i-11.25])
      translate([cos(22.5)*(dd/2-((dh-dd*0.431)-(dd/2*(1-cos(360/32))*tan(cag3)))/tan(cag4)),0,dh-dd*0.431])
      rotate([0,-90+cag5,0])
      translate([0, -dd/4, -dd])
      cube(size=[dd/2,dd/2,dd], center=false);
  }
}

}
