mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Merge pull request #1098 from revarbat/revarbat_dev
Prismoid anchoring fixes.
This commit is contained in:
commit
25427acf01
3 changed files with 42 additions and 8 deletions
|
@ -2542,12 +2542,25 @@ function _find_anchor(anchor, geom) =
|
|||
bot = point3d(v_mul(point2d(size )/2, axy), -h/2),
|
||||
top = point3d(v_mul(point2d(size2)/2, axy) + shift, h/2),
|
||||
pos = point3d(cp) + lerp(bot,top,u) + offset,
|
||||
vecs = [
|
||||
if (anch.x!=0) unit(rot(from=UP, to=[(top-bot).x,0,h], p=[axy.x,0,0]), UP),
|
||||
if (anch.y!=0) unit(rot(from=UP, to=[0,(top-bot).y,h], p=[0,axy.y,0]), UP),
|
||||
if (anch.z!=0) anch==CENTER? UP : unit([0,0,anch.z],UP)
|
||||
],
|
||||
vec = anchor==CENTER? UP : rot(from=UP, to=axis, p=unit(sum(vecs) / len(vecs))),
|
||||
vecs = anchor==CENTER? [UP]
|
||||
: [
|
||||
if (anch.x!=0) unit(rot(from=UP, to=[(top-bot).x,0,h], p=[axy.x,0,0]), UP),
|
||||
if (anch.y!=0) unit(rot(from=UP, to=[0,(top-bot).y,h], p=[0,axy.y,0]), UP),
|
||||
if (anch.z!=0) unit([0,0,anch.z],UP)
|
||||
],
|
||||
vec2 = anchor==CENTER? UP
|
||||
: len(vecs)==1? unit(vecs[0],UP)
|
||||
: len(vecs)==2? vector_bisect(vecs[0],vecs[1])
|
||||
: let(
|
||||
v1 = vector_bisect(vecs[0],vecs[2]),
|
||||
v2 = vector_bisect(vecs[1],vecs[2]),
|
||||
p1 = plane_from_normal(yrot(90,p=v1)),
|
||||
p2 = plane_from_normal(xrot(-90,p=v2)),
|
||||
line = plane_intersection(p1,p2),
|
||||
v3 = unit(line[1]-line[0],UP) * anch.z
|
||||
)
|
||||
unit(v3,UP),
|
||||
vec = rot(from=UP, to=axis, p=vec2),
|
||||
pos2 = rot(from=UP, to=axis, p=pos)
|
||||
) [anchor, pos2, vec, oang]
|
||||
) : type == "conoid"? ( //r1, r2, l, shift
|
||||
|
|
|
@ -670,11 +670,12 @@ module prismoid(
|
|||
rounding=rounding, chamfer=chamfer,
|
||||
rounding1=rounding1, rounding2=rounding2,
|
||||
chamfer1=chamfer1, chamfer2=chamfer2,
|
||||
l=l, height=height, length=length, center=CENTER, _return_dim=true
|
||||
l=l, height=height, length=length, anchor=BOT, _return_dim=true
|
||||
);
|
||||
anchor = get_anchor(anchor, center, BOT, BOT);
|
||||
attachable(anchor,spin,orient, size=vnf_s1_s2_shift[1], size2=vnf_s1_s2_shift[2], shift=vnf_s1_s2_shift[3]) {
|
||||
vnf_polyhedron(vnf_s1_s2_shift[0], convexity=4);
|
||||
down(vnf_s1_s2_shift[1].z/2)
|
||||
vnf_polyhedron(vnf_s1_s2_shift[0], convexity=4);
|
||||
children();
|
||||
}
|
||||
}
|
||||
|
|
20
vectors.scad
20
vectors.scad
|
@ -284,6 +284,26 @@ function vector_axis(v1,v2=undef,v3=undef) =
|
|||
) unit(cross(w1,w3));
|
||||
|
||||
|
||||
// Function: vector_bisect()
|
||||
// Usage:
|
||||
// newv = vector_bisect(v1,v2);
|
||||
// Description:
|
||||
// Returns a unit vector that exactly bisects the minor angle between two given vectors.
|
||||
// If given two vectors that are directly opposed, returns `undef`.
|
||||
function vector_bisect(v1,v2) =
|
||||
assert(is_vector(v1))
|
||||
assert(is_vector(v2))
|
||||
assert(!approx(norm(v1),0), "Zero length vector.")
|
||||
assert(!approx(norm(v2),0), "Zero length vector.")
|
||||
assert(len(v1)==len(v2), "Vectors are of different sizes.")
|
||||
let( v1 = unit(v1), v2 = unit(v2) )
|
||||
approx(v1,-v2)? undef :
|
||||
let(
|
||||
axis = vector_axis(v1,v2),
|
||||
ang = vector_angle(v1,v2),
|
||||
v3 = rot(ang/2, v=axis, p=v1)
|
||||
) v3;
|
||||
|
||||
|
||||
|
||||
// Section: Vector Searching
|
||||
|
|
Loading…
Reference in a new issue