Bugfix for rotate_points3d(from,to) optimization.

This commit is contained in:
Revar Desmera 2019-06-01 17:41:29 -07:00
parent e33990c141
commit e6fa4f3d71
2 changed files with 11 additions and 7 deletions

View file

@ -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]))];

View file

@ -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);