jw_cad 外部変形 - (1345) mshtaで円弧の端点に矢印を描く -

外部変形は データのやり取りをテキストファイルで行うので プログラム言語は 自由に選ぶことができます。図形は機能的かつシンプルなため、数多くのユーザーに受け入れられています。

 

mshtaで円弧の端点に矢印を描く

:mshtaで円弧の端点に矢印を描く
@echo off
if exist jwc_temp.txt (
  copy jwc_temp.txt myfiles > nul
  mshta %~f0 < myfiles > jwc_temp.txt
)
goto:eof

REM #jww
REM #1ci 円・円弧を指示してください。
REM #bz
REM #e

<script>
function cipoint(ci, pm) {
  x = ci[0]
  y = ci[1]
  r = ci[2]
  p1 = ci[3]
  p2 = ci[4]
  w = ci[5]
  d = ci[6] * Math.PI / 180
  co = Math.cos(d)
  si = Math.sin(d)
  if (pm == -1) { q = p1 } else { q = p2 }
  q *= Math.PI / 180.0
  xr = r * Math.cos(q)
  yr = r * Math.sin(q) * w
  a = Math.atan2(yr / w, xr * w) + d
  return [[x + xr * co - yr * si, y + xr * si + yr * co], a]
}
function hypot(x, y) {
  return Math.sqrt(x * x + y * y)
}
function lnslope(x) { //線の角度を返す
  return Math.atan2(x[3] - x[1], x[2] - x[0])
}
function ptdist(pt1, pt2) {
  return hypot(pt2[0]-pt1[0],pt2[1]-pt1[1])
}
function polarto(pt, r, d) {
  return [pt[0] + r * Math.cos(d), pt[1] + r * Math.sin(d)]
}
function arrow(pt1, d, size, xang, xan2) {
  l = size
  d *= Math.PI / 180
  a = xang * Math.PI / 180 / 2.0
  pt2 = polarto(pt1, l, d - a)
  pt4 = polarto(pt1, l, d + a)
  if (xan2 == 180) {
    sl = ["sl", pt1, pt2, pt4].join(" ").replace(/,/g, " ")
  } else {
    c = Math.cos(a) - Math.sin(a) * Math.tan( (90.0 - xan2 / 2.0) * Math.PI / 180)
    pt3 = polarto(pt1, l * c, d)
    sl = ["sl", pt1, pt2, pt3, pt4].join(" ").replace(/,/g, " ")
  }
  return sl
}

with (new ActiveXObject("Scripting.FileSystemObject")) {
  f = GetStandardStream(0) //stdin
  g = GetStandardStream(1) //stdout
  while (! f.AtEndOfStream) {
    F = ($_ = f.ReadLine()).split(/\s+/)
    if (/^hp1/i .test($_)) {
      hp1 = F.slice(1, 3)
      if (hp1) for (i = 0; i < hp1.length; i++) hp1[i] *= 1.0;
    }
    if (/^ci/i .test($_)) { //ci 指示円
      for (i = 1; i < F.length; i++) F[i] *= 1.0;
      ci1 = F.slice(1, F.length)
      if (F.length == 4) {
        ci1 = ci1.concat(0, 360, 1, 0)
      }
    }
  }
  f.close()
  size = 5 //矢印の長さ( 図寸 )
  xang = 45 //矢印の交角( ゚ )
  xan2 = 120 //矢尻の交角( ゚ )
  pta1 = cipoint(ci1, -1)
  pt1 = pta1[0]
  a1 = pta1[1]
  pta2 = cipoint(ci1, 1)
  pt2 = pta2[0]
  a2 = pta2[1]
  l1 = ptdist(hp1, pt1)
  l2 = ptdist(hp1, pt2)
  pm = l1 <= l2 ? -1 : 1
  pt = pm == 1 ? pt2 : pt1
  d = (pm == 1 ? a2 : a1) + Math.PI / 2
  g.WriteLine("bz")
  g.WriteLine(arrow(pt, d * 180 / Math.PI, -size * pm, xang, xan2))
}
close()
</script>

 

 

スクリプト言語jscript を使用しています。