app
SOLIDWORKS Bridge
Public Made by Adomby adom
Launch, model and quit SOLIDWORKS from any Adom container. Nothing is ever lost.
main
import math
def arc(cx,cy,r,a0,a1,n=4000):
return [(cx+r*math.cos(a0+(a1-a0)*i/n), cy+r*math.sin(a0+(a1-a0)*i/n)) for i in range(n+1)]
def area(pts):
s=0
for i in range(len(pts)):
x0,y0=pts[i]; x1,y1=pts[(i+1)%len(pts)]
s+=x0*y1-x1*y0
return abs(s)/2
def toolblock(A,B,C, top=24.0, vdepth=19.0, redge=0.0, hole_y=14.0, line_start_x=0.0, lobe_h=32.0, r29_mode="flank"):
xL=-14.0; yB=-hole_y; yT=yB+lobe_h
xR=A-14.0; xRL=xR-29.0
yRT=top; yV=yB-vdepth; yRE=redge
th=math.radians(10); d=(math.cos(th),-math.sin(th)); nrm=(math.sin(th),math.cos(th))
P0=(line_start_x,yT); P=(xRL,yRT)
ox=P0[0]+19*nrm[0]-P[0]; oy=P0[1]+19*nrm[1]-P[1]
b=2*(ox*d[0]+oy*d[1]); c=ox*ox+oy*oy-361; disc=b*b-4*c
assert disc>=0
sols=[]
for t in [(-b-math.sqrt(disc))/2,(-b+math.sqrt(disc))/2]:
cxx=P0[0]+t*d[0]+19*nrm[0]; cyy=P0[1]+t*d[1]+19*nrm[1]
if cxx<P[0]: sols.append((t,cxx,cyy,(P0[0]+t*d[0],P0[1]+t*d[1])))
t,c19x,c19y,T=sols[0]
fx0,fy0=xRL,yV; fx1,fy1=xR,yRE
s=(yB-fy0)/(fy1-fy0); c29x=fx0+s*(fx1-fx0); c29y=yB
xv=c29x-math.sqrt(29**2-(c29y-yV)**2)
c5y=yB-5; c5x=c29x-math.sqrt(34**2-25)
ux,uy=(c29x-c5x)/34,(c29y-c5y)/34; tp=(c5x+5*ux,c5y+5*uy)
pts=[(xL,yB+7),(xL,yT-7),(-7.0,yT),(line_start_x,yT)]
a0=math.atan2(T[1]-c19y,T[0]-c19x); a1=math.atan2(P[1]-c19y,P[0]-c19x); pts+=arc(c19x,c19y,19,a0,a1)
pts+=[(xR-5,yRT),(xR,yRT-5),(xR,yRE),(xRL,yV),(xv,yV)]
a0=math.atan2(yV-c29y,xv-c29x); a1=math.atan2(tp[1]-c29y,tp[0]-c29x); pts+=arc(c29x,c29y,29,a0,a1)
a0=math.atan2(tp[1]-c5y,tp[0]-c5x); a1=math.pi/2
if a1<a0: a1+=2*math.pi
if a1-a0>math.pi: a1-=2*math.pi
pts+=arc(c5x,c5y,5,a0,a1)
pts+=[(c5x,yB),(-7.0,yB)]
prof=area(pts)-math.pi*49
return prof, prof*C*0.0079, dict(T=T,c19=(c19x,c19y),c29=(c29x,c29y),xv=xv,c5=(c5x,c5y),tp=tp), pts
p,m,info,pts=toolblock(81,57,43)
print("STEP1 corrected: area=%.2f mass=%.2f (key 939.54, diff %.2f%%)"%(p,m,(m/939.54-1)*100)); print(info)
# top boundary samples vs measured (x from left edge, drop from right-lobe top)
meas={14:6.15,20:7.18,25:8.06,30:9.01,35:9.52,40:9.01,45:7.03,50:2.86}
for xm,v in meas.items():
x=xm-14; ys=[y for (xx,y) in pts if abs(xx-x)<0.3] or [24-99]
print(" x=%d measured drop %.2f model drop %.2f"%(xm,v,24-max(ys)))
print("STEP2 target area %.2f"%(1032.32/0.0079/45))
for name,kw in [("top=26",dict(top=26.0)),("top=26,redge=2",dict(top=26.0,redge=2.0)),("vdepth=21",dict(vdepth=21.0)),("hole_y=16,lobe_h=34",dict(hole_y=16.0,lobe_h=34.0)),("hole_y=16,lobe_h=32",dict(hole_y=16.0)),("top=25,vdepth=20",dict(top=25.0,vdepth=20.0))]:
p,m,info,_=toolblock(84,59,45,**kw); print(" %-22s area=%.2f mass=%.2f diff=%.2f%%"%(name,p,m,(m/1032.32-1)*100))