1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00

add square_pursuit_curves_3d

This commit is contained in:
Justin Lin 2020-10-10 14:44:43 +08:00
parent 858685f22f
commit b1c6180269

View File

@ -0,0 +1,44 @@
use <hull_polyline3d.scad>;
length = 100;
diff_scale = 0.125;
thickness = 2;
n = 30;
$fn = 6;
module square_pursuit_curves_3d(length, diff_scale, thickness, n) {
function inter_p(p1, p2, leng, d) =
let(
vp = p2 - p1,
u = vp / leng
)
p1 + u * d;
module _square_pursuit_curves_3d(pts, diff_scale, thickness, n) {
if(n != 0) {
vp = pts[1] - pts[0];
leng = norm(vp);
d = leng * diff_scale;
npts = [for(i = [0:3]) inter_p(pts[i], pts[(i + 1) % 4], leng, d)];
hull_polyline3d(concat(npts, [npts[3], npts[0]]), thickness);
_square_pursuit_curves_3d(npts, diff_scale, thickness, n - 1);
}
}
half_length = length / 2;
pts = [
[0, 0, 0],
[length, 0, 0],
[half_length, half_length, sqrt(2) * half_length],
[0, length, 0]
];
hull_polyline3d(concat(pts, [pts[3], pts[0]]), thickness);
_square_pursuit_curves_3d(pts, diff_scale, thickness, n - 1);
}
square_pursuit_curves_3d(length, diff_scale, thickness, n);