外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
clispで線の端点に矢印を描く
:clispで線の端点に矢印を描く
@echo off
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
more +%%n %0 | clisp -q > nul
)
goto:eof
REM #jww
REM #1ln 線を指示してください
REM #bz
REM #e
#!この次の行からプログラムを書いてください
;ユーザ定義関数
( ;文字列 "x" を 数値 xd0 (倍精度 double-float) に変換
defun to_f (x)
(if (equal x nil) (setq x "0"))
(if (listp x)
(mapcar #'to_f x)
(progn
(if (typep x 'double-float)
x
(progn
(if (stringp x) nil (setq x (write-to-string x)))
(if (search "e" x)
(progn
(setq s (search "e" x))
(read-from-string
(concatenate 'string (subseq x 0 s) "d" (subseq x (+ 1 s) (length x)))
)
) ;progn (search "e" x)
(if (search "d" x)
x
(read-from-string
(concatenate 'string x "d0")
)
)
)
) ;progn (typep x 'double-float)
)
) ;progn (listp x)
)
)
( ;線長を返す
; x : (x1 y1 x2 y2)
defun lnlength (x)
(setq x1 (to_f (nth 0 x)))
(setq y1 (to_f (nth 1 x)))
(setq x2 (to_f (nth 2 x)))
(setq y2 (to_f (nth 3 x)))
(sqrt (+ (* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y1))))
)
( ;線角を返す
; x : (x1 y1 x2 y2)
defun lnslope (x)
(setq x1 (to_f (nth 0 x)))
(setq y1 (to_f (nth 1 x)))
(setq x2 (to_f (nth 2 x)))
(setq y2 (to_f (nth 3 x)))
(atan (- y2 y1) (- x2 x1))
)
( ;2点間の距離を返す
; x : (x1 y1)
; y : (x2 y2)
defun ptdist (x y)
(lnlength (append x y))
)
(
defun polarto (pt r d)
(setq x1 (to_f (nth 0 pt)))
(setq y1 (to_f (nth 1 pt)))
(list (+ x1 (* r (cos d))) (+ y1 (* r (sin d))))
)
(
defun arrow (pt1 d pm &optional (size 3d0) (xang 60d0) (xan2 90d0))
(setq l (* (* -1 size) pm))
(setq a (/ (* xang (/ pi 180)) 2d0))
(setq pt2 (polarto pt1 l (- d a)))
(setq pt4 (polarto pt1 l (+ d a)))
(if (= xan2 180)
(append pt1 pt2 pt4)
(progn
(setq c (- (cos a) (* (sin a) (tan (* (- 90 (/ xan2 2d0)) (/ pi 180))))))
(setq pt3 (polarto pt1 (* l c) d))
(append pt1 pt2 pt3 pt4)
)
)
)
;本文
( ;jwc_temp.txt から 入力
with-open-file (f "jwc_temp.txt" :direction :input)
(loop for line = (read-line f nil) while line do
(setq a (regexp:regexp-split "\\s\\+" line))
(if (regexp:match "^hp1ln" line) (setq pt (cdr a)))
(if (regexp:match "^\\s\\+" line) (setq ln1 (cdr a)))
)
)
( ;準備計算
progn
(setq size 5d0) ;矢印の長さ( 図寸 )
(setq xang 45d0) ;矢印の交角( ゚ )
(setq xan2 120d0) ;矢尻の交角( ゚ )
(setq d (lnslope ln1))
(setq l1 (ptdist pt (subseq ln1 0 2)))
(setq l2 (ptdist pt (subseq ln1 2 4)))
(setq pm (if (<= l1 l2) -1 1))
(setq x1 (to_f (nth 0 ln1)))
(setq y1 (to_f (nth 1 ln1)))
(setq x2 (to_f (nth 2 ln1)))
(setq y2 (to_f (nth 3 ln1)))
(setq pt1 (if (= pm 1) (list x2 y2) (list x1 y1)))
)
( ;jwc_temp.txt へ 出力
with-open-file (g "jwc_temp.txt" :direction :output)
(write-line "bz" g)
(format g "sl~{ ~f~}~%" (arrow pt1 d pm size xang xan2))
)