1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-22 22:35:18 +02:00
This commit is contained in:
Justin Lin
2022-05-04 21:04:38 +08:00
parent 6e4efe2e9f
commit 4e406b19cf

View File

@@ -15,17 +15,20 @@ function _combi(n, k) =
function bezier_curve_coordinate(t, pn, n, i) = function bezier_curve_coordinate(t, pn, n, i) =
let(one_t = 1 - t) let(one_t = 1 - t)
sum([for(j = [0:n]) _combi(n, j) * pn[j][i] * one_t ^ (n - j) * t ^ j]); sum([for(j = [0:n]) _combi(n, j) * pn[j][i] * one_t ^ (n - j) * t ^ j]);
function _bezier_curve_point2(t, points) = _bezier_curve_point2 = function(t, points, n)
let(n = len(points) - 1)
[for(i = [0, 1]) bezier_curve_coordinate(t, points, n, i)]; [for(i = [0, 1]) bezier_curve_coordinate(t, points, n, i)];
function _bezier_curve_point3(t, points) = _bezier_curve_point3 = function(t, points, n)
let(n = len(points) - 1)
[for(i = [0:2]) bezier_curve_coordinate(t, points, n, i)]; [for(i = [0:2]) bezier_curve_coordinate(t, points, n, i)];
function _bezier_curve_impl(t_step, points) = function _bezier_curve_impl(t_step, points) =
let(t_end = ceil(1 / t_step)) let(
len(points[0]) == 3 ? t_end = ceil(1 / t_step),
[each [for(t = 0; t < t_end; t = t + 1) _bezier_curve_point3(t * t_step, points)], _bezier_curve_point3(1, points)] : n = len(points) - 1,
[each [for(t = 0; t < t_end; t = t + 1) _bezier_curve_point2(t * t_step, points)], _bezier_curve_point2(1, points)]; _bezier_curve = len(points[0]) == 3 ? _bezier_curve_point3 : _bezier_curve_point2
)
[
each [for(t = 0; t < t_end; t = t + 1) _bezier_curve(t * t_step, points, n)],
_bezier_curve(1, points, n)
];