mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Corrected prismoid geometry corner anchor vectors.
This commit is contained in:
parent
ee3e2466bd
commit
2f1266e8c3
2 changed files with 39 additions and 6 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
|
||||
|
|
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