mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-11 11:05:40 +02:00
Merge pull request #1723 from adrianVmariano/master
wedge and prismoid edge anchor improvements
This commit is contained in:
@@ -3985,14 +3985,20 @@ function _find_anchor(anchor, geom)=
|
||||
axy = point2d(anch),
|
||||
bot = point3d(v_mul(point2d(size )/2, axy), -h/2),
|
||||
top = point3d(v_mul(point2d(size2)/2, axy) + shift, h/2),
|
||||
degenerate = sum(v_abs(point2d(anch)))==1 && (point2d(bot)==[0,0] || v_mul(point2d(size2)/2, axy)==[0,0]),
|
||||
edge = top-bot,
|
||||
other_edge = degenerate ? move(shift,mirror(axy, move(-shift,top))) - mirror(point3d(point2d(anch)), p=bot):CTR,
|
||||
pos = point3d(cp) + lerp(bot,top,u) + offset,
|
||||
// Find vectors of the faces involved in the anchor
|
||||
facevecs =
|
||||
[
|
||||
if (anch.x!=0) unit(rot(from=UP, to=[edge.x,0,max(0.01,h)], p=[axy.x,0,0]), UP),
|
||||
if (anch.y!=0) unit(rot(from=UP, to=[0,edge.y,max(0.01,h)], p=[0,axy.y,0]), UP),
|
||||
if (anch.z!=0) unit([0,0,anch.z],UP)
|
||||
if (anch.z!=0 && !degenerate) unit([0,0,anch.z],UP),
|
||||
if (anch.z!=0 && degenerate && anch.y!=0)
|
||||
unit(rot(from=UP, to=[0,other_edge.y,max(0.01,h)], p=[0,-axy.y,0]), UP),
|
||||
if (anch.z!=0 && degenerate && anch.x!=0)
|
||||
unit(rot(from=UP, to=[other_edge.x,0,max(0.01,h)], p=[-axy.x,0,0]), UP),
|
||||
],
|
||||
dir = anch==CENTER? UP
|
||||
: len(facevecs)==1? unit(facevecs[0],UP)
|
||||
@@ -4031,8 +4037,8 @@ function _find_anchor(anchor, geom)=
|
||||
// with a correction for top/bottom (anchor.z).
|
||||
// Otherwise use the standard BACK/UP definition
|
||||
// The precomputed oang value seems to be wrong, at least when axis!=UP
|
||||
|
||||
spin = is_def(edgedir) && !approx(edgedir.z,0) ? _compute_spin(final_dir, edgedir * (edgedir*UP>0?1:-1))
|
||||
spin = is_def(edgedir) && degenerate ? _compute_spin(final_dir, unit(((BACK+RIGHT)*edgedir)*edgedir))
|
||||
: is_def(edgedir) && !approx(edgedir.z,0) ? _compute_spin(final_dir, edgedir * (edgedir*UP>0?1:-1))
|
||||
: is_def(edgedir) ? _compute_spin(final_dir,
|
||||
edgedir * (approx(unit(cross(UP,edgedir)),unit([final_dir.x,final_dir.y,0])*anchor.z) ? 1 : -1))
|
||||
: _compute_spin(final_dir, final_dir==DOWN || final_dir==UP ? BACK : UP)
|
||||
|
@@ -577,14 +577,14 @@ module partition(size=100, spread=10, cutsize=10, cutpath="jigsaw", gap=0, cutpa
|
||||
move(vec) {
|
||||
$idx = 0;
|
||||
intersection() {
|
||||
children();
|
||||
if ($children>0) children();
|
||||
partition_mask(l=rsize.x, w=rsize.y, h=rsize.z, cutsize=cutsize, cutpath=cutpath, gap=gap, cutpath_centered=cutpath_centered, spin=spin);
|
||||
}
|
||||
}
|
||||
move(-vec) {
|
||||
$idx = 1;
|
||||
intersection() {
|
||||
children();
|
||||
if ($children>0) children();
|
||||
partition_mask(l=rsize.x, w=rsize.y, h=rsize.z, cutsize=cutsize, cutpath=cutpath, gap=gap, cutpath_centered=cutpath_centered, inverse=true, spin=spin);
|
||||
}
|
||||
}
|
||||
|
@@ -190,7 +190,7 @@ function cube(size=1, center, anchor, spin=0, orient=UP) =
|
||||
// );
|
||||
// Example: Roundings and Chamfers can be as large as the full size of the cuboid, so long as the edges would not interfere.
|
||||
// cuboid([40,20,10], rounding=20, edges=[FWD+RIGHT,BACK+LEFT]);
|
||||
// Example: Standard Connectors
|
||||
// Example: Standard anchors
|
||||
// cuboid(40) show_anchors();
|
||||
|
||||
module cuboid(
|
||||
@@ -616,6 +616,11 @@ function cuboid(
|
||||
// The anchors on the top and bottom faces have spin pointing back. The anchors on the side faces have spin point UP.
|
||||
// The anchors on the top and bottom edges also have anchors that point clockwise as viewed from outside the shapep.
|
||||
// The anchors on the side edges and the corners have spin with positive Z component, pointing along the edge where the anchor is located.
|
||||
// A degenerate prismoid with a line segment for the top or bottom has its top or bottom edge anchors set to provide an anchor for that top
|
||||
// or bottom edge. So for example, if the top is `[0,10]` then the top edge is parallel to the Y axis and you can anchor to that
|
||||
// edge using the `TOP+RIGHT` or `TOP+LEFT` anchors; these anchors point in the direction that divides the edge in half and provide
|
||||
// the `$edge_angle` and `$edge_length` values generally provided by edge anchors. The UP or DOWN anchor is in the same location but always points
|
||||
// in the Z direction and provides no edge data.
|
||||
// Arguments:
|
||||
// size1 = [width, length] of the bottom end of the prism.
|
||||
// size2 = [width, length] of the top end of the prism.
|
||||
@@ -689,9 +694,14 @@ function cuboid(
|
||||
// mask2d_roundover(h=5,mask_angle=$edge_angle);
|
||||
// }
|
||||
// }
|
||||
// Example(Spin,VPD=160,VPT=[0,0,10]): Standard Connectors
|
||||
// Example(Spin,VPD=160,VPT=[0,0,10]): Standard anchors
|
||||
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5])
|
||||
// show_anchors();
|
||||
// Example(3D): When the top or bottom is degenerate, you can anchor to and round the degenerate edge by using either one of the edge anchors that correspond to that edge. But note that {{edge_profile()}} does not work for this degenerate case. We used `TOP+RIGHT` below as the anchor point, but `TOP+LEFT` will produce an identical result.
|
||||
// diff()
|
||||
// prismoid([10,14],[0,8], shift=[4,3], h=7)
|
||||
// attach(TOP+RIGHT, FWD+LEFT, inside=true)
|
||||
// rounding_edge_mask(r=2,l=$edge_length+6);
|
||||
|
||||
module prismoid(
|
||||
size1=undef, size2=undef, h, shift=[undef,undef],
|
||||
@@ -1753,6 +1763,7 @@ function rect_tube(
|
||||
// "hypot" = Center of angled wedge face, perpendicular to that face.
|
||||
// "hypot_left" = Left side of angled wedge face, bisecting the angle between the left side and angled faces.
|
||||
// "hypot_right" = Right side of angled wedge face, bisecting the angle between the right side and angled faces.
|
||||
// "top_edge" = Top edge anchor which, unlike the UP anchor, points in direction that bisects the edge, and provides `$edge_length` and `$edge_angle`.
|
||||
//
|
||||
// Example: Centered
|
||||
// wedge([20, 40, 15], center=true);
|
||||
@@ -1766,6 +1777,11 @@ function rect_tube(
|
||||
// Example(3D,Med,VPR=[55.00,0.00,25.00],VPD=151.98,VPT=[2.30,-11.81,-5.66]): Named Anchors
|
||||
// wedge([40, 80, 30], center=true)
|
||||
// show_anchors(std=false);
|
||||
// Example(3D): Rounding the top of the wedge using the "top_edge" anchor
|
||||
// diff()
|
||||
// wedge([10,15,7])
|
||||
// attach("top_edge", FWD+LEFT, inside=true)
|
||||
// rounding_edge_mask(r=2, l=$edge_length+1);
|
||||
|
||||
module wedge(size=[1, 1, 1], center, anchor, spin=0, orient=UP)
|
||||
{
|
||||
@@ -1778,10 +1794,13 @@ module wedge(size=[1, 1, 1], center, anchor, spin=0, orient=UP)
|
||||
left_dir = unit(hypot_dir+LEFT);
|
||||
right_dir = unit(hypot_dir+RIGHT);
|
||||
hedge_spin=vector_angle(spindir,rot(from=UP,to=left_dir, p=BACK));
|
||||
topedge_dir = [0, each unit(unit([size.z,size.y])+[-1,0])];
|
||||
anchors = [
|
||||
named_anchor("hypot", CTR, hypot_dir, 180),
|
||||
named_anchor("hypot_left", [-size.x/2,0,0], left_dir,-hedge_spin),
|
||||
named_anchor("hypot_right", [size.x/2,0,0], right_dir,hedge_spin),
|
||||
named_anchor("top_edge", [0,-size.y/2,size.z/2], topedge_dir, _compute_spin(topedge_dir,RIGHT),
|
||||
info=[["edge_angle",atan2(size.y,size.z)],["edge_length",size.x]])
|
||||
];
|
||||
attachable(anchor,spin,orient, size=size, anchors=anchors) {
|
||||
if (size.z > 0) {
|
||||
@@ -1811,10 +1830,13 @@ function wedge(size=[1,1,1], center, anchor, spin=0, orient=UP) =
|
||||
left_dir = unit(hypot_dir+LEFT),
|
||||
right_dir = unit(hypot_dir+RIGHT),
|
||||
hedge_spin=vector_angle(spindir,rot(from=UP,to=left_dir, p=BACK)),
|
||||
topedge_dir = [0, each unit(unit([size.z,size.y])+[-1,0])],
|
||||
anchors = [
|
||||
named_anchor("hypot", CTR, hypot_dir, 180),
|
||||
named_anchor("hypot_left", [-size.x/2,0,0], left_dir,-hedge_spin),
|
||||
named_anchor("hypot_right", [size.x/2,0,0], right_dir,hedge_spin),
|
||||
named_anchor("top_edge", [0,-size.y/2,size.z/2], topedge_dir, _compute_spin(topedge_dir,RIGHT),
|
||||
info=[["edge_angle",atan2(size.y,size.z)],["edge_length",size.x]])
|
||||
]
|
||||
)
|
||||
reorient(anchor,spin,orient, size=size, anchors=anchors, p=vnf);
|
||||
|
@@ -1082,7 +1082,7 @@ function zscale(z=1, p=_NO_ARG, cp=0) =
|
||||
function mirror(v, p=_NO_ARG) =
|
||||
assert(is_vector(v))
|
||||
assert(p==_NO_ARG || is_list(p),"Invalid pointlist")
|
||||
let(m = len(v)==2? affine2d_mirror(v) : affine3d_mirror(v))
|
||||
let(m = affine3d_mirror(v))
|
||||
p==_NO_ARG? m : apply(m,p);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user