1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-29 11:58:39 +01:00

add midpt_smooth

This commit is contained in:
Justin Lin 2019-05-28 07:29:40 +08:00
parent 4e1eca2df2
commit 04fd1590a7

11
src/midpt_smooth.scad Normal file
View File

@ -0,0 +1,11 @@
function _midpt_smooth_sub(points, iend, i, closed = false) =
i == iend ? (
closed ? [(points[i] + points[0]) / 2]
: []
) : concat([(points[i] + points[i + 1]) / 2], _midpt_smooth_sub(points, iend, i + 1, closed));
function midpt_smooth(points, n, closed = false) =
let(
smoothed = _midpt_smooth_sub(points, len(points) - 1, 0, closed)
)
n == 1 ? smoothed : midpt_smooth(smoothed, n - 1, closed);