1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-20 13:31:30 +02:00

refactor: use radians, degrees

This commit is contained in:
Justin Lin
2022-04-16 16:42:23 +08:00
parent d69e08c506
commit 5ddc184e8b

View File

@@ -1,25 +1,26 @@
function _radian_step(b, theta, l) = use <../util/radians.scad>;
let( use <../util/degrees.scad>;
r_square = (b * theta) ^ 2,
double_r_square = 2 * r_square
)
acos((double_r_square - l ^ 2) / double_r_square) / 180 * PI;
function _find_radians(b, point_distance, radians, n, count = 1) = function _radian_step(b, theta, dist) =
let(pre_radians = radians[count - 1]) let(r_square = (b * theta) ^ 2)
count == n ? radians : ( radians(acos(1 - dist ^ 2 / (2 * r_square)));
function _find_radians(b, point_distance, rads, n, count = 1) =
let(pre_rads = rads[count - 1])
count == n ? rads : (
_find_radians( _find_radians(
b, b,
point_distance, point_distance,
[each radians, pre_radians + _radian_step(b, pre_radians, point_distance)], [each rads, pre_rads + _radian_step(b, pre_rads, point_distance)],
n, n,
count + 1) count + 1
)
); );
function _archimedean_spiral_impl(arm_distance, init_angle, point_distance, num_of_points, rt_dir) = 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, sgn = rt_dir == "CT_CLK" ? 1 : -1) let(b = arm_distance / (2 * PI), init_radian = radians(init_angle), sgn = rt_dir == "CT_CLK" ? 1 : -1)
[ [
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 = sgn * theta * 57.2958) let(r = b * theta, a = degrees(sgn * theta))
[r * [cos(a), sin(a)], a] [r * [cos(a), sin(a)], a]
]; ];