mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 14:18:13 +01:00
fixed variable problem and refactored
This commit is contained in:
parent
c9ce69712b
commit
34b03780d1
@ -5,7 +5,7 @@ Puts children along the given path. If there's only one child, it will put the c
|
||||
## Parameters
|
||||
|
||||
- `points` : The points along the path.
|
||||
- `angles` : If it's given, rotate before translate each child.
|
||||
- `angles` : Rotate before translate each child. If not given, `angles` will be calculated automatically according to `points`.
|
||||
|
||||
## Examples
|
||||
|
||||
@ -60,4 +60,44 @@ Puts children along the given path. If there's only one child, it will put the c
|
||||
linear_extrude(1, center = true)
|
||||
text("A", valign = "center", halign = "center");
|
||||
|
||||
![along_with](images/lib-along_with-3.JPG)
|
||||
![along_with](images/lib-along_with-3.JPG)
|
||||
|
||||
include <bezier_curve.scad>;
|
||||
include <along_with.scad>;
|
||||
|
||||
module scales() {
|
||||
module one_scale() {
|
||||
rotate([0, 60, 0])
|
||||
linear_extrude(1, center = true)
|
||||
scale([2, 1])
|
||||
circle(1.25, $fn = 24);
|
||||
}
|
||||
|
||||
for(a = [0:30:360 - 15]) {
|
||||
rotate(a)
|
||||
translate([5, 0, 0])
|
||||
one_scale();
|
||||
rotate(a + 15)
|
||||
translate([5, 0, 1.75])
|
||||
one_scale();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
t_step = 0.01;
|
||||
|
||||
p0 = [0, 0, 0];
|
||||
p1 = [0, 50, 35];
|
||||
p2 = [-100, 70, 0];
|
||||
p3 = [30, 120, -35];
|
||||
p4 = [30, 150, -40];
|
||||
p5 = [0, 200, -3];
|
||||
|
||||
path_pts = bezier_curve(t_step,
|
||||
[p0, p1, p2, p3, p4, p5]
|
||||
);
|
||||
|
||||
along_with(path_pts)
|
||||
scales();
|
||||
|
||||
![along_with](images/lib-along_with-4.JPG)
|
@ -14,26 +14,25 @@
|
||||
include <__private__/__angy_angz.scad>;
|
||||
|
||||
module along_with(points, angles) {
|
||||
function _path_angles(path_pts, leng_path_pts, i = 0) =
|
||||
i == leng_path_pts - 1 ?
|
||||
leng_points = len(points);
|
||||
|
||||
function _path_angles(i = 0) =
|
||||
i == leng_points - 1 ?
|
||||
[] :
|
||||
concat(
|
||||
[__angy_angz(path_pts[i], path_pts[i + 1])],
|
||||
_path_angles(path_pts, leng_path_pts, i + 1)
|
||||
[__angy_angz(points[i], points[i + 1])],
|
||||
_path_angles(i + 1)
|
||||
);
|
||||
|
||||
function path_angles(path_pts) =
|
||||
let(
|
||||
leng_path_pts = len(path_pts),
|
||||
angs = _path_angles(path_pts, leng_path_pts)
|
||||
)
|
||||
function path_angles(points) =
|
||||
let(angs = _path_angles())
|
||||
concat(
|
||||
[[0, -angs[0][0], angs[0][1]]],
|
||||
[for(a = angs) [0, -a[0], a[1]]]
|
||||
);
|
||||
|
||||
angles_defined = angles != undef;
|
||||
angs = angles_defined ? angles : path_angles(path_pts);
|
||||
angs = angles_defined ? angles : path_angles(points);
|
||||
|
||||
module align(i) {
|
||||
translate(points[i])
|
||||
|
Loading…
x
Reference in New Issue
Block a user