mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-27 08:25:45 +02:00
refactor
This commit is contained in:
@@ -1,20 +1,25 @@
|
|||||||
use <torus_knot.scad>;
|
use <torus_knot.scad>;
|
||||||
use <cross_sections.scad>;
|
use <cross_sections.scad>;
|
||||||
use <util/rand.scad>;
|
|
||||||
use <circle_path.scad>;
|
use <circle_path.scad>;
|
||||||
use <shape_pentagram.scad>;
|
use <shape_pentagram.scad>;
|
||||||
use <hull_polyline3d.scad>;
|
|
||||||
use <experimental/tri_bisectors.scad>;
|
use <experimental/tri_bisectors.scad>;
|
||||||
|
use <experimental/hollow_out_sweep.scad>;
|
||||||
|
|
||||||
p = 2;
|
p = 2;
|
||||||
q = 3;
|
q = 3;
|
||||||
phi_step = 0.075;
|
phi_step = 0.075;
|
||||||
thickness = .1;
|
thickness = .1;
|
||||||
shape = shape_pentagram(.5); // circle_path(radius = .5, $fn = 12);
|
section_style = "STAR"; // [STAR, CIRCLE]
|
||||||
|
line_style = "HULL_LINES"; // [LINES, HULL_LINES]
|
||||||
|
|
||||||
hollow_out_torus_knot(shape, p, q, phi_step, thickness, $fn = 4);
|
if(section_style == "STAR") {
|
||||||
|
hollow_out_torus_knot(shape_pentagram(.5), p, q, phi_step, thickness, line_style);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hollow_out_torus_knot(circle_path(radius = .5, $fn = 12), p, q, phi_step, thickness, line_style);
|
||||||
|
}
|
||||||
|
|
||||||
module hollow_out_torus_knot(shape, p, q, phi_step, thickness) {
|
module hollow_out_torus_knot(shape, p, q, phi_step, thickness, line_style) {
|
||||||
function angy_angz(p1, p2) =
|
function angy_angz(p1, p2) =
|
||||||
let(
|
let(
|
||||||
dx = p2[0] - p1[0],
|
dx = p2[0] - p1[0],
|
||||||
@@ -37,40 +42,9 @@ module hollow_out_torus_knot(shape, p, q, phi_step, thickness) {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
cross_sections(shape, path, concat([angles[0]], angles));
|
cross_sections(shape, path, concat([angles[0]], angles));
|
||||||
|
|
||||||
function rects(sects) =
|
|
||||||
let(
|
|
||||||
sects_leng = len(sects),
|
|
||||||
shape_pt_leng = len(sects[0])
|
|
||||||
)
|
|
||||||
[
|
|
||||||
for(i = [0:sects_leng - 1])
|
|
||||||
let(
|
|
||||||
sect1 = sects[i],
|
|
||||||
sect2 = sects[(i + 1) % sects_leng]
|
|
||||||
)
|
|
||||||
for(j = [0:shape_pt_leng - 1])
|
|
||||||
let(k = (j + 1) % shape_pt_leng)
|
|
||||||
[sect1[j], sect1[k], sect2[k], sect2[j]]
|
|
||||||
];
|
|
||||||
|
|
||||||
function rand_tris(rect) =
|
|
||||||
let(
|
|
||||||
i = ceil(rand() * 10) % 2
|
|
||||||
)
|
|
||||||
i == 0 ?
|
|
||||||
[[rect[0], rect[1], rect[2]], [rect[0], rect[2], rect[3]]] :
|
|
||||||
[[rect[1], rect[2], rect[3]], [rect[1], rect[3], rect[0]]];
|
|
||||||
|
|
||||||
|
|
||||||
pts = torus_knot(p, q, phi_step);
|
pts = torus_knot(p, q, phi_step);
|
||||||
sects = sects_by_path(shape, pts);
|
sects = sects_by_path(shape, pts);
|
||||||
|
|
||||||
for(rect = rects(sects)) {
|
hollow_out_sweep(concat(sects, [sects[0]]), thickness, line_style);
|
||||||
for(tri = rand_tris(rect)) {
|
|
||||||
for(line = tri_bisectors(tri)) {
|
|
||||||
hull_polyline3d(line, thickness = thickness);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
54
src/experimental/hollow_out_sweep.scad
Normal file
54
src/experimental/hollow_out_sweep.scad
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
use <util/rand.scad>;
|
||||||
|
use <line3d.scad>;
|
||||||
|
use <hull_polyline3d.scad>;
|
||||||
|
use <experimental/tri_bisectors.scad>;
|
||||||
|
|
||||||
|
// style: LINES or HULL_LINES
|
||||||
|
module hollow_out_sweep(sections, thickness, style = "LINES") {
|
||||||
|
function rects(sects) =
|
||||||
|
let(
|
||||||
|
sects_leng = len(sections),
|
||||||
|
shape_pt_leng = len(sections[0])
|
||||||
|
)
|
||||||
|
[
|
||||||
|
for(i = [0:sects_leng - 2])
|
||||||
|
let(
|
||||||
|
sect1 = sects[i],
|
||||||
|
sect2 = sects[i + 1]
|
||||||
|
)
|
||||||
|
for(j = [0:shape_pt_leng - 1])
|
||||||
|
let(k = (j + 1) % shape_pt_leng)
|
||||||
|
[sect1[j], sect1[k], sect2[k], sect2[j]]
|
||||||
|
];
|
||||||
|
|
||||||
|
function rand_tris(rect) =
|
||||||
|
let(
|
||||||
|
i = ceil(rand() * 10) % 2
|
||||||
|
)
|
||||||
|
i == 0 ?
|
||||||
|
[[rect[0], rect[1], rect[2]], [rect[0], rect[2], rect[3]]] :
|
||||||
|
[[rect[1], rect[2], rect[3]], [rect[1], rect[3], rect[0]]];
|
||||||
|
|
||||||
|
lines = [
|
||||||
|
for(rect = rects(sections))
|
||||||
|
for(tri = rand_tris(rect))
|
||||||
|
each tri_bisectors(tri)
|
||||||
|
];
|
||||||
|
|
||||||
|
if(style == "LINES") {
|
||||||
|
for(line = lines) {
|
||||||
|
line3d(
|
||||||
|
p1 = line[0],
|
||||||
|
p2 = line[1],
|
||||||
|
thickness = thickness,
|
||||||
|
p1Style = "CAP_SPHERE",
|
||||||
|
p2Style = "CAP_SPHERE"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(style == "HULL_LINES") {
|
||||||
|
for(line = lines) {
|
||||||
|
hull_polyline3d(line, thickness = thickness);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user