app
SOLIDWORKS Bridge
Public Made by Adomby adom
Launch, model and quit SOLIDWORKS from any Adom container. Nothing is ever lost.
main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
import math, sys
sys.path.insert(0,'.')
from tb2 import toolblock, area
def clip_halfplane(poly, nx, ny, c):
# keep points with nx*x+ny*y <= c
out=[]; n=len(poly)
for i in range(n):
P=poly[i]; Q=poly[(i+1)%n]
pin=nx*P[0]+ny*P[1]<=c; qin=nx*Q[0]+ny*Q[1]<=c
if pin: out.append(P)
if pin!=qin:
t=(c-nx*P[0]-ny*P[1])/((nx*(Q[0]-P[0])+ny*(Q[1]-P[1])))
out.append((P[0]+t*(Q[0]-P[0]),P[1]+t*(Q[1]-P[1])))
return out
def clip_disc(poly,cx,cy,r,n=720):
for k in range(n):
a=2*math.pi*k/n; nx,ny=math.cos(a),math.sin(a)
poly=clip_halfplane(poly,nx,ny,nx*cx+ny*cy+r)
if not poly: break
return poly
def circle_poly(cx,cy,r,n=2000): return [(cx+r*math.cos(2*math.pi*i/n),cy+r*math.sin(2*math.pi*i/n)) for i in range(n)]
A,B,C=86,58,44
prof,_,info,P=toolblock(A,B,C,top=B-33.0,redge=B-57.0)
Aprof=area(P) # outer profile without holes
hole14=math.pi*49; hole11=math.pi*5.5**2
xstep=(A-52)-14.0 # hole coords
Pstep=clip_halfplane(P,1,0,xstep); Astep=area(Pstep)
print("profile area (no holes) %.2f ; step region (x<=%.0f) area %.2f"%(Aprof,xstep,Astep))
target3=628.18/0.0079; target4=432.58/0.0079
def vol3(cx,cy,zslot=24.0,zstep=19.0):
Aslot=area(clip_disc(P,cx,cy,41.0))
V=Aprof*C - Astep*zstep - Aslot*zslot - hole14*(C-zstep) - hole11*(C-zslot)
return V,Aslot
xR=A-14.0
# hypotheses for R41 center
yc_flank36 = -11+math.sqrt(41**2-(xR-(43+29*(22/34.0)))**2)
cands=[("center on right edge, thru flank@36 -> (72,%.2f)"%yc_flank36,(xR,yc_flank36)),
("center top-right corner (72,25)",(xR,25.0)),
("pixel fit (72.4,28.6)",(72.4,28.6)),
("center (72,28.0)",(xR,28.0)),("center (72,29.5)",(xR,29.5))]
for name,(cx,cy) in cands:
V,As=vol3(cx,cy); print("STEP3 %-50s slotA=%.1f V=%.1f mass=%.2f (key 628.18, diff %+.2f%%)"%(name,As,V,V*0.0079,(V/target3-1)*100))
# sensitivity: slot z-width 24 vs step side
cx,cy=xR,yc_flank36
for zs in (22,24,26):
V,_=vol3(cx,cy,zslot=zs); print(" zslot=%d -> mass %.2f"%(zs,V*0.0079))
# STEP 4: pocket. Outline = outer profile offset 1 inward, clipped to x>=xstep+1 and y>=-13; depth 32 from front (leaves 12 at back)
def offset_inward(poly,d,n=None):
# approximate inward offset by clipping with every edge's half-plane shifted by d (valid for convex-ish boundary parts; polygon here is non-convex, so do per-edge clipping only on edges we care about -> use generic approach: clip by each edge halfplane shifted inward)
out=poly
m=len(poly)
# signed area to know orientation
s=sum(poly[i][0]*poly[(i+1)%m][1]-poly[(i+1)%m][0]*poly[i][1] for i in range(m))
ccw = s>0
for i in range(m):
P0=poly[i]; P1=poly[(i+1)%m]
ex,ey=P1[0]-P0[0],P1[1]-P0[1]; L=math.hypot(ex,ey)
if L<1e-9: continue
# outward normal
nx,ny=(ey/L,-ex/L) if ccw else (-ey/L,ex/L)
c=nx*P0[0]+ny*P0[1]-d
# only clip with edges that are on the right-lobe region boundary (x>xstep-5) to avoid the notch/left lobe edges eating the pocket wrongly
if max(P0[0],P1[0])<xstep-1: continue
if P0[1]<-13.5 and P1[1]<-13.5 and max(P0[0],P1[0])<xR-29: continue # skip V-notch edges (below pocket floor)
out=clip_halfplane(out,nx,ny,c)
if not out: break
return out
Ppk=offset_inward(P,1.0)
Ppk=clip_halfplane(Ppk,-1,0,-(xstep+1.0)) # x >= xstep+1
Ppk=clip_halfplane(Ppk,0,-1,13.0) # y >= -13
Apk=area(Ppk); Apk_in=area(clip_disc(Ppk,cx,cy,41.0)); Apk_out=Apk-Apk_in
print("pocket area total %.2f (inside slot disc %.2f, outside %.2f); bbox x %.2f..%.2f y %.2f..%.2f"%(Apk,Apk_in,Apk_out,min(p[0] for p in Ppk),max(p[0] for p in Ppk),min(p[1] for p in Ppk),max(p[1] for p in Ppk)))
V3,_=vol3(cx,cy)
for name,pv in [("pocket depth 32 (floor 12 at back)",Apk_out*32+(Apk_in-hole11)*8),
("pocket depth 32, hole not excluded",Apk_out*32+Apk_in*8),
("pocket depth 12 only (front ear 8 + 4 into slot)",Apk_out*12+(Apk_in-hole11)*8)]:
V4=V3-pv; print("STEP4 %-45s V=%.1f mass=%.2f (key 432.58, diff %+.2f%%)"%(name,V4,V4*0.0079,(V4/target4-1)*100))