jw_cad 外部変形 - (1025) tclshで2点間の勾配を計算する(ptslope) -

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

 

tclshで2点間の勾配を計算する(ptslope)

:tclshで2点間の勾配を計算する(ptslope)
@echo off
for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
  copy jwc_temp.txt myfiles > nul
  more +%%n %0 | tclsh - > jwc_temp.txt
)
goto:eof

REM #jww
REM #1-%d 始点を指示してください
REM #2%d 終点を指示してください
REM #e

#!この次の行からプログラムを書いてください
set tcl_precision 16; #文字列を数値演算するとき有効桁数 16 (デフォルト 12)
set PI [expr acos(-1)]
set hk 0

set f [open myfiles]
foreach 0 [split [read $f] \n] {
  lassign $0 1 2 3
  switch -regexp -- $0 {
    ^hk {
      lassign $0 1 hk
      continue
    }
    ^hp1 { set p1 "$2 $3" }
    ^hp2 { set p2 "$2 $3"
      lassign "$p1 $p2" 1 2 3 4
      puts [format "h#2点間の勾配∠ = %.03f゚" \
        [expr atan2($4 - $2, $3 - $1) * 180 / $PI - $hk]]
    }
  }
}
close $f