From 9967d4a0c96550e9b60398ed3c3cc330005fd31f Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 30 Mar 2017 12:21:00 +0800 Subject: [PATCH] added parameter rt_dir --- docs/lib-archimedean_spiral.md | 1 + src/archimedean_spiral.scad | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/lib-archimedean_spiral.md b/docs/lib-archimedean_spiral.md index cd11a749..f1efb5c1 100644 --- a/docs/lib-archimedean_spiral.md +++ b/docs/lib-archimedean_spiral.md @@ -12,6 +12,7 @@ An `init_angle` less than 180 degrees is not recommended because the function us - `init_angle` : In polar coordinates `(r, θ)` Archimedean spiral can be described by the equation `r = bθ ` where `θ` is measured in radians. For being consistent with OpenSCAD, the function here use degrees. The `init_angle` is which angle the first point want to start. - `point_distance` : Distance between two points on the path. - `num_of_points` : How many points do you want? +- `rt_dir` : `"CT_CLK"` for counterclockwise. `"CLK"` for clockwise. The default value is `"CT_CLK"`. ## Examples diff --git a/src/archimedean_spiral.scad b/src/archimedean_spiral.scad index 73f0b13a..5b819797 100644 --- a/src/archimedean_spiral.scad +++ b/src/archimedean_spiral.scad @@ -46,10 +46,22 @@ function _find_radians(b, point_distance, radians, n, count = 1) = is required. To avoid a small error value at the calculated distance between two points, you may try a smaller point_distance. */ -function archimedean_spiral(arm_distance, init_angle, point_distance, num_of_points) = +function archimedean_spiral(arm_distance, init_angle, point_distance, num_of_points, rt_dir = "CT_CLK") = let(b = arm_distance / 6.28318, init_radian = init_angle *3.14159 / 180) [ for(theta = _find_radians(b, point_distance, [init_radian], num_of_points)) - let(r = b * theta, a = theta * 57.2958) + let(r = b * theta, a = (rt_dir == "CT_CLK" ? 1 : -1) * theta * 57.2958) [[r * cos(a), r * sin(a)], a] - ]; \ No newline at end of file + ]; + +points_angles = archimedean_spiral( + arm_distance = 10, + init_angle = 180, + point_distance = 5, + num_of_points = 100 +); + +for(pa = points_angles) { + translate(pa[0]) + circle(2); +} \ No newline at end of file