距離測定
---------- 小数点第4位切下げ
@if(0==1) //距離測定 切下げ
@echo off
REM #jww
REM #cd
REM #1- 始点を指示してください
REM #2# 終点を指示してください
REM #hr
REM #e
cscript //nologo //e:jscript "%~f0" %*
copy temp.txt jwc_temp.txt
del temp.txt
goto:eof
@end
//ファイルオープン
fso=new ActiveXObject("Scripting.FileSystemObject")
r=fso.OpenTextFile("jwc_temp.txt")
w=fso.CreateTextFile("temp.txt")
//ユーザー設定
ut=1000 //単位: m
unt="m"//単位表記:"m"、表記なし:""
k=3 //小数点第3位
cor=0.0001 //補正値
//初期設定
dq="\"" //ダブルコーテーション
sp=" " //スペース
k=Math.pow(10,k) //累乗
/////jwc_temp.txt読込み
while (!r.AtEndOfLine){
line=r.ReadLine()
//
if(/hq/.test(line)){ }
//始点座標取得
else if(/hp1/.test(line)){
xys=line.split(/\s+/)
xs=Number(xys[1]);ys=Number(xys[2])
}
//終点座標取得
else if(/hp2/.test(line)){
xye=line.split(/\s+/)
xe=Number(xye[1]);ye=Number(xye[2])
//座標・距離計算
dx=(xe-xs)/ut;dy=(ye-ys)/ut //傾き
xc=(xs+xe)/2;yc=(ys+ye)/2 //中点座標
dis=Math.pow((xs-xe),2)+Math.pow((ys-ye),2)
dis=Math.sqrt(dis) //距離
// w.WriteLine(dis)
dis=(dis+cor)/ut*k
// w.WriteLine(dis)
dis=Math.floor(dis)/k //切下げ
}
//設定情報
else{
w.WriteLine(line)}
} //while
//距離作図
{
//ゼロパディング
if(dis<10){
str=String(dis) //数値→文字列変換
num=str.length //文字列長さ
if(num==1){
dis=dis+".000"}
else if(num==3){
dis=dis+"00"}
else if(num==4){
dis=dis+"0"}
else{}
}
else if(dis>=10 && dis<100){
str=String(dis) //数値→文字列変換
num=str.length //文字列長さ
if(num==2){
dis=dis+".000"}
else if(num==4){
dis=dis+"00"}
else if(num==5){
dis=dis+"0"}
else{}
}
else{}
/////
w.WriteLine("cc1") //文字基点"中下"
dist=["ch",xc,yc,dx,dy,dq+dis+unt]
dist=dist.join(sp)
w.WriteLine(dist)
}
r.Close();w.close()
---------- 四捨五入
@if(0==1) //距離測定
@echo off
REM #jww
REM #cd
REM #1- 始点を指示してください
REM #2# 終点を指示してください
REM #hr
REM #e
cscript //nologo //e:jscript "%~f0" %*
copy temp.txt jwc_temp.txt
del temp.txt
goto:eof
@end
//ファイルオープン
fso=new ActiveXObject("Scripting.FileSystemObject")
r=fso.OpenTextFile("jwc_temp.txt")
w=fso.CreateTextFile("temp.txt")
//ユーザー設定
ut=1000 //単位: m
unt="m"//単位表記:"m"、表記なし:""
k=3 //小数点第3位
//初期設定
dq="\"" //ダブルコーテーション
sp=" " //スペース
/////jwc_temp.txt読込み
while (!r.AtEndOfLine){
line=r.ReadLine()
//
if(/hq/.test(line)){
}
//始点座標取得
else if(/hp1/.test(line)){
xys=line.split(/\s+/)
xs=Number(xys[1]);ys=Number(xys[2])
}
//終点座標取得
else if(/hp2/.test(line)){
xye=line.split(/\s+/)
xe=Number(xye[1]);ye=Number(xye[2])
//座標・距離計算
dx=(xe-xs)/ut;dy=(ye-ys)/ut //傾き
xc=(xs+xe)/2;yc=(ys+ye)/2 //中点座標
dis=Math.pow((xs-xe),2)+Math.pow((ys-ye),2)
dis=Math.sqrt(dis)/ut //距離
k=Math.pow(10,k)
dis=Math.round(dis*k)/k //四捨五入
}
//設定情報
else{
w.WriteLine(line)}
} //while
//距離作図
{
w.WriteLine("cc1") //文字基点"中下"
dist=["ch",xc,yc,dx,dy,dq+dis+unt]
dist=dist.join(sp)
w.WriteLine(dist)
}
r.Close();w.close()
| 固定リンク
コメント
お世話になっております
距離測定
有難く使わせて頂いてます
因みにですが…円弧測定で
測定値が円弧なり配置できないでしょうか?
よろしければご一考頂けないでしょうか
よろしくお願いします
投稿: a.fujii | 2022年8月17日 (水) 14時59分
a.fujiiさん、こんばんは。
測定値の傾きは、円弧中央の接線と平行になるかと思います。
少しお待ちください。
投稿: somem | 2022年8月17日 (水) 20時03分