Revision: 1.1.1.1 - (view) (download)
1 : | ktanaka | 1.1 | ; |
2 : | ; アレイの定義 | ||
3 : | ; | ||
4 : | (defun array-rank (a) | ||
5 : | (cond ((vectorp a) (1+ (array-rank (vref a 0)))) | ||
6 : | (t 0))) | ||
7 : | ; | ||
8 : | (defun array-dimension (a dim) | ||
9 : | (lets ((tmparray a)) | ||
10 : | (do ((i 0 (1+ i))) | ||
11 : | ((= i dim)) | ||
12 : | (setq tmparray (vref tmparray 0))) | ||
13 : | (vector-length tmparray))) | ||
14 : | ; | ||
15 : | (defun array-dimensions (a) | ||
16 : | (lets ((dimlist)) | ||
17 : | (do ((tmparray a (vref tmparray 0))) | ||
18 : | ((not (vectorp tmparray))) | ||
19 : | (push (vector-length tmparray) dimlist)) | ||
20 : | (reverse dimlist))) | ||
21 : | ; | ||
22 : | ;(defun make-array (dimlist) | ||
23 : | ; (lets ((tmpvec)) | ||
24 : | ; (do ((rev (reverse dimlist) (cdr rev))) | ||
25 : | ; ((atom rev)) | ||
26 : | ; (print rev) | ||
27 : | ; (setq tmpvec (vector (car rev) `(,tmpvec))) | ||
28 : | ; (print-vec tmpvec) | ||
29 : | ; ) | ||
30 : | ; tmpvec)) | ||
31 : | ; | ||
32 : | |||
33 : | |||
34 : | |||
35 : | ; | ||
36 : | ; ベクトルの加算 | ||
37 : | ; | ||
38 : | (defun vplus (v1 v2) | ||
39 : | (cond ((= (vector-length v1) (vector-length v2)) | ||
40 : | (lets ((l (vector-length v1))(v (vector l))) | ||
41 : | (do ((i 0 (1+ i))) | ||
42 : | ((= i l)) | ||
43 : | (vset v i (plus (vref v1 i)(vref v2 i)))) | ||
44 : | v)) | ||
45 : | (t nil))) | ||
46 : | ; | ||
47 : | ; ベクトルの減算 | ||
48 : | ; | ||
49 : | (defun vminus (v1 v2) | ||
50 : | (cond ((= (vector-length v1)(vector-length v2)) | ||
51 : | (lets ((l (vector-length v1))(v (vector l))) | ||
52 : | (do ((i 0 (1+ i))) | ||
53 : | ((= i l)) | ||
54 : | (vset v i (difference (vref v1 i)(vref v2 i)))) | ||
55 : | v)) | ||
56 : | (t nil))) | ||
57 : | ; | ||
58 : | ; ベクトルの加算(自動拡張あり) | ||
59 : | ; | ||
60 : | (defun vpluse (v1 v2) | ||
61 : | (lets ((l1 (vector-length v1))(l2 (vector-length v2)) | ||
62 : | (v (vector (max l1 l2)))) | ||
63 : | (do ((i 0 (1+ i))) | ||
64 : | ((= i (min l1 l2))) | ||
65 : | (vset v i (plus (vref v1 i)(vref v2 i)))) | ||
66 : | (cond ((> l1 l2) | ||
67 : | (do ((i l2 (1+ i))) | ||
68 : | ((= i l1)) | ||
69 : | (vset v i (vref v1 i)))) | ||
70 : | (t (do ((i l1 (1+ i))) | ||
71 : | ((= i l2)) | ||
72 : | (vset v i (vref v2 i))))) | ||
73 : | v)) | ||
74 : | ; | ||
75 : | ; ベクトルの減算(自動拡張あり) | ||
76 : | ; | ||
77 : | (defun vminuse (v1 v2) | ||
78 : | (lets ((l1 (vector-length v1))(l2 (vector-length v2)) | ||
79 : | (v (vector (max l1 l2)))) | ||
80 : | (do ((i 0 (1+ i))) | ||
81 : | ((= i (min l1 l2))) | ||
82 : | (vset v i (difference (vref v1 i)(vref v2 i)))) | ||
83 : | (cond ((> l1 l2) | ||
84 : | (do ((i l2 (1+ i))) | ||
85 : | ((= i l1)) | ||
86 : | (vset v i (vref v1 i)))) | ||
87 : | (t (do ((i l1 (1+ i))) | ||
88 : | ((= i l2)) | ||
89 : | (vset v i (minus (vref v2 i)))))) | ||
90 : | v)) | ||
91 : | ; | ||
92 : | ; ベクトルのスカラー倍 | ||
93 : | ; | ||
94 : | (defun vtimes (v k) | ||
95 : | (mapvector v #'(lambda (e)(times e k)))) | ||
96 : | ; | ||
97 : | ; ベクトルの要素ごとの積 | ||
98 : | ; | ||
99 : | (defun vproduct (v1 v2) | ||
100 : | (cond ((= (vector-length v1)(vector-length v2)) | ||
101 : | (lets ((l (vector-length v1))(v (vector l))) | ||
102 : | (do ((i 0 (1+ i))) | ||
103 : | ((= i l)) | ||
104 : | (vset v i (times (vref v1 i)(vref v2 i)))) | ||
105 : | v)) | ||
106 : | (t nil))) | ||
107 : | ; | ||
108 : | ; ベクトルの内積 | ||
109 : | ; | ||
110 : | (defun vip (v1 v2) | ||
111 : | (cond ((= (vector-length v1)(vector-length v2)) | ||
112 : | (do ((i 0 (1+ i)) | ||
113 : | (l (vector-length v1)) | ||
114 : | (sum 0 (plus sum (times (vref v1 i)(vref v2 i))))) | ||
115 : | ((= i l) sum))) | ||
116 : | (t nil))) | ||
117 : | ; | ||
118 : | ; 行列(=ベクトルのベクトル)のある要素へのアクセス | ||
119 : | ; | ||
120 : | (defun matrix (v i j) | ||
121 : | (cond ((and (<= 0 i)(> (vector-length v) i)) | ||
122 : | (cond ((and (<= 0 j)(> (vector-length (vref v i)) j)) | ||
123 : | (vref (vref v i) j)) | ||
124 : | (t nil))) | ||
125 : | (t nil))) | ||
126 : | ; | ||
127 : | ; 4元連立一次方程式を解く(ピボットなし) | ||
128 : | ; | ||
129 : | (defun solve4 (a1 a2 a3 a4 b) | ||
130 : | (lets ((a11 (float(car a1)))(a12 (float(cadr a1)))(a13 (float(caddr a1)))(a14 (float(cadddr a1))) | ||
131 : | (a21 (float(car a2)))(a22 (float(cadr a2)))(a23 (float(caddr a2)))(a24 (float(cadddr a2))) | ||
132 : | (a31 (float(car a3)))(a32 (float(cadr a3)))(a33 (float(caddr a3)))(a34 (float(cadddr a3))) | ||
133 : | (a41 (float(car a4)))(a42 (float(cadr a4)))(a43 (float(caddr a4)))(a44 (float(cadddr a4))) | ||
134 : | (b1 (float(car b)))(b2 (float(cadr b)))(b3 (float(caddr b)))(b4 (float(cadddr b))) | ||
135 : | ; 1st | ||
136 : | (a12 (//$ a12 a11)) | ||
137 : | (a13 (//$ a13 a11)) | ||
138 : | (a14 (//$ a14 a11)) | ||
139 : | (b1 (//$ b1 a11)) | ||
140 : | (a22 (-$ a22 (*$ a21 a12))) | ||
141 : | (a23 (-$ a23 (*$ a21 a13))) | ||
142 : | (a24 (-$ a24 (*$ a21 a14))) | ||
143 : | (b2 (-$ b2 (*$ a21 b1))) | ||
144 : | (a32 (-$ a32 (*$ a31 a12))) | ||
145 : | (a33 (-$ a33 (*$ a31 a13))) | ||
146 : | (a34 (-$ a34 (*$ a31 a14))) | ||
147 : | (b3 (-$ b3 (*$ a31 b1))) | ||
148 : | (a42 (-$ a42 (*$ a41 a12))) | ||
149 : | (a43 (-$ a43 (*$ a41 a13))) | ||
150 : | (a44 (-$ a44 (*$ a41 a14))) | ||
151 : | (b4 (-$ b4 (*$ a41 b1))) | ||
152 : | ; 2nd | ||
153 : | (a23 (//$ a23 a22)) | ||
154 : | (a24 (//$ a24 a22)) | ||
155 : | (b2 (//$ b2 a22)) | ||
156 : | (a13 (-$ a13 (*$ a12 a23))) | ||
157 : | (a14 (-$ a14 (*$ a12 a24))) | ||
158 : | (b1 (-$ b1 (*$ a12 b2))) | ||
159 : | (a33 (-$ a33 (*$ a32 a23))) | ||
160 : | (a34 (-$ a34 (*$ a32 a24))) | ||
161 : | (b3 (-$ b3 (*$ a32 b2))) | ||
162 : | (a43 (-$ a43 (*$ a42 a23))) | ||
163 : | (a44 (-$ a44 (*$ a42 a24))) | ||
164 : | (b4 (-$ b4 (*$ a42 b2))) | ||
165 : | ; 3rd | ||
166 : | (a34 (//$ a34 a33)) | ||
167 : | (b3 (//$ b3 a33)) | ||
168 : | (a14 (-$ a14 (*$ a13 a34))) | ||
169 : | (b1 (-$ b1 (*$ a13 b3))) | ||
170 : | (a24 (-$ a24 (*$ a23 a34))) | ||
171 : | (b2 (-$ b2 (*$ a23 b3))) | ||
172 : | (a44 (-$ a44 (*$ a43 a34))) | ||
173 : | (b4 (-$ b4 (*$ a43 b3))) | ||
174 : | ; 4th | ||
175 : | (b4 (//$ b4 a44)) | ||
176 : | (b1 (-$ b1 (*$ a14 b4))) | ||
177 : | (b2 (-$ b2 (*$ a24 b4))) | ||
178 : | (b3 (-$ b3 (*$ a34 b4)))) | ||
179 : | (list b1 b2 b3 b4))) | ||
180 : | ; | ||
181 : | ; 4元連立一次方程式を解く(ピボットあり) | ||
182 : | ; | ||
183 : | (defun solve4p (a1 a2 a3 a4 b) | ||
184 : | (lets ((m1 (vector 5 `(,(float (car a1)),(float (cadr a1)),(float (caddr a1)),(float (cadddr a1)),(float (car b))))) | ||
185 : | (m2 (vector 5 `(,(float (car a2)),(float (cadr a2)),(float (caddr a2)),(float (cadddr a2)),(float (cadr b))))) | ||
186 : | (m3 (vector 5 `(,(float (car a3)),(float (cadr a3)),(float (caddr a3)),(float (cadddr a3)),(float (caddr b))))) | ||
187 : | (m4 (vector 5 `(,(float (car a4)),(float (cadr a4)),(float (caddr a4)),(float (cadddr a4)),(float (cadddr b))))) | ||
188 : | (m (vector 4 (list m1 m2 m3 m4)))) | ||
189 : | (do ((i 0 (1+ i)) | ||
190 : | (v (vector 5)) | ||
191 : | (p -1)) | ||
192 : | ((>= i 4)) | ||
193 : | (do ((ii (1+ i) (1+ ii))) | ||
194 : | ((>= ii 4)) | ||
195 : | (cond ((>$ (abs (vref (vref m ii) i))(abs (vref (vref m i) i))) | ||
196 : | (setq p ii)))) | ||
197 : | (cond ((> p i) | ||
198 : | ; (format "p =/c is larger than i =/c, Swapping!!/n" p i) | ||
199 : | (setq v (vref m i)) | ||
200 : | (vset m i (vref m p)) | ||
201 : | (vset m p v))) | ||
202 : | (vset m i (vtimes (vref m i)(//$ 1.0 (vref (vref m i) i)))) | ||
203 : | (do ((ii 0 (1+ ii))) | ||
204 : | ((>= ii i)) | ||
205 : | (vset m ii | ||
206 : | (vminus (vref m ii) (vtimes (vref m i)(vref (vref m ii) i))))) | ||
207 : | (do ((ii (1+ i) (1+ ii))) | ||
208 : | ((>= ii 4)) | ||
209 : | (vset m ii | ||
210 : | (vminus (vref m ii) (vtimes (vref m i)(vref (vref m ii) i))))) | ||
211 : | ; (do ((l 0 (1+ l))) | ||
212 : | ; ((>= l 4)) | ||
213 : | ; (print-vec (vref m l))) | ||
214 : | ) | ||
215 : | (list (vref (vref m 0) 4)(vref (vref m 1) 4)(vref (vref m 2) 4)(vref (vref m 3) 4)))) | ||
216 : | ; | ||
217 : | ; 幅のあるベジェ曲線(ピボットなし) | ||
218 : | ; | ||
219 : | (defun curveto (z1 z2 z3 z4 w) | ||
220 : | (lets ((l (times2 0.25 (plus2 (plus2 z1 z2) (plus2 z2 z3)))) | ||
221 : | (r (times2 0.25 (plus2 (plus2 z2 z3) (plus2 z3 z4)))) | ||
222 : | (v1 (diff2 z2 z1)) | ||
223 : | (v2 (diff2 z3 z4)) | ||
224 : | (zi1 (plus2 z1 (times2 w (norm2 (rot90 v1))))) | ||
225 : | (zo1 (plus2 z1 (times2 w (norm2 (rot270 v1))))) | ||
226 : | (zi4 (plus2 z4 (times2 w (norm2 (rot270 v2))))) | ||
227 : | (zo4 (plus2 z4 (times2 w (norm2 (rot90 v2))))) | ||
228 : | (c (times2 0.5 (plus2 l r))) | ||
229 : | (vc (diff2 r l)) | ||
230 : | (ci (plus2 c (times2 w (norm2 (rot90 vc))))) | ||
231 : | (co (plus2 c (times2 w (norm2 (rot270 vc))))) | ||
232 : | (l1 (list (times 2 (car v1)) (car v2) (times -4 (car vc)) 0)) | ||
233 : | (l2 (list (times 2 (cadr v1)) (cadr v2) (times -4 (cadr vc)) 0)) | ||
234 : | (l3 (list (car v1) (times 2 (car v2)) 0 (times -4 (car vc)))) | ||
235 : | (l4 (list (cadr v1) (times 2 (cadr v2)) 0 (times -4 (cadr vc)))) | ||
236 : | (bi (list (plus (times -3 (car zi1))(times -1 (car zi4))(times 4 (car ci))) | ||
237 : | (plus (times -3 (cadr zi1))(times -1 (cadr zi4))(times 4 (cadr ci))) | ||
238 : | (plus (times -1 (car zi1))(times -3 (car zi4))(times 4 (car ci))) | ||
239 : | (plus (times -1 (cadr zi1))(times -3 (cadr zi4))(times 4 (cadr ci))))) | ||
240 : | (bo (list (plus (times -3 (car zo1))(times -1 (car zo4))(times 4 (car co))) | ||
241 : | (plus (times -3 (cadr zo1))(times -1 (cadr zo4))(times 4 (cadr co))) | ||
242 : | (plus (times -1 (car zo1))(times -3 (car zo4))(times 4 (car co))) | ||
243 : | (plus (times -1 (cadr zo1))(times -3 (cadr zo4))(times 4 (cadr co))))) | ||
244 : | (ansi (solve4 l1 l2 l3 l4 bi)) | ||
245 : | (anso (solve4 l1 l2 l3 l4 bo))) | ||
246 : | (list (list zi1 (list (plus (car zi1)(times (car ansi)(car v1)))(plus (cadr zi1)(times (car ansi)(cadr v1)))) | ||
247 : | (list (plus (car zi4)(times (cadr ansi)(car v2)))(plus (cadr zi4)(times (cadr ansi)(cadr v2)))) zi4) | ||
248 : | (list zo1 (list (plus (car zo1)(times (car anso)(car v1)))(plus (cadr zo1)(times (car anso)(cadr v1)))) | ||
249 : | (list (plus (car zo4)(times (cadr anso)(car v2)))(plus (cadr zo4)(times (cadr anso)(cadr v2)))) zo4)))) | ||
250 : | ; | ||
251 : | ; 幅のあるベジェ曲線(2)(ピボットあり) | ||
252 : | ; | ||
253 : | (defun curvetop (z1 z2 z3 z4 w) | ||
254 : | (lets ((l (times2 0.25 (plus2 (plus2 z1 z2) (plus2 z2 z3)))) | ||
255 : | (r (times2 0.25 (plus2 (plus2 z2 z3) (plus2 z3 z4)))) | ||
256 : | (v1 (diff2 z2 z1)) | ||
257 : | (v2 (diff2 z3 z4)) | ||
258 : | (zi1 (plus2 z1 (times2 w (norm2 (rot90 v1))))) | ||
259 : | (zo1 (plus2 z1 (times2 w (norm2 (rot270 v1))))) | ||
260 : | (zi4 (plus2 z4 (times2 w (norm2 (rot270 v2))))) | ||
261 : | (zo4 (plus2 z4 (times2 w (norm2 (rot90 v2))))) | ||
262 : | (c (times2 0.5 (plus2 l r))) | ||
263 : | (vc (diff2 r l)) | ||
264 : | (ci (plus2 c (times2 w (norm2 (rot90 vc))))) | ||
265 : | (co (plus2 c (times2 w (norm2 (rot270 vc))))) | ||
266 : | (l1 (list (times -1 (car v1)) (car v2) (times -4 (car vc)) 0)) | ||
267 : | (l2 (list (times -1 (cadr v1)) (cadr v2) (times -4 (cadr vc)) 0)) | ||
268 : | (l3 (list (times 2 (car v1)) (car v2) 0 (times 4 (car vc)))) | ||
269 : | (l4 (list (times 2 (cadr v1)) (cadr v2) 0 (times 4 (cadr vc)))) | ||
270 : | (bi (list (plus (times 2 (car zi1))(times -2 (car zi4))) | ||
271 : | (plus (times 2 (cadr zi1))(times -2 (cadr zi4))) | ||
272 : | (plus (times -3 (car zi1))(times -1 (car zi4))(times 4 (car ci))) | ||
273 : | (plus (times -3 (cadr zi1))(times -1 (cadr zi4))(times 4 (cadr ci))))) | ||
274 : | (bo (list (plus (times 2 (car zo1))(times -2 (car zo4))) | ||
275 : | (plus (times 2 (cadr zo1))(times -2 (cadr zo4))) | ||
276 : | (plus (times -3 (car zo1))(times -1 (car zo4))(times 4 (car co))) | ||
277 : | (plus (times -3 (cadr zo1))(times -1 (cadr zo4))(times 4 (cadr co))))) | ||
278 : | (ansi (solve4p l1 l2 l3 l4 bi)) | ||
279 : | (anso (solve4p l1 l2 l3 l4 bo))) | ||
280 : | (list (list zi1 (list (plus (car zi1)(times (car ansi)(car v1)))(plus (cadr zi1)(times (car ansi)(cadr v1)))) | ||
281 : | (list (plus (car zi4)(times (cadr ansi)(car v2)))(plus (cadr zi4)(times (cadr ansi)(cadr v2)))) zi4) | ||
282 : | (list zo1 (list (plus (car zo1)(times (car anso)(car v1)))(plus (cadr zo1)(times (car anso)(cadr v1)))) | ||
283 : | (list (plus (car zo4)(times (cadr anso)(car v2)))(plus (cadr zo4)(times (cadr anso)(cadr v2)))) zo4)))) | ||
284 : | ; | ||
285 : | ; 簡単な出力 | ||
286 : | ; | ||
287 : | ;(drawcurves (curvetop z1 z2 z3 z3 width)) として使う | ||
288 : | (defun drawcurves (lines (psfile 'testcurve.ps)) | ||
289 : | (lets ((standard-output (outopen (stream psfile))) | ||
290 : | (zi (car lines))(zo (cadr lines)) | ||
291 : | (zi1 (car zi))(zi2 (cadr zi))(zi3 (caddr zi))(zi4 (cadddr zi)) | ||
292 : | (zo1 (car zo))(zo2 (cadr zo))(zo3 (caddr zo))(zo4 (cadddr zo)) | ||
293 : | (date (date-time))) | ||
294 : | (format "%!/nnewpath/n") | ||
295 : | (format "//X {moveto currentlinewidth 1 setlinewidth 5 5 rmoveto -10 -10 rlineto 10 0 rmoveto -10 10 rlineto stroke setlinewidth} def/n") | ||
296 : | (format "//Times-Roman findfont 20 scalefont setfont/n") | ||
297 : | (format "50 50 moveto (/c /c-/c-/c /c:/c) show/n" | ||
298 : | psfile (substring date 0 2)(substring date 2 4) | ||
299 : | (substring date 4 6)(substring date 6 8) | ||
300 : | (substring date 8 10)) | ||
301 : | (format "100 100 translate/n") | ||
302 : | (format "2 setlinewidth/n") | ||
303 : | (format "/c /c moveto " (fix (car zi1))(fix (cadr zi1))) | ||
304 : | (format "/c /c /c /c /c /c curveto stroke/n" (fix (car zi2))(fix (cadr zi2))(fix (car zi3))(fix (cadr zi3))(fix (car zi4))(fix (cadr zi4))) | ||
305 : | (format "/c /c moveto " (fix (car zo1))(fix (cadr zo1))) | ||
306 : | (format "/c /c /c /c /c /c curveto stroke/n" (fix (car zo2))(fix (cadr zo2))(fix (car zo3))(fix (cadr zo3))(fix (car zo4))(fix (cadr zo4))) | ||
307 : | (format "/c /c X /c /c X /c /c X /c /c X/n" (fix (car zi1))(fix (cadr zi1))(fix (car zi2))(fix (cadr zi2))(fix (car zi3))(fix (cadr zi3))(fix (car zi4))(fix (cadr zi4))) | ||
308 : | (format "/c /c X /c /c X /c /c X /c /c X/n" (fix (car zo1))(fix (cadr zo1))(fix (car zo2))(fix (cadr zo2))(fix (car zo3))(fix (cadr zo3))(fix (car zo4))(fix (cadr zo4))) | ||
309 : | (format "showpage/n"))) | ||
310 : | ; | ||
311 : | ; | ||
312 : | ; | ||
313 : |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |