jw_cad 外部変形 - (1092) clispでソリッド図形の矩形を描く -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

clispでソリッド図形の矩形を描く

:clispでソリッド図形の矩形を描く
@echo off
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
  more +%%n %0 | clisp -q > nul
)
goto:eof

REM #jww
REM #1-%d 矩形の始点を指示してください
REM #2%d 対頂点を指示してください
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)
    )
)
( ;数値 xd0 (倍精度 double-float) を 文字列 "x" に変換
  defun to_s (x)
    (if (equal x nil) (setq x 0))
    (if (listp x)
        (mapcar #'to_s x)
        (progn
          (if (stringp x) nil (setq x (write-to-string x)))
          (if (search "d0" x)
              (subseq x 0 (search "d" x))
              (if (search "d" x)
                  (progn
                    (setq s (search "d" x))
                    (concatenate 'string (subseq x 0 s) "e" (subseq x (+ 1 s) (length x)))
                  )
                  x
              )
          )
        ) ;progn (listp x)
    )
)
;本文
( ;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 "^hk" line) (setq hk (cadr a)) nil)
    (if (regexp:match "^hp1" line) (setq p1 (cdr a)) nil)
    (if (regexp:match "^hp2" line) (setq p2 (cdr a)) nil)
  )
)
( ;準備計算
  progn
  (setq hk (to_f hk))
  (setq x1 (to_f (car p1)))
  (setq y1 (to_f (cadr p1)))
  (setq x2 (to_f (car p2)))
  (setq y2 (to_f (cadr p2)))
  (setq co (cos (* hk (/ pi 180))))
  (setq si (sin (* hk (/ pi 180))))
  (setq ww (+ (* (- x2 x1) co) (* (- y2 y1) si)))
  (setq hh (- (* (- y2 y1) co) (* (- x2 x1) si)))
  (setq x3 (- x1 (* hh si)))
  (setq y3 (+ y1 (* hh co)))
  (setq x4 (+ x1 (* ww co)))
  (setq y4 (+ y1 (* ww si)))
  (multiple-value-setq (r g b) (values 0 128 128))
  (setq p3 (to_s (list x3 y3)))
  (setq p4 (to_s (list x4 y4)))
)
( ;jwc_temp.txt へ 出力
  with-open-file (f "jwc_temp.txt" :direction :output)
    (format f "lc10 ~a~%" (+ r (* 256 g) (* 256 256 b)))
    (format f "sl~{ ~a~}~%" (append p1 p3 p2 p4))
)