diff --git a/docs/images/lib-bend-1.JPG b/docs/images/lib-bend-1.JPG new file mode 100644 index 00000000..6a6b5ec3 Binary files /dev/null and b/docs/images/lib-bend-1.JPG differ diff --git a/docs/images/lib-bend-2.JPG b/docs/images/lib-bend-2.JPG new file mode 100644 index 00000000..9d8c9f2d Binary files /dev/null and b/docs/images/lib-bend-2.JPG differ diff --git a/docs/images/lib-bend-3.JPG b/docs/images/lib-bend-3.JPG new file mode 100644 index 00000000..672bcbcf Binary files /dev/null and b/docs/images/lib-bend-3.JPG differ diff --git a/docs/lib-bend.md b/docs/lib-bend.md new file mode 100644 index 00000000..312a30d3 --- /dev/null +++ b/docs/lib-bend.md @@ -0,0 +1,51 @@ +# bend + +Bend a 3D object into an arc shape. + +## Parameters + +- `size` : The size of a cube which can contain the target object. +- `angle` : The central angle of the arc shape. The radius of the arc is calculated automatically. +- `fn` : Number of fragments. The target object will be cut into `fn` fragments and recombined into an arc shape. + +## Examples + +The containing cube of the target object should be laid down on the x-y plane. For examples. + + x = 9.25; + y = 9.55; + z = 1; + + %cube(size = [x, y, z]); + linear_extrude(z) text("A"); + +![bend](images/lib-bend-1.JPG) + +Once you have the size of the containing cube, you can use it as the `size` argument of the `bend` module. + + x = 9.25; + y = 9.55; + z = 1; + + *cube(size = [x, y, z]); + + bend(size = [x, y, z], angle = 270) + linear_extrude(z) text("A"); + +![bend](images/lib-bend-2.JPG) + +The arc shape is smoother if the `frags` is larger. + + x = 9.25; + y = 9.55; + z = 1; + + bend(size = [x, y, z], angle = 270, frags = 360) + linear_extrude(z) + text("A"); + +![bend](images/lib-bend-3.JPG) + +This module is especially useful when you want to create things such as [zentangle bracelet](https://www.thingiverse.com/thing:1569263). + +[![zentangle bracelet](http://thingiverse-production-new.s3.amazonaws.com/renders/eb/93/4f/62/1f/3bd1f628e1e566dcb5313035e4f3345b_preview_featured.JPG)](https://www.thingiverse.com/thing:1569263) \ No newline at end of file diff --git a/src/bend.scad b/src/bend.scad new file mode 100644 index 00000000..7215d112 --- /dev/null +++ b/src/bend.scad @@ -0,0 +1,53 @@ +/** +* bend.scad +* +* Bend a 3D object into an arc shape. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-bend.html +* +**/ + + +module bend(size, angle, frags = 24) { + x = size[0]; + y = size[1]; + z = size[2]; + frag_width = x / frags; + frag_angle = angle / frags; + half_frag_width = 0.5 * frag_width; + half_frag_angle = 0.5 * frag_angle; + r = half_frag_width / sin(half_frag_angle); + h = r * cos(half_frag_angle); + + module triangle_frag() { + translate([0, -z, 0]) + linear_extrude(y) + polygon( + [ + [0, 0], + [half_frag_width, h], + [frag_width, 0], + [0, 0] + ] + ); + } + + module get_frag(i) { + translate([-frag_width * i - half_frag_width, -h + z, 0]) + intersection() { + translate([frag_width * i, 0, 0]) + triangle_frag(); + rotate([90, 0, 0]) + children(); + } + } + + for(i = [0 : frags - 1]) { + rotate(i * frag_angle + half_frag_angle) + get_frag(i) + children(); + } +} \ No newline at end of file