1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-16 03:34:42 +02:00
This commit is contained in:
Justin Lin
2022-03-01 09:01:28 +08:00
parent cb7c28d01a
commit 943d7bffca
3 changed files with 17 additions and 22 deletions

View File

@@ -1,9 +1,9 @@
function _radian_step(b, theta, l) = function _radian_step(b, theta, l) =
let( let(
r_square = pow(b * theta, 2), r_square = (b * theta) ^ 2,
double_r_square = 2 * r_square double_r_square = 2 * r_square
) )
acos((double_r_square - pow(l, 2)) / double_r_square) / 180 * PI; acos((double_r_square - l ^ 2) / double_r_square) / 180 * PI;
function _find_radians(b, point_distance, radians, n, count = 1) = function _find_radians(b, point_distance, radians, n, count = 1) =
let(pre_radians = radians[count - 1]) let(pre_radians = radians[count - 1])
@@ -21,5 +21,5 @@ function _archimedean_spiral_impl(arm_distance, init_angle, point_distance, num_
[ [
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 = (rt_dir == "CT_CLK" ? 1 : -1) * 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), sin(a)], a]
]; ];

View File

@@ -7,7 +7,7 @@ function _combi(n, k) =
[1,3,3,1] // n = 3: for Cubic Bézier curves [1,3,3,1] // n = 3: for Cubic Bézier curves
] ]
) )
n < len(bi_coef) ? bi_coef[n][k] : ( n < 4 ? bi_coef[n][k] : (
k == 0 ? 1 : (_combi(n, k - 1) * (n - k + 1) / k) k == 0 ? 1 : (_combi(n, k - 1) * (n - k + 1) / k)
); );
@@ -21,12 +21,12 @@ function _bezier_curve_point2(t, points) =
[ [
bezier_curve_coordinate( bezier_curve_coordinate(
t, t,
[for(p = points) p[0]], [for(p = points) p.x],
n n
), ),
bezier_curve_coordinate( bezier_curve_coordinate(
t, t,
[for(p = points) p[1]], [for(p = points) p.y],
n n
) )
]; ];
@@ -36,17 +36,17 @@ function _bezier_curve_point3(t, points) =
[ [
bezier_curve_coordinate( bezier_curve_coordinate(
t, t,
[for(p = points) p[0]], [for(p = points) p.x],
n n
), ),
bezier_curve_coordinate( bezier_curve_coordinate(
t, t,
[for(p = points) p[1]], [for(p = points) p.y],
n n
), ),
bezier_curve_coordinate( bezier_curve_coordinate(
t, t,
[for(p = points) p[2]], [for(p = points) p.z],
n n
) )
]; ];

View File

@@ -21,7 +21,7 @@ function interpolated_pt(p0, p1, threshold) =
function _isolines_pn_label(pts, threshold) = function _isolines_pn_label(pts, threshold) =
[ [
for(row = pts) for(row = pts)
[for(p = row) [p.x, p.y, p.z, p.z >= threshold]] [for(p = row) [each p, p.z >= threshold]]
]; ];
function _isolines_corner_value(cell_pts) = function _isolines_corner_value(cell_pts) =
@@ -116,10 +116,7 @@ function _isolines_of(cell_pts, threshold) =
function _marching_squares_isolines(points, threshold) = function _marching_squares_isolines(points, threshold) =
let(labeled_pts = _isolines_pn_label(points, threshold)) let(labeled_pts = _isolines_pn_label(points, threshold))
[ [
for( for(y = [0:len(labeled_pts) - 2], x = [0:len(labeled_pts[0]) - 2])
y = [0:len(labeled_pts) - 2],
x = [0:len(labeled_pts[0]) - 2]
)
let( let(
p0 = labeled_pts[y][x], p0 = labeled_pts[y][x],
p1 = labeled_pts[y + 1][x], p1 = labeled_pts[y + 1][x],
@@ -145,11 +142,12 @@ function _isobands_tri_label(pts, lower, upper) =
for(row = pts) for(row = pts)
[ [
for(p = row) for(p = row)
let(label = let(
p[2] < lower ? "0" : z = p.z,
p[2] >= lower && p[2] <= upper ? "1" : "2" label = z < lower ? "0" :
z >= lower && z <= upper ? "1" : "2"
) )
[p[0], p[1], p[2], label] [each p, label]
] ]
]; ];
@@ -1393,10 +1391,7 @@ function _isobands_of(cell_pts, lower, upper) =
function _marching_squares_isobands(points, lower, upper) = function _marching_squares_isobands(points, lower, upper) =
let(labeled_pts = _isobands_tri_label(points, lower, upper)) let(labeled_pts = _isobands_tri_label(points, lower, upper))
[ [
for( for(y = [0:len(labeled_pts) - 2], x = [0:len(labeled_pts[0]) - 2])
y = [0:len(labeled_pts) - 2],
x = [0:len(labeled_pts[0]) - 2]
)
let( let(
p0 = labeled_pts[y][x], p0 = labeled_pts[y][x],
p1 = labeled_pts[y + 1][x], p1 = labeled_pts[y + 1][x],