Changes all references to polyline to path.

This commit is contained in:
Garth Minette 2020-11-16 17:50:08 -08:00
parent bf80c1193a
commit e4f2497863
12 changed files with 67 additions and 111 deletions

View file

@ -9,10 +9,8 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
include <skin.scad>
// Section: Terminology // Section: Terminology
// **Polyline**: A series of points joined by straight line segements. // **Path**: A series of points joined by straight line segements.
// . // .
// **Bezier Curve**: A mathematical curve that joins two endpoints, following a curve determined by one or more control points. // **Bezier Curve**: A mathematical curve that joins two endpoints, following a curve determined by one or more control points.
// . // .
@ -27,7 +25,7 @@ include <skin.scad>
// . // .
// **Bezier Path**: A list of bezier segments flattened out into a list of points, where each segment shares the endpoint of the previous segment as a start point. A cubic Bezier Path looks something like: // **Bezier Path**: A list of bezier segments flattened out into a list of points, where each segment shares the endpoint of the previous segment as a start point. A cubic Bezier Path looks something like:
// `[endpt1, cp1, cp2, endpt2, cp3, cp4, endpt3]` // `[endpt1, cp1, cp2, endpt2, cp3, cp4, endpt3]`
// **NOTE**: A bezier path is *NOT* a polyline. It is only the points and controls used to define the curve. // **NOTE**: A "bezier path" is *NOT* a standard path. It is only the points and controls used to define the curve.
// . // .
// **Bezier Patch**: A surface defining grid of (N+1) by (N+1) bezier points. If a Bezier Segment defines a curved line, a Bezier Patch defines a curved surface. // **Bezier Patch**: A surface defining grid of (N+1) by (N+1) bezier points. If a Bezier Segment defines a curved line, a Bezier Patch defines a curved surface.
// . // .
@ -374,7 +372,7 @@ function bezier_segment_length(curve, start_u=0, end_u=1, max_deflect=0.01) =
// p0 = [40, 0]; // p0 = [40, 0];
// p1 = [0, 0]; // p1 = [0, 0];
// p2 = [30, 30]; // p2 = [30, 30];
// trace_polyline([p0,p1,p2], showpts=true, size=0.5, color="green"); // trace_path([p0,p1,p2], showpts=true, size=0.5, color="green");
// fbez = fillet3pts(p0,p1,p2, 10); // fbez = fillet3pts(p0,p1,p2, 10);
// trace_bezier(slice(fbez, 1, -2), size=1); // trace_bezier(slice(fbez, 1, -2), size=1);
function fillet3pts(p0, p1, p2, r, d, maxerr=0.1, w=0.5, dw=0.25) = let( function fillet3pts(p0, p1, p2, r, d, maxerr=0.1, w=0.5, dw=0.25) = let(
@ -482,11 +480,11 @@ function bezier_path_length(path, N=3, max_deflect=0.001) =
// Function: bezier_polyline() // Function: bezier_path()
// Usage: // Usage:
// bezier_polyline(bezier, [splinesteps], [N]) // bezier_path(bezier, [splinesteps], [N])
// Description: // Description:
// Takes a bezier path and converts it into a polyline. // Takes a bezier path and converts it into a path of points.
// Arguments: // Arguments:
// bezier = A bezier path to approximate. // bezier = A bezier path to approximate.
// splinesteps = Number of straight lines to split each bezier segment into. default=16 // splinesteps = Number of straight lines to split each bezier segment into. default=16
@ -498,9 +496,9 @@ function bezier_path_length(path, N=3, max_deflect=0.001) =
// [60,25], [70,0], [80,-25], // [60,25], [70,0], [80,-25],
// [80,-50], [50,-50] // [80,-50], [50,-50]
// ]; // ];
// trace_polyline(bez, size=1, N=3, showpts=true); // trace_path(bez, size=1, N=3, showpts=true);
// trace_polyline(bezier_polyline(bez, N=3), size=3); // trace_path(bezier_path(bez, N=3), size=3);
function bezier_polyline(bezier, splinesteps=16, N=3) = function bezier_path(bezier, splinesteps=16, N=3) =
assert(is_path(bezier)) assert(is_path(bezier))
assert(is_int(N)) assert(is_int(N))
assert(is_int(splinesteps)) assert(is_int(splinesteps))
@ -598,15 +596,15 @@ function path_to_bezier(path, tangents, size, relsize, uniform=false, closed=fal
// Usage: // Usage:
// fillet_path(pts, fillet, [maxerr]); // fillet_path(pts, fillet, [maxerr]);
// Description: // Description:
// Takes a 3D polyline path and fillets the corners, returning a 3d cubic (degree 3) bezier path. // Takes a 3D path and fillets the corners, returning a 3d cubic (degree 3) bezier path.
// Arguments: // Arguments:
// pts = 3D Polyline path to fillet. // pts = 3D path to fillet.
// fillet = The radius to fillet/round the polyline corners by. // fillet = The radius to fillet/round the path corners by.
// maxerr = Max amount bezier curve should diverge from actual radius curve. Default: 0.1 // maxerr = Max amount bezier curve should diverge from actual radius curve. Default: 0.1
// Example(2D): // Example(2D):
// pline = [[40,0], [0,0], [35,35], [0,70], [-10,60], [-5,55], [0,60]]; // pline = [[40,0], [0,0], [35,35], [0,70], [-10,60], [-5,55], [0,60]];
// bez = fillet_path(pline, 10); // bez = fillet_path(pline, 10);
// trace_polyline(pline, showpts=true, size=0.5, color="green"); // trace_path(pline, showpts=true, size=0.5, color="green");
// trace_bezier(bez, size=1); // trace_bezier(bez, size=1);
function fillet_path(pts, fillet, maxerr=0.1) = concat( function fillet_path(pts, fillet, maxerr=0.1) = concat(
[pts[0], pts[0]], [pts[0], pts[0]],
@ -722,7 +720,7 @@ module bezier_polygon(bezier, splinesteps=16, N=3) {
assert(is_int(N)); assert(is_int(N));
assert(is_int(splinesteps)); assert(is_int(splinesteps));
assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
polypoints=bezier_polyline(bezier, splinesteps, N); polypoints=bezier_path(bezier, splinesteps, N);
polygon(points=slice(polypoints, 0, -1)); polygon(points=slice(polypoints, 0, -1));
} }
@ -803,7 +801,7 @@ module rotate_sweep_bezier(bezier, splinesteps=16, N=3, convexity=undef, angle=3
assert(is_int(N)); assert(is_int(N));
assert(is_num(angle)); assert(is_num(angle));
assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
oline = bezier_polyline(bezier, splinesteps=splinesteps, N=N); oline = bezier_path(bezier, splinesteps=splinesteps, N=N);
maxx = max([for (pt = oline) abs(pt[0])]); maxx = max([for (pt = oline) abs(pt[0])]);
miny = min(subindex(oline,1)); miny = min(subindex(oline,1));
maxy = max(subindex(oline,1)); maxy = max(subindex(oline,1));
@ -839,7 +837,7 @@ module bezier_path_extrude(bezier, splinesteps=16, N=3, convexity=undef, clipsiz
assert(is_int(N)); assert(is_int(N));
assert(is_num(clipsize)); assert(is_num(clipsize));
assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
path = slice(bezier_polyline(bezier, splinesteps, N), 0, -1); path = slice(bezier_path(bezier, splinesteps, N), 0, -1);
path_extrude(path, convexity=convexity, clipsize=clipsize) children(); path_extrude(path, convexity=convexity, clipsize=clipsize) children();
} }
@ -876,8 +874,8 @@ module bezier_sweep_bezier(bezier, path, pathsteps=16, bezsteps=16, bezN=3, path
assert(is_int(pathN)); assert(is_int(pathN));
assert(len(bezier)%bezN == 1, str("For argument bezier, a degree ",bezN," bezier path shound have a multiple of ",bezN," points in it, plus 1.")); assert(len(bezier)%bezN == 1, str("For argument bezier, a degree ",bezN," bezier path shound have a multiple of ",bezN," points in it, plus 1."));
assert(len(path)%pathN == 1, str("For argument bezier, a degree ",pathN," bezier path shound have a multiple of ",pathN," points in it, plus 1.")); assert(len(path)%pathN == 1, str("For argument bezier, a degree ",pathN," bezier path shound have a multiple of ",pathN," points in it, plus 1."));
bez_points = simplify_path(bezier_polyline(bezier, bezsteps, bezN)); bez_points = simplify_path(bezier_path(bezier, bezsteps, bezN));
path_points = simplify_path(path3d(bezier_polyline(path, pathsteps, pathN))); path_points = simplify_path(path3d(bezier_path(path, pathsteps, pathN)));
path_sweep(bez_points, path_points); path_sweep(bez_points, path_points);
} }
@ -902,8 +900,8 @@ module trace_bezier(bez, N=3, size=1) {
assert(is_path(bez)); assert(is_path(bez));
assert(is_int(N)); assert(is_int(N));
assert(len(bez)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); assert(len(bez)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1."));
trace_polyline(bez, N=N, showpts=true, size=size, color="green"); trace_path(bez, N=N, showpts=true, size=size, color="green");
trace_polyline(bezier_polyline(bez, N=N), size=size, color="cyan"); trace_path(bezier_path(bez, N=N), size=size, color="cyan");
} }

View file

@ -8,32 +8,30 @@
// ``` // ```
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
include <skin.scad>
// Section: Debugging Paths and Polygons // Section: Debugging Paths and Polygons
// Module: trace_polyline() // Module: trace_path()
// Description: // Description:
// Renders lines between each point of a polyline path. // Renders lines between each point of a path.
// Can also optionally show the individual vertex points. // Can also optionally show the individual vertex points.
// Arguments: // Arguments:
// pline = The array of points in the polyline. // path = The list of points in the path.
// closed = If true, draw the segment from the last vertex to the first. Default: false // closed = If true, draw the segment from the last vertex to the first. Default: false
// showpts = If true, draw vertices and control points. // showpts = If true, draw vertices and control points.
// N = Mark the first and every Nth vertex after in a different color and shape. // N = Mark the first and every Nth vertex after in a different color and shape.
// size = Diameter of the lines drawn. // size = Diameter of the lines drawn.
// color = Color to draw the lines (but not vertices) in. // color = Color to draw the lines (but not vertices) in.
// Example(FlatSpin): // Example(FlatSpin):
// polyline = [for (a=[0:30:210]) 10*[cos(a), sin(a), sin(a)]]; // path = [for (a=[0:30:210]) 10*[cos(a), sin(a), sin(a)]];
// trace_polyline(polyline, showpts=true, size=0.5, color="lightgreen"); // trace_path(path, showpts=true, size=0.5, color="lightgreen");
module trace_polyline(pline, closed=false, showpts=false, N=1, size=1, color="yellow") { module trace_path(path, closed=false, showpts=false, N=1, size=1, color="yellow") {
assert(is_path(pline),"Input pline is not a path"); assert(is_path(path),"Invalid path argument");
sides = segs(size/2); sides = segs(size/2);
pline = closed? close_path(pline) : pline; path = closed? close_path(path) : path;
if (showpts) { if (showpts) {
for (i = [0:1:len(pline)-1]) { for (i = [0:1:len(path)-1]) {
translate(pline[i]) { translate(path[i]) {
if (i%N == 0) { if (i%N == 0) {
color("blue") sphere(d=size*2.5, $fn=8); color("blue") sphere(d=size*2.5, $fn=8);
} else { } else {
@ -47,11 +45,11 @@ module trace_polyline(pline, closed=false, showpts=false, N=1, size=1, color="ye
} }
} }
if (N!=3) { if (N!=3) {
color(color) stroke(path3d(pline), width=size, $fn=8); color(color) stroke(path3d(path), width=size, $fn=8);
} else { } else {
for (i = [0:1:len(pline)-2]) { for (i = [0:1:len(path)-2]) {
if (N!=3 || (i%N) != 1) { if (N!=3 || (i%N) != 1) {
color(color) extrude_from_to(pline[i], pline[i+1]) circle(d=size, $fn=sides); color(color) extrude_from_to(path[i], path[i+1]) circle(d=size, $fn=sides);
} }
} }
} }

View file

@ -10,7 +10,6 @@
include <rounding.scad> include <rounding.scad>
include <skin.scad>
// Section: Half Joiners // Section: Half Joiners
@ -989,7 +988,7 @@ module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1
: let(side_smooth=select(pin_smooth, 0, 2)) : let(side_smooth=select(pin_smooth, 0, 2))
concat(side_smooth, [socket_smooth], reverse(side_smooth)); concat(side_smooth, [socket_smooth], reverse(side_smooth));
bez = path_to_bezier(path,relsize=smoothing,tangents=tangent); bez = path_to_bezier(path,relsize=smoothing,tangents=tangent);
rounded = bezier_polyline(bez,splinesteps=splinesteps); rounded = bezier_path(bez,splinesteps=splinesteps);
bounds = pointlist_bounds(rounded); bounds = pointlist_bounds(rounded);
//kk = search([bounds[1].y], subindex(rounded,1)); //kk = search([bounds[1].y], subindex(rounded,1));
//echo(rounded[kk[0]]); //echo(rounded[kk[0]]);

View file

@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// LibFile: paths.scad // LibFile: paths.scad
// Polylines, polygons and paths. // Support for polygons and paths.
// To use, add the following lines to the beginning of your file: // To use, add the following lines to the beginning of your file:
// ``` // ```
// include <BOSL2/std.scad> // include <BOSL2/std.scad>
@ -421,7 +421,7 @@ function path_torsion(path, closed=false) =
// cp = Centerpoint of spiral. Default: `[0,0]` // cp = Centerpoint of spiral. Default: `[0,0]`
// scale = [X,Y] scaling factors for each axis. Default: `[1,1]` // scale = [X,Y] scaling factors for each axis. Default: `[1,1]`
// Example(3D): // Example(3D):
// trace_polyline(path3d_spiral(turns=2.5, h=100, n=24, r=50), N=1, showpts=true); // trace_path(path3d_spiral(turns=2.5, h=100, n=24, r=50), N=1, showpts=true);
function path3d_spiral(turns=3, h=100, n=12, r, d, cp=[0,0], scale=[1,1]) = let( function path3d_spiral(turns=3, h=100, n=12, r, d, cp=[0,0], scale=[1,1]) = let(
rr=get_radius(r=r, d=d, dflt=100), rr=get_radius(r=r, d=d, dflt=100),
cnt=floor(turns*n), cnt=floor(turns*n),
@ -435,44 +435,6 @@ function path3d_spiral(turns=3, h=100, n=12, r, d, cp=[0,0], scale=[1,1]) = let(
]; ];
// Function: points_along_path3d()
// Usage:
// points_along_path3d(polyline, path);
// Description:
// Calculates the vertices needed to create a `polyhedron()` of the
// extrusion of `polyline` along `path`. The closed 2D path shold be
// centered on the XY plane. The 2D path is extruded perpendicularly
// along the 3D path. Produces a list of 3D vertices. Vertex count
// is `len(polyline)*len(path)`. Gives all the reoriented vertices
// for `polyline` at the first point in `path`, then for the second,
// and so on.
// Arguments:
// polyline = A closed list of 2D path points.
// path = A list of 3D path points.
function points_along_path3d(
polyline, // The 2D polyline to drag along the 3D path.
path, // The 3D polyline path to follow.
q=Q_Ident(), // Used in recursion
n=0 // Used in recursion
) = let(
end = len(path)-1,
v1 = (n == 0)? [0, 0, 1] : unit(path[n]-path[n-1]),
v2 = (n == end)? unit(path[n]-path[n-1]) : unit(path[n+1]-path[n]),
crs = cross(v1, v2),
axis = norm(crs) <= 0.001? [0, 0, 1] : crs,
ang = vector_angle(v1, v2),
hang = ang * (n==0? 1.0 : 0.5),
hrot = Quat(axis, hang),
arot = Quat(axis, ang),
roth = Q_Mul(hrot, q),
rotm = Q_Mul(arot, q)
) concat(
[for (i = [0:1:len(polyline)-1]) Qrot(roth,p=point3d(polyline[i])) + path[n]],
(n == end)? [] : points_along_path3d(polyline, path, rotm, n+1)
);
// Function: path_self_intersections() // Function: path_self_intersections()
// Usage: // Usage:
// isects = path_self_intersections(path, [eps]); // isects = path_self_intersections(path, [eps]);
@ -529,9 +491,9 @@ function path_self_intersections(path, closed=true, eps=EPSILON) =
// Function: split_path_at_self_crossings() // Function: split_path_at_self_crossings()
// Usage: // Usage:
// polylines = split_path_at_self_crossings(path, [closed], [eps]); // paths = split_path_at_self_crossings(path, [closed], [eps]);
// Description: // Description:
// Splits a path into polyline sections wherever the path crosses itself. // Splits a path into sub-paths wherever the original path crosses itself.
// Splits may occur mid-segment, so new vertices will be created at the intersection points. // Splits may occur mid-segment, so new vertices will be created at the intersection points.
// Arguments: // Arguments:
// path = The path to split up. // path = The path to split up.
@ -539,8 +501,8 @@ function path_self_intersections(path, closed=true, eps=EPSILON) =
// eps = Acceptable variance. Default: `EPSILON` (1e-9) // eps = Acceptable variance. Default: `EPSILON` (1e-9)
// Example(2D): // Example(2D):
// path = [ [-100,100], [0,-50], [100,100], [100,-100], [0,50], [-100,-100] ]; // path = [ [-100,100], [0,-50], [100,100], [100,-100], [0,50], [-100,-100] ];
// polylines = split_path_at_self_crossings(path); // paths = split_path_at_self_crossings(path);
// rainbow(polylines) stroke($item, closed=false, width=2); // rainbow(paths) stroke($item, closed=false, width=2);
function split_path_at_self_crossings(path, closed=true, eps=EPSILON) = function split_path_at_self_crossings(path, closed=true, eps=EPSILON) =
let( let(
path = cleanup_path(path, eps=eps), path = cleanup_path(path, eps=eps),
@ -681,11 +643,11 @@ function _extreme_angle_fragment(seg, fragments, rightmost=true, eps=EPSILON) =
// Usage: // Usage:
// assemble_a_path_from_fragments(subpaths); // assemble_a_path_from_fragments(subpaths);
// Description: // Description:
// Given a list of incomplete paths, assembles them together into one complete closed path, and // Given a list of paths, assembles them together into one complete closed polygon path, and
// remainder fragments. Returns [PATH, FRAGMENTS] where FRAGMENTS is the list of remaining // remainder fragments. Returns [PATH, FRAGMENTS] where FRAGMENTS is the list of remaining
// polyline path fragments. // unused path fragments.
// Arguments: // Arguments:
// fragments = List of polylines to be assembled into complete polygons. // fragments = List of paths to be assembled into complete polygons.
// rightmost = If true, assemble paths using rightmost turns. Leftmost if false. // rightmost = If true, assemble paths using rightmost turns. Leftmost if false.
// startfrag = The fragment to start with. Default: 0 // startfrag = The fragment to start with. Default: 0
// eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9) // eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9)
@ -738,9 +700,9 @@ function assemble_a_path_from_fragments(fragments, rightmost=true, startfrag=0,
// Usage: // Usage:
// assemble_path_fragments(subpaths); // assemble_path_fragments(subpaths);
// Description: // Description:
// Given a list of incomplete paths, assembles them together into complete closed paths if it can. // Given a list of paths, assembles them together into complete closed polygon paths if it can.
// Arguments: // Arguments:
// fragments = List of polylines to be assembled into complete polygons. // fragments = List of paths to be assembled into complete polygons.
// eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9) // eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9)
function assemble_path_fragments(fragments, eps=EPSILON, _finished=[]) = function assemble_path_fragments(fragments, eps=EPSILON, _finished=[]) =
len(fragments)==0? _finished : len(fragments)==0? _finished :
@ -832,10 +794,10 @@ module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slic
// Module: spiral_sweep() // Module: spiral_sweep()
// Description: // Description:
// Takes a closed 2D polyline path, centered on the XY plane, and // Takes a closed 2D polygon path, centered on the XY plane, and sweeps/extrudes it along a 3D spiral path
// extrudes it along a 3D spiral path of a given radius, height and twist. // of a given radius, height and twist.
// Arguments: // Arguments:
// polyline = Array of points of a polyline path, to be extruded. // path = Array of points of a polygon path, to be extruded.
// h = height of the spiral to extrude along. // h = height of the spiral to extrude along.
// r = Radius of the spiral to extrude along. Default: 50 // r = Radius of the spiral to extrude along. Default: 50
// d = Diameter of the spiral to extrude along. // d = Diameter of the spiral to extrude along.
@ -847,10 +809,10 @@ module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slic
// Example: // Example:
// poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]]; // poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]];
// spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36); // spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36);
module spiral_sweep(polyline, h, r, twist=360, center, d, anchor, spin=0, orient=UP) { module spiral_sweep(poly, h, r, twist=360, center, d, anchor, spin=0, orient=UP) {
r = get_radius(r=r, d=d, dflt=50); r = get_radius(r=r, d=d, dflt=50);
polyline = path3d(polyline); poly = path3d(poly);
pline_count = len(polyline); pline_count = len(poly);
steps = ceil(segs(r)*(twist/360)); steps = ceil(segs(r)*(twist/360));
anchor = get_anchor(anchor,center,BOT,BOT); anchor = get_anchor(anchor,center,BOT,BOT);
@ -863,7 +825,7 @@ module spiral_sweep(polyline, h, r, twist=360, center, d, anchor, spin=0, orient
dy = r*sin(a), dy = r*sin(a),
dz = h * (p/steps), dz = h * (p/steps),
pts = apply_list( pts = apply_list(
polyline, [ poly, [
affine3d_xrot(90), affine3d_xrot(90),
affine3d_zrot(a), affine3d_zrot(a),
affine3d_translate([dx, dy, dz-h/2]) affine3d_translate([dx, dy, dz-h/2])
@ -902,7 +864,7 @@ module spiral_sweep(polyline, h, r, twist=360, center, d, anchor, spin=0, orient
// Module: path_extrude() // Module: path_extrude()
// Description: // Description:
// Extrudes 2D children along a 3D polyline path. This may be slow. // Extrudes 2D children along a 3D path. This may be slow.
// Arguments: // Arguments:
// path = array of points for the bezier path to extrude along. // path = array of points for the bezier path to extrude along.
// convexity = maximum number of walls a ran can pass through. // convexity = maximum number of walls a ran can pass through.

View file

@ -154,9 +154,9 @@ function region_path_crossings(path, region, closed=true, eps=EPSILON) = sort([
// Function: split_path_at_region_crossings() // Function: split_path_at_region_crossings()
// Usage: // Usage:
// polylines = split_path_at_region_crossings(path, region, [eps]); // paths = split_path_at_region_crossings(path, region, [eps]);
// Description: // Description:
// Splits a path into polyline sections wherever the path crosses the perimeter of a region. // Splits a path into sub-paths wherever the path crosses the perimeter of a region.
// Splits may occur mid-segment, so new vertices will be created at the intersection points. // Splits may occur mid-segment, so new vertices will be created at the intersection points.
// Arguments: // Arguments:
// path = The path to split up. // path = The path to split up.
@ -166,9 +166,9 @@ function region_path_crossings(path, region, closed=true, eps=EPSILON) = sort([
// Example(2D): // Example(2D):
// path = square(50,center=false); // path = square(50,center=false);
// region = [circle(d=80), circle(d=40)]; // region = [circle(d=80), circle(d=40)];
// polylines = split_path_at_region_crossings(path, region); // paths = split_path_at_region_crossings(path, region);
// color("#aaa") region(region); // color("#aaa") region(region);
// rainbow(polylines) stroke($item, closed=false, width=2); // rainbow(paths) stroke($item, closed=false, width=2);
function split_path_at_region_crossings(path, region, closed=true, eps=EPSILON) = function split_path_at_region_crossings(path, region, closed=true, eps=EPSILON) =
let( let(
path = deduplicate(path, eps=eps), path = deduplicate(path, eps=eps),

View file

@ -181,7 +181,6 @@ include <structs.scad>
// path_sweep(regular_ngon(n=36,or=.1),round_corners(list2,closed=false, method="circle", cut = 0.75)); // path_sweep(regular_ngon(n=36,or=.1),round_corners(list2,closed=false, method="circle", cut = 0.75));
// Example(FlatSpin): Rounding a spiral with increased rounding along the length // Example(FlatSpin): Rounding a spiral with increased rounding along the length
// // Construct a square spiral path in 3D // // Construct a square spiral path in 3D
// include <BOSL2/skin.scad>
// $fn=36; // $fn=36;
// square = [[0,0],[1,0],[1,1],[0,1]]; // square = [[0,0],[1,0],[1,1],[0,1]];
// spiral = flatten(repeat(concat(square,reverse(square)),5)); // Squares repeat 10 times, forward and backward // spiral = flatten(repeat(concat(square,reverse(square)),5)); // Squares repeat 10 times, forward and backward
@ -454,7 +453,7 @@ function smooth_path(path, tangents, size, relsize, splinesteps=10, uniform=fals
let ( let (
bez = path_to_bezier(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=closed) bez = path_to_bezier(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=closed)
) )
bezier_polyline(bez,splinesteps=splinesteps); bezier_path(bez,splinesteps=splinesteps);

View file

@ -377,7 +377,7 @@ module stroke(
// stroke(closed=true, path); // stroke(closed=true, path);
// Example(FlatSpin): // Example(FlatSpin):
// path = arc(points=[[0,30,0],[0,0,30],[30,0,0]]); // path = arc(points=[[0,30,0],[0,0,30],[30,0,0]]);
// trace_polyline(path, showpts=true, color="cyan"); // trace_path(path, showpts=true, color="cyan");
function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, long=false, cw=false, ccw=false) = function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, long=false, cw=false, ccw=false) =
// First try for 2D arc specified by width and thickness // First try for 2D arc specified by width and thickness
is_def(width) && is_def(thickness)? ( is_def(width) && is_def(thickness)? (

View file

@ -10,7 +10,6 @@
// - https://github.com/openscad/list-comprehension-demos/blob/master/skin.scad // - https://github.com/openscad/list-comprehension-demos/blob/master/skin.scad
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
include <vnf.scad>
// Section: Skinning // Section: Skinning
@ -824,7 +823,7 @@ function associate_vertices(polygons, split, curpoly=0) =
// Function&Module: sweep() // Function&Module: sweep()
// Usage: As Module // Usage: As Module
// sweep(shape, transformations, <closed<, <caps>) // sweep(shape, transformations, <closed>, <caps>)
// Usage: As Function // Usage: As Function
// vnf = sweep(shape, transformations, <closed>, <caps>); // vnf = sweep(shape, transformations, <closed>, <caps>);
// Description: // Description:

View file

@ -31,6 +31,7 @@ include <coords.scad>
include <geometry.scad> include <geometry.scad>
include <regions.scad> include <regions.scad>
include <strings.scad> include <strings.scad>
include <skin.scad>
include <vnf.scad> include <vnf.scad>
include <common.scad> include <common.scad>
include <debug.scad> include <debug.scad>

View file

@ -671,8 +671,8 @@ function yscale(y=1, p=undef, planar=false) = (planar || (!is_undef(p) && len(p)
// //
// Example: Scaling Points // Example: Scaling Points
// path = xrot(90,p=path3d(circle(d=50,$fn=12))); // path = xrot(90,p=path3d(circle(d=50,$fn=12)));
// #trace_polyline(path); // #trace_path(path);
// trace_polyline(zscale(2,p=path)); // trace_path(zscale(2,p=path));
module zscale(z=1) scale([1,1,z]) children(); module zscale(z=1) scale([1,1,z]) children();
function zscale(z=1, p=undef) = scale([1,1,z],p=p); function zscale(z=1, p=undef) = scale([1,1,z],p=p);
@ -917,7 +917,7 @@ function zflip(z=0,p) =
// color("blue") move_copies(pts) circle(d=3, $fn=8); // color("blue") move_copies(pts) circle(d=3, $fn=8);
// Example(FlatSpin): Calling as a 3D Function // Example(FlatSpin): Calling as a 3D Function
// pts = skew(p=path3d(square(40,center=true)), szx=0.5, szy=0.3); // pts = skew(p=path3d(square(40,center=true)), szx=0.5, szy=0.3);
// trace_polyline(close_path(pts), showpts=true); // trace_path(close_path(pts), showpts=true);
module skew(sxy=0, sxz=0, syx=0, syz=0, szx=0, szy=0) module skew(sxy=0, sxz=0, syx=0, syz=0, szx=0, szy=0)
{ {
multmatrix( multmatrix(

View file

@ -8,7 +8,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,465]; BOSL_VERSION = [2,0,466];
// Section: BOSL Library Version Functions // Section: BOSL Library Version Functions

View file

@ -72,7 +72,7 @@ function hex_offsets(n, d, lev=0, arr=[]) =
// Usage: // Usage:
// wiring(path, wires, [wirediam], [rounding], [wirenum], [bezsteps]); // wiring(path, wires, [wirediam], [rounding], [wirenum], [bezsteps]);
// Arguments: // Arguments:
// path = The 3D polyline path that the wire bundle should follow. // path = The 3D path that the wire bundle should follow.
// wires = The number of wires in the wiring bundle. // wires = The number of wires in the wiring bundle.
// wirediam = The diameter of each wire in the bundle. // wirediam = The diameter of each wire in the bundle.
// rounding = The radius that the path corners will be rounded to. // rounding = The radius that the path corners will be rounded to.
@ -90,7 +90,7 @@ module wiring(path, wires, wirediam=2, rounding=10, wirenum=0, bezsteps=12) {
]; ];
offsets = hex_offsets(wires, wirediam); offsets = hex_offsets(wires, wirediam);
bezpath = fillet_path(path, rounding); bezpath = fillet_path(path, rounding);
poly = simplify_path(path3d(bezier_polyline(bezpath, bezsteps))); poly = simplify_path(path3d(bezier_path(bezpath, bezsteps)));
n = max(segs(wirediam), 8); n = max(segs(wirediam), 8);
r = wirediam/2; r = wirediam/2;
for (i = [0:1:wires-1]) { for (i = [0:1:wires-1]) {