2017-04-23 11:16:34 +08:00
|
|
|
/**
|
|
|
|
* along_with.scad
|
|
|
|
*
|
|
|
|
* Puts children along the given path. If there's only one child,
|
|
|
|
* it will put the child for each point.
|
|
|
|
*
|
|
|
|
* @copyright Justin Lin, 2017
|
|
|
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
|
|
|
*
|
|
|
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2017-05-19 11:14:09 +08:00
|
|
|
include <__private__/__angy_angz.scad>;
|
|
|
|
|
2017-05-19 13:19:03 +08:00
|
|
|
module along_with(points, angles, twist = 0) {
|
2017-05-19 11:24:43 +08:00
|
|
|
leng_points = len(points);
|
2017-05-19 13:19:03 +08:00
|
|
|
twist_step_a = twist / leng_points;
|
|
|
|
echo(twist_step_a);
|
2017-05-19 11:24:43 +08:00
|
|
|
|
|
|
|
function _path_angles(i = 0) =
|
|
|
|
i == leng_points - 1 ?
|
2017-05-19 11:14:09 +08:00
|
|
|
[] :
|
|
|
|
concat(
|
2017-05-19 11:24:43 +08:00
|
|
|
[__angy_angz(points[i], points[i + 1])],
|
|
|
|
_path_angles(i + 1)
|
2017-05-19 11:14:09 +08:00
|
|
|
);
|
|
|
|
|
2017-05-19 11:24:43 +08:00
|
|
|
function path_angles(points) =
|
|
|
|
let(angs = _path_angles())
|
2017-05-19 11:14:09 +08:00
|
|
|
concat(
|
|
|
|
[[0, -angs[0][0], angs[0][1]]],
|
|
|
|
[for(a = angs) [0, -a[0], a[1]]]
|
|
|
|
);
|
|
|
|
|
|
|
|
angles_defined = angles != undef;
|
2017-05-19 11:24:43 +08:00
|
|
|
angs = angles_defined ? angles : path_angles(points);
|
2017-05-19 11:14:09 +08:00
|
|
|
|
|
|
|
module align(i) {
|
|
|
|
translate(points[i])
|
|
|
|
rotate(angs[i])
|
|
|
|
if(angles_defined) {
|
2017-05-19 13:19:03 +08:00
|
|
|
rotate(twist_step_a * i)
|
|
|
|
children(0);
|
2017-05-19 11:14:09 +08:00
|
|
|
} else {
|
|
|
|
rotate([90, 0, -90])
|
2017-05-19 13:19:03 +08:00
|
|
|
rotate(twist_step_a * i)
|
|
|
|
children(0);
|
2017-05-19 11:14:09 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-03 16:21:49 +08:00
|
|
|
|
|
|
|
if($children == 1) {
|
|
|
|
for(i = [0:len(points) - 1]) {
|
2017-05-19 11:14:09 +08:00
|
|
|
align(i) children(0);
|
2017-04-23 11:16:34 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i = [0:min(len(points), $children) - 1]) {
|
2017-05-19 11:14:09 +08:00
|
|
|
align(i) children(i);
|
2017-04-23 11:16:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|