Bugfix for rot

This commit is contained in:
Revar Desmera 2020-03-03 19:17:14 -08:00
parent 12d3a46a12
commit ee30513644
4 changed files with 15 additions and 8 deletions

View file

@ -633,7 +633,7 @@ module regular_ngon(n=6, r, d, or, od, ir, id, side, rounding=0, realign=false,
r = get_radius(r1=ir*sc, r2=or, r=r, d1=id*sc, d2=od, d=d, dflt=side/2/sin(180/n));
assert(!is_undef(r), "regular_ngon(): need to specify one of r, d, or, od, ir, id, side.");
path = regular_ngon(n=n, r=r, rounding=rounding, realign=realign);
attachable(anchor,spin, two_d=true, path=path) {
attachable(anchor,spin, two_d=true, path=path, extent=false) {
polygon(path);
children();
}

View file

@ -369,7 +369,11 @@ module rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false)
function rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false, p=undef, planar=false) =
assert(is_undef(from)==is_undef(to), "from and to must be specified together.")
let(rev = reverse? -1 : 1)
let(
rev = reverse? -1 : 1,
from = is_undef(from)? undef : point3d(from),
to = is_undef(to)? undef : point3d(to)
)
is_undef(p)? (
is_undef(cp)? (
planar? (
@ -416,7 +420,7 @@ function rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false, p=unde
(planar || (p!=[] && len(p[0])==2)) && !(
(is_vector(a) && norm(point2d(a))>0) ||
(!is_undef(v) && norm(point2d(v))>0 && !approx(a,0)) ||
(!is_undef(from) && !approx(from,to) && !(abs(from.z)>0 || abs(to.z))) ||
(!is_undef(from) && !approx(from,to) && !(abs(point3d(from).z)>0 || abs(point3d(to).z))) ||
(!is_undef(from) && approx(from,to) && norm(point2d(from))>0 && a!=0)
)
)? (
@ -425,7 +429,8 @@ function rot(a=0, v=undef, cp=undef, from=undef, to=undef, reverse=false, p=unde
rotate_points2d(p, a=vector_angle(from,to)*sign(vector_axis(from,to)[2])*rev, cp=cp)
)
) : (
rotate_points3d(p, a=a, v=v, cp=(is_undef(cp)? [0,0,0] : cp), from=from, to=to, reverse=reverse)
let( cp = is_undef(cp)? [0,0,0] : cp )
rotate_points3d(p, a=a, v=v, cp=cp, from=from, to=to, reverse=reverse)
)
)
);

View file

@ -140,9 +140,11 @@ function vector_angle(v1,v2=undef,v3=undef) =
assert(false, "Bad arguments.")
) :
(is_vector(v1) && is_vector(v2) && is_vector(v3))? vector_angle(v1-v2, v3-v2) :
// NOTE: constrain() corrects crazy FP rounding errors that exceed acos()'s domain.
(is_vector(v1) && is_vector(v2) && is_undef(v3))? acos(constrain((v1*v2)/(norm(v1)*norm(v2)), -1, 1)) :
assert(false, "Bad arguments.");
(is_vector(v1) && is_vector(v2) && is_undef(v3))? (
assert(len(v1)==len(v2))
// NOTE: constrain() corrects crazy FP rounding errors that exceed acos()'s domain.
acos(constrain((v1*v2)/(norm(v1)*norm(v2)), -1, 1))
) : assert(false, "Bad arguments.");
// Function: vector_axis()

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,152];
BOSL_VERSION = [2,0,153];
// Section: BOSL Library Version Functions