Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1f55097bdd | ||
|
136584d086 | ||
|
225ea9b451 |
10
CHANGELOG.md
@@ -3,6 +3,16 @@
|
||||
This changelog is generated by `changelog.py` using manually added semantic version tags to classify commits as breaking changes, additions or fixes.
|
||||
|
||||
|
||||
### [v19.6.0](https://github.com/nophead/NopSCADlib/releases/tag/v19.6.0 "show release") Additions [...](https://github.com/nophead/NopSCADlib/compare/v19.5.1...v19.6.0 "diff with v19.5.1")
|
||||
* 2022-02-06 [`225ea9b`](https://github.com/nophead/NopSCADlib/commit/225ea9b45160195bdf316e7ffdb383a63f898d3c "show commit") [C.P.](# "Chris Palmer") Added `rounded_path()` function to `sweep.scad`.
|
||||
|
||||
#### [v19.5.1](https://github.com/nophead/NopSCADlib/releases/tag/v19.5.1 "show release") Fixes [...](https://github.com/nophead/NopSCADlib/compare/v19.5.0...v19.5.1 "diff with v19.5.0")
|
||||
* 2022-02-06 [`d341ce4`](https://github.com/nophead/NopSCADlib/commit/d341ce499e56972ff5267d3187387fe7df9d4130 "show commit") [C.P.](# "Chris Palmer") Added `render()` to `pocket_handle()`.
|
||||
|
||||
* 2022-02-06 [`e7376e2`](https://github.com/nophead/NopSCADlib/commit/e7376e28c44355efa425b98aa0511ccdf0b63301 "show commit") [C.P.](# "Chris Palmer") Fixed corner block assembly names when overridden.
|
||||
|
||||
* 2022-02-06 [`e238eaa`](https://github.com/nophead/NopSCADlib/commit/e238eaa473bac72136507d15c57f6156560d6cfe "show commit") [C.P.](# "Chris Palmer") Removed unused, undocumented function.
|
||||
|
||||
### [v19.5.0](https://github.com/nophead/NopSCADlib/releases/tag/v19.5.0 "show release") Additions [...](https://github.com/nophead/NopSCADlib/compare/v19.4.1...v19.5.0 "diff with v19.4.1")
|
||||
* 2022-02-01 [`04e94a8`](https://github.com/nophead/NopSCADlib/commit/04e94a859aa0d21f840c992b487a901f096790a4 "show commit") [C.P.](# "Chris Palmer") Added `earth_rot` parameter to `NEMA_screws()`.
|
||||
|
||||
|
11
readme.md
@@ -6565,6 +6565,12 @@ Subsequent rotations use the minimum rotation method.
|
||||
The path can be open or closed. If closed sweep ensures that the start and end have the same rotation to line up.
|
||||
An additional twist around the path can be specified. If the path is closed this should be a multiple of 360.
|
||||
|
||||
`rounded_path()` can be used to generate a path of lines connected by arcs, useful for wire runs, etc.
|
||||
The vertices specify where the the path would be without any rounding.
|
||||
Each vertex, apart from the first and the last, has an associated radius and the path shortcuts the vertex with an arc specified by the radius.
|
||||
|
||||
`spiral_paths()` makes a list of new paths that spiral around a given path. It can be used to make twisted wires that follow a rounded_path, for example.
|
||||
|
||||
[utils/sweep.scad](utils/sweep.scad) Implementation.
|
||||
|
||||
[tests/sweep.scad](tests/sweep.scad) Code for this example.
|
||||
@@ -6580,12 +6586,17 @@ An additional twist around the path can be specified. If the path is closed this
|
||||
| `helical_twist_per_segment(r, pitch, sides)` | Calculate the twist around Z that rotate_from_to() introduces |
|
||||
| `path_length(path, i = 0, length = 0)` | Calculated the length along a path |
|
||||
| `rectangle_points(w, h)` | Generate the points of a rectangle |
|
||||
| `rounded_path(path)` | Convert a rounded_path, consisting of a start coordinate, vertex / radius pairs and then an end coordinate, to a path of points for sweep. |
|
||||
| `rounded_path_vertices(path)` | Show the unrounded version of a rounded_path for debug |
|
||||
| `segmented_path(path, min_segment)` | Add points to a path to enforce a minimum segment length |
|
||||
| `skin_faces(points, npoints, facets, loop, offset = 0)` | Create the mesh for the swept volume without end caps |
|
||||
| `spiral_paths(path, n, r, twists, start_angle)` | Create a new paths which sprial around the given path. Use for making twisted cables |
|
||||
| `sweep(path, profile, loop = false, twist = 0)` | Generate the point list and face list of the swept volume |
|
||||
|
||||
### Modules
|
||||
| Module | Description |
|
||||
|:--- |:--- |
|
||||
| `show_path(path)` | Show a path using a chain of hulls for debugging, duplicate points are highlighted. |
|
||||
| `sweep(path, profile, loop = false, twist = 0, convexity = 1)` | Draw a polyhedron that is the swept volume |
|
||||
|
||||

|
||||
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 142 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 117 KiB |
Before Width: | Height: | Size: 115 KiB After Width: | Height: | Size: 115 KiB |
Before Width: | Height: | Size: 149 KiB After Width: | Height: | Size: 149 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
Before Width: | Height: | Size: 117 KiB After Width: | Height: | Size: 117 KiB |
Before Width: | Height: | Size: 152 KiB After Width: | Height: | Size: 152 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 141 KiB After Width: | Height: | Size: 141 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 112 KiB |
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 106 KiB |
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 116 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 188 KiB After Width: | Height: | Size: 189 KiB |
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 80 KiB |
Before Width: | Height: | Size: 176 KiB After Width: | Height: | Size: 176 KiB |
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 129 KiB |
Before Width: | Height: | Size: 219 KiB After Width: | Height: | Size: 218 KiB |
Before Width: | Height: | Size: 149 KiB After Width: | Height: | Size: 149 KiB |
@@ -32,22 +32,33 @@ loop_y = transform_points(loop, rotate([0, -90, $t * 360]));
|
||||
|
||||
loop_z = transform_points(loop, rotate([$t * 360, 0, 0]));
|
||||
|
||||
sweep(loop_z, L_points, loop = true);
|
||||
color("yellow") {
|
||||
sweep(loop_z, L_points, loop = true);
|
||||
|
||||
sweep(loop_x, L_points, loop = true);
|
||||
|
||||
sweep(loop_y, L_points, loop = true);
|
||||
sweep(loop_x, L_points, loop = true);
|
||||
|
||||
sweep(loop_y, L_points, loop = true);
|
||||
}
|
||||
|
||||
knot = [ for(i=[0:.2:359])
|
||||
[ (19*cos(3*i) + 40)*cos(2*i),
|
||||
(19*cos(3*i) + 40)*sin(2*i),
|
||||
19*sin(3*i) ] ];
|
||||
|
||||
sweep(knot, L_points, loop = true);
|
||||
color("red") sweep(knot, L_points, loop = true);
|
||||
|
||||
p = transform_points([[0,0,0], [20,0,5], [10,30,4], [0,0,0], [0,0,20]], scale(10));
|
||||
n = 100;
|
||||
path = bezier_path(p, n);
|
||||
|
||||
rotate(45) sweep(path, circle_points(5, $fn = 64));
|
||||
color("blue") rotate(45) sweep(path, circle_points(5, $fn = 64));
|
||||
|
||||
vertices = [[-170, 0, 0], [-170, 170, 0], 10, [-170, 170, 30], 20, [-50, 170, 31], 10, [-130, 100, 40]];
|
||||
rounded_path = rounded_path(vertices);
|
||||
|
||||
show_path(rounded_path_vertices(vertices));
|
||||
|
||||
paths = spiral_paths(rounded_path, 2, 1.5, 15, 0);
|
||||
for(i = [0 : len(paths) - 1])
|
||||
color(["red", "green"][i])
|
||||
sweep(paths[i], circle_points(1.5, $fn = 64));
|
||||
|
@@ -25,6 +25,12 @@
|
||||
//!
|
||||
//! The path can be open or closed. If closed sweep ensures that the start and end have the same rotation to line up.
|
||||
//! An additional twist around the path can be specified. If the path is closed this should be a multiple of 360.
|
||||
//!
|
||||
//! `rounded_path()` can be used to generate a path of lines connected by arcs, useful for wire runs, etc.
|
||||
//! The vertices specify where the the path would be without any rounding.
|
||||
//! Each vertex, apart from the first and the last, has an associated radius and the path shortcuts the vertex with an arc specified by the radius.
|
||||
//!
|
||||
//! `spiral_paths()` makes a list of new paths that spiral around a given path. It can be used to make twisted wires that follow a rounded_path, for example.
|
||||
//
|
||||
include <../utils/core/core.scad>
|
||||
|
||||
@@ -103,18 +109,19 @@ function helical_twist_per_segment(r, pitch, sides) = //! Calculate the twist ar
|
||||
) step_angle * sin(slope); // angle tangent should rotate around z projected onto axis rotate_from_to() uses
|
||||
|
||||
//
|
||||
// Generate all the surface points of the swept volume.
|
||||
// Generate all the transforms for the profile of the swept volume.
|
||||
//
|
||||
function skin_points(profile, path, loop, twist = 0) =
|
||||
function sweep_transforms(path, loop = false, twist = 0) =
|
||||
let(len = len(path),
|
||||
last = len - 1,
|
||||
|
||||
profile4 = [for(p = profile) [p.x, p.y, p.z, 1]],
|
||||
|
||||
tangents = [tangent(path, loop ? last : 0, 0, 1),
|
||||
for(i = [1 : last - 1]) tangent(path, i - 1, i, i + 1),
|
||||
tangent(path, last - 1, last, loop ? 0 : last)],
|
||||
|
||||
lengths = [for(i = 0, t = 0; i < len; t = t + norm(path[min(i + 1, last)] - path[i]), i = i + 1) t],
|
||||
length = lengths[last],
|
||||
|
||||
rotations = [for(i = 0, rot = fs_frame(tangents);
|
||||
i < len;
|
||||
i = i + 1,
|
||||
@@ -124,8 +131,20 @@ function skin_points(profile, path, loop, twist = 0) =
|
||||
rotation = missmatch + twist
|
||||
)
|
||||
[for(i = [0 : last])
|
||||
let(za = rotation * i / last)
|
||||
each profile4 * orientate(path[i], rotations[i] * rot3_z(za))
|
||||
let(za = rotation * lengths[i] / length)
|
||||
orientate(path[i], rotations[i] * rot3_z(za))
|
||||
];
|
||||
|
||||
//
|
||||
// Generate all the surface points of the swept volume.
|
||||
//
|
||||
function skin_points(profile, path, loop, twist = 0) =
|
||||
let(profile4 = [for(p = profile) [p.x, p.y, p.z, 1]],
|
||||
|
||||
transforms = sweep_transforms(path, loop, twist)
|
||||
)
|
||||
[for(t = transforms)
|
||||
each profile4 * t
|
||||
];
|
||||
|
||||
function cap(facets, segment = 0, end) = //! Create the mesh for an end cap
|
||||
@@ -179,3 +198,65 @@ function before(path1, path2) = //! Translate `path1` so its end meets the star
|
||||
function after(path1, path2) = //! Translate `path2` so its start meets the end of `path1` and then concatenate
|
||||
let(end1 = len(path1) - 1, end2 = len(path2) - 1, offset = path1[end1] - path2[0])
|
||||
concat(path1, [for(i = [1 : end2]) path2[i] + offset]);
|
||||
|
||||
function rounded_path(path) = //! Convert a rounded_path, consisting of a start coordinate, vertex / radius pairs and then an end coordinate, to a path of points for sweep.
|
||||
let(len = len(path)) assert(len > 3 && len % 2 == 0) [
|
||||
path[0], // First point has no radius
|
||||
for(i = [1 : 2 : len - 3]) let( // Step through the vertices with radii, i.e. not the first or last
|
||||
prev = max(i - 2, 0), // Index of previous point, might be the first point, which is a special case
|
||||
p0 = path[prev], // Point before the vertex
|
||||
p1 = path[i], // Vertex
|
||||
r = path[i + 1], // Radius of shortcut curve
|
||||
p2 = path[i + 2], // Point after the vertex
|
||||
v1 = assert(Len(p0) == 3, str("expected path[", prev, "] to be a vertex coordinate, got ", p0))
|
||||
assert(Len(p1) == 3, str("expected path[", i, "] to be a vertex coordinate, got ", p1))
|
||||
assert(Len(p2) == 3, str("expected path[", i + 2, "] to be a vertex coordinate, got ", p2))
|
||||
assert(is_num(r), str("expected path[", i + 1, "] to be a radius, got ", r))
|
||||
p0 - p1, // Calculate vectors between vertices
|
||||
v2 = p2 - p1,
|
||||
a = angle_between(v1, -v2), // Angle turned through
|
||||
arc_start = p1 + unit(v1) * r * tan(a / 2), // Calc the start position
|
||||
z_axis = unit(cross(v1, v2)), // z_axis is perpendicular to both vectors
|
||||
centre = arc_start + unit(cross(z_axis, v1)) * r, // Arc center is a radius away, and perpendicular to v1 and the z_axis.
|
||||
x_axis = arc_start - centre, // Make the x_axis along the radius to the start point, includes radius a scale factor
|
||||
y_axis = cross(x_axis, z_axis), // y_axis perpendicular to the other two
|
||||
sides = r2sides(ceil(r2sides(r) * a / 360)) // Sides needed to make the arc
|
||||
)
|
||||
for(j = [0 : sides], t = a * j / sides) // For each vertex in the arc
|
||||
cos(t) * x_axis + sin(t) * y_axis + centre, // Circular arc in the tiled xy plane.
|
||||
path[len - 1], // Last point has no radius
|
||||
];
|
||||
|
||||
function segmented_path(path, min_segment) = [ //! Add points to a path to enforce a minimum segment length
|
||||
for(i = [0 : len(path) - 2])
|
||||
let(delta =
|
||||
assert(path[i] != path[i + 1], str("Coincident points at path[", i, "] = ", path[i]))
|
||||
path[i+1] - path[i],
|
||||
segs = ceil(norm(delta) / min_segment)
|
||||
)
|
||||
for(j = [0 : segs - 1])
|
||||
path[i] + delta * j / segs, // Linear interpolation
|
||||
path[len(path) - 1]
|
||||
];
|
||||
|
||||
function spiral_paths(path, n, r, twists, start_angle) = let( //! Create a new paths which sprial around the given path. Use for making twisted cables
|
||||
segment = path_length(path) / twists / r2sides(2 * r),
|
||||
transforms = sweep_transforms(segmented_path(path, segment), twist = 360 * twists),
|
||||
initial = [r, 0, 0, 1] * rotate(start_angle)
|
||||
) [for(i = [0 : n - 1]) let(initial = [r, 0, 0, 1] * rotate(start_angle + i * 360 / n)) [for(t = transforms) initial * t]];
|
||||
|
||||
function rounded_path_vertices(path) = [path[0], for(i = [1 : 2 : len(path) - 1]) path[i]]; //! Show the unrounded version of a rounded_path for debug
|
||||
|
||||
module show_path(path) //! Show a path using a chain of hulls for debugging, duplicate points are highlighted.
|
||||
for(i = [0 : len(path) - 2]) {
|
||||
hull($fn = 16) {
|
||||
translate(path[i])
|
||||
sphere(0.1);
|
||||
|
||||
translate(path[i + 1])
|
||||
sphere(0.1);
|
||||
}
|
||||
if(path[i] == path[i + 1])
|
||||
translate(path[i])
|
||||
color("red") sphere(1);
|
||||
}
|
||||
|