summaryrefslogtreecommitdiff
path: root/graphics/sketch/Doc/hand.sk
blob: 71cf6c0b5795318bb84e5543d1d2e7abe292b81c (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
%
% Very simple model of my hand
%
% Gene Ressler
%
% In particular, this completely ignores the carpal joints.
%
% Try this with various options to sketch.
%
% -D fist   \
% -D ok      > none or one of these
% -D spread /
%
% -D topview   \
% -D frontview  > none or one of these
% -D sideview  /
%
% -D repeated 
%
% I am not responsible for modifications to draw
% obscene gestures.

% parameterization of model

% for fingers, 0 is thumb, 1 is index, 
%   2 is middle, 3 is ring, 4 is little

% lateral angle between fingers
def spread_rot              
  <fist> 0
  <ok> 5
  <spread>10
  <> 0
% and between thumb and index finger
def spread_rot_0 
  <fist> 40
  <ok> 55
  <spread> 55
  <> 25

% rotations of finger parts
% distal is the finger tip
% middle is below that
% meta is the knuckle
def distal_0_rot           
  <fist> 60
  <ok> 45
  <> -10
def middle_0_rot           
  <fist> 50
  <ok> 40
  <spread> 0
  <> 10
def meta_0_rot 
  <fist> 40
  <ok> 33
  <> 0

def distal_1_rot 
  <fist> 90
  <ok> 60
  <> 0
def meta_1_rot 
  <fist> 90
  <ok> 55
  <> 0

def distal_2_rot
  <fist> 90
  <ok> 30
  <> 0
def meta_2_rot
  <fist> 90
  <ok> 35
  <> 0

def distal_3_rot
  <fist> 90
  <ok> 30
  <> 0
def meta_3_rot
  <fist> 90
  <ok> 30
  <> 0

def distal_4_rot 
  <fist> 90
  <ok> 30
  <> 0
def meta_4_rot 
  <fist> 90
  <ok> 25
  <> 0

% end parameters

% useful stuff
def O (0,0,0)
def I [1,0,0]
def J [0,1,0]
def K [0,0,1]

% dependent rotations 
% fingers have the last two joints wired together
def middle_1_rot distal_1_rot
def middle_2_rot distal_2_rot
def middle_3_rot distal_3_rot
def middle_4_rot distal_4_rot

% proportions 
def proximal_rad           .6
def distal_rad             .5
def distal_len            1.8
def joint_rad              .6
def joint_gap              .7
def middle_ratio	  1.8
def proximal_distal_ratio  proximal_rad / distal_rad

% primitive segment of a finger is a truncated cone
def segment {
  def n_faces 8
  sweep { n_faces<>, rotate(360 / n_faces, [J]) } 
    line(proximal_rad, 0)(distal_rad, distal_len)
}

% spheres to connect segments at joints
def joint_sphere {
  def n_joint_faces 8
  sweep [fillcolor=red] { n_joint_faces, rotate(360 / n_joint_faces, [J]) }
    sweep { n_joint_faces, rotate(180 / n_joint_faces) } 
      (0, -joint_rad)
}

% following is five separate definitions for five fingers
% with parameters, this would be much shorter!

def distal_0 {
  put { translate(joint_gap * joint_rad * [J]) 
        then rotate(distal_0_rot, [I]) 
        then translate((distal_len + joint_gap * joint_rad) * [J]) }
    {segment}
  put { rotate(distal_0_rot / 2, [I])
        then translate((distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( [J] + proximal_distal_ratio * ([I]+[K]) ) }
    {segment}
}  

def finger_0 {
  put { translate(joint_gap * joint_rad * [J])
        then rotate(middle_0_rot, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) }
    {distal_0}
  put { scale(proximal_distal_ratio)
        then rotate(middle_0_rot / 2, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( middle_ratio * [J] + proximal_distal_ratio^2 * ([I]+[K]) ) }
    {segment}
}

def distal_1 {
  put { translate(joint_gap * joint_rad * [J]) 
        then rotate(distal_1_rot, [I]) 
        then translate((distal_len + joint_gap * joint_rad) * [J]) }
    {segment}
  put { rotate(distal_1_rot / 2, [I])
        then translate((distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( [J] + proximal_distal_ratio * ([I]+[K]) ) }
    {segment}
}  

def finger_1 {
  put { translate(joint_gap * joint_rad * [J])
        then rotate(middle_1_rot, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) }
    {distal_1}
  put { scale(proximal_distal_ratio)
        then rotate(middle_1_rot / 2, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( middle_ratio * [J] + proximal_distal_ratio^2 * ([I]+[K]) ) }
    {segment}
}

def distal_2 {
  put { translate(joint_gap * joint_rad * [J]) 
        then rotate(distal_2_rot, [I]) 
        then translate((distal_len + joint_gap * joint_rad) * [J]) }
    {segment}
  put { rotate(distal_2_rot / 2, [I])
        then translate((distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( [J] + proximal_distal_ratio * ([I]+[K]) ) }
    {segment}
}  

def finger_2 {
  put { translate(joint_gap * joint_rad * [J])
        then rotate(middle_2_rot, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) }
    {distal_2}
  put { scale(proximal_distal_ratio)
        then rotate(middle_2_rot / 2, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( middle_ratio * [J] + proximal_distal_ratio^2 * ([I]+[K]) ) }
    {segment}
}

def distal_3 {
  put { translate(joint_gap * joint_rad * [J]) 
        then rotate(distal_3_rot, [I]) 
        then translate((distal_len + joint_gap * joint_rad) * [J]) }
    {segment}
  put { rotate(distal_3_rot / 2, [I])
        then translate((distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( [J] + proximal_distal_ratio * ([I]+[K]) ) }
    {segment}
}  

def finger_3 {
  put { translate(joint_gap * joint_rad * [J])
        then rotate(middle_3_rot, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) }
    {distal_3}
  put { scale(proximal_distal_ratio)
        then rotate(middle_3_rot / 2, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( middle_ratio * [J] + proximal_distal_ratio^2 * ([I]+[K]) ) }
    {segment}
}

def distal_4 {
  put { translate(joint_gap * joint_rad * [J]) 
        then rotate(distal_4_rot, [I]) 
        then translate((distal_len + joint_gap * joint_rad) * [J]) }
    {segment}
  put { rotate(distal_4_rot / 2, [I])
        then translate((distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( [J] + proximal_distal_ratio * ([I]+[K]) ) }
    {segment}
}  

def finger_4 {
  put { translate(joint_gap * joint_rad * [J])
        then rotate(middle_4_rot, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) }
    {distal_4}
  put { scale(proximal_distal_ratio)
        then rotate(middle_4_rot / 2, [I])
        then translate((middle_ratio * distal_len + joint_gap * joint_rad) * [J]) } 
    {joint_sphere}
  put { scale( middle_ratio * [J] + proximal_distal_ratio^2 * ([I]+[K]) ) }
    {segment}
}

% points on the palm of the hand
def proximal_0_loc (1.8,-5.5,0)
def proximal_1_loc (1.8,.1,0)
def proximal_2_loc (O)
def proximal_3_loc (-1.8,-.2,0)
def proximal_4_loc (-3.6,-.5,0)
def h5 (proximal_4_loc) + [-.6,-.2]
def h6 (h5) + [1,-5]
def h8 (proximal_0_loc) + [.75,-.5]
def h7 (h8) + [-.6,-.8]
def h6a (h6) + .6 * ((h7) - (h6))
def h9 (h8) + [-1.9,1]
def h10 (proximal_1_loc) + [.85,-.3]

def hand {

  % thumb has an extra rotation for opposable-ness!
  def opposition_rot rotate(-50, [J])
  def thk_scale_0 1.2
  put { scale([thk_scale_0,.9,thk_scale_0]) % this distorts a little; oh well
        then translate((joint_gap * joint_rad) * [J])
        then [[opposition_rot]]
	then rotate(meta_0_rot, [I])
        then rotate(-spread_rot_0, [K])
        then translate((proximal_0_loc) - (O)) } 
    {finger_0}

  put { scale(thk_scale_0 * proximal_distal_ratio^2)
        then [[opposition_rot]]
        then rotate(meta_0_rot / 2, [I])
        then rotate(-spread_rot_0, [K])
        then translate((proximal_0_loc) - (O)) } 
    {joint_sphere}

  % index finger
  def scale_1 .85
  put { scale(scale_1) 
        then translate((joint_gap * joint_rad) * [J])
	then rotate(meta_1_rot, [I])
        then rotate(-spread_rot, [K])
        then translate((proximal_1_loc) - (O)) } 
    {finger_1}

  put { scale(scale_1 * proximal_distal_ratio^2)
        then rotate(meta_1_rot / 2, [I])
        then rotate(-spread_rot, [K])
        then translate((proximal_1_loc) - (O)) } 
    {joint_sphere}

  % middle finger
  put { % no scale then
        translate((joint_gap * joint_rad) * [J])
	then rotate(meta_2_rot, [I])
        % no spread rotation
        then translate((proximal_2_loc) - (O)) } 
    {finger_2}

  put { scale(proximal_distal_ratio^2)
        then rotate(meta_2_rot / 2, [I])
        then translate((proximal_2_loc) - (O)) } 
    {joint_sphere}

  % ring finger
  def scale_3 .85
  put { scale(scale_3) 
        then translate((joint_gap * joint_rad) * [J])
	then rotate(meta_3_rot, [I])
        then rotate(spread_rot, [K])
        then translate((proximal_3_loc) - (O)) } 
    {finger_3}

  put { scale(scale_3 * proximal_distal_ratio^2)
        then rotate(meta_3_rot / 2, [I])
        then rotate(spread_rot, [K])
        then translate((proximal_3_loc) - (O)) } 
    {joint_sphere}

  % little finger
  def scale_4 .7
  put { scale(scale_4) 
        then translate((joint_gap * joint_rad) * [J])
	then rotate(meta_4_rot, [I])
        then rotate(2 * spread_rot, [K])
        then translate((proximal_4_loc) - (O)) } 
    {finger_4}

  put { scale(scale_4 * proximal_distal_ratio^2)
        then rotate(meta_4_rot / 2, [I])
        then rotate(2 * spread_rot, [K])
        then translate((proximal_4_loc) - (O)) } 
    {joint_sphere}

  % palm is built by sweeping a polygon through a small
  % angle in order to make it thicker at the wrist
  put { translate(joint_gap * joint_rad * -[J]) } % drop polytope to expose knuckles
    sweep { 1, rotate(6, (0,15,0), [I]) }
      put { rotate(-3, (0,15,0), [I]) } {
        % need two polygons for convexity; the desired shape is concave at the thumb
        polygon(proximal_1_loc)(proximal_2_loc)(proximal_3_loc)(proximal_4_loc)
               (h5)(h6)(h6a)(h9)(h10)
        polygon(h6a)(h7)(h8)(h9)
      }
}

% a few views
def viewxf 
 <frontview> view((0,0,10))
 <sideview>  view((10,0,0))
 <topview>   view((0,10,0), (O), -[K])
 <>          view((7,3,10))

% either a single copy or a repeat to show different angles
def scene 
  <repeated>
    put { [[viewxf]] then scale(.25) }  {
      def N 4
      repeat { N, rotate(270/N, [3,2,1]), translate(14*[I]) } {hand}
    }
  <> put { [[viewxf]] then scale(.3) } {hand}

{scene}