summaryrefslogtreecommitdiff
path: root/src/dactyl_cave/alternathumb.clj
blob: ddfb42afa262eb98b5e81198e4fa765105b7aba1 (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
(ns dactyl-cave.alternathumb
  (: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- scoop [angle radius [x y :as direction] shape]
  (->> shape
       (translate [0 0 radius])))

(defn thumb-x+x-column [shape]
  (let [α (/ π 12)
        radius (/ (/ key/pillar-depth 2)
                  (Math/sin (/ α 2)))
        spin-shape (->> shape
                        (translate [0 0 (+ (- key/full-height)
                                           (- radius))]))]
    (translate
     [0 0 (+ radius key/full-height)]
     (union
      spin-shape

      (->> spin-shape
           (rotate (- α) [1 0 0]))))))

(defn thumb-2x-column [shape]
  (let [α (/ π 12)
        radius (/ (/ key/pillar-depth 2)
                  (Math/sin (/ α 2)))
        spin-shape (->> shape
                        (translate [0 0 (+ (- key/full-height)
                                           (- radius))]))]
    (translate
     [0 0 (+ radius key/full-height)]
     (union
      (->> spin-shape
           (rotate (* α -1/2) [1 0 0]))))))

(defn thumb-2x-row [shape]
  (let [α (/ π 12)
        radius (/ (/ key/pillar-depth 2)
                  (Math/sin (/ α 2)))
        spin-shape (->> shape
                        (translate [0 0 (+ (- key/full-height)
                                           (- radius))]))]
    (translate
     [0 0 (+ radius key/full-height)]
     (union
      (->> spin-shape
           (rotate (* α 1) [1 0 0]))))))


(defn spin-thumb [column shape]
  (let [β (/ π 36)
        radius (/ (/ (+ key/pillar-width 5) 2)
                  (Math/sin (/ β 2)))]
    (->>
     (translate
      [0 0 (- (- radius key/full-height))]
      (->> shape
           (translate [0 0 (- radius key/full-height)])
           (rotate (* column β) [0 1 0])))
     (translate [key/pillar-width 0 0])
     (rotate (/ π 12) [0 0 1])
     #_(rotate (/ π -12) [0 1 0])
     #_(rotate (/ π 6) [0 0 1])
     (translate [-7 -47 35]))))

(defn thumb-layout [shape]
  (union
   (spin-thumb 2 (thumb-x+x-column shape))
   (spin-thumb 1 (thumb-x+x-column shape))
   (spin-thumb 0 (thumb-2x-column shape))
   (spin-thumb 1/2 (thumb-2x-row shape))))

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

(defn thumb-support [shape]
  (union
   (support (union
             (spin-thumb 2 (thumb-x+x-column shape))
             (spin-thumb 1 (thumb-x+x-column shape))
             (spin-thumb 0 (thumb-2x-column shape))))
   (support (union
             (spin-thumb 0 (thumb-2x-column shape))
             (spin-thumb 1/2 (thumb-2x-row shape))))
   
))

(def bottom
  (translate [0 0 -100]
             (cube 2000 2000 200))
  )


#_(def thumb-base
  (difference
   (hull
    (thumb-layout (translate [0 0 (/ key/pillar-height -2)]
                             (scale [1 1 1/10] key/full-pillar)))
    (extrude-linear {:height 10 :twist 0 :convexity 0}
                    (project (hull (thumb-layout key/full-pillar)))))
   bottom
   (thumb-layout key/keyswitch-full-hole)))

(def thumb-base
  (union
   (thumb-support (scale [1 1 1/10] key/full-pillar))
   #_(->> (cube 150 150 50)
        (translate [150 75 25])))

  )

(defn move-to-corner [shape]
  (translate [-265 -215 0] shape))

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

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