main
Drew Owens 0.11.0 source 1b7115e 5d ago
import math, sys, io, contextlib, json
sys.path.insert(0,'.')
with contextlib.redirect_stdout(io.StringIO()):
    from tb2 import toolblock, area
    from tb34 import clip_halfplane, clip_disc
A,B,C=86,58,44
prof,_,info,P=toolblock(A,B,C,top=B-33.0,redge=B-57.0)
S=json.load(open("step3.json")); V3=S['V3']; cx,cy=S['cx'],S['cy']
c19x,c19y=info['c19']; T=info['T']
hole11=math.pi*5.5**2; ring=math.pi*6.5**2
xstep=(A-52)-14.0; xR=A-14.0; top=B-33.0; yRE=B-57.0
th=math.radians(10); lnx,lny=math.sin(th),math.cos(th)   # outward normal of the 10deg line
def K1(d):
    big=[(-200,-200),(200,-200),(200,200),(-200,200)]
    K=clip_halfplane(big,-1,0,-(xstep+d)); K=clip_halfplane(K,0,-1,14.0-d); K=clip_halfplane(K,0,1,top-d)
    s2=math.sqrt(0.5); K=clip_halfplane(K,s2,s2,s2*(xR-5)+s2*top-d); K=clip_halfplane(K,1,0,xR-d)
    fx,fy=29.0,(yRE+33.0); L=math.hypot(fx,fy); nx,ny=fy/L,-fx/L
    K=clip_halfplane(K,nx,ny,nx*(xR-29)+ny*(-33.0)-d)
    return K
def face_area(poly,d):
    if not poly: return 0.0
    r=19.0+d; Tx=T[0]-d*lnx
    a=area(poly)-area(clip_disc(poly,c19x,c19y,r))
    W=clip_halfplane(poly,1,0,Tx); W=clip_halfplane(W,-lnx,-lny,-(lny*18.0-d))   # x<=Tx and above the (shifted) line
    if W: a-=area(W)-area(clip_disc(W,c19x,c19y,r))
    return a
A0=face_area(K1(0.0),0.0); A1=face_area(K1(1.0),1.0)
chk=area(clip_halfplane(clip_halfplane(P,-1,0,-xstep),0,-1,14.0))
print("front-face area (no offset) %.2f  vs profile-derived check %.2f ; offset-1 outline area %.2f"%(A0,chk,A1))
t4=432.58/0.0079
def Ain(d,r): return face_area(clip_disc(K1(d),cx,cy,r),d)
rows=[]
for wall_out in (0.0,1.0,2.0):
    for wall_in in (0.0,1.0,2.0):
        for ringflag in (False,True):
            for skin in (1.0,0.0):
                ai=Ain(1.0,41.0-wall_in); ao=A1-Ain(1.0,41.0+wall_out)
                Vp=ao*32+(ai-(ring if ringflag else hole11))*(8.0-skin)
                V4=V3-Vp; rows.append(((V4/t4-1)*100,wall_out,wall_in,ringflag,skin,V4*0.0079,ao,ai))
rows.sort(key=lambda r:abs(r[0]))
for d,wo,wi,rf,sk,m,ao,ai in rows[:10]:
    print("wall_out=%.0f wall_in=%.0f ring=%-5s skin=%.0f  Aout=%.1f Ain=%.1f -> mass %.2f (diff %+.3f%%)"%(wo,wi,rf,sk,ao,ai,m,d))