module compensate() { //compensate for printer skew (xd mm in x direction for every yd mm in y direction) xd=-1.23; yd=100; l=sqrt(xd*xd + yd*yd); multmatrix(m=[ [1,-xd/yd,0,0], [0,l/yd,0,0], [0,0,1,0], [0,0,0,1] ]) children(); } module mx(d){ translate([d,0,0]) children(); } module my(d){ translate([0,d,0]) children(); } module mz(d){ translate([0,0,d]) children(); } module rx(d){ rotate([d,0,0]) children(); } module ry(d){ rotate([0,d,0]) children(); } module rz(d){ rotate([0,0,d]) children(); } module sx(a){ scale([a,1,1]) children(); } module sy(a){ scale([1,a,1]) children(); } module sz(a){ scale([1,1,a]) children(); } module xrotsym(angle=180) { children(); rx(angle) children(); } module yrotsym(angle=180) { children(); ry(angle) children(); } module zrotsym(angle=180) { children(); rz(angle) children(); } module xsym() { children(); sx(-1) children(); } module ysym() { children(); sy(-1) children(); } module zsym() { children(); sz(-1) children(); } module hole(h, d) { n = max(round(2 * d),3); cylinder(h = h, r = .5*d/cos(180/n), $fn = n); } module box(a, b, h) { translate([-a/2,-b/2,0]) cube([a,b,h], center=false); } module rbox(a,b,h,d) //rounded box (corners with radius d/2) { union(){ mx((a-d)/2) my((b-d)/2) cylinder(d=d,h=h); mx((a-d)/2) my(-(b-d)/2) cylinder(d=d,h=h); mx(-(a-d)/2) my((b-d)/2) cylinder(d=d,h=h); mx(-(a-d)/2) my(-(b-d)/2) cylinder(d=d,h=h); } } module sector(alfa, beta) { if(beta-alfa<180){ intersection(){ children(); rz(alfa) my(1000) mz(-1000) box(2000,2000,2000); rz(beta) my(-1000) mz(-1000) box(2000,2000,2000); } }else{ intersection(){ children(); union(){ rz(alfa) my(1000) mz(-1000) box(2000,2000,2000); rz(beta) my(-1000) mz(-1000) box(2000,2000,2000); } } } } module torus(R,rc) { rotate_extrude(convexity=10) mx(R) circle(r=rc); } module odtrhovnik(w,l, h=18) { box(3,w,h); mx(-l/2+1.5)box(l,w,0.25); } // Pozor -- trpi gymbal-lock effektem, jak je ukazano ve funkci wheel_test() module link(from, to, r) { d=to-from; h=norm(d); nd=d/h; c=sqrt(nd[0]*nd[0]+nd[2]*nd[2]); s=-nd[1]; w=nd[2]/c; z=-nd[0]/c; T = [ [w, -z*s, -z*c, from[0]], [0, c, -s, from[1]], [z, s*w, c*w, from[2]], [0, 0, 0, 1 ] ]; multmatrix(T) cylinder(h=h, r=r); } module wheel(n, R, r) { for(k=[0:n]){ link([0,0,0],R*[cos(360*k/n), sin(360*k/n), 0], r); link((1-0.5*(sqrt(5)-1))*R*[cos(360*k/n), sin(360*k/n), 0], R*[cos(360*(k+1)/n), sin(360*(k+1)/n), 0], r); } } module wheel_test() {wheel(35, 10, 0.2);}