Files
2026-09-24 10:40:57 +08:00

53 lines
2.9 KiB
Python

"""Actual wire-junction tangency and sampled root-band curvature, no CAD trace."""
import math
from build123d import Vector
from OCP.BRepAdaptor import BRepAdaptor_Curve
from OCP.gp import gp_Pnt,gp_Vec
from OCP.GeomAbs import GeomAbs_BSplineCurve
def root_band_measurements(wire,center,u,v,low,high):
cutoff=low+.35*(high-low)
def radius(p):
q=p-center;return math.hypot(q.dot(u),q.dot(v))
endpoints=[];curves=[];straight=0
for edge in wire.edges():
for t in (0.,1.):
p=edge.position_at(t)
if radius(p)<=cutoff+1e-7:
tangent=edge.tangent_at(t).normalized()*(1 if t==0 else -1)
endpoints.append((p,tangent))
curve=BRepAdaptor_Curve(edge.wrapped)
first,last=curve.FirstParameter(),curve.LastParameter()
knots=[first,last]
if curve.GetType()==GeomAbs_BSplineCurve:
spline=curve.BSpline()
knots += [spline.Knot(i) for i in range(1,spline.NbKnots()+1) if first<spline.Knot(i)<last]
knots=sorted(set(knots))
# Sample every spline knot span; a tiny fillet may be merged into a long edge.
for start,end in zip(knots,knots[1:]):
for f in (.1,.3,.5,.7,.9):
t=start+f*(end-start);point=gp_Pnt();d1=gp_Vec();d2=gp_Vec()
curve.D2(t,point,d1,d2)
if radius(Vector(point.X(),point.Y(),point.Z()))>cutoff:continue
speed=d1.Magnitude();cross=d1.Crossed(d2).Magnitude()
if speed<1e-12:continue
curvature=cross/(speed**3)
if curvature<1e-8/max(1,high):straight+=1;continue
r=1/curvature
if math.isfinite(r):curves.append(r)
jumps=[];unpaired=0;used=set()
for i,(p,a) in enumerate(endpoints):
if i in used:continue
matches=[j for j,(q,b) in enumerate(endpoints) if j!=i and j not in used and (p-q).length<1e-5]
if len(matches)!=1:unpaired+=1;continue
j=matches[0];used.update((i,j));b=endpoints[j][1]
angle=math.degrees(math.acos(max(-1,min(1,-a.dot(b)))))
jumps.append({'point':list(p),'angle_deg':angle})
return {'radial_band_mm':[low,cutoff],'junction_count':len(jumps),'unpaired_endpoints':unpaired,
'max_tangent_jump_deg':max((j['angle_deg'] for j in jumps),default=None),
'worst_junctions':sorted(jumps,key=lambda j:j['angle_deg'],reverse=True)[:4],
'curvature_radius_sample_range_mm':[min(curves),max(curves)] if curves else None,
'curved_samples':len(curves),'straight_samples':straight,
'note':'在实际截面外轮廓半径较低的35%区域检查相邻边切向跳变,并按BRep曲线各样条节点区间采样一、二阶导数计算曲率半径。仅对该截面采样区域有效,不是全齿面连续性或指定刀具半径的证明。无接点/曲率采样不能视为圆角通过。'}