import sys; sys.path.insert(0,".") import collections, math, io, json, numpy as np, pickle sys.path.insert(0,'pylib') from swdots import dots o=io.open('swcol2.txt','w',encoding='utf-8') def fit(pts): A=np.array([[2*x,2*y,1] for x,y in pts]); b=np.array([x*x+y*y for x,y in pts]) s=np.linalg.lstsq(A,b,rcond=None)[0]; cx,cy=s[0],s[1]; r=math.sqrt(s[2]+cx*cx+cy*cy); return cx,cy,r for nm,(y0,y1) in (('C-C',(-271000,-262500)),('D-D',(-279500,-271500)),('E-E',(-287500,-279500))): D=[d for d in dots(31500,37500,y0,y1,maxlen=60) if d[2]==22.5 and d[3]==22.5] pts=[(d[0],d[1]) for d in D] cx,cy,r=fit(pts) rr=[math.hypot(x-cx,y-cy) for x,y in pts] ang=sorted(math.degrees(math.atan2(y-cy,x-cx))%360 for x,y in pts) o.write(u'%s 점 %d 중심 (%.1f, %.1f) 반지름 평균 %.1f (min %.1f max %.1f)\n'%(nm,len(pts),cx,cy,r,min(rr),max(rr))) # 반지름 분포 군집 c=collections.Counter(round(v/10)*10 for v in rr); o.write(u' 반지름 군집 %s\n'%sorted(c.items())) # 모델 P1/P2 중심선 반지름 import rhino3dm m3=rhino3dm.File3dm.Read(r"D:\★Pier 자료\심수석님 검토 파일\검토_산외교P1\산외교P1 G5.3dm") R=collections.defaultdict(list) for ob in m3.Objects: g=ob.Geometry if isinstance(g,rhino3dm.Brep) or not hasattr(g,'PointAtStart'): continue us=dict(ob.Attributes.GetUserStrings()); mk=us.get('mark') if mk in ('P1','P2','P3','P4','P5'): try: n=40 dom=(g.Domain.T0,g.Domain.T1) for i in range(n+1): p=g.PointAt(dom[0]+(dom[1]-dom[0])*i/n); R[mk].append((p.X,p.Y,p.Z)) except Exception as e: pass for mk,L in sorted(R.items()): rs=np.array([math.hypot(x,y) for x,y,z in L]); zs=np.array([z for x,y,z in L]) o.write(u'모델 %s 점 %d: r min %.1f median %.1f max %.1f, z %.0f~%.0f\n'%(mk,len(L),rs.min(),np.median(rs),rs.max(),zs.min(),zs.max()))