diff --git a/docs/images/lib-ellipse-1.JPG b/docs/images/lib-ellipse-1.JPG new file mode 100644 index 00000000..1926ea2e Binary files /dev/null and b/docs/images/lib-ellipse-1.JPG differ diff --git a/docs/images/lib-ellipse-2.JPG b/docs/images/lib-ellipse-2.JPG new file mode 100644 index 00000000..c4297ba2 Binary files /dev/null and b/docs/images/lib-ellipse-2.JPG differ diff --git a/docs/lib-ellipse.md b/docs/lib-ellipse.md new file mode 100644 index 00000000..d958e4d3 --- /dev/null +++ b/docs/lib-ellipse.md @@ -0,0 +1,24 @@ +# ellipse + +Creates an ellipse. + +## Parameters + +- `axes` : 2 element vector `[x, y]` where x is the semi-major axis and y is the semi-minor axis. +- `$fa`, `$fs`, `$fn` : The shape created by this module can be viewd as `resize([x, y]) circle(r = x)` (but not the real implementation inside the module) so you can use these global variables to control it. Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details. + +## Examples + + include ; + + ellipse([40, 20]); + +![ellipse](images/lib-ellipse-1.JPG) + + include ; + + $fn = 8; + ellipse([20, 40]); + +![ellipse](images/lib-ellipse-2.JPG) + diff --git a/src/ellipse.scad b/src/ellipse.scad new file mode 100644 index 00000000..4a26ef21 --- /dev/null +++ b/src/ellipse.scad @@ -0,0 +1,26 @@ + +/** +* ellipse.scad +* +* Creates an ellipse. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-ellipse.html +* +**/ + +module ellipse(axes) { + frags = $fn > 0 ? + ($fn >= 3 ? $fn : 3) : + max(min(360 / $fa, axes[0] * 2 * 3.14159 / $fs), 5); + + step_a = 360 / frags; + polygon( + [ + for(a = [0:step_a:360 - step_a]) + [axes[0] * cos(a), axes[1] * sin(a)] + ] + ); +} \ No newline at end of file