mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-09 08:16:50 +02:00
added path_extend
This commit is contained in:
BIN
docs/images/lib-path_extend-1.JPG
Normal file
BIN
docs/images/lib-path_extend-1.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
42
docs/lib-path_extend.md
Normal file
42
docs/lib-path_extend.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# path_extend
|
||||||
|
|
||||||
|
It extends a 2D stroke along a path. This module is suitable for a path created by a continuous function.
|
||||||
|
|
||||||
|
It depends on the rotate_p function and the polytransversals module. Remember to include "rotate_p.scad" and "polytransversals.scad".
|
||||||
|
|
||||||
|
When using this module, you should use points to represent the 2D stroke.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `stroke_pts` : A list of points represent a stroke. See the example below.
|
||||||
|
- `path_pts` : A list of points represent the path.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
include <rotate_p.scad>;
|
||||||
|
include <polytransversals.scad>;
|
||||||
|
include <path_extend.scad>;
|
||||||
|
include <circle_path.scad>;
|
||||||
|
include <archimedean_spiral.scad>;
|
||||||
|
|
||||||
|
$fn = 96;
|
||||||
|
|
||||||
|
stroke1 = [[-5, 2.5], [-2.5, 0], [0, 2.5], [2.5, 0], [5, 2.5]];
|
||||||
|
path_pts1 = circle_path(50, 60);
|
||||||
|
path_extend(stroke1, path_pts1);
|
||||||
|
|
||||||
|
stroke2 = [[-4, 0], [0, 4], [4, 0]];
|
||||||
|
pts_angles = archimedean_spiral(
|
||||||
|
arm_distance = 17,
|
||||||
|
init_angle = 180,
|
||||||
|
point_distance = 5,
|
||||||
|
num_of_points = 85
|
||||||
|
);
|
||||||
|
|
||||||
|
translate([120, 0, 0])
|
||||||
|
path_extend(
|
||||||
|
stroke2,
|
||||||
|
[for(pa = pts_angles) pa[0]]
|
||||||
|
);
|
||||||
|
|
||||||
|

|
66
src/path_extend.scad
Normal file
66
src/path_extend.scad
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* path_extend.scad
|
||||||
|
*
|
||||||
|
* It extends a 2D stroke along a path.
|
||||||
|
* This module is suitable for a path created by a continuous function.
|
||||||
|
* It depends on the rotate_p function and the polytransversals module.
|
||||||
|
* Remember to include "rotate_p.scad" and "polytransversals.scad".
|
||||||
|
*
|
||||||
|
* @copyright Justin Lin, 2017
|
||||||
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
|
*
|
||||||
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib-path_extend.html
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
module path_extend(stroke_pts, path_pts) {
|
||||||
|
function length(p1, p2) =
|
||||||
|
let(
|
||||||
|
x1 = p1[0],
|
||||||
|
y1 = p1[1],
|
||||||
|
x2 = p2[0],
|
||||||
|
y2 = p2[1]
|
||||||
|
) sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
|
||||||
|
|
||||||
|
function az(p1, p2) =
|
||||||
|
let(
|
||||||
|
x1 = p1[0],
|
||||||
|
y1 = p1[1],
|
||||||
|
x2 = p2[0],
|
||||||
|
y2 = p2[1]
|
||||||
|
) -90 + atan2((y2 - y1), (x2 - x1));
|
||||||
|
|
||||||
|
leng_path_pts = len(path_pts);
|
||||||
|
|
||||||
|
function first_stroke() =
|
||||||
|
let(
|
||||||
|
p1 = path_pts[0],
|
||||||
|
p2 = path_pts[1],
|
||||||
|
a = az(p1, p2)
|
||||||
|
)
|
||||||
|
[
|
||||||
|
for(p = stroke_pts)
|
||||||
|
rotate_p(p, a) + p1
|
||||||
|
];
|
||||||
|
|
||||||
|
function stroke(p1, p2) =
|
||||||
|
let(
|
||||||
|
leng = length(p1, p2),
|
||||||
|
a = az(p1, p2)
|
||||||
|
)
|
||||||
|
[
|
||||||
|
for(p = stroke_pts)
|
||||||
|
rotate_p(p + [0, leng], a) + p1
|
||||||
|
];
|
||||||
|
|
||||||
|
function path_extend_inner(index) =
|
||||||
|
index == leng_path_pts ? [] :
|
||||||
|
concat(
|
||||||
|
[stroke(path_pts[index - 1], path_pts[index])],
|
||||||
|
path_extend_inner(index + 1)
|
||||||
|
);
|
||||||
|
|
||||||
|
polytransversals(
|
||||||
|
concat([first_stroke()], path_extend_inner(1))
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user