mirror of
https://github.com/nophead/NopSCADlib.git
synced 2025-08-03 22:17:25 +02:00
Added offset_paths() to sweep.scad.
show_path() now takes an optional radius.
This commit is contained in:
@@ -7451,6 +7451,7 @@ Each vertex, apart from the first and the last, has an associated radius and the
|
|||||||
| `cap(facets, segment = 0, end)` | Create the mesh for an end cap |
|
| `cap(facets, segment = 0, end)` | Create the mesh for an end cap |
|
||||||
| `circle_points(r = 1, z = 0, dir = -1)` | Generate the points of a circle, setting z makes a single turn spiral |
|
| `circle_points(r = 1, z = 0, dir = -1)` | Generate the points of a circle, setting z makes a single turn spiral |
|
||||||
| `helical_twist_per_segment(r, pitch, sides)` | Calculate the twist around Z that rotate_from_to() introduces |
|
| `helical_twist_per_segment(r, pitch, sides)` | Calculate the twist around Z that rotate_from_to() introduces |
|
||||||
|
| `offset_paths(path, offsets, twists = 0)` | Create new paths offset from the original, optionally spiralling around it |
|
||||||
| `rectangle_points(w, h)` | Generate the points of a rectangle |
|
| `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(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 |
|
| `rounded_path_vertices(path)` | Show the unrounded version of a rounded_path for debug |
|
||||||
@@ -7462,7 +7463,7 @@ Each vertex, apart from the first and the last, has an associated radius and the
|
|||||||
### Modules
|
### Modules
|
||||||
| Module | Description |
|
| Module | Description |
|
||||||
|:--- |:--- |
|
|:--- |:--- |
|
||||||
| `show_path(path)` | Show a path using a chain of hulls for debugging, duplicate points are highlighted. |
|
| `show_path(path, r = 0.1)` | 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 |
|
| `sweep(path, profile, loop = false, twist = 0, convexity = 1)` | Draw a polyhedron that is the swept volume |
|
||||||
|
|
||||||

|

|
||||||
|
@@ -111,7 +111,7 @@ function helical_twist_per_segment(r, pitch, sides) = //! Calculate the twist ar
|
|||||||
//
|
//
|
||||||
// Generate all the transforms for the profile of the swept volume.
|
// Generate all the transforms for the profile of the swept volume.
|
||||||
//
|
//
|
||||||
function sweep_transforms(path, loop = false, twist = 0) =
|
function sweep_transforms(path, loop = false, twist = 0, initial_rotation = undef) =
|
||||||
let(len = len(path),
|
let(len = len(path),
|
||||||
last = len - 1,
|
last = len - 1,
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ function sweep_transforms(path, loop = false, twist = 0) =
|
|||||||
lengths = [for(i = 0, t = 0; i < len; t = t + norm(path[min(i + 1, last)] - path[i]), i = i + 1) t],
|
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],
|
length = lengths[last],
|
||||||
|
|
||||||
rotations = [for(i = 0, rot = fs_frame(tangents);
|
rotations = [for(i = 0, rot = is_undef(initial_rotation) ? fs_frame(tangents) : rot3_z(initial_rotation);
|
||||||
i < len;
|
i < len;
|
||||||
i = i + 1,
|
i = i + 1,
|
||||||
rot = i < len ? rotate_from_to(tangents[i - 1], tangents[i]) * rot : undef) rot],
|
rot = i < len ? rotate_from_to(tangents[i - 1], tangents[i]) * rot : undef) rot],
|
||||||
@@ -239,6 +239,10 @@ function segmented_path(path, min_segment) = [ //! Add points to a path to enfo
|
|||||||
path[len(path) - 1]
|
path[len(path) - 1]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function offset_paths(path, offsets, twists = 0) = let( //! Create new paths offset from the original, optionally spiralling around it
|
||||||
|
transforms = sweep_transforms(path, twist = 360 * twists, initial_rotation = 0)
|
||||||
|
) [for(o = offsets) let(initial = [o.x, o.y, o.z, 1]) [for(t = transforms) initial * t]];
|
||||||
|
|
||||||
function spiral_paths(path, n, r, twists, start_angle) = let( //! Create a new paths which spiral around the given path. Use for making twisted cables
|
function spiral_paths(path, n, r, twists, start_angle) = let( //! Create a new paths which spiral around the given path. Use for making twisted cables
|
||||||
segment = twists ? path_length(path) / twists / r2sides(2 * r) : inf,
|
segment = twists ? path_length(path) / twists / r2sides(2 * r) : inf,
|
||||||
transforms = sweep_transforms(segmented_path(path, segment), twist = 360 * twists)
|
transforms = sweep_transforms(segmented_path(path, segment), twist = 360 * twists)
|
||||||
@@ -246,16 +250,16 @@ function spiral_paths(path, n, r, twists, start_angle) = let( //! Create a new p
|
|||||||
|
|
||||||
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
|
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.
|
module show_path(path, r = 0.1) //! Show a path using a chain of hulls for debugging, duplicate points are highlighted.
|
||||||
for(i = [0 : len(path) - 2]) {
|
for(i = [0 : len(path) - 2]) {
|
||||||
hull($fn = 16) {
|
hull($fn = 16) {
|
||||||
translate(path[i])
|
translate(path[i])
|
||||||
sphere(0.1);
|
sphere(r);
|
||||||
|
|
||||||
translate(path[i + 1])
|
translate(path[i + 1])
|
||||||
sphere(0.1);
|
sphere(r);
|
||||||
}
|
}
|
||||||
if(path[i] == path[i + 1])
|
if(path[i] == path[i + 1])
|
||||||
translate(path[i])
|
translate(path[i])
|
||||||
color("red") sphere(1);
|
color("red") sphere($fn = 16, r * 4);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user