Indexへ
(25386)//【25387】//(25389)
------------------------
【タイトル】つし様(測定の外部変形)
【記事番号】 25387 (*)
【 日時 】04/12/25 00:18
【 発言者 】コジマ

つし様、こちらに書き込みました。

以下の外部変形の実行には、mswin32 版 Ruby のインストールが必要です。
以下で入手できます。
http://www61.tok2.com/home2/gravelroad/libraries.html

コピペ後、全角スペースを半角スペースに一括置換してください。

◎バッチファイル(ファイル名 点測定.bat)

@REM 複数の点間座標を一気に測定
@echo off
goto do%1
REM #jww
REM #cd
rem #hm |1)距離(L) |2)角度(R) |
rem #:1
rem #mc
REM #c書込文字種を入力・・・無指定:3/_/a
REM #k長さの単位を選択・・・無指定:1|1)MM(L)|2)M(R)|/_/b
REM #c小数点以下有効桁数・・・無指定:3/_/c
REM #0原点を指示してください。
REM #1測定点を指示してください。
REM #99#
rem #c
REM #e
rem #:2
rem #mc
REM #c書込文字種を入力・・・無指定:3/_/a
REM #c小数点以下有効桁数・・・無指定:3/_/b
REM #0原点を指示してください。
REM #1角度基準点を指示してください。
REM #2測定点を指示してください。
REM #99#
rem #c
REM #e
:do1
copy jwc_temp.txt temp.txt > nul
del jwc_temp.txt
ruby -Ks 点距離取得.rb temp.txt %2 %3 %4 > jwc_temp.txt
goto end
:do2
copy jwc_temp.txt temp.txt > nul
del jwc_temp.txt
ruby -Ks 点角度取得.rb temp.txt %2 %3 > jwc_temp.txt
:end

◎スクリプトファイル(点距離取得.rb)

BEGIN{
    $no=1
    $moji="3"
    $tani="1"
    $keta="3"
    while ARGV.length > 1
        case argument = ARGV.pop
            when /^\/a/
                $moji=argument[ 2 .. -1]
            when /^\/b/
                $tani=argument[ 2 .. -1]
            when /^\/c/
                $keta=argument[ 2 .. -1]
        end
    end
}
def main
    print"cn"+$moji+"\n"
    by=[];tendeta=[]
    while ARGF.gets
        xy = split

        if xy[0] =~/^hp/
            xy.collect!{|item| item.to_f}
            $xy=Math.sqrt(xy[1]**2+xy[2]**2)
            if $tani=="2"
                xyl=$xy/1000
                word="(m)"
            else
                xyl=$xy
                word="(mm)"
            end
            printf("ch%e %e %e %e\"点%s_原点より%s%s\n",
                    xy[1], xy[2], 1, 0,$no,ika(xyl),word)
            tendeta << ["点#{$no}",ika(xyl)].join("\t")
            $no+=1
        end
    end
    printf("ch %e %e %e %e\"原点\n",0,0, 1, 0)
    printf("pt %e %e \n",0,0)
    tendeta.unshift("点名\t距離#{word}")
    File.open("点座標.txt","w"){|file|
                    tendeta.each{|line|
                            file.puts line};}
    print "h#点座標.txtにデータを書込しました\n"
end
def ika(x)
    if $keta=="0"
        a=((x.to_f).round).to_s
        return a
    else
        keta=$keta.to_i
        a=(((x.to_f)*(10**keta)).round/(10**keta).to_f).to_s
        if a=~ /.0$/
            a=(a.to_i).to_s
        end
        return a
    end
end
main()

◎スクリプトファイル(点角度取得.rb)

BEGIN{
    $no=1
    $moji="3"
    $keta="3"
    while ARGV.length > 1
        case argument = ARGV.pop
            when /^\/a/
                $moji=argument[ 2 .. -1]
            when /^\/b/
                $keta=argument[ 2 .. -1]
        end
    end
}
def main
    print"cn"+$moji+"\n"
    by=[];tendeta=[]
    while ARGF.gets
        xy = split

        if xy[0] =~/^hp1/
            ax=xy[1].to_f
            ay=xy[2].to_f
            $kizyun_kaku=Math.atan2(ay,ax)*360/(2*Math::PI)
        end
        if xy[0] =~/^hp/ && xy[0] !="hp1"
            xy.collect!{|item| item.to_f}
            $kakudo=(Math.atan2(xy[2],xy[1]))*360/(2*Math::PI)
            $niten_kaku=$kakudo-$kizyun_kaku
            printf("ch%e %e %e %e\"点%s_基準点より%s°\n",
                xy[1], xy[2], 1, 0,$no,ika($niten_kaku))
            tendeta << ["点#{$no}",ika($niten_kaku)].join("\t")
            $no+=1
        end
    end
    printf("ch%e %e %e %e\"原点\n",0, 0,1,0)
    printf("pt %e %e\n",0,0)
    printf("ch%e %e %e %e\"角度基準点\n",ax, ay,1,0)
    printf("pt %e %e\n",ax, ay)
    tendeta.unshift("点名\t角度(°)")
    File.open("点座標.txt","w"){|file|
                    tendeta.each{|line|
                            file.puts line};}
    print "h#点座標.txtにデータを書込しました\n"
end
def ika(x)
    if $keta=="0"
        a=((x.to_f).round).to_s
        return a
    else
        keta=$keta.to_i
        a=(((x.to_f)*(10**keta)).round/(10**keta).to_f).to_s
        if a=~ /.0$/
            a=(a.to_i).to_s
        end
        return a
    end
end
main()