diff --git a/polyround.scad b/polyround.scad index a932bee..fb98355 100644 --- a/polyround.scad +++ b/polyround.scad @@ -432,22 +432,23 @@ function CentreN2PointsArc(p1,p2,cen,mode=0,fn)= mode==3, plotted counter clockwise */ let( - CWorCCW=CWorCCW([cen,p1,p2]),//determine the direction of rotation + isCWorCCW=CWorCCW([cen,p1,p2]),//determine the direction of rotation //determine the arc angle depending on the mode p1p2Angle=cosineRuleAngle(p2,cen,p1), arcAngle= mode==0?p1p2Angle: mode==1?p1p2Angle-360: - mode==2&&CWorCCW==-1?p1p2Angle: - mode==2&&CWorCCW== 1?p1p2Angle-360: - mode==3&&CWorCCW== 1?p1p2Angle: - mode==3&&CWorCCW==-1?p1p2Angle-360: - cosineRuleAngle(p2,cen,p1) - , + mode==2&&isCWorCCW==-1?p1p2Angle: + mode==2&&isCWorCCW== 1?p1p2Angle-360: + mode==3&&isCWorCCW== 1?p1p2Angle: + mode==3&&isCWorCCW==-1?p1p2Angle-360: + cosineRuleAngle(p2,cen,p1), r=pointDist(p1,cen),//determine the radius p1Angle=getAngle(cen,p1) //angle of line 1 ) - [for(i=[0:fn]) [cos(p1Angle+(arcAngle/fn)*i*CWorCCW)*r+cen[0],sin(p1Angle+(arcAngle/fn)*i*CWorCCW)*r+cen[1]]]; + [for(i=[0:fn]) + let(angleIncrement=(arcAngle/fn)*i*isCWorCCW) + [cos(p1Angle+angleIncrement)*r+cen.x,sin(p1Angle+angleIncrement)*r+cen.y]]; function translateRadiiPoints(radiiPoints,tran=[0,0],rot=0)= [for(i=radiiPoints) @@ -539,7 +540,7 @@ function mirrorPoints(radiiPoints,rot=0,endAttenuation=[0,0])= //mirrors a list concat(radiiPoints,temp2); function processRadiiPoints(rp)= - [for(i=[0:len(rp)-1]) + [for(i=[0:len(rp)-1]) processRadiiPoints2(rp,i) ]; @@ -663,9 +664,9 @@ function getAngle(p1,p2)=p1==p2?0:invtan(p2[0]-p1[0],p2[1]-p1[1]); function getMidpoint(p1,p2)=[(p1[0]+p2[0])/2,(p1[1]+p2[1])/2]; //returns the midpoint of two points function pointDist(p1,p2)=sqrt(abs(sq(p1[0]-p2[0])+sq(p1[1]-p2[1]))); //returns the distance between two points function isColinear(p1,p2,p3)=getGradient(p1,p2)==getGradient(p2,p3)?1:0;//return 1 if 3 points are colinear -module polyline(p) { +module polyline(p, width=0.3) { for(i=[0:max(0,len(p)-1)]){ - line(p[i],p[listWrap(i+1,len(p) )]); + color([i*1/len(p),1-i*1/len(p),0,0.5])line(p[i],p[listWrap(i+1,len(p) )],width); } } // polyline plotter module line(p1, p2 ,width=0.3) { // single line plotter diff --git a/roundAnythingExamples.scad b/roundAnythingExamples.scad index 96f076f..b558580 100644 --- a/roundAnythingExamples.scad +++ b/roundAnythingExamples.scad @@ -1,6 +1,7 @@ include basicPolyRoundExample(); +// polyLineExample(); // parametricPolyRoundExample(); // experimentalParametricPolyRoundExample(); // conflicResolutionExample(); @@ -9,15 +10,23 @@ basicPolyRoundExample(); // beamChainExample(); // mirrorPointsExample(); // radiusExtrudeExample(); -// radiusExtrudePolygon(); // polyRoundExtrudeExample(); module basicPolyRoundExample(){ + // polyLine is a dev helper. Aim is to show the points of the polygon and their order before + // you're ready to move on to polyRound and a polygon radiiPoints=[[-4,0,1],[5,3,1.5],[0,7,0.1],[8,7,10],[20,20,0.8],[10,0,10]]; polygon(polyRound(radiiPoints,30)); %translate([0,0,0.3])polygon(getpoints(radiiPoints));//transparent copy of the polgon without rounding } +module polyLineExample() { + radiiPoints=[[-4,0,1],[5,3,1.5],[0,7,0.1],[8,7,10],[20,20,0.8],[10,0,10]]; + polyline(polyRound(radiiPoints,3), 0.05); + translate([0,10,0]) + polyline(radiiPoints, 0.05); +} + module parametricPolyRoundExample() { //Example of how a parametric part might be designed with this tool width=20; height=25; @@ -67,7 +76,7 @@ module experimentalParametricPolyRoundExample() { module conflicResolutionExample(){ //example of radii conflict handling and debuging feature - function makeRadiiPoints(r1, r2)=[[0,0,0],[0,20,r1],[20,20,r1],[20,0,0]]; + function makeRadiiPoints(r1, r2)=[[0,0,0],[0,20,r1],[20,20,r2],[20,0,0]]; // the squre shape being 20 wide, two radii of 10 both fit into the shape (just) translate([-25,0,0])polygon(polyRound(makeRadiiPoints(10,10),50)); @@ -79,7 +88,7 @@ module conflicResolutionExample(){ translate([25,0,0])polygon(polyRound(makeRadiiPoints(10,40),50)); //mode 2 = no radii limiting - translate([50,0,0])polygon(polyRound(makeRadiiPoints(15,20),50,mode=2)); + translate([50,0,0])polygon(polyRound(makeRadiiPoints(12,20),50,mode=2)); } module translateRadiiPointsExample() { @@ -124,9 +133,9 @@ module beamChainExample(){ function beamPoints(r1,r2,rStart=0,rEnd=0)=[[0,0,rStart],[2,8,0],[5,4,r1],[15,10,r2],[17,2,rEnd]]; // chained lines by themselves - translate(){ + translate([0,0,0]){ radiiPoints=beamPoints(0,0); - for(i=[0: len(radiiPoints)]){color("red")translate([radiiPoints[i].x,radiiPoints[i].y,0])cylinder(d=0.2, h=1);} + for(i=[0: len(radiiPoints)-1]){color("red")translate([radiiPoints[i].x,radiiPoints[i].y,0])cylinder(d=0.2, h=1);} polygon(polyRound(beamChain(radiiPoints,offset1=0.02, offset2=-0.02),20)); } @@ -134,7 +143,7 @@ module beamChainExample(){ // Add some radii to the line transitions translate([0,-7,0]){ radiiPoints=beamPoints(2,1); - for(i=[0: len(ex3)]){color("red")translate([radiiPoints[i].x,radiiPoints[i].y,0])cylinder(d=0.2, h=1);} + for(i=[0: len(radiiPoints)-1]){color("red")translate([radiiPoints[i].x,radiiPoints[i].y,0])cylinder(d=0.2, h=1);} polygon(polyRound(beamChain(radiiPoints,offset1=0.02, offset2=-0.02),20)); } @@ -184,7 +193,8 @@ module beamChainExample(){ // Define multiple shells from the the one set of points translate([0,-7*9,0]){ - for(i=[0:2]){polygon(polyRound(beamChain(ex3,offset1=-1+i*0.4, offset2=-1+i*0.4+0.25),20));} + radiiPoints=beamPoints(2,1,rEnd=3); + for(i=[0:2]){polygon(polyRound(beamChain(radiiPoints,offset1=-1+i*0.4, offset2=-1+i*0.4+0.25),20));} } }