From e6fa4f3d713108bde984433a1c3cb4ea592abcc7 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Sat, 1 Jun 2019 17:41:29 -0700 Subject: [PATCH] Bugfix for rotate_points3d(from,to) optimization. --- coords.scad | 14 +++++++++----- masks.scad | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/coords.scad b/coords.scad index 17f4f3d..a906700 100644 --- a/coords.scad +++ b/coords.scad @@ -122,12 +122,16 @@ function rotate_points2d(pts, ang, cp=[0,0]) = // reverse = If true, performs an exactly reversed rotation. function rotate_points3d(pts, a=0, v=undef, cp=[0,0,0], from=undef, to=undef, reverse=false) = assert(is_undef(from)==is_undef(to), "`from` and `to` must be given together.") - let( + (is_undef(from) && (a==0 || a==[0,0,0]))? pts : + let ( + from = is_undef(from)? undef : (from / norm(from)), + to = is_undef(to)? undef : (to / norm(to)) + ) + (!is_undef(from) && approx(from,to))? pts : + let ( mrot = reverse? ( !is_undef(from)? ( let ( - from = from / norm(from), - to = to / norm(from), ang = vector_angle(from, to), v = vector_axis(from, to) ) @@ -147,6 +151,7 @@ function rotate_points3d(pts, a=0, v=undef, cp=[0,0,0], from=undef, to=undef, re ang = vector_angle(from, to), v = vector_axis(from, to) ) + echo("EEE",from=from,to=to,ang=ang,v=v,a=a) affine3d_rot_by_axis(v, ang) * affine3d_rot_by_axis(from, a) ) : !is_undef(v)? ( affine3d_rot_by_axis(v, a) @@ -157,8 +162,7 @@ function rotate_points3d(pts, a=0, v=undef, cp=[0,0,0], from=undef, to=undef, re ) ), m = affine3d_translate(cp) * mrot * affine3d_translate(-cp) - ) (!is_undef(from) && approx(from,to))? pts : - (a==0 || a==[0,0,0])? pts : + ) [for (pt = pts) point3d(m*concat(point3d(pt),[1]))]; diff --git a/masks.scad b/masks.scad index 545199e..dd70022 100644 --- a/masks.scad +++ b/masks.scad @@ -438,7 +438,7 @@ module rounding_mask(l=undef, r=1.0, anchor=CENTER, spin=0, orient=UP, h=undef) // } module rounding_mask_x(l=1.0, r=1.0, anchor=CENTER, spin=0) { - anchor = rotate_points3d([anchor], from=RIGHT, to=TOP)[0]; + anchor = rot(p=anchor, from=RIGHT, to=TOP); rounding_mask(l=l, r=r, anchor=anchor, spin=spin, orient=RIGHT) { for (i=[0:1:$children-2]) children(i); if ($children) children($children-1); @@ -465,7 +465,7 @@ module rounding_mask_x(l=1.0, r=1.0, anchor=CENTER, spin=0) // } module rounding_mask_y(l=1.0, r=1.0, anchor=CENTER, spin=0) { - anchor = rotate_points3d([anchor], from=BACK, to=TOP)[0]; + anchor = rot(p=anchor, from=BACK, to=TOP); rounding_mask(l=l, r=r, anchor=anchor, spin=spin, orient=BACK) { for (i=[0:1:$children-2]) children(i); if ($children) children($children-1);