1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 01:34:12 +02:00

added circle_path

This commit is contained in:
Justin Lin
2017-03-23 11:33:38 +08:00
parent 3cfbfde746
commit f9d077350b
4 changed files with 51 additions and 0 deletions

View File

@@ -24,4 +24,5 @@ I've been using OpenSCAD for years and created some funny things. Some of them i
- [bend](https://openhome.cc/eGossip/OpenSCAD/lib-bend.html)
- Path
- [circle_path](https://openhome.cc/eGossip/OpenSCAD/lib-circle_path.html)
- [bezier](https://openhome.cc/eGossip/OpenSCAD/lib-bezier.html)

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

27
docs/lib-circle_path.md Normal file
View File

@@ -0,0 +1,27 @@
# circle_path
Sometimes you need all points on the path of a circle. Here's the function. Its `$fa`, `$fs` and `$fn` parameters are consistent with the `circle` module.
## Parameters
- `radius` : The radius of the circle.
- `$fa`, `$fs`, `$fn` : Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details.
## Examples
$fn = 24;
points = circle_path(radius = 50);
polygon(points);
leng = len(points);
step_angle = 360 / leng;
for(i = [0:leng - 1]) {
translate(points[i])
rotate([90, 0, 90 + i * step_angle])
linear_extrude(1, center = true)
text("A", valign = "center", halign = "center");
}
![circle_path](images/lib-circle_path-1.JPG)

23
src/circle_path.scad Normal file
View File

@@ -0,0 +1,23 @@
/**
* circle_path.scad
*
* Sometimes you need all points on the path of a circle. Here's
* the function. Its $fa, $fs and $fn parameters are consistent
* with the circle module.
*
* @copyright Justin Lin, 2017
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-circle_path.html
*
**/
function _frags(radius) = $fn > 0 ?
($fn >= 3 ? $fn : 3) :
max(min(360 / $fa, radius * 2 * 3.14159 / $fs), 5);
function circle_path(radius) =
[
for(a = [0 : 360 / _frags(radius) : 360 - 360 / _frags(radius)])
[radius * cos(a), radius * sin(a)]
];