Added subdivide_long_segments(), path_add_jitter(), jittered_poly()

This commit is contained in:
Garth Minette
2021-03-17 18:27:10 -07:00
parent 8da792e0f2
commit df9d045475
2 changed files with 93 additions and 0 deletions

View File

@@ -542,6 +542,7 @@ function _skin_core(profiles, caps) =
// Function: subdivide_and_slice()
// Topics: Paths, Path Subdivision
// Usage:
// newprof = subdivide_and_slice(profiles, slices, <numpoints>, <method>, <closed>);
// Description:
@@ -569,7 +570,39 @@ function subdivide_and_slice(profiles, slices, numpoints, method="length", close
slice_profiles(fixpoly, slices, closed);
// Function: subdivide_long_segments()
// Topics: Paths, Path Subdivision
// See Also: subdivide_path(), subdivide_and_slice(), path_add_jitter(), jittered_poly()
// Usage:
// spath = subdivide_long_segments(path, maxlen, <closed=>);
// Description:
// Evenly subdivides long `path` segments until they are all shorter than `maxlen`.
// Arguments:
// path = The path to subdivide.
// maxlen = The maximum allowed path segment length.
// ---
// closed = If true, treat path like a closed polygon. Default: true
// Example:
// path = pentagon(d=100);
// spath = subdivide_long_segments(path, 10, closed=true);
// stroke(path);
// color("lightgreen") move_copies(path) circle(d=5,$fn=12);
// color("blue") move_copies(spath) circle(d=3,$fn=12);
function subdivide_long_segments(path, maxlen, closed=false) =
assert(is_path(path))
assert(is_finite(maxlen))
assert(is_bool(closed))
[
for (p=pair(path,closed)) let(
steps = ceil(norm(p[1]-p[0])/maxlen)
) each lerp(p[0],p[1],[0:1/steps:1-EPSILON]),
if (!closed) last(path)
];
// Function: slice_profiles()
// Topics: Paths, Path Subdivision
// Usage:
// profs = slice_profiles(profiles, slices, <closed>);
// Description: