CascadeStudio_3D_Manual
230 строк · 6.8 Кб
1// Three armed lever
2
3function Dxy(currentPoint,dx,dy)4{5let newPoint = [];6newPoint[0] = currentPoint[0] + dx;7newPoint[1] = currentPoint[1] + dy;8return newPoint9}
10
11function Dx(currentPoint,dx)12{13let newPoint = [];14newPoint[0] = currentPoint[0] + dx;15newPoint[1] = currentPoint[1] ;16return newPoint17}
18
19function Dy(currentPoint,dy)20{21let newPoint = [];22newPoint[0] = currentPoint[0];23newPoint[1] = currentPoint[1] + dy;24return newPoint25}
26
27function Polar(currentPoint,distance,angleDegToX)28{29let newPoint = [];30let angleRad = angleDegToX * Math.PI/180;31newPoint[0] = currentPoint[0] + (distance * Math.cos(angleRad));32newPoint[1] = currentPoint[1] + (distance * Math.sin(angleRad));33return newPoint34}
35
36function PolarX(currentPoint,xdistance,angleDegToX)37{38let newPoint = [];39let angleRad = angleDegToX * Math.PI/180;40newPoint[0] = currentPoint[0] + xdistance;41newPoint[1] = currentPoint[1] + xdistance * Math.tan(angleRad);42return newPoint43}
44
45function PolarY(currentPoint,ydistance,angleDegToX)46{47let newPoint = [];48let angleRad = angleDegToX * Math.PI/180;49newPoint[0] = currentPoint[0] + ydistance/Math.tan(angleRad);50newPoint[1] = currentPoint[1] + ydistance;51return newPoint52}
53
54function RadiusArc(currentPoint,endPoint,radius, clockwise)55{
56let midPoint = [];57let dx = endPoint[0] - currentPoint[0];58let dy = endPoint[1] - currentPoint[1];59let dist = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));60let alpha = Math.asin(dy/dist);61let beta = Math.asin((dist/2)/radius);62let sag = radius - (Math.cos(beta) * radius)63if (dx<0){clockwise = !clockwise}64if (clockwise == true)65{66midPoint[0] = currentPoint[0] + dx/2 - Math.sin(alpha)*sag;67midPoint[1] = currentPoint[1] + dy/2 + Math.cos(alpha)*sag;68}69else70{71midPoint[0] = currentPoint[0] + dx/2 + Math.sin(alpha)*sag;72midPoint[1] = currentPoint[1] + dy/2 - Math.cos(alpha)*sag;73}74return midPoint75}
76
77
78function SagArc(currentPoint,endPoint,sag,clockwise)79{
80let midPoint = [];81let dx = endPoint[0] - currentPoint[0];82let dy = endPoint[1] - currentPoint[1];83let dist = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));84let alpha = Math.asin(dy/dist);85if (dx<0){clockwise = !clockwise}86if (clockwise == true)87{88midPoint[0] = currentPoint[0] + dx/2 - Math.sin(alpha)*sag;89midPoint[1] = currentPoint[1] + dy/2 + Math.cos(alpha)*sag;90}91else92{93midPoint[0] = currentPoint[0] + dx/2 + Math.sin(alpha)*sag;94midPoint[1] = currentPoint[1] + dy/2 - Math.cos(alpha)*sag;95}96return midPoint97}
98
99function MirrorX(currentPoint, yvalue)100{101let mirrorPoint = [];102mirrorPoint[0] = currentPoint[0];103mirrorPoint[1] = yvalue - (currentPoint[1]-yvalue);104return mirrorPoint105}106
107function MirrorY(currentPoint, xvalue)108{109let mirrorPoint = [];110mirrorPoint[0] = xvalue - (currentPoint[0]-xvalue);111mirrorPoint[1] = currentPoint[1];112return mirrorPoint113}114
115// testing function to check if sketching commands work correctly
116// let q0 = [0,0]
117// let q1= [50,0]
118// let q1a = SagArc(q0,q1,5,false)
119// let q2= [50,50]
120// let q2a = SagArc(q1,q2,5,false)
121// let q3= [0,50]
122// let q3a= SagArc(q2,q3,5,false)
123// let q4= [0,0]
124// let q4a= SagArc(q3,q4,5,false)
125
126// let qsketch=new Sketch(q0)
127// .ArcTo(q1a,q1)
128// .ArcTo(q2a,q2)
129// .ArcTo(q3a,q3)
130// .ArcTo(q4a,q4)
131// .End().Face()
132
133
134
135// Box(10,10,10,false) // can be used to determine position of the axes.
136
137// parameters that define the design intent
138let d = 45; // distance center to radius of arm139let r0 = 10; // radius top of arm140let adeg = 13; // widening angle of arm141let arad = adeg * Math.PI/180;142let d1 = d + Math.sin(arad)*r0143let r1 = 13; // inner radius of center cylinder144let t1 = 5 ; // wall thickness of center cylinder145let h1 = 37; // height of inner cylinder146let h2 = 10; // height at end of the arm147let gamma = 25; // angle deg from tip of arm to cylinder148let r2 = 25; // radius of fillets between arms149let t3 = 7 ; // wallthickness arms150let r3 = 10; // cylinder at end of arms151let r4 = 1.5 // rounding of cutout152let ra = 2.5 // radius of hole at end of arm153let rcb = 5 // radius of counterbore154let hcb = 7 // height of counterbore155
156
157// generate center cylinder
158let centerCyl0 = Translate([0,0,h1/2],Cylinder((r1+t1),h1,true))159let armCyl = Translate([0,d,h1/2], Cylinder(r3,h1,true))160
161// points for sketch of the arm
162let p0 = [0,0];163let p1 = Dy(p0, d);164let p2 = Polar(p1,r0,adeg);165let p3 = MirrorY(p2,0);166let p4 = RadiusArc(p2,p3,r0,false);167let p5 = PolarY(p2,-d1,adeg-90)168let p6 = MirrorY(p5,0)169
170// generate sketch of one arm
171let armSketch = new Sketch(p0)172.LineTo(p5)173.LineTo(p2)174.ArcTo(p4,p3)175.LineTo(p6)176.LineTo(p0)177.End().Face()178let arm1 = Extrude(armSketch,[0,0,h1]);179let armCutout = Offset(arm1,-t3,0.01,true);180let armCutout1 = Difference(armCutout,[centerCyl0,armCyl]);181let armCutout2 = Translate([0,0,h1/2],armCutout1,true);182let armCutout3 = Translate([0,0,-h1/2],armCutout1,true);183armCutout = Union([armCutout1,armCutout2,armCutout3]);184armCutout = Offset(armCutout,-r4);185armCutout = Offset(armCutout,r4);186arm1 = Difference(arm1,[armCutout]);187
188// copy three rotated arms
189let arm2 = Rotate([0,0,1],120,arm1,true)190let arm3 = Rotate([0,0,1],240,arm1,true)191
192let arms = Union([arm1,arm2,arm3])193arms = FilletEdges(arms, r2, [34,39,61])194
195// create sketch of cutting object to taper arms
196let pc0 = [d+r0+5,h2]197let pc1 = [d+r0,h2];198let pc2 = PolarX(pc1, -(r0+d)+(r1+t1),(180-gamma));199let pc3 = Dx(pc2,-t1-r1/2)200let pc4 = Dy(pc3,h1);201let pc5 = Dx(pc4,d+r0+10);202let pc6 = pc0;203
204let cutterSketch = new Sketch(pc0)205.LineTo(pc0)206.LineTo(pc1)207.LineTo(pc2)208.LineTo(pc3)209.LineTo(pc4)210.LineTo(pc5)211.LineTo(pc6)212.End().Face(true);213let cutterFace = Rotate([1,0,0],90,cutterSketch);214let cutterShape= Revolve(cutterFace);215let shapedArms = Difference(arms,[cutterShape]);216shapedArms = FilletEdges(shapedArms,1.5,[51])217
218let centerCyl1 = Translate([0,0,h1/2],Cylinder((r1+t1),h1,true))219let centerHole = Translate([0,0,h1/2],Cylinder((r1),h1+20,true))220let armHole = Translate([0,d,h1/2],Cylinder((ra),h1+20,true))221let countHole = Translate([0,d,hcb],Cylinder((rcb),h1+20,false))222let armHoleCb1 = Union([countHole,armHole])223let armHoleCb2 = Rotate([0,0,1],120,armHoleCb1,true)224let armHoleCb3 = Rotate([0,0,1],240,armHoleCb1,true)225
226
227
228let armsTot = Union([shapedArms,centerCyl1])229let armsTot1 = Difference(armsTot,[centerHole]);230let armsTot2 = Difference(armsTot1,[armHoleCb1,armHoleCb2,armHoleCb3]);231
232
233
234
235
236
237
238