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

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

 

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

:pythonで円弧の端点に矢印を描く
@echo off
if not exist %~dpn0.py (
  for /f "delims=:" %%n in ('findstr /n "^#!" %0') do (
    more +%%n %0 > %~dpn0.py
  )
)
copy jwc_temp.txt myfiles > nul
python %~dpn0.py > jwc_temp.txt
goto:eof

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

#!この次の行からプログラムを書いてください
# coding: shift_jis
def ptdist(pt1, pt2):
  x1, y1 = pt1
  x2, y2 = pt2
  return hypot(x2 - x1, y2 - y1)

def polarto(pt, r, d):
  return [pt[0] + r * cos(d), pt[1] + r * sin(d)]

def arrow(pt1, d, size = 3, xang = 60, xan2 = 90):
  l = size
  a = xang * pi / 180 / 2.0
  pt2 = polarto(pt1, l, d - a)
  pt4 = polarto(pt1, l, d + a)
  if xan2 == 180:
    print("sl %s %s %s %s %s %s" % tuple(pt1 + pt2 + pt4))
  else:
    c = cos(a) - sin(a) * tan( (90.0 - xan2 / 2.0) * pi / 180)
    pt3 = polarto(pt1, l * c, d)
    print("sl %s %s %s %s %s %s %s %s" % tuple(pt1 + pt2 + pt3 + pt4))

def cipoint(ci, pm = 1):
  x, y, r, p1, p2, w, d = ci
  d *= PI / 180
  co = cos(d) * r
  si = sin(d) * r
  q = (pm == -1 and p1 or p2) * pi / 180
  xr = cos(q)
  yr = sin(q) * w
  a = atan2(yr / w, xr * w) + d
  return [x + xr * co - yr * si, y + xr * si + yr * co], a


import sys,re
from math import *

try :
  f = open("myfiles", "r")
  for a in f:
    F = a.split()
    if re.compile("^hp1ci").search(a): pt = F[1:3]
    if re.compile("^ci").search(a):
      ci1 = F[1:]
      if len(ci1) == 3: ci1 = ci1 + [0, 360, 1, 0]
  f.close()
except :
  sys.exit()

ci1 = tuple(map(float, ci1))
pt = tuple(map(float, pt))

size = 5 #矢印の長さ( 図寸 )
xang = 45 #矢印の交角( ゚ )
xan2 = 120 #矢尻の交角( ゚ )
pt1, a1 = cipoint(ci1,-1)
pt2, a2 = cipoint(ci1, 1)
l1 = ptdist(pt, pt1)
l2 = ptdist(pt, pt2)
if l1 <= l2 :
  pm = -1
  pz = pt1
  a = a1
else :
  pm = 1
  pz = pt2
  a = a2

print("bz")
arrow(pz, a + pi / 2, -size * pm, xang, xan2)