1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-20 05:21:38 +02:00
This commit is contained in:
Justin Lin
2020-01-27 09:41:16 +08:00
parent d8c4d8f51f
commit b9590c4a10
2 changed files with 30 additions and 26 deletions

View File

@@ -0,0 +1,28 @@
function _radian_step(b, theta, l) =
let(
r_square = pow(b * theta, 2),
double_r_square = 2 * r_square
)
acos((double_r_square - pow(l, 2)) / double_r_square) / 180 * PI;
function _find_radians(b, point_distance, radians, n, count = 1) =
let(pre_radians = radians[count - 1])
count == n ? radians : (
_find_radians(
b,
point_distance,
concat(
radians,
[pre_radians + _radian_step(b, pre_radians, point_distance)]
),
n,
count + 1)
);
function _archimedean_spiral_impl(arm_distance, init_angle, point_distance, num_of_points, rt_dir) =
let(b = arm_distance / (2 * PI), init_radian = init_angle * PI / 180)
[
for(theta = _find_radians(b, point_distance, [init_radian], num_of_points))
let(r = b * theta, a = (rt_dir == "CT_CLK" ? 1 : -1) * theta * 57.2958)
[[r * cos(a), r * sin(a)], a]
];

View File

@@ -8,31 +8,7 @@
*
**/
function _radian_step(b, theta, l) =
let(
r_square = pow(b * theta, 2),
double_r_square = 2 * r_square
)
acos((double_r_square - pow(l, 2)) / double_r_square) / 180 * PI;
function _find_radians(b, point_distance, radians, n, count = 1) =
let(pre_radians = radians[count - 1])
count == n ? radians : (
_find_radians(
b,
point_distance,
concat(
radians,
[pre_radians + _radian_step(b, pre_radians, point_distance)]
),
n,
count + 1)
);
use <_impl/_archimedean_spiral_impl.scad>;
function archimedean_spiral(arm_distance, init_angle, point_distance, num_of_points, rt_dir = "CT_CLK") =
let(b = arm_distance / (2 * PI), init_radian = init_angle * PI / 180)
[
for(theta = _find_radians(b, point_distance, [init_radian], num_of_points))
let(r = b * theta, a = (rt_dir == "CT_CLK" ? 1 : -1) * theta * 57.2958)
[[r * cos(a), r * sin(a)], a]
];
_archimedean_spiral_impl(arm_distance, init_angle, point_distance, num_of_points, rt_dir);