Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

OpenSCAD User Manual/Example/Strandbeest/Code

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

///------------------------ // Trigonometry Functions //------------------------ function add2D(v1=[0,0],v2=[0,0]) = [ v1[0]+v2[0], v1[1]+v2[1] ]; function addAngle2D(v1=[0,0],ang=0,l=0) = [ v1[0]+cos(ang)*l, v1[1]+sin(ang)*l ]; function getAngle2D(v1,v2=[0,0]) = atan2( (v2[1]-v1[1]), //dy (v2[0]-v1[0]) //dx ); function length2D(v1,v2=[0,0]) = sqrt( (v1[0]-v2[0])*(v1[0]-v2[0]) + (v1[1]-v2[1])*(v1[1]-v2[1]) ); // Intersection of two circles function VVLL2D(V1,V2,L1,L2) = let (D = length2D(V1,V2)) let (L = (L1*L1-L2*L2+D*D)/2/D) let (H = sqrt(L1*L1-L*L)) [L/D*(V2[0]-V1[0])-H/D*(V2[1]-V1[1])+V1[0], L/D*(V2[1]-V1[1])+H/D*(V2[0]-V1[0])+V1[1]]; //---------------------- // modules (Graphic Functions) //---------------------- // draw "rod" from v1 to v2 with thickness t module rod(v1=[0,0],v2=[0,0],t=6) { angle=getAngle2D(v1,v2); length=length2D(v1,v2); translate([v1[0],v1[1]]) rotate([0,0,angle]) { translate([0,0,0]) { cylinder(r=t,h=t+2,center = true); } translate([0,-t/2,-t/2]) { cube([length,t,t]); } } } //---------------------- // Leg Module // Jansen mechanism //---------------------- module leg ( ang=0, a=38.0, //a..m Theo Jansens Constants b=41.5, c=39.3, d=40.1, e=55.8, f=39.4, g=36.7, h=65.7, i=49.0, j=50.0, k=61.9, l= 7.8, m=15.0 ) { // Note parameter order matters! Z = [0,0]; //Origin X = addAngle2D(Z,ang,m); // Crank Y = add2D(Z,[a,-l]); // Base // Note: X is adjacent to j and Y is adjacent to b // and W is adjacent to j and b W = VVLL2D(X,Y,j,b); V = VVLL2D(W,Y,e,d); U = VVLL2D(Y,X,c,k); T = VVLL2D(V,U,f,g); S = VVLL2D(T,U,h,i); // Foot rod(Z, X); rod(X, W); rod(W, Y); rod(W, V); rod(Y, V); rod(X, U); rod(Y, U); rod(U, T); rod(V, T); rod(U, S); rod(T, S); rod(Z, Y); //draw the foot point translate(S){ cylinder(r=8,h=8,center = true); } } //---------------------- // Strandbeest //---------------------- module Strandbeest(ang=-$t*360,o=360/3,sgap=20,mgap=50) { { color([1, 0, 0]) translate([0,0,sgap*0]) leg(ang+o*0); color([0, 1, 0]) translate([0,0,sgap*1]) leg(ang+o*1); color([0, 0, 1]) translate([0,0,sgap*2]) leg(ang+o*2); } mirror(v= [1, 0, 0] ){ color([1, 0, 0]) translate([0,0,sgap*0]) leg(180-ang-o*0); color([0, 1, 0]) translate([0,0,sgap*1]) leg(180-ang-o*1); color([0, 0, 1]) translate([0,0,sgap*2]) leg(180-ang-o*2); } translate([0,0,sgap*2 + mgap]) { color([1, 0, 0]) translate([0,0,sgap*0]) leg(180+ang+o*0); color([0, 1, 0]) translate([0,0,sgap*1]) leg(180+ang+o*1); color([0, 0, 1]) translate([0,0,sgap*2]) leg(180+ang+o*2); } translate([0,0,sgap*2 + mgap]) mirror(v= [1, 0, 0] ){ color([1, 0, 0]) translate([0,0,sgap*0]) leg(0-ang-o*0); color([0, 1, 0]) translate([0,0,sgap*1]) leg(0-ang-o*1); color([0, 0, 1]) translate([0,0,sgap*2]) leg(0-ang-o*2); } } rotate([90,0,0]) Strandbeest();