further extrude2d fixes

This commit is contained in:
Adrian Mariano 2021-10-31 00:36:51 -04:00
parent 12b8e7438c
commit 5934705dcd

View file

@ -477,7 +477,9 @@ module chain_hull()
// Usage: // Usage:
// path_extrude2d(path, [caps], [closed]) {...} // path_extrude2d(path, [caps], [closed]) {...}
// Description: // Description:
// Extrudes 2D children along the given 2D path, with optional rounded endcaps that work only if the children are symmetric across the y axis. // Extrudes 2D children along the given 2D path, with optional rounded endcaps. This module works properly in general only if the given
// children are symmetric across the Y axis. It works by constructing flat sections corresponding to each segment of the path and
// inserting rounded joints at each corner.
// Arguments: // Arguments:
// path = The 2D path to extrude the geometry along. // path = The 2D path to extrude the geometry along.
// caps = If true, caps each end of the path with a `rotate_extrude()`d copy of the children. This may interact oddly when given asymmetric profile children. Default: false // caps = If true, caps each end of the path with a `rotate_extrude()`d copy of the children. This may interact oddly when given asymmetric profile children. Default: false
@ -502,40 +504,30 @@ module chain_hull()
// path_extrude2d(path, caps=false) // path_extrude2d(path, caps=false)
// trapezoid(w1=10, w2=1, h=5, anchor=BACK); // trapezoid(w1=10, w2=1, h=5, anchor=BACK);
module path_extrude2d(path, caps=false, closed=false) { module path_extrude2d(path, caps=false, closed=false) {
assert(caps==false || closed==false assert(caps==false || closed==false, "Cannot have caps on a closed extrusion");
thin = 0.01; thin = 0.01;
path = deduplicate(path); path = deduplicate(path);
for (p=pair(path,wrap=closed)) { for (p=pair(path,wrap=closed))
delt = p[1]-p[0]; extrude_from_to(p[0],p[1]) xflip()rot(-90)children();
translate(p[0]) {
frame_map(y=point3d(delt),z=UP){
minkowski() {
cube([thin,norm(delt),thin], anchor=FRONT);
rotate([90,0,0]) linear_extrude(height=thin,center=true) children();
}
}
}
}
for (t=triplet(path,wrap=closed)) { for (t=triplet(path,wrap=closed)) {
ang = v_theta(t[2]-t[1]) - v_theta(t[1]-t[0]); ang = 180-vector_angle(t);
rightside = _point_left_of_line2d(t[2],[t[0],t[1]])>0;
delt = point3d(t[2] - t[1]); delt = point3d(t[2] - t[1]);
if (ang>0)
translate(t[1]) { translate(t[1]) {
minkowski() { if (rightside){ //ang >= 0) {
cube(thin,center=true); rotate(90-ang)
if (ang >= 0) { frame_map(x=-delt, z=UP)
rotate(90-ang) rotate_extrude(angle=ang)
frame_map(x=-delt, z=UP) right_half(planar=true) children();
rotate_extrude(angle=ang+0.01) } else {
right_half(planar=true) children(); rotate(-(90-ang))
} else { frame_map(x=delt, z=UP)
rotate(-90) rotate_extrude(angle=-ang)
frame_map(x=delt, z=UP) left_half(planar=true) children();
rotate_extrude(angle=-ang+0.01)
left_half(planar=true) children();
}
} }
} }
} }
if (caps) { if (caps) {
move_copies([path[0],last(path)]) move_copies([path[0],last(path)])