diff --git a/README.md b/README.md index 9e274aba..b75d0910 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Some modules may depend on other modules. For example, the `polyline2d` module d - Other - [box_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-box_extrude.html) + - [stereographic_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-stereographic_extrude.html) ## About dotSCAD diff --git a/docs/images/lib-stereographic_extrude-1.JPG b/docs/images/lib-stereographic_extrude-1.JPG new file mode 100644 index 00000000..5aec3dfb Binary files /dev/null and b/docs/images/lib-stereographic_extrude-1.JPG differ diff --git a/docs/lib-stereographic_extrude.md b/docs/lib-stereographic_extrude.md new file mode 100644 index 00000000..cc307cd4 --- /dev/null +++ b/docs/lib-stereographic_extrude.md @@ -0,0 +1,31 @@ +# stereographic_extrude + +Takes a 2D polygon as input and extends it onto a sphere. If you light up a lamp on the north pole of the sphere, the shadow will return to the original 2D polygon. For more information, take a look at [Stereographic projection](https://en.wikipedia.org/wiki/Stereographic_projection). + +The 2D polygon should center at the origin and you have to determine the side length of a square which can cover the 2D polygon. Because the 2D polygon will be extended onto a sphere, you can use `$fa`, `$fs` or `$fn` to controll the sphere resolution. + +## Parameters + +- `shadow_side_leng` : The side length of a square which can cover the 2D polygon. +- `$fa`, `$fs`, `$fn` : Check [the sphere module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Primitive_Solids#sphere for more details. + + +## Examples + + dimension = 100; + + render() stereographic_extrude(shadow_side_leng = dimension) + text( + "M", size = dimension, + valign = "center", halign = "center" + ); + + color("black") + text( + "M", size = dimension, + valign = "center", halign = "center" + ); + +![stereographic_extrude](images/lib-stereographic_extrude-1.JPG) + +For more advanced examples, take a look at [my stereographic_projection collection](https://www.thingiverse.com/JustinSDK/collections/stereographic-projection). \ No newline at end of file diff --git a/src/stereographic_extrude.scad b/src/stereographic_extrude.scad new file mode 100644 index 00000000..2b4e16b9 --- /dev/null +++ b/src/stereographic_extrude.scad @@ -0,0 +1,35 @@ +/** +* stereographic_extrude.scad +* +* Takes a 2D polygon as input and extends it onto a sphere. +* If you light up a lamp on the north pole of the sphere, the +* shadow will return to the original 2D polygon. For more +* information, take a look at [Stereographic projection](https://en.wikipedia.org/wiki/Stereographic_projection). +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-stereographic_extrude.html +* +**/ + +module stereographic_extrude(shadow_side_leng) { + half_side_length = shadow_side_leng / 2; + outer_sphere_r = half_side_length / 3; + a = atan(sqrt(2) * half_side_length / (2 * outer_sphere_r)); + inner_sphere_r = outer_sphere_r * sin(a); + + intersection() { + translate([0, 0, outer_sphere_r]) difference() { + sphere(outer_sphere_r); + sphere(outer_sphere_r / 2 + inner_sphere_r / 2); + + translate([0, 0, outer_sphere_r / 2]) + linear_extrude(outer_sphere_r) + circle(inner_sphere_r * cos(a)); + } + + linear_extrude(outer_sphere_r * 2, scale = 0.01) + children(); + } +} \ No newline at end of file