///////////////////////////////////////////////////////////////////////////////////////////////////////////

//Configurable parameters


//Parameters for the base plate rows:
base_height = 7;            // Height of the chessboard (blue part without black/white tiles)
hole_diam = 2;              // Diameter of the holes of the hinges. 
                            // should be ok for 1.75mm filament if the printer is well calibrated. 
                            // Otherwise enlarge this value.

offset1 = 0.1;              // Offset between inner and outer part of hinges. 
offset2 = 0.5;              // Offset between male and female part of a hinge.
offset3 = 0.5;              // Offset between chess tiles when being folded up as pencil.
offset4 = 0.5;              // Offset between neighboring hinges. 

color_layer = 0.4;          // Thickness of extension of the rows at the tip which generate the typical sharpener look

tile_dist = 39;             // width of rows and columns of the chessboard, thus distance between tile positions
tile_height = 3;            // height of the tiles

magnet_diameter = 5;        // diameter of the cylindrical magnets
magnet_height = 3;          // height of the cylindrical magnets
magnet_offset = 0.25;       // height offset of the magnets
magnet_offset_diam = 0.25;  // diameter offset of the magnets
magnet_displacement = 1.0;  // how much inbounds is a magnet at the rows 1 and 8

hook_width=tile_dist*0.65;  // width of the hooks at the back of the tiles
hook_height=4;              // leight of the hooks at the back of the tiles
hook_thickness=1.2;         // thickness of the hooks at the back of the tiles
hook_offset=0.2;            // offset between hook and hook eye

mine_base_thickness = 8;    // Thickness of the base of the mine at the end of the tip

rubber1_height_factor = 1.8;     // height of the rubber (including part inside the metal) relatively to the radius of rhe pencil
rubber2_height_factor = 0.5;       // height of the metal part which holds the rubber relatively to the radius of rhe pencil
rubber_metal_base = 5;                  // wall thickness of the rubber box
rubber_offset=1;                        // offset between rubber and metal
rubber_lock_height=10;                  // position of the lock of the rubber box

neat_offset=0.15;           // offset between male pins at octagonal mount and female plugs at tip and metal 

pillar_offset=1;            // offset between octagonal mount plates and tiles when folded to a pillar
pillar_wall=4;              // thickness of the octagonally aligned mount plates


///////////////////////////////////////////////////////////////////////////////////////////////////////////

// Dependent global parameters and constants

//Level of detail for cylinders, cones and tori
$fn=120;
$fa=2;

// The base shape of the folded chessboard is an octagon. angle thus needs to be 180 / 8.
angle = 22.5; 

tan_angle=tan(angle);
sin_angle=sin(angle);
cos_angle=cos(angle);

tile_width = tile_dist-2*tan_angle*base_height/2 - offset3; // actual width of each tile
tile_scale = (tile_width-2*tan_angle*tile_height)/tile_width;

inner_radius = tile_dist/2/tan_angle;
outer_radius = tile_dist/2/sin(22.5);
outer2_radius = sqrt((inner_radius+base_height/2)*(inner_radius+base_height/2)+(tile_dist/2)*(tile_dist/2));

mine_radius = inner_radius*0.55;    // radius of the black mine at the end of the tip

tip_height=(outer_radius+base_height/2)*4;
tip_radius= mine_radius*3/4;        // radius of the shperical cap of the mine

rubber_metal_radius = outer2_radius;
rubber1_height = rubber1_height_factor*rubber_metal_radius;
rubber2_height = rubber2_height_factor*rubber_metal_radius;
rubber_radius = inner_radius+base_height/2;
rubber_wall = rubber_metal_radius-rubber_radius;
pillar_width=2*(inner_radius-base_height/2-tile_height) - pillar_offset;

mine_b = outer_radius+base_height/2;
mine_h = tip_height;
mine_r = tip_radius;
mine_a = sqrt(mine_h*mine_h+mine_b*mine_b);
mine_d = mine_r*mine_a/mine_b;
mine_d2 = mine_r*mine_h/mine_b;
mine_r2 = mine_d2*mine_b/mine_a;
mine_d3 = mine_d2*mine_h/mine_a;
mine_h2 = mine_h-mine_d3;
mine_h1 = mine_h-mine_d;
mine_baseheight = mine_h*mine_radius/mine_b;
mine_R = mine_b*sqrt((2*mine_a-2*mine_b)/(2*mine_a+2*mine_b));

