外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。
rubyで円弧の端点に矢印を描く
:rubyで円弧の端点に矢印を描く
@echo off
ruby -x %0 jwc_temp.txt
goto:eof
REM #jww
REM #1ci 円・円弧を指示してください
REM #bz
REM #e
#!ruby -Ks -an -i.bak
def ptdist(pt1, pt2)
return hypot(pt2[0] - pt1[0], pt2[1] - pt1[1])
end
def polarto(pt, r, d)
return [pt[0] + r * cos(d), pt[1] + r * sin(d)]
end
def arrow(pt1, d, pm, size = 3, xang = 60, xan2 = 90)
l = -size * pm
a = xang * PI / 180 / 2.0
pt2 = polarto(pt1, l, d - a)
pt4 = polarto(pt1, l, d + a)
if xan2 == 180
sl = pt1 + pt2 + pt4
else
c = cos(a) - sin(a) * tan((90.0 - xan2 / 2.0) * PI / 180)
pt3 = polarto(pt1, l * c, d)
sl = pt1 + pt2 + pt3 + pt4
end
puts "sl" + " %s" * sl.size % sl
end
def cipoint(ci, pm = 1)
x, y, r, p1, p2, w, d = ci
d *= PI / 180
co = cos(d)
si = sin(d)
q = (pm == -1 ? p1 : p2) * PI / 180
xr = cos(q) * r
yr = sin(q) * r * w
a = atan2(yr / w, xr * w) + d
return [x + xr * co - yr * si, y + xr * si + yr * co], a
end
BEGIN { include Math }
case $_
when /^hp1ci/
pt = $F[1..2].map{|x| x.to_f}
when /^ci/
ci = $F[1..-1].map{|x| x.to_f}
if ci.size == 3
ci += [0, 0, 1.0, 0]
end
puts "bz"
size = 5 #矢印の長さ( 図寸 )
xang = 45 #矢印の交角( ゚ )
xan2 = 120 #矢尻の交角( ゚ )
pt1, a1 = cipoint(ci,-1)
pt2, a2 = cipoint(ci, 1)
l1 = ptdist(pt, pt1)
l2 = ptdist(pt, pt2)
pm = l1 <= l2 ? -1 : 1
if pm == -1
arrow(pt1, a1 + PI / 2, pm, size, xang, xan2)
elsif pm == 1
arrow(pt2, a2 + PI / 2, pm, size, xang, xan2)
end
end
__END__