Revision: 1.1 - (view) (download)
1 : | ktanaka | 1.1 | (defun kanjilib()) |
2 : | (declare (trans minchowidth meshsize) special) | ||
3 : | ; ベクトルの長さ | ||
4 : | ; | ||
5 : | (defun length2 (a) | ||
6 : | (lets ((x (car a)) | ||
7 : | (y (cadr a))) | ||
8 : | (sqrt (float (plus (times x x)(times y y)))))) | ||
9 : | ; | ||
10 : | ; ベクトルの単位ベクトル | ||
11 : | ; | ||
12 : | (defun norm2 (a) | ||
13 : | (lets ((x (car a)) | ||
14 : | (y (cadr a)) | ||
15 : | (len (sqrt (float (plus (times x x)(times y y)))))) | ||
16 : | (list (quotient x len)(quotient y len)))) | ||
17 : | ; | ||
18 : | ; ベクトルの長さを指定 | ||
19 : | ; | ||
20 : | (defun normlen2 (len a) | ||
21 : | (times2 len (norm2 a))) | ||
22 : | ; | ||
23 : | ; ベクトルのスカラー倍 | ||
24 : | ; | ||
25 : | (defun times2 (len a) | ||
26 : | (list (times len (car a))(times len (cadr a)))) | ||
27 : | ; | ||
28 : | ; 2点の距離 | ||
29 : | ; | ||
30 : | (defun metric2 (a b) | ||
31 : | (let ((x0 (car a))(y0 (cadr a))(x1 (car b))(y1 (cadr b))) | ||
32 : | (sqrt (plus (times (difference x0 x1)(difference x0 x1)) | ||
33 : | (times (difference y0 y1)(difference y0 y1)))))) | ||
34 : | ; | ||
35 : | ; ベクトルの足し算 | ||
36 : | ; | ||
37 : | (defun _plus2 (a b) | ||
38 : | (list (plus (car a)(car b))(plus (cadr a)(cadr b)))) | ||
39 : | ; | ||
40 : | (macro plus2 (l) | ||
41 : | (do ((ll (cdr l) (cdr ll)) | ||
42 : | (ret (car l))) | ||
43 : | ((atom ll)ret) | ||
44 : | (setq ret `(_plus2 ,(car ll) ,ret)))) | ||
45 : | ; | ||
46 : | ; ベクトルの引き算 | ||
47 : | ; | ||
48 : | (defun diff2 (a b) | ||
49 : | (list (difference (car a)(car b))(difference (cadr a)(cadr b)))) | ||
50 : | ; | ||
51 : | ; 2点の分割点 | ||
52 : | ; | ||
53 : | (defun inter2 (p0 p1 s) | ||
54 : | (lets ((x0 (car p0))(y0 (cadr p0)) | ||
55 : | (x1 (car p1))(y1 (cadr p1)) | ||
56 : | (s1 (difference 1.0 s))) | ||
57 : | (list (plus (times x0 s1)(times x1 s)) | ||
58 : | (plus (times y0 s1)(times y1 s))))) | ||
59 : | ; | ||
60 : | ; 2点の内積 | ||
61 : | ; | ||
62 : | (defun mul2 (a b) | ||
63 : | (plus (times (car a)(car b))(times (cadr a)(cadr b)))) | ||
64 : | ; | ||
65 : | ; ベクトルの90度回転 | ||
66 : | ; | ||
67 : | (defun rot90 (point) | ||
68 : | (let ((x (car point)) | ||
69 : | (y (cadr point))) | ||
70 : | (list y (minus x)))) | ||
71 : | ; | ||
72 : | ; ベクトルの-90度回転 | ||
73 : | ; | ||
74 : | (defun rot270 (point) | ||
75 : | (let ((x (car point)) | ||
76 : | (y (cadr point))) | ||
77 : | (list (minus y) x))) | ||
78 : | ; | ||
79 : | ; ベクトルの任意度回転(thetaは0から2piまで) | ||
80 : | ; | ||
81 : | (defun rot (vector theta) | ||
82 : | (lets ((y (rot90 vector)) | ||
83 : | (costheta (cos theta)) | ||
84 : | (sintheta (sin theta))) | ||
85 : | (plus2 (times2 costheta vector)(times2 sintheta y)))) | ||
86 : | ; | ||
87 : | ; degree | ||
88 : | ; | ||
89 : | (defun degree (deg) | ||
90 : | (quotient (times 3.14159265 deg) 180)) | ||
91 : | ; | ||
92 : | ; ベクトルbから見たaの角度のcos | ||
93 : | ; | ||
94 : | (defun costheta (a b) | ||
95 : | (let ((len (times (length2 a)(length2 b)))) | ||
96 : | (cond ((equal len 0.0)0.0) | ||
97 : | (t (quotient (mul2 a b) len))))) | ||
98 : | ; | ||
99 : | ; ベクトルbから見たaの角度のsin | ||
100 : | ; | ||
101 : | (defun sintheta (a b) | ||
102 : | (costheta (rot270 a) b)) | ||
103 : | ; | ||
104 : | ; | ||
105 : | ; | ||
106 : | (defun arccos1 (cos) | ||
107 : | (cond ((greaterp cos 1.0)0.0) | ||
108 : | ((lessp cos -1.0)3.14159) | ||
109 : | (t (arccos cos)))) | ||
110 : | ; | ||
111 : | ; ベクトルd1から見たd0の角度 | ||
112 : | ; | ||
113 : | (defun theta (d1 d0) | ||
114 : | (lets ((costheta (costheta d1 d0)) | ||
115 : | (sintheta (costheta (rot270 d1) d0)) | ||
116 : | (theta (arccos1 costheta))) | ||
117 : | ; (print costheta) | ||
118 : | (cond ((minusp sintheta)(minus theta)) | ||
119 : | (t theta)))) | ||
120 : | ; | ||
121 : | (defun minustheta (theta) | ||
122 : | (let ((minustheta (difference theta 3.14159265))) | ||
123 : | (cond ((lessp minustheta -3.14159265)minustheta) | ||
124 : | (t (plus minustheta 6.2831853))))) | ||
125 : | ; | ||
126 : | ; 逆行列 | ||
127 : | ; | ||
128 : | (defun rmat (mat) | ||
129 : | (let ((eigen (quotient 1.0 (difference (times (vref mat 0)(vref mat 3)) | ||
130 : | (times (vref mat 1)(vref mat 2))))) | ||
131 : | (ret (vector 4))) | ||
132 : | (vset ret 0 (times eigen (vref mat 3))) | ||
133 : | (vset ret 1 (times eigen -1.0 (vref mat 1))) | ||
134 : | (vset ret 2 (times eigen -1.0 (vref mat 2))) | ||
135 : | (vset ret 3 (times eigen (vref mat 0))) | ||
136 : | ret)) | ||
137 : | ; | ||
138 : | ; アフィン変換 | ||
139 : | ; | ||
140 : | (defun affine (point trans) | ||
141 : | (let ((x (car point)) | ||
142 : | (y (cadr point))) | ||
143 : | (list | ||
144 : | (plus (vref trans 4)(times x (vref trans 0))(times y (vref trans 2))) | ||
145 : | (plus (vref trans 5)(times x (vref trans 1))(times y (vref trans 3)))))) | ||
146 : | ; | ||
147 : | ; | ||
148 : | ; | ||
149 : | (macro defelement (l) | ||
150 : | `(defprop ,(cadr l) | ||
151 : | (lambda (points alist) .,(cddr l)) | ||
152 : | ; mincho)) | ||
153 : | ,(car l))) | ||
154 : | ; | ||
155 : | (defmacro defprimitive (fonttype name data) | ||
156 : | (cond (fonttype `(putprop ',name ,data ',fonttype)) | ||
157 : | (t `(setq ,name ,data)))) | ||
158 : | ; | ||
159 : | (defmacro defjoint (fonttype name data) | ||
160 : | (cond (fonttype `(putprop ',name ,data ',fonttype)) | ||
161 : | (t `(setq ,name ,data)))) | ||
162 : | ; | ||
163 : | (defmacro deftypehook (fonttype data) | ||
164 : | `(putprop 'typehook ,data ',fonttype)) | ||
165 : | ; | ||
166 : | (defmacro subfont (child parent) | ||
167 : | `(putprop ',child ',parent 'parent)) | ||
168 : | ; | ||
169 : | (macro defkazari (l) | ||
170 : | (let ((sym (gensym (car l)))) | ||
171 : | `(progn | ||
172 : | (defun ,sym (cross).,(cddr l)) | ||
173 : | (putprop 'allkazari | ||
174 : | `(,',(append (cadr l) (ncons sym)) | ||
175 : | . ,(get 'allkazari ',(car l))) | ||
176 : | ',(car l))))) | ||
177 : | ; | ||
178 : | (defmacro def-type1-hint (type elements body) | ||
179 : | (cond ((consp elements) | ||
180 : | (do ((ret) | ||
181 : | (l elements (cdr l))) | ||
182 : | ((atom l) `(progn .,ret)) | ||
183 : | (push `(def-type1-hint ,type ,(car l) ,body) ret))) | ||
184 : | (t | ||
185 : | `(putprop ',elements | ||
186 : | (cons (cons ',type (function (lambda (points (alist)) | ||
187 : | ,body))) | ||
188 : | (get ',elements 'type1)) | ||
189 : | 'type1)))) | ||
190 : | ; | ||
191 : | ; | ||
192 : | (defun mincho1 (d0 d1 src ratio) | ||
193 : | (lets ((d0x (float (car d0)))(d0y (float (cadr d0))) | ||
194 : | (d1x (float (car d1)))(d1y (float (cadr d1))) | ||
195 : | (s (car src))(outline (cdr src)) | ||
196 : | (s0x (float (car s)))(s0y (float (cadr s))) | ||
197 : | (s1x (float (caddr s)))(s1y (float (cadddr s))) | ||
198 : | (trans (type1-trans s0x s0y s1x s1y d0x d0y d1x d1y ratio))) | ||
199 : | (affine-outline outline trans))) | ||
200 : | ; | ||
201 : | ; | ||
202 : | (defun type1-trans (s0x s0y s1x s1y d0x d0y d1x d1y ratio) | ||
203 : | (lets ((rvec (vector 6)) | ||
204 : | (slen (metric2 (list s0x s0y)(list s1x s1y))) | ||
205 : | (dlen (metric2 (list d0x d0y)(list d1x d1y))) | ||
206 : | (a (quotient dlen slen)) | ||
207 : | (b ratio) | ||
208 : | (costheta (quotient (difference s1x s0x) slen)) | ||
209 : | (sintheta (minus (quotient (difference s1y s0y) slen))) | ||
210 : | (offx (difference (times costheta s0x)(times sintheta s0y))) | ||
211 : | (offy (plus (times sintheta s0x)(times costheta s0y))) | ||
212 : | (cosfai (quotient (difference d1x d0x) dlen)) | ||
213 : | (sinfai (quotient (difference d1y d0y) dlen))) | ||
214 : | (vset rvec 0 (difference (times a costheta cosfai)(times b sintheta sinfai))) | ||
215 : | (vset rvec 1 (plus (times a costheta sinfai)(times b sintheta cosfai))) | ||
216 : | (vset rvec 2 (difference 0.0 (times a sintheta cosfai)(times b costheta sinfai))) | ||
217 : | (vset rvec 3 (difference (times b costheta cosfai)(times a sintheta sinfai))) | ||
218 : | (vset rvec 4 (plus d0x (minus (times a cosfai offx)) (times b sinfai offy))) | ||
219 : | (vset rvec 5 (difference d0y (times a sinfai offx)(times b cosfai offy))) | ||
220 : | rvec)) | ||
221 : | ; | ||
222 : | ; | ||
223 : | (defun affine-outline (outline trans) | ||
224 : | (mapcar outline (function(lambda (y) (mapcar y (function(lambda (x) (cons (car x)(affine (cdr x) trans))))))))) | ||
225 : | ; | ||
226 : | ; | ||
227 : | ; | ||
228 : | (defun niku2 (p0 p1 r0 r1 w0 w1 w2 w3) | ||
229 : | (lets ((l0 (norm2 (rot270 (diff2 p1 p0))))) | ||
230 : | ; (break) | ||
231 : | `(((angle .,(plus2 p0 (times2 w0 l0))) | ||
232 : | (bezier .,(plus2 (inter2 p0 p1 r0)(times2 w1 l0))) | ||
233 : | (bezier .,(plus2 (inter2 p1 p0 r1)(times2 w2 l0))) | ||
234 : | (angle .,(plus2 p1 (times2 w3 l0)))) | ||
235 : | ((angle .,(diff2 p0 (times2 w0 l0))) | ||
236 : | (bezier .,(diff2 (inter2 p0 p1 r0)(times2 w1 l0))) | ||
237 : | (bezier .,(diff2 (inter2 p1 p0 r1)(times2 w2 l0))) | ||
238 : | (angle .,(diff2 p1 (times2 w3 l0))))))) | ||
239 : | ; | ||
240 : | ; | ||
241 : | ; | ||
242 : | (comment | ||
243 : | (defun niku3 (p0 p1 p2 r0 r1 w0 w1 w2 w3) | ||
244 : | (lets ((len (plus (metric2 p0 p1)(metric2 p1 p2))) | ||
245 : | (d0 (diff2 p1 p0)) | ||
246 : | (d1 (diff2 p1 p2)) | ||
247 : | (l0 (norm2 (list (minus (cadr d0))(car d0)))) | ||
248 : | (l1 (norm2 (list (cadr d1)(minus (car d1))))) | ||
249 : | (l2 (times2 0.5 (plus2 l0 l1))) | ||
250 : | (tt (metric2 l2 l0)) | ||
251 : | (s (metric2 l2 '(0.0 0.0))) | ||
252 : | (dlen (times (plus w0 w3) (quotient tt s)))) | ||
253 : | (cond ((minusp (mul2 l0 d1))(setq dlen (minus dlen)))) | ||
254 : | `(((angle .,(plus2 p0 (times2 w0 l0))) | ||
255 : | (bezier .,(plus2 p0 (plus2 (normlen2 (times r0 (plus len dlen))d0)(times2 w1 l0)))) | ||
256 : | (bezier .,(plus2 p2 (plus2 (normlen2 (times r1 (plus len dlen))d1)(times2 w2 l1)))) | ||
257 : | (angle .,(plus2 p2 (times2 w3 l1)))) | ||
258 : | ((angle .,(diff2 p0 (times2 w0 l0))) | ||
259 : | (bezier .,(plus2 p0 (diff2 (normlen2 (times r0 (difference len dlen))d0)(times2 w1 l0)))) | ||
260 : | (bezier .,(plus2 p2 (diff2 (normlen2 (times r1 (difference len dlen))d1)(times2 w2 l1)))) | ||
261 : | (angle .,(diff2 p2 (times2 w3 l1))))))) | ||
262 : | |||
263 : | ) | ||
264 : | ; | ||
265 : | ; | ||
266 : | ; | ||
267 : | (defun bez3 (p0 p1 p2 w0 w1 w2 w3 alpha beta) | ||
268 : | (lets ((d0 (diff2 p2 p0)) | ||
269 : | (d1 (diff2 p1 p0)) | ||
270 : | (theta (theta d1 d0)) | ||
271 : | (d2 (diff2 p2 p1)) | ||
272 : | (psi (minus (theta d2 d0))) | ||
273 : | (len (length2 d0)) | ||
274 : | (f1 (min (length2 d1) (times len (quotient (_f theta psi) alpha)))) | ||
275 : | (f2 (min (length2 d2) (times len (quotient (_f psi theta) beta)))) | ||
276 : | (p3 (plus2 p0 (normlen2 f1 d1))) | ||
277 : | (p4 (plus2 p2 (normlen2 (minus f2)d2))) | ||
278 : | (v1 (rot270 d1)) | ||
279 : | (v2 (rot270 d2))) | ||
280 : | ; (prind (list theta psi)) | ||
281 : | `(((angle .,(plus2 p0 (normlen2 w0 v1))) | ||
282 : | (bezier .,(plus2 p3(normlen2 w1 v1))) | ||
283 : | (bezier .,(plus2 p4(normlen2 w2 v2))) | ||
284 : | (angle .,(plus2 p2 (normlen2 w3 v2)))) | ||
285 : | ((angle .,(plus2 p0 (normlen2 (minus w0) v1))) | ||
286 : | (bezier .,(plus2 p3 (normlen2 (minus w1) v1))) | ||
287 : | (bezier .,(plus2 p4 (normlen2 (minus w2) v2))) | ||
288 : | (angle .,(plus2 p2 (normlen2 (minus w3) v2))))))) | ||
289 : | ; | ||
290 : | ; | ||
291 : | ; | ||
292 : | (defun movexy (x y (trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
293 : | (let ((ret (vector 6 trans))) | ||
294 : | (vset ret 4 (plus (vref ret 4)(float x))) | ||
295 : | (vset ret 5 (plus (vref ret 5)(float y))) | ||
296 : | ret)) | ||
297 : | |||
298 : | (defun movex (x (trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
299 : | (let ((ret (vector 6 trans))) | ||
300 : | (vset ret 4 (plus (vref ret 4)(float x))) | ||
301 : | ret)) | ||
302 : | |||
303 : | (defun movey (y (trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
304 : | (let ((ret (vector 6 trans))) | ||
305 : | (vset ret 5 (plus (vref ret 5)(float y))) | ||
306 : | ret)) | ||
307 : | |||
308 : | (defun scalex (x (trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
309 : | (let ((ret (vector 6 trans))) | ||
310 : | (vset ret 0 (times (vref ret 0)(float x))) | ||
311 : | (vset ret 2 (times (vref ret 2)(float x))) | ||
312 : | (vset ret 4 (times (vref ret 4)(float x))) | ||
313 : | ret)) | ||
314 : | |||
315 : | (defun scalexy (x y(trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
316 : | (let ((ret (vector 6 trans))) | ||
317 : | (vset ret 0 (times (vref ret 0)(float x))) | ||
318 : | (vset ret 1 (times (vref ret 1)(float y))) | ||
319 : | (vset ret 2 (times (vref ret 2)(float x))) | ||
320 : | (vset ret 3 (times (vref ret 3)(float y))) | ||
321 : | (vset ret 4 (times (vref ret 4)(float x))) | ||
322 : | (vset ret 5 (times (vref ret 5)(float y))) | ||
323 : | ret)) | ||
324 : | |||
325 : | (defun scaley (y (trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
326 : | (let ((ret (vector 6 trans))) | ||
327 : | (vset ret 1 (times (vref ret 1)(float y))) | ||
328 : | (vset ret 3 (times (vref ret 3)(float y))) | ||
329 : | (vset ret 5 (times (vref ret 5)(float y))) | ||
330 : | ret)) | ||
331 : | ; | ||
332 : | (defun rotate (theta (trans (vector 6 '(1.0 0.0 0.0 1.0 0.0 0.0)))) | ||
333 : | (lets ((ret (vector 6)) | ||
334 : | (costheta (cos theta)) | ||
335 : | (sintheta (sin theta)) | ||
336 : | (msintheta (minus sintheta))) | ||
337 : | (vset ret 0 (plus (times costheta (vref trans 0)) | ||
338 : | (times msintheta (vref trans 1)))) | ||
339 : | (vset ret 1 (plus (times sintheta (vref trans 0)) | ||
340 : | (times costheta (vref trans 1)))) | ||
341 : | (vset ret 2 (plus (times costheta (vref trans 2)) | ||
342 : | (times msintheta (vref trans 3)))) | ||
343 : | (vset ret 3 (plus (times sintheta (vref trans 2)) | ||
344 : | (times costheta (vref trans 3)))) | ||
345 : | (vset ret 4 (plus (times costheta (vref trans 4)) | ||
346 : | (times msintheta (vref trans 5)))) | ||
347 : | (vset ret 5 (plus (times sintheta (vref trans 4)) | ||
348 : | (times costheta (vref trans 5)))))) | ||
349 : | |||
350 : | ; | ||
351 : | (defun points2spline (points) | ||
352 : | (do ((l (cdr points)(cdr l)) | ||
353 : | (outline `((angle .,(car points))))) | ||
354 : | ((atom (cdr l)) | ||
355 : | (rplacd (car outline) (car l)) | ||
356 : | (nreverse outline)) | ||
357 : | (push `(bezier .,(car l)) outline) | ||
358 : | (push `(bezier .,(car l)) outline) | ||
359 : | (push `(angle .,(inter2 (car l)(cadr l) 0.5)) outline))) | ||
360 : | ; | ||
361 : | ; dwは | ||
362 : | ; | ||
363 : | (defun curve1 (p0 p1 p2 p3 w0 w1 w2 w3 (dlist '(nil nil))) | ||
364 : | (width-curve p0 p3 (times2 3.0 (diff2 p1 p0)) | ||
365 : | (times2 3.0 (diff2 p3 p2)) | ||
366 : | w0 w3 | ||
367 : | (times 3.0 (difference w1 w0)) | ||
368 : | (times 3.0 (difference w3 w2)) | ||
369 : | 1.0 dlist)) | ||
370 : | ; | ||
371 : | (defun width-curve (p1 p2 dp1 dp2 w1 w2 dw1 dw2 ti (dlist '(nil nil))) | ||
372 : | ; (prind `(,p1 ,p2 ,dp1 ,dp2 ,w1 ,w2 ,dw1 ,dw2 ,ti)) | ||
373 : | (lets ((titi (times ti ti)) | ||
374 : | (ddp1 (plus2 (times2 (quotient 6.0 titi) | ||
375 : | (diff2 p2 p1)) | ||
376 : | (times2 (quotient -4.0 ti) dp1) | ||
377 : | (times2 (quotient -2.0 ti) dp2))) | ||
378 : | (ddp2 (plus2 (times2 (quotient 6.0 titi) | ||
379 : | (diff2 p1 p2)) | ||
380 : | (times2 (quotient 4.0 ti) dp2) | ||
381 : | (times2 (quotient 2.0 ti) dp1))) | ||
382 : | (mid-p (plus2 (times2 0.5 p1) | ||
383 : | (times2 (times 0.125 ti) dp1) | ||
384 : | (times2 (times -0.125 ti) dp2) | ||
385 : | (times2 0.5 p2))) | ||
386 : | (mid-dp (plus2 (times2 (quotient 1.5 ti) (diff2 p2 p1)) | ||
387 : | (times2 -0.25 (plus2 dp2 dp1)))) | ||
388 : | (mid-w (plus (times 0.5 w1) | ||
389 : | (times ti 0.125 dw1) | ||
390 : | (times ti -0.125 dw2) | ||
391 : | (times 0.5 w2))) | ||
392 : | (mid-dw (plus (times (quotient 1.5 ti) (difference w2 w1)) | ||
393 : | (times -0.25 (plus dw2 dw1)))) | ||
394 : | (mid-1 (plus2 mid-p (normlen2 mid-w (rot270 mid-dp)))) | ||
395 : | (mid-2 (diff2 mid-p (normlen2 mid-w (rot270 mid-dp)))) | ||
396 : | (dp1_ddp1 (mul2 dp1 ddp1)) | ||
397 : | (dp2_ddp2 (mul2 dp2 ddp2)) | ||
398 : | (lendp1 (length2 dp1)) | ||
399 : | (lendp2 (length2 dp2)) | ||
400 : | (lendp1_3 (quotient 1.0 (times lendp1 lendp1 lendp1))) | ||
401 : | (lendp2_3 (quotient 1.0 (times lendp2 lendp2 lendp2))) | ||
402 : | (a1 (plus2 p1 (normlen2 w1 (rot270 dp1)))) | ||
403 : | (a2 (plus2 p2 (normlen2 w2 (rot270 dp2)))) | ||
404 : | (a3 (plus2 a1 | ||
405 : | (times2 (quotient ti 3.0) | ||
406 : | (plus2 dp1 | ||
407 : | (times2 (quotient dw1 lendp1) (rot270 dp1)) | ||
408 : | (times2 (quotient w1 lendp1) (rot270 ddp1)) | ||
409 : | (times2 (times -1.0 w1 dp1_ddp1 lendp1_3) | ||
410 : | (rot270 dp1)))))) | ||
411 : | (a4 (plus2 a2 | ||
412 : | (times2 (quotient ti -3.0) | ||
413 : | (plus2 dp2 | ||
414 : | (times2 (quotient dw2 lendp2)(rot270 dp2)) | ||
415 : | (times2 (quotient w2 lendp2) (rot270 ddp2)) | ||
416 : | (times2 (times -1.0 w2 dp2_ddp2 lendp2_3) | ||
417 : | (rot270 dp2)))))) | ||
418 : | (mid-a (plus2 (times2 0.125 a1)(times2 0.375 a3) | ||
419 : | (times2 0.375 a4)(times2 0.125 a2))) | ||
420 : | (b1 (diff2 p1 (normlen2 w1 (rot270 dp1)))) | ||
421 : | (b2 (diff2 p2 (normlen2 w2 (rot270 dp2)))) | ||
422 : | (b3 (plus2 b1 | ||
423 : | (times2 (quotient ti 3.0) | ||
424 : | (plus2 dp1 | ||
425 : | (times2 (quotient dw1 lendp1) (rot90 dp1)) | ||
426 : | (times2 (quotient w1 lendp1) (rot90 ddp1)) | ||
427 : | (times2 (times -1.0 w1 dp1_ddp1 lendp1_3) | ||
428 : | (rot90 dp1)))))) | ||
429 : | (b4 (plus2 b2 | ||
430 : | (times2 (quotient ti -3.0) | ||
431 : | (plus2 dp2 | ||
432 : | (times2 (quotient dw2 lendp2) (rot90 dp2)) | ||
433 : | (times2 (quotient w2 lendp2) (rot90 ddp2)) | ||
434 : | (times2 (times -1.0 w2 dp2_ddp2 lendp2_3) | ||
435 : | (rot90 dp2)))))) | ||
436 : | (mid-b (plus2 (times2 0.125 b1)(times2 0.375 b3) | ||
437 : | (times2 0.375 b4)(times2 0.125 b2))) | ||
438 : | (test 'bezier)) | ||
439 : | (cond ((or (lessp 1.0 (metric2 mid-1 mid-a)) | ||
440 : | (lessp 1.0 (metric2 mid-2 mid-b))) | ||
441 : | (lets ((out2 (width-curve mid-p p2 mid-dp dp2 mid-w w2 mid-dw dw2 | ||
442 : | (times 0.5 ti) dlist)) | ||
443 : | (out1 (width-curve p1 mid-p dp1 mid-dp w1 mid-w dw1 mid-dw | ||
444 : | (times 0.5 ti) out2)) | ||
445 : | ) | ||
446 : | out1)) | ||
447 : | (t | ||
448 : | `(((angle .,a1) | ||
449 : | (,test .,a3) | ||
450 : | (,test .,a4) | ||
451 : | (angle .,a2) | ||
452 : | .,(car dlist) | ||
453 : | ) | ||
454 : | ((angle .,b1) | ||
455 : | (,test .,b3) | ||
456 : | (,test .,b4) | ||
457 : | (angle .,b2) | ||
458 : | .,(cadr dlist))))))) | ||
459 : | ; | ||
460 : | ; | ||
461 : | (defun curve2 (p0 p1 p2 p3 w0 w1 w2 w3 (dlist '(nil nil))) | ||
462 : | (lets ((mid-p (cross2 p0 p3 (diff2 p1 p0)(diff2 p2 p3))) | ||
463 : | (rate1 (//$ (metric2 p1 p0)(metric2 mid-p p0))) | ||
464 : | (rate2 (//$ (metric2 p2 p3)(metric2 mid-p p3))) | ||
465 : | (l0 (rot270 (diff2 p1 p0))) | ||
466 : | (l3 (rot270 (diff2 p3 p2))) | ||
467 : | (a0 (plus2 p0 (normlen2 w0 l0))) | ||
468 : | (da0 (diff2 (plus2 p1 (normlen2 w1 l0)) a0)) | ||
469 : | (a3 (plus2 p3 (normlen2 w3 l3))) | ||
470 : | (da3 (diff2 (plus2 p2 (normlen2 w2 l3)) a3)) | ||
471 : | (mid-a (cross2 a0 a3 da0 da3)) | ||
472 : | (a1 (inter2 a0 mid-a rate1)) | ||
473 : | (a2 (inter2 a3 mid-a rate2)) | ||
474 : | (r0 (rot90 (diff2 p1 p0))) | ||
475 : | (r3 (rot90 (diff2 p3 p2))) | ||
476 : | (b0 (plus2 p0 (normlen2 w0 r0))) | ||
477 : | (db0 (diff2 (plus2 p1 (normlen2 w1 r0)) b0)) | ||
478 : | (b3 (plus2 p3 (normlen2 w3 r3))) | ||
479 : | (db3 (diff2 (plus2 p2 (normlen2 w2 r3)) b3)) | ||
480 : | (mid-b (cross2 b0 b3 db0 db3)) | ||
481 : | (b1 (inter2 b0 mid-b rate1)) | ||
482 : | (b2 (inter2 b3 mid-b rate2)) | ||
483 : | (test 'bezier)) | ||
484 : | ; (break) | ||
485 : | `(((angle .,a0)(,test .,a1)(,test .,a2)(angle .,a3).,(car dlist)) | ||
486 : | ((angle .,b0)(,test .,b1)(,test .,b2)(angle .,b3).,(cadr dlist))))) | ||
487 : | ; | ||
488 : | (defun niku3 (p0 p1 p2 r0 r1 w0 w1 w2 w3) | ||
489 : | (lets ((len0 (metric2 p0 p1)) | ||
490 : | (len1 (metric2 p1 p2)) | ||
491 : | (len (plus len0 len1)) | ||
492 : | (rate0 (min 1.0 (quotient (times r0 len) len0))) | ||
493 : | (rate1 (min 1.0 (quotient (times r1 len) len1)))) | ||
494 : | (curve2 p0 (inter2 p0 p1 rate0) (inter2 p2 p1 rate1) p2 w0 w1 w2 w3))) | ||
495 : | |||
496 : | ; | ||
497 : | (defun cross2 (p0 p1 dp0 dp1) | ||
498 : | (cond ((lessp (abs (sintheta dp0 dp1)) 0.0001) | ||
499 : | (times2 0.5 (plus2 p0 p1))) | ||
500 : | (t | ||
501 : | (lets ((ax (float (car p0))) | ||
502 : | (ay (float (cadr p0))) | ||
503 : | (bx (float (car dp0))) | ||
504 : | (by (float (cadr dp0))) | ||
505 : | (cx (float (car p1))) | ||
506 : | (cy (float (cadr p1))) | ||
507 : | (dx (float (car dp1))) | ||
508 : | (dy (float (cadr dp1))) | ||
509 : | (mat2 (vector 4 (list bx by (-$ dx)(-$ dy)))) | ||
510 : | (rmat nil) | ||
511 : | (rmat2 nil) | ||
512 : | (s nil)) | ||
513 : | (setq rmat2 (rmat mat2)) | ||
514 : | (setq s (+$ | ||
515 : | (*$ (vref rmat2 1)(-$ cx ax)) | ||
516 : | (*$ (vref rmat2 3)(-$ cy ay)))) | ||
517 : | `(,(+$ cx (*$ s dx)),(+$ cy (*$ s dy))))))) | ||
518 : | |||
519 : | ; | ||
520 : | (defun tenhokan (points | ||
521 : | (hokanfunc #'(lambda (x) (exp (times 0.66666 (log x))))) | ||
522 : | (roundp nil) | ||
523 : | ) | ||
524 : | ; (prind roundp) | ||
525 : | (lets ((npoints (length points)) | ||
526 : | (array (vector (* npoints npoints) 0.0)) | ||
527 : | (ti | ||
528 : | (vector npoints | ||
529 : | (do ((l points (cdr l)) | ||
530 : | (ret)) | ||
531 : | ((atom (cdr l)) | ||
532 : | (push (funcall hokanfunc (metric2 (car l)(car points))) | ||
533 : | ret) | ||
534 : | (nreverse ret)) | ||
535 : | (push (funcall hokanfunc (metric2 (car l)(cadr l))) ret)))) | ||
536 : | (titi (vector npoints)) | ||
537 : | (pi | ||
538 : | (vector npoints | ||
539 : | (do ((l points (cdr l)) | ||
540 : | (ret)) | ||
541 : | ((atom l)(nreverse ret)) | ||
542 : | (push (car l) ret)))) | ||
543 : | (bi (vector npoints)) | ||
544 : | (bix (vector npoints)) | ||
545 : | (biy (vector npoints)) | ||
546 : | (dpix (vector npoints)) | ||
547 : | (dpiy (vector npoints)) | ||
548 : | (dpi (vector npoints)) | ||
549 : | (ddpi (vector npoints)) | ||
550 : | ) | ||
551 : | (do ((i 0 (1+ i)))((>= i npoints)) | ||
552 : | (vset titi i (times (vref ti i)(vref ti i)))) | ||
553 : | (vset array 1 (quotient 1.0 (vref ti 0))) | ||
554 : | (cond (roundp | ||
555 : | (vset array 0 (plus (quotient 2.0 (vref ti 0)) | ||
556 : | (quotient 2.0 (vref ti (- npoints 1))))) | ||
557 : | (vset array (- npoints 1) | ||
558 : | (quotient 1.0 (vref ti (- npoints 1)))) | ||
559 : | (vset bi 0 | ||
560 : | (plus2 | ||
561 : | (times2 (quotient -3.0 (vref titi (1- npoints))) | ||
562 : | (vref pi (1- npoints))) | ||
563 : | (times2 (difference (quotient 3.0 (vref titi (1- npoints))) | ||
564 : | (quotient 3.0 (vref titi 0))) | ||
565 : | (vref pi 0)) | ||
566 : | (times2 (quotient 3.0 (vref titi 0)) | ||
567 : | (vref pi 1))))) | ||
568 : | (t | ||
569 : | (vset array 0 (quotient 2.0 (vref ti 0))) | ||
570 : | (vset bi 0 (times2 (quotient 3.0 (vref titi 0)) | ||
571 : | (diff2 (vref pi 1)(vref pi 0)))))) | ||
572 : | (do ((i 0 (1+ i)) | ||
573 : | (j npoints (+ j npoints))) | ||
574 : | ((>= i (- npoints 2))) | ||
575 : | (vset array (+ j i) (quotient 1.0 (vref ti i))) | ||
576 : | (vset array (+ j i 1)(plus (quotient 2.0 (vref ti i)) | ||
577 : | (quotient 2.0 (vref ti (1+ i))))) | ||
578 : | (vset array (+ j i 2) (quotient 1.0 (vref ti (1+ i)))) | ||
579 : | (vset bi (1+ i ) | ||
580 : | (plus2 | ||
581 : | (times2 (quotient -3.0 (vref titi i))(vref pi i)) | ||
582 : | (times2 (difference (quotient 3.0 (vref titi i)) | ||
583 : | (quotient 3.0 (vref titi (1+ i))))(vref pi (1+ i))) | ||
584 : | (times2 (quotient 3.0 (vref titi (1+ i)))(vref pi (+ i 2)))))) | ||
585 : | (vset array (- (* npoints npoints) 2) | ||
586 : | (quotient 1.0 (vref ti (- npoints 2)))) | ||
587 : | (cond (roundp | ||
588 : | (vset array (1- (* npoints npoints)) | ||
589 : | (plus | ||
590 : | (quotient 2.0 (vref ti (- npoints 2))) | ||
591 : | (quotient 2.0 (vref ti (1- npoints))))) | ||
592 : | (vset array (* (1- npoints) npoints) (quotient 1.0 (vref ti (1- npoints)))) | ||
593 : | (vset bi (1- npoints) | ||
594 : | (plus2 | ||
595 : | (times2 (quotient -3.0 (vref titi (- npoints 2))) | ||
596 : | (vref pi (- npoints 2))) | ||
597 : | (times2 (difference (quotient 3.0 (vref titi (- npoints 2))) | ||
598 : | (quotient 3.0 (vref titi (1- npoints)))) | ||
599 : | (vref pi (1- npoints))) | ||
600 : | (times2 (quotient 3.0 (vref titi (1- npoints))) | ||
601 : | (vref pi 0))))) | ||
602 : | (t | ||
603 : | (vset array (1- (* npoints npoints)) | ||
604 : | (quotient 2.0 (vref ti (- npoints 2)))) | ||
605 : | (vset bi (1- npoints) | ||
606 : | (times2 (quotient 3.0 (vref titi (- npoints 2))) | ||
607 : | (diff2 (vref pi (1- npoints))(vref pi (- npoints 2))))))) | ||
608 : | (do ((i 0 (1+ i)))((>= i npoints)) | ||
609 : | (vset bix i (car (vref bi i))) | ||
610 : | (vset biy i (cadr (vref bi i))) | ||
611 : | (vset dpix i 0.0) | ||
612 : | (vset dpiy i 0.0) | ||
613 : | ) | ||
614 : | ; (prind array) | ||
615 : | ; (prind bix) | ||
616 : | ; (prind biy) | ||
617 : | (gs npoints array dpix bix) | ||
618 : | (gs npoints array dpiy biy) | ||
619 : | (do ((i 0 (1+ i)))((>= i npoints)) | ||
620 : | (vset dpi i `(,(vref dpix i) ,(vref dpiy i)))) | ||
621 : | ; (prind pi) | ||
622 : | ; (prind dpi) | ||
623 : | (do ((i 0 (1+ i)) | ||
624 : | (ret)) | ||
625 : | ((>= i (1- npoints)) | ||
626 : | (push `(angle .,(vref pi (1- npoints))) ret) | ||
627 : | (and roundp | ||
628 : | (push `(bezier .,(plus2 (vref pi (1- npoints)) | ||
629 : | (times2 (times (vref ti (1- npoints)) 0.333333) | ||
630 : | (vref dpi (1- npoints))))) ret) | ||
631 : | (push `(bezier .,(plus2 (vref pi 0) | ||
632 : | (times2 (times (vref ti (1- npoints)) -0.333333) | ||
633 : | (vref dpi 0)))) ret) | ||
634 : | (push `(angle .,(vref pi 0)) ret)) | ||
635 : | (nreverse ret)) | ||
636 : | (push `(angle .,(vref pi i)) ret) | ||
637 : | (push `(bezier .,(plus2 (vref pi i) | ||
638 : | (times2 (times (vref ti i) 0.333333) | ||
639 : | (vref dpi i)))) ret) | ||
640 : | (push `(bezier .,(plus2 (vref pi (1+ i)) | ||
641 : | (times2 (times (vref ti i) -0.333333) | ||
642 : | (vref dpi (1+ i))))) ret)))) | ||
643 : | ; | ||
644 : | ; | ||
645 : | (defun line2 (p0 p1 width (dlist '(nil nil))) | ||
646 : | (lets ((diff (diff2 p1 p0)) | ||
647 : | (l0 (normlen2 width (rot270 diff)))) | ||
648 : | `(((angle .,(plus2 p0 l0)) | ||
649 : | (angle .,(plus2 p1 l0)) | ||
650 : | .,(car dlist)) | ||
651 : | ((angle .,(diff2 p0 l0)) | ||
652 : | (angle .,(diff2 p1 l0)) | ||
653 : | .,(cadr dlist))))) | ||
654 : | ; | ||
655 : | (defun gridxy (point) | ||
656 : | `(,(times meshsize | ||
657 : | (fix (plus 0.5 (quotient (car point) meshsize)))) | ||
658 : | ,(times meshsize | ||
659 : | (fix (plus 0.5 (quotient (cadr point) meshsize)))))) | ||
660 : | (defun gridhalfxy (point) | ||
661 : | `(,(plus (times 0.5 meshsize) | ||
662 : | (times meshsize | ||
663 : | (fix (quotient (car point) meshsize)))) | ||
664 : | ,(plus (times 0.5 meshsize) | ||
665 : | (times meshsize | ||
666 : | (fix (quotient (cadr point) meshsize)))))) | ||
667 : | (defun grid (point dotsize) | ||
668 : | (cond ((oddp dotsize) | ||
669 : | (gridxy point)) | ||
670 : | ((gridhalfxy point)))) | ||
671 : | ; | ||
672 : | (defun gridx (point dotsize) | ||
673 : | (cond ((not (oddp dotsize)) | ||
674 : | `(,(plus (times 0.5 meshsize) | ||
675 : | (times meshsize | ||
676 : | (fix (quotient (car point) meshsize)))) | ||
677 : | ,(cadr point))) | ||
678 : | (`(,(times meshsize | ||
679 : | (fix (plus 0.5 (quotient (car point) meshsize)))) | ||
680 : | ,(cadr point))))) | ||
681 : | ; | ||
682 : | (defun gridy (point dotsize) | ||
683 : | (cond ((not (oddp dotsize)) | ||
684 : | `(,(car point) | ||
685 : | ,(plus (times 0.5 meshsize) | ||
686 : | (times meshsize | ||
687 : | (fix (quotient (cadr point) meshsize)))))) | ||
688 : | (`(,(car point) | ||
689 : | ,(times meshsize | ||
690 : | (fix (plus 0.5 (quotient (cadr point) meshsize)))))))) | ||
691 : | ; | ||
692 : | (defun meshwidth (width) | ||
693 : | (fix (plus 0.5 (quotient (times 2 width) meshsize)))) | ||
694 : | ; | ||
695 : | (defun normwidth (dotsize) | ||
696 : | (times 0.5 meshsize (difference dotsize 0.5))) | ||
697 : | ; | ||
698 : | (defun inter (a b s) | ||
699 : | (plus (times (difference 1.0 s) a)(times s b))) | ||
700 : | ; | ||
701 : | (defun newbez (p0 p1 b0 b1 b2 b3) | ||
702 : | (lets ((crosses (cross2bez p0 p1 b0 b1 b2 b3)) | ||
703 : | (t1 (cdr crosses))(t2 (times t1 t1))(t3 (times t2 t1)) | ||
704 : | (db0 (times2 3.0 (diff2 b1 b0))) | ||
705 : | (db3 (times2 3.0 (diff2 b3 b2))) | ||
706 : | (n1 (plus2 | ||
707 : | (times2 t3 (plus2 (times2 2.0 (diff2 b0 b3)) | ||
708 : | db0 db3)) | ||
709 : | (times2 t2 (diff2 (times2 3.0 (diff2 b3 b0)) | ||
710 : | (plus2 (times2 2.0 db0) db3))) | ||
711 : | (times2 t1 db0) | ||
712 : | b0)) | ||
713 : | (dn1 (plus2 | ||
714 : | (times2 t2 (plus2 (times2 6.0 (diff2 b0 b3)) | ||
715 : | (times2 3.0 (plus2 db0 db3)))) | ||
716 : | (times2 t1 (diff2 (times2 6.0 (diff2 b3 b0)) | ||
717 : | (plus2 (times2 4.0 db0) (times2 2.0 db3)))) | ||
718 : | db0))) | ||
719 : | `(,b0 | ||
720 : | ,(plus2 b0 (times2 (quotient t1 3.0) db0)) | ||
721 : | ,(diff2 n1 (times2 (quotient t1 3.0) dn1)) | ||
722 : | ,n1))) | ||
723 : | |||
724 : |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |