外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
gawkで円弧の端点に矢印を描く
:gawkで円弧の端点に矢印を描く
@echo off
for /f %%n in ('gawk "/^#!/ { print NR }" %0') do (
copy jwc_temp.txt myfiles > nul
more +%%n %0 | gawk -f - myfiles > jwc_temp.txt
)
goto:eof
REM #jww
REM #1ci 円・円弧を指示してください
REM #bz
REM #e
#!ここから more +n %0 の n 行目:最初の行は 0 行
function deg(x) { return x / PI * 180 }
function rad(x) { return x * PI / 180 }
function cipoint(ci, pm) {
$0 = ci
x = $1
y = $2
r = $3
p1 = $4 ? $4 : 0
p2 = $5 ? $5 : 2*PI
w = $6 ? $6 : 1
d = $7 ? rad($7) : 0
co = cos(d)
si = sin(d)
if (pm == -1) { q = p1 } else { q = p2 }
q *= PI / 180.0
xr = r * cos(q)
yr = r * sin(q) * w
a = atan2(yr / w, xr * w) + d
return x + xr * co - yr * si FS y + xr * si + yr * co FS a
}
function hypot(x, y){
return sqrt(x * x + y * y)
}
function lnslope(x) { #線の角度を返す
$0 = x
return atan2($4 - $2, $3 - $1)
}
function ptdist(pt1, pt2) {
$0 = pt1 FS pt2
return hypot($3 - $1, $4 - $2)
}
function polar(r, d, w) { #方向余弦のセット
return r * cos(d) FS r * sin(d) * (w ? w : 1)
}
function rot(x, d, co, si) { #回転による点の座標変換(部材系→全体系)
co = cos(d)
si = sin(d)
return ($0 = x) ? $1 * co - $2 * si FS $1 * si + $2 * co : 0 FS 0
}
function moveto(x, y, d) { #点x を 相対距離 y [ a, b ] へ移動
if (d == "") d = 0
return ($0 = x FS (d == 0 ? y : rot(y, d))) ? ($1 + $3) FS ($2 + $4) : 0 FS 0
}
function polarto(x, r, d, w) { #点x を 極座標 [ r, d ] で相対的に移動する
return moveto(x, polar(r, d, w))
}
function arrow(pt1, d, size, xang, xan2) {
l = size
d *= PI / 180
a = xang * PI / 180 / 2.0
pt2 = polarto(pt1, l, d - a)
pt4 = polarto(pt1, l, d + a)
if (xan2 == 180) {
sl = "sl" FS pt1 FS pt2 FS pt4
} else {
b = (90.0 - xan2 / 2.0) * PI / 180
c = cos(a) - sin(a) * sin(b) / cos(b)
pt3 = polarto(pt1, l * c, d)
sl = "sl" FS pt1 FS pt2 FS pt3 FS pt4
}
return sl
}
BEGIN { CONVFMT = OFMT = "%.15g"; PI = atan2(1, 1) * 4 }
/^hq/ { print "bz" }
/^hp1ci/ { hp1 = $2 FS $3 }
/^ci/ {
x = $2; y = $3; r = $4; p1 = p2 = 0; w = 1; d = 0
if (NF == 8) { p1 = $5; p2 = $6; w = $7; d = $8 }
ci1 = x FS y FS r FS p1 FS p2 FS w FS d
$0 = cipoint(ci1, -1)
pt1 = $1 FS $2
a1 = $3 + PI / 2
$0 = cipoint(ci1, 1)
pt2 = $1 FS $2
a2 = $3 - PI /2
l1 = ptdist(hp1, pt1)
l2 = ptdist(hp1, pt2)
pm = l1 <= l2 ? -1 : 1
pt = pm == 1 ? pt2 : pt1
d = (pm == 1 ? a2 : a1)
print arrow(pt, deg(d), size = 5, xang = 45, xan2 = 120)
}