aboutsummaryrefslogtreecommitdiff
path: root/lib/dice.scad
blob: d42d1ea443035e682f1d6349564cb9b1d13d17b3 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use <utils.scad>

module d4(size=false, side=false) {
    l = side ? side : s2s_d4(size);
    if (l == false) {
        echo("ERROR: d4: 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);
    }
}

module d8(size=false, side=false) {
    l = side ? side : s2s_d8(size);
    if (l == false) {
        echo("ERROR: d8: one of side or size should be defined");
    }
    r = sqrt(2)/2*l;
    c = r*2;
    i_r = sqrt(6)/6*l;
    difference() {
        intersection() {
            sphere(r*0.86, $fn=64);
            cube([c, c, i_r*2], center=true);
            intersection_for ( i = [0:2] ) {

                rotate([0, 0, 120*i]) rotate([acos(-1/3), 0, 0]) cube([c, c, i_r*2], center=true);
            }
        }
        translate([0, 0, i_r]) child(0);
        rotate([acos(-1/3), 0, 0]) translate([0, 0, i_r]) child(1);
        rotate([0, 0, 120]) rotate([acos(-1/3)+180, 0, 0]) translate([0, 0, i_r]) child(2);
        rotate([0, 0, -120]) rotate([acos(-1/3)+180, 0, 0]) translate([0, 0, i_r]) child(3);
        rotate([0, 0, -120]) rotate([acos(-1/3), 0, 0]) translate([0, 0, i_r]) child(4);
        rotate([0, 0, 120]) rotate([acos(-1/3), 0, 0]) translate([0, 0, i_r]) child(5);
        rotate([acos(-1/3)+180, 0, 0]) translate([0, 0, i_r]) child(6);
        rotate([180, 0, 0]) translate([0, 0, i_r]) child(0);
    }
}

module d12(size=false, side=false) {
    l = side ? side : s2s_d12(size);
    if (l == false) {
        echo("ERROR: d12: one of side or size should be defined");
    }
    r = l*sqrt(3)*(1+sqrt(5))/4;
    c = r*2;
    i_r = (l/2)*sqrt(5/2 + 11*sqrt(5)/10);
    difference() {
        intersection() {
            sphere(r*0.96, $fn=64);
            cube([c, c, i_r*2], center=true);
            intersection_for ( i = [0:4] ) {

                rotate([0, 0, 72*i]) rotate([acos(-1/sqrt(5)), 0, 0]) cube([c, c, i_r*2], center=true);
            }
        }
        translate([0, 0, i_r]) child(0);
        rotate([acos(-1/sqrt(5))+180, 0, 0]) translate([0, 0, i_r]) child(1);
        rotate([0, 0, 72]) rotate([acos(-1/sqrt(5))+180, 0, 0]) translate([0, 0, i_r]) child(3);
        rotate([0, 0, 144]) rotate([acos(-1/sqrt(5))+180, 0, 0]) translate([0, 0, i_r]) child(5);
        rotate([0, 0, 216]) rotate([acos(-1/sqrt(5))+180, 0, 0]) translate([0, 0, i_r]) child(4);
        rotate([0, 0, 288]) rotate([acos(-1/sqrt(5))+180, 0, 0]) translate([0, 0, i_r]) child(2);

        rotate([acos(-1/sqrt(5)), 0, 0]) translate([0, 0, i_r]) child(10);
        rotate([0, 0, 72]) rotate([acos(-1/sqrt(5)), 0, 0]) translate([0, 0, i_r]) child(8);
        rotate([0, 0, 144]) rotate([acos(-1/sqrt(5)), 0, 0]) translate([0, 0, i_r]) child(6);
        rotate([0, 0, 216]) rotate([acos(-1/sqrt(5)), 0, 0]) translate([0, 0, i_r]) child(7);
        rotate([0, 0, 288]) rotate([acos(-1/sqrt(5)), 0, 0]) translate([0, 0, i_r]) child(9);
        rotate([180, 0, 0]) translate([0, 0, i_r]) child(11);
    }
}