外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
tclshでレムニスケートを描く
:tclshでレムニスケートを描く
@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 X軸上の点を指示してください
REM #e
#!この次の行からプログラムを書いてください
proc f {p} {
return [expr cos($p) * sqrt(1.0 - 0.5 * pow(sin($p), 2))]
}
proc g {p} {
return [expr sin($p) * cos($p) / sqrt(2.0)]
}
set tcl_precision 16; #文字列を数値演算するとき有効桁数 16 (デフォルト 12)
set PI [expr acos(-1)]
set f [open myfiles]
foreach 0 [split [read $f] \n] {
lassign $0 1 2 3
switch -regexp -- $0 {
^hp1 { set p1 "$2 $3" }
^hp2 { set p2 "$2 $3" }
}
}
close $f
lassign "$p1 $p2" x1 y1 x2 y2
set n 100
set a [expr hypot($x2 - $x1, $y2 - $y1)]
set d [expr atan2($y2 - $y1, $x2 - $x1) + $PI / 2]
set co [expr cos($d)]
set si [expr sin($d)]
set p [expr 2 * $PI / $n]
for {set i 0} {$i <= $n} {incr i} {
set x [expr $a * [f [expr $i * $p]]]
set y [expr $a * [g [expr $i * $p]]]
puts "[expr $x * $si + $y * $co + $x1]\
[expr -$x * $co + $y * $si + $y1]"
}