aboutsummaryrefslogtreecommitdiff
path: root/lib/dice.scad
blob: ed63d3f541e72af4cd996e3f38b86e6e1eb00d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use <utils.scad>

module d4(size=false, side=false) {
    l = side ? side : s2s_d4(size);
    if (l == false) {
        echo("ERROR: d6: one of side or size should be defined");
    }
    r = sqrt(6)/4*l;
    c = r*2;
    difference() {
        intersection() {
            sphere(r=r*0.79, $fn=64);
            translate([0, 0, r-r/3]) cube(c, center=true);
            intersection_for ( i = [0:2] ) {
                rotate([0, 0, 120*i]) rotate([acos(1/3)+180, 0, 0]) 
                    translate([0, 0, r-r/3]) cube(c, center=true);
            }
        }
        rotate([180, 0, 0]) translate([0, 0, r/3]) child(0);
        rotate([acos(1/3)+180, 0, 0]) rotate([180, 0, 0]) translate([0, 0, r/3]) child(1);
        rotate([0, 0, 120]) rotate([acos(1/3)+180, 0, 0]) rotate([180, 0, 0]) translate([0, 0, r/3]) child(2);
        rotate([0, 0, 240]) rotate([acos(1/3)+180, 0, 0]) rotate([180, 0, 0]) translate([0, 0, r/3]) child(3);
    }
}

module d6(size=false, side=false) {
    l = side ? side : s2s_d6(size);
    if (l == false) {
        echo("ERROR: d6: one of side or size should be defined");
    }
    difference() {
        intersection() {
            cube(l, center=true);
            sphere(l*0.79);
        }
        translate([0, 0, l/2]) child(0);
        rotate([90, 0, 0]) translate([0, 0, l/2]) child(1);
        rotate([0, 90, 0]) translate([0, 0, l/2]) child(2);
        rotate([-90, 0, 0]) translate([0, 0, l/2]) child(3);
        rotate([0, -90, 0]) translate([0, 0, l/2]) child(4);
        rotate([180, 0, 0]) translate([0, 0, l/2]) child(5);
    }
}