1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-21 05:52:16 +02:00

added parameter rt_dir

This commit is contained in:
Justin Lin
2017-03-30 12:21:00 +08:00
parent 549de8e06a
commit 9967d4a0c9
2 changed files with 16 additions and 3 deletions

View File

@@ -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. - `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. - `point_distance` : Distance between two points on the path.
- `num_of_points` : How many points do you want? - `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 ## Examples

View File

@@ -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 is required. To avoid a small error value at the calculated distance between two points, you
may try a smaller point_distance. 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) 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)) 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] [[r * cos(a), r * sin(a)], a]
]; ];
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);
}