summaryrefslogtreecommitdiff
path: root/src/dactyl_cave/thumb.clj
blob: 0dfce976b773f4ab46a2ad8432e34aea296734cd (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
(ns dactyl-cave.thumb
  (:use [scad-clj.scad])
  (:use [scad-clj.model])
  (:use [unicode-math.core])
  (:require [dactyl-cave.key :as key])
  (:require [dactyl-cave.cave :as cave]))

(defn thumb-place [column row shape]
  (let [α (/ π 12)
        row-radius (+ (/ (/ key/pillar-depth 2)
                         (Math/sin (/ α 2)))
                      key/full-height)
        β (/ π 36)
        column-radius (+ (/ (/ (+ key/pillar-width 5) 2)
                            (Math/sin (/ β 2)))
                         key/full-height)]
    (->> shape
         (translate [0 0 (- row-radius)])
         (rotate (* α row) [1 0 0])
         (translate [0 0 row-radius])
         (translate [0 0 (- column-radius)])
         (rotate (* column β) [0 1 0])
         (translate [0 0 column-radius])
         (translate [key/pillar-width 0 0])
         (rotate (/ π 12) [0 1 0])
         (rotate (* π (- 1/4 1/16)) [0 0 1])
         (rotate (/ π 12) [1 1 0])
         (translate [254/45 127/15 1778/45]))))

(defn thumb-2x-column [shape]
  (thumb-place 0 -1/2 shape))

(defn thumb-2x+1-column [shape]
  (union (thumb-place 1 -1/2 shape)
         (thumb-place 1 1 shape)))

(defn thumb-1x-column [shape]
  (union (thumb-place 2 -1 shape)
         (thumb-place 2 0 shape)
         (thumb-place 2 1 shape)))

(defn thumb-layout [shape]
  (union
   (thumb-2x-column shape)
   (thumb-2x+1-column shape)
   (thumb-1x-column shape)))

(defn support [shape]
  (hull
   shape
   (extrude-linear {:height 127/45 :twist 0 :convexity 0}
                   (project (hull shape)))))

(defn thumb-support [shape]
  (let [column-supports
        (union
         (support (thumb-2x-column shape))
         (support (thumb-2x+1-column shape))
         (support (thumb-1x-column shape)))]
    (union column-supports
           (support column-supports))))
(fn [])
(def bottom
  (translate [0 0 -254/9] (cube 5080/9 5080/9 508/9)))

(def thumb-base
  (thumb-support (scale [1 1 1/10] key/full-pillar)))

#_(defn move-to-corner [shape]
  (translate [-6731/90 -5461/90 0] shape))

(defn move-to-corner [shape]
  (translate [(+ -6731/90 10) (- -5461/90 10) 0] shape))

(/ -6731 90.0) -74.78888888888889
(double -5461/90) -60.67777777777778

(def thumb-cluster
  (difference
   (translate [0 0 -254/45]
              (difference
               (union
                (thumb-layout key/pillar)
                thumb-base)
               (thumb-layout key/keyswitch-full-hole)))
   bottom))

(def connection-stems
  (difference
   (hull (union
          (->> (cylinder 127/90 508/9)
               (translate [-0 -2413/45 0]))
          (->> (cylinder 127/90 508/9)
               (translate [-127/3 -0 0]))
          (->> (cylinder 127/90 508/9)
               (translate [-2159/30 -127/5 0]))
          (->> (cylinder 127/90 508/9)
               (translate [-508/9 -381/5 0]))))
   bottom
   cave/main-sphere
   (translate [0 0 -254/45]
              (thumb-layout key/keyswitch-full-hole))))

(def wire-network
  (apply union
         (for [[column row] [[0 -1/2]
                             [1 -1/2]
                             [1 1]
                             [2 -1]
                             [2 0]
                             [2 1]]]
           (let [middle-hole (->> (thumb-place column row (cube 6 6 6))
                                  (translate [0 0 -127/9])
                                  move-to-corner)]
             #_(thumb-place column row (sphere 127/9))
             (union (hull (->> (cube 254/45 254/45 key/keyswitch-height)
                               (thumb-place column row)
                               move-to-corner)
                          middle-hole)
                    (hull middle-hole (cave/bottom-cube 0 4))
                    (hull (cave/bottom-cube 0 4) cave/hole-destination))))))


(spit "thumb.scad"
      (write-scad (difference
                   (union
                    (move-to-corner thumb-cluster)
                    connection-stems
                    
                    #_cave/base
                    #_cave/fingers)
                   cave/base
                   wire-network)))

#_(spit "thumb.scad"
      (write-scad (scale [(/ 25.4 90) (/ 25.4 90) (/ 25.4 90)]
                         (mirror [-1 0 0]
                                 (difference
                                  (union
                                   (move-to-corner thumb-cluster)
                                   connection-stems
                                   
                                   #_cave/base
                                   #_cave/fingers)
                                  cave/base
                                  wire-network)))))

#_(spit "thumb.scad"
      (write-scad (scale [(/ 25.4 90) (/ 25.4 90) (/ 25.4 90)]
                         (mirror [-1 0 0]
                                 (difference
                                  (union
                                   (move-to-corner thumb-cluster)
                                   connection-stems
                                   
                                   #_cave/base
                                   #_cave/fingers)
                                  cave/base
                                  wire-network)))))




(spit "one-piece.scad"
      (write-scad
       (mirror [-1 0 0]
               (union (difference cave/fingers cave/wire-network)
                      (difference
                       (union
                        (move-to-corner thumb-cluster)
                        connection-stems)
                       cave/base
                       wire-network)))))