if kouten_x>=x1_1 && kouten_x<=x1_2
x=kouten_x-x1_1
y=kouten_y-y1_1
xy=sqrt(x**2+y**2)
kouten_xt=x1_1+xy*cos(sen1_arg)
kouten_yt=y1_1+xy*sin(sen1_arg)
return [kouten_xt,kouten_yt]
end
end
end
def ika3(x)
a=(((x.to_f)*1000).to_i/1000.to_f)
return a
end
#範囲の内(true)外(false)を返す
def area(x,y)
hn=[]
open("temp.txt","r"){|f|
while line=f.gets
xy =line.split
if xy[0] =~ /^hn/
hnx1=xy[1].to_f
hny1=xy[2].to_f
hnx2=xy[3].to_f
hny2=xy[4].to_f
hn<<[hnx1,hny1,hnx1,hny2]
hn<<[hnx1,hny2,hnx2,hny2]
hn<<[hnx2,hny2,hnx2,hny1]
hn<<[hnx2,hny1,hnx1,hny1]
end
end
}
zahyo=[]
hn.each{|item|zahyo< if zahyo.size==1 or zahyo.size>1 && zahyo.size%2==1
return true
else
return false
end
end
k_sen=[]
while ARGF.gets
xy=split
if xy[0]=~/^[^\d,-]/
kyokusen=xy[0]
end
if xy[0]=~/^\d|^-/
if kyokusen=="pl"
xy.collect!{|item|item.to_f}
k_sen< end
end
end
if k_sen.size>0
puts "hd"
open("temp.txt","r"){|f|
while line=f.gets
xy=line.split
if xy[0]=~/^hq/
elsif xy[0]=~/^[^\d,-]/
kyokusen2=xy[0]
print line
elsif xy[0]=~/^\d|^-/
kouten=[]
xy.collect!{|item|item.to_f}
n=0
if kyokusen2!="pl"
k_sen.each{|item|
if sen_sen_kouten3(item,xy) !=nil
if xy[0]==xy[2]
if area(xy[2],xy[3]) && area(xy[0],xy[1])==false
kouten<< [x1,y1,xy[0],xy[1]]
elsif area(xy[0],xy[1]) && area(xy[2],xy[3])==false
kouten<< [x1,y1,xy[2],xy[3]]
else
kouten<< [x1,y1,xy[2],xy[3]] if (xy[1]-y1).abs<(xy[3]-y1).abs;kouten<< [x1,y1,xy[0],xy[1]] if (xy[1]-y1).abs>(xy[3]-y1).abs
end
else
if area(xy[2],xy[3]) && area(xy[0],xy[1])==false
kouten<< [x1,y1,xy[0],xy[1]]
elsif area(xy[0],xy[1]) && area(xy[2],xy[3])==false
kouten<< [x1,y1,xy[2],xy[3]]
else
kouten<< [x1,y1,xy[2],xy[3]] if (xy[0]-x1).abs<(xy[2]-x1).abs;kouten<< [x1,y1,xy[0],xy[1]] if (xy[0]-x1).abs>(xy[2]-x1).abs
end
end
n+=1
end
}
if kouten.size>1
kouten2=[]
kouten.each{|item|
kouten2< itemx=item[2]-item[0]
itemy=item[3]-item[1]
itemxy=sqrt(itemx**2+itemy**2)
kouten2x=kouten2[0][2]-kouten2[0][0]
kouten2y=kouten2[0][3]-kouten2[0][1]
kouten2xy=sqrt(kouten2x**2+kouten2y**2)
kouten2< }
puts kouten2[-1].join("\s")
else
puts kouten[0].join("\s") if n>0
end
print line if n==0
else
print line
end
else
print line
end
end
}
else
printf("h#曲線がありません\n")
end
#範囲の内(true)外(false)を返す
def area(x,y)
hn=[]
open("temp.txt","r"){|f|
while line=f.gets
xy =line.split
if xy[0] =~ /^hn/
hnx1=xy[1].to_f
hny1=xy[2].to_f
hnx2=xy[3].to_f
hny2=xy[4].to_f
hn<<[hnx1,hny1,hnx1,hny2]
hn<<[hnx1,hny2,hnx2,hny2]
hn<<[hnx2,hny2,hnx2,hny1]
hn<<[hnx2,hny1,hnx1,hny1]
end
end
}
zahyo=[]
hn.each{|item|zahyo< if zahyo.size==1 or zahyo.size>1 && zahyo.size%2==1
return true
else
return false
end
end
en=[]
while ARGF.gets
xy=split
if xy[0]=~/^ci/
xy.collect!{|item|item.to_f}
en< end
end
if en.size>0
puts "hd"
open("temp.txt","r"){|f|
while line=f.gets
xy=line.split
if xy[0]=~/^hq/
en.each{|item|
if sen_en_zahyo(xy,item).size>0
sen_en_zahyo(xy,item).each{|item2|
x1=item2[0]
y1=item2[1]
if xy[0]==xy[2]
if area(xy[2],xy[3]) && area(xy[0],xy[1])==false
kouten<< [x1,y1,xy[0],xy[1]]
elsif area(xy[0],xy[1]) && area(xy[2],xy[3])==false
kouten<< [x1,y1,xy[2],xy[3]]
else
kouten<< [x1,y1,xy[2],xy[3]] if (xy[1]-y1).abs<(xy[3]-y1).abs;kouten<< [x1,y1,xy[0],xy[1]] if (xy[1]-y1).abs>(xy[3]-y1).abs
end
else
if area(xy[2],xy[3]) && area(xy[0],xy[1])==false
kouten<< [x1,y1,xy[0],xy[1]]
elsif area(xy[0],xy[1]) && area(xy[2],xy[3])==false
kouten<< [x1,y1,xy[2],xy[3]]
else
kouten<< [x1,y1,xy[2],xy[3]] if (xy[0]-x1).abs<(xy[2]-x1).abs;kouten<< [x1,y1,xy[0],xy[1]] if (xy[0]-x1).abs>(xy[2]-x1).abs
end
end
n+=1
}
end
}
if kouten.size>1
kouten2=[]
kouten.each{|item|
kouten2< itemx=item[2]-item[0]
itemy=item[3]-item[1]
itemxy=sqrt(itemx**2+itemy**2)
kouten2x=kouten2[0][2]-kouten2[0][0]
kouten2y=kouten2[0][3]-kouten2[0][1]
kouten2xy=sqrt(kouten2x**2+kouten2y**2)
kouten2< }
puts kouten2[-1].join("\s")
else
puts kouten[0].join("\s") if n>0
end
print line if n==0
else
print line
end
end
}
else
printf("h#円がありません\n")
end
@REM 直線を円・円弧との交点まで一括伸縮
@echo off
REM #jww
REM #cd
REM #ht10
REM #ht30
REM #ht40
REM #hp
REM #zz
REM #zw
REM #h2
REM #e
copy jwc_temp.txt temp.txt > nul
ruby -Ks ex_l_ci.rb temp.txt > jwc_temp.txt