Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $fn=15;
- /* [circle offsets] */
- crcXoff=0;//[-20:1:20]
- crcYoff=0;//[-20:1:20]
- crctopXoff=0;//[-20:1:20]
- crctopYoff=0;//[-20:1:20]
- /* [segment height, bottom and top circle radiuses] */
- seghght=10;//[0:1:20]
- crcrad=10;//[0:1:20]
- crctoprad=15;//[5:1:30]
- /* [rotation angles] */
- linerotAngle=0;//[-180:15:180]
- fixRotAngle=0;//[-180:1:180]
- // 2 circles to simulate segment
- translate([0+crcXoff,crcYoff,0]) { %cylinder(h=.1,r=crcrad);
- color("blue") hull(){ translate([crcrad,0,.1])cube(.1,true); translate([-crcrad,0,.1])cube(.2,true); }
- color("blue") hull(){ translate([0,crcrad,.1])cube(.1,true); translate([0,-crcrad,.1])cube(.2,true); } }
- translate([0+crctopXoff,crctopYoff,seghght]) { %cylinder(h=.1,r=crctoprad);
- color("blue") hull(){translate([crctoprad,0,0])cube(.2,true); translate([-crctoprad,0,0])cube(.2,true);}
- color("blue") hull(){translate([0,crctoprad,0])cube(.2,true); translate([0,-crctoprad,0])cube(.2,true);} }
- // red line connecting points on circles at various rotation angles
- color("red")hull(){ translate([crcXoff,crcYoff]) rotate(linerotAngle) translate([crcrad,0,0]) cube(0.2,true);
- translate([crctopXoff,crctopYoff]) rotate(linerotAngle) translate([crctoprad,0,seghght]) cube(0.2,true); }
- module part() { // centered, X aligned, cyan top -X
- //translate([seghght/2-1.5,0,.5])color("cyan")cube([1,2,1],true); translate([-.5,0,.5])color("grey")cube([seghght-2-1,2,1],true); translate([0,0,-.5])color("yellow")cube([seghght-2,2,1],true);
- translate([-seghght/2+1.5,0,.5])color("cyan")cube([1,2,1],true); translate([.5,0,.5])color("grey")cube([seghght-2-1,2,1],true); translate([0,0,-.5])color("yellow")cube([seghght-2,2,1],true);
- }
- rotMulti=cos(PI*linerotAngle/180);
- rotateFromTo( p1=[crcrad*cos(linerotAngle)+crcXoff*rotMulti,crcrad*sin(linerotAngle)+crcYoff*rotMulti,0],
- p2=[crctoprad*cos(linerotAngle)+crctopXoff*rotMulti,crctoprad*sin(linerotAngle)+crctopYoff*rotMulti,seghght] )
- {
- // prerotate part to align with segment surface
- // rotate([0,-90,fixRotAngle-90]) // if part's top in +X
- rotate([0, 90,fixRotAngle+90]) // if part's top in -X
- part();
- };
- module rotateFromTo(p1,p2){ // rotates part to align with 2-point vector line and moves to it's mid
- translate((p1+p2)/2) // move to mid
- rotate([-acos((p2[2]-p1[2])/norm(p1-p2)),0,-atan2(p2[0]-p1[0],p2[1]-p1[1]) ]) // rotate to slope
- children();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement