mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Bugfixes for rotate_points3d
This commit is contained in:
parent
5edbb339bf
commit
aa429aa1a1
1 changed files with 13 additions and 10 deletions
23
coords.scad
23
coords.scad
|
@ -91,18 +91,20 @@ function scale_points(pts, v=[0,0,0], cp=[0,0,0]) = [for (pt = pts) [for (i = [0
|
|||
|
||||
// Function: rotate_points2d()
|
||||
// Usage:
|
||||
// rotate_points2d(pts, ang, [cp]);
|
||||
// rotate_points2d(pts, a, [cp]);
|
||||
// Description:
|
||||
// Rotates each 2D point in an array by a given amount, around an optional centerpoint.
|
||||
// Arguments:
|
||||
// pts = List of 3D points to rotate.
|
||||
// ang = Angle to rotate by.
|
||||
// a = Angle to rotate by.
|
||||
// cp = 2D Centerpoint to rotate around. Default: `[0,0]`
|
||||
function rotate_points2d(pts, ang, cp=[0,0]) =
|
||||
approx(ang,0)? pts :
|
||||
function rotate_points2d(pts, a, cp=[0,0]) =
|
||||
approx(a,0)? pts :
|
||||
let(
|
||||
m = affine2d_zrot(ang)
|
||||
) [for (pt = pts) m*point3d(pt-cp)+cp];
|
||||
cp = point2d(cp),
|
||||
pts = path2d(pts),
|
||||
m = affine2d_zrot(a)
|
||||
) [for (pt = pts) point2d(m*concat(pt-cp, [1])+cp)];
|
||||
|
||||
|
||||
// Function: rotate_points3d()
|
||||
|
@ -125,9 +127,11 @@ function rotate_points3d(pts, a=0, v=undef, cp=[0,0,0], from=undef, to=undef, re
|
|||
(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))
|
||||
to = is_undef(to)? undef : (to / norm(to)),
|
||||
cp = point3d(cp),
|
||||
pts2 = path3d(pts)
|
||||
)
|
||||
(!is_undef(from) && approx(from,to))? pts :
|
||||
(!is_undef(from) && approx(from,to))? pts2 :
|
||||
let (
|
||||
mrot = reverse? (
|
||||
!is_undef(from)? (
|
||||
|
@ -151,7 +155,6 @@ 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)
|
||||
|
@ -163,7 +166,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)
|
||||
)
|
||||
[for (pt = pts) point3d(m*concat(point3d(pt),[1]))];
|
||||
[for (pt = pts2) point3d(m*concat(pt, fill=1))];
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue