diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..dc33e61 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# Round-Anything examples + +These examples are mostly to go with the [library Documentation](https://learn.cadhub.xyz/docs/round-anything/overview) and so are best viewed there. \ No newline at end of file diff --git a/examples/beamChain-1.scad b/examples/beamChain-1.scad new file mode 100644 index 0000000..57d2f07 --- /dev/null +++ b/examples/beamChain-1.scad @@ -0,0 +1,29 @@ +// beamChain example 1 + +include + +function beamPoints(r1,r2,rStart=0,rEnd=0)=[[0,0,rStart],[2,8,0],[5,4,r1],[15,10,r2],[17,2,rEnd]]; + +linear_extrude(1){ + + // chained lines by themselves + translate(){ + radiiPoints=beamPoints(0,0); + polygon(polyRound(beamChain(radiiPoints,offset1=0.02, offset2=-0.02),20)); + } + + + // Add some radii to the line transitions + translate([0,-7,0]){ + radiiPoints=beamPoints(2,1); + for(i=[0: len(beamPoints(2,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)); + } + + // Give make the lines beams with some thickness + translate([0,-7*2,0]){ + radiiPoints=beamPoints(2,1); + polygon(polyRound(beamChain(radiiPoints,offset1=0.5, offset2=-0.5),20)); + } + +} diff --git a/examples/beamChain-2.scad b/examples/beamChain-2.scad new file mode 100644 index 0000000..10aab9b --- /dev/null +++ b/examples/beamChain-2.scad @@ -0,0 +1,21 @@ +// beamChain example 2 + +include + +function beamPoints(r1,r2,rStart=0,rEnd=0)=[[0,0,rStart],[2,8,0],[5,4,r1],[15,10,r2],[17,2,rEnd]]; + +linear_extrude(1){ + + // Add an angle to the start of the beam + translate([0,-7*3,0]){ + radiiPoints=beamPoints(2,1); + polygon(polyRound(beamChain(radiiPoints,offset1=0.5, offset2=-0.5, startAngle=45),20)); + } + + // Put a negative radius at the start for transationing to a flat surface + translate([0,-7*4,0]){ + radiiPoints=beamPoints(2,1,rStart=-0.7); + polygon(polyRound(beamChain(radiiPoints,offset1=0.5, offset2=-0.5, startAngle=45),20)); + } + +} diff --git a/examples/beamChain-3.scad b/examples/beamChain-3.scad new file mode 100644 index 0000000..2b3eb45 --- /dev/null +++ b/examples/beamChain-3.scad @@ -0,0 +1,35 @@ +// beamChain example 3 + +include + +function beamPoints(r1,r2,rStart=0,rEnd=0)=[[0,0,rStart],[2,8,0],[5,4,r1],[15,10,r2],[17,2,rEnd]]; + +// Define more points for a polygon to be atteched to the end of the beam chain +clipP=[[16,1.2,0],[16,0,0],[16.5,0,0],[16.5,1,0.2],[17.5,1,0.2],[17.5,0,0],[18,0,0],[18,1.2,0]]; + +linear_extrude(1){ + // end hook + translate([-15,-7*5+3,0]){ + polygon(polyRound(clipP,20)); + } + + // Attached to the end of the beam chain by dividing the beam paths in forward and return and + // concat other polygon inbetween + translate([0,-7*6,0]){ + radiiPoints=beamPoints(2,1); + forwardPath=beamChain(radiiPoints,offset1=0.5,startAngle=-15,mode=2); + returnPath=revList(beamChain(radiiPoints,offset1=-0.5,startAngle=-15,mode=2)); + entirePath=concat(forwardPath,clipP,returnPath); + polygon(polyRound(entirePath,20)); + } + + // Add transitioning radii into the end polygong + translate([0,-7*7-2,0]){ + radiiPoints=beamPoints(2,1,rEnd=3); + forwardPath=beamChain(radiiPoints,offset1=0.5,startAngle=-15,mode=2); + returnPath=revList(beamChain(radiiPoints,offset1=-0.5,startAngle=-15,mode=2)); + entirePath=concat(forwardPath,clipP,returnPath); + polygon(polyRound(entirePath,20)); + } + +} diff --git a/examples/beamChain-4.scad b/examples/beamChain-4.scad new file mode 100644 index 0000000..f00db61 --- /dev/null +++ b/examples/beamChain-4.scad @@ -0,0 +1,16 @@ +// beamChain example 4 + +include + +function beamPoints(r1,r2,rStart=0,rEnd=0)=[[0,0,rStart],[2,8,0],[5,4,r1],[15,10,r2],[17,2,rEnd]]; + +linear_extrude(1){ + + translate([0,-7*9,0]){ + // Define multiple shells from the the one set of points + for(i=[0:2]){ + polygon(polyRound(beamChain(beamPoints(2,1),offset1=-1+i*0.4, offset2=-1+i*0.4+0.25),20)); + } + } + +} diff --git a/examples/extrudeWithRadius.scad b/examples/extrudeWithRadius.scad new file mode 100644 index 0000000..d9de98a --- /dev/null +++ b/examples/extrudeWithRadius.scad @@ -0,0 +1,13 @@ +// extrudeWithRadius example + +include + +radiiPoints=[ + [-4, 0, 1 ], + [5, 3, 1.5 ], + [0, 7, 0.1 ], + [8, 7, 10 ], + [20, 20, 0.8 ], + [10, 0, 10 ] +]; +extrudeWithRadius(3,0.5,0.5,5)polygon(polyRound(radiiPoints,30)); diff --git a/examples/mirrorPoints.scad b/examples/mirrorPoints.scad new file mode 100644 index 0000000..b5bcec9 --- /dev/null +++ b/examples/mirrorPoints.scad @@ -0,0 +1,10 @@ +// mirrorPoints example + +include + +centerRadius=7; +points=[[0,0,0],[2,8,0],[5,4,3],[15,10,0.5],[10,2,centerRadius]]; +mirroredPoints=mirrorPoints(points,0,[0,0]); +linear_extrude(1) + translate([0,-20,0]) + polygon(polyRound(mirroredPoints,20)); diff --git a/examples/polyRoundExtrude.scad b/examples/polyRoundExtrude.scad new file mode 100644 index 0000000..b731381 --- /dev/null +++ b/examples/polyRoundExtrude.scad @@ -0,0 +1,13 @@ +// polyRoundExtrude example + +include + +radiiPoints=[ + [10, 0, 10 ], + [20, 20, 1.1], + [8, 7, 10 ], + [0, 7, 0.3], + [5, 3, 0.1], + [-4, 0, 1 ] +]; +polyRoundExtrude(radiiPoints,2,0.5,-0.8,fn=20); diff --git a/examples/polyround.scad b/examples/polyround.scad new file mode 100644 index 0000000..b587144 --- /dev/null +++ b/examples/polyround.scad @@ -0,0 +1,13 @@ +// polyRound example + +include + +radiiPoints=[ + [-4, 0, 1 ], + [5, 3, 1.5 ], + [0, 7, 0.1 ], + [8, 7, 10 ], + [20, 20, 0.8 ], + [10, 0, 10 ] +]; +linear_extrude(3)polygon(polyRound(radiiPoints,30)); diff --git a/examples/radii-conflict.scad b/examples/radii-conflict.scad new file mode 100644 index 0000000..a254090 --- /dev/null +++ b/examples/radii-conflict.scad @@ -0,0 +1,25 @@ +// radii conflict example + +include + +//example of radii conflict handling and debuging feature +function makeRadiiPoints(r1, r2)=[ + [0, 0, 0 ], + [0, 20, r1 ], + [20, 20, r2 ], + [20, 0, 0 ] +]; + +linear_extrude(3){ + // 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)); + + //radii are too large and are reduced to fit and will be reduce to 10 and 10 + translate([0,0,0])polygon(polyRound(makeRadiiPoints(30,30),50)); + + //radii are too large again and are reduced to fit, but keep their ratios r1 will go from 10 to 4 and r2 will go from 40 to 16 + 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)); +} diff --git a/examples/shell2d.scad b/examples/shell2d.scad new file mode 100644 index 0000000..6f24b72 --- /dev/null +++ b/examples/shell2d.scad @@ -0,0 +1,29 @@ +// shell2d example + +include + +module gridpattern(memberW = 4, sqW = 12, iter = 5, r = 3){ + round2d(0, r)rotate([0, 0, 45])translate([-(iter * (sqW + memberW) + memberW) / 2, -(iter * (sqW + memberW) + memberW) / 2])difference(){ + square([(iter) * (sqW + memberW) + memberW, (iter) * (sqW + memberW) + memberW]); + for (i = [0:iter - 1], j = [0:iter - 1]){ + translate([i * (sqW + memberW) + memberW, j * (sqW + memberW) + memberW])square([sqW, sqW]); + } + } +} + +radiiPoints=[ + [-4, 0, 1 ], + [5, 3, 1.5 ], + [0, 7, 0.1 ], + [8, 7, 10 ], + [20, 20, 0.8 ], + [10, 0, 10 ] +]; + +linear_extrude(1){ + shell2d(-0.5)polygon(polyRound(radiiPoints,30)); + translate([0,-10,0])shell2d(-0.5){ + polygon(polyRound(radiiPoints,30)); + translate([8,8])gridpattern(memberW = 0.3, sqW = 1, iter = 17, r = 0.2); + } +} diff --git a/examples/translateRadiiPoints.scad b/examples/translateRadiiPoints.scad new file mode 100644 index 0000000..36692b9 --- /dev/null +++ b/examples/translateRadiiPoints.scad @@ -0,0 +1,30 @@ +// translateRadiiPoints example + +include + +nutW=5.5; nutH=3; boltR=1.6; +minT=2; minR=0.8; +function nutCapture(startAndEndRadius=0)=[ + [-boltR, 0, startAndEndRadius], + [-boltR, minT, 0], + [-nutW/2, minT, minR], + [-nutW/2, minT+nutH, minR], + [nutW/2, minT+nutH, minR], + [nutW/2, minT, minR], + [boltR, minT, 0], + [boltR, 0, startAndEndRadius], +]; +linear_extrude(3)translate([-5,0,0])polygon(polyRound(nutCapture(),20)); + +negativeNutCapture=translateRadiiPoints(nutCapture(),tran=[5,0]); +rotatedNegativeNutCapture=translateRadiiPoints(nutCapture(1),tran=[20,5],rot=90); +aSquare=concat( + [[0,0,0]], + negativeNutCapture, + [[20,0,0]], + rotatedNegativeNutCapture, + [[20,10,0]], + [[0,10,0]] +); + +linear_extrude(3)polygon(polyRound(aSquare,20));