mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +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()
|
// Function: rotate_points2d()
|
||||||
// Usage:
|
// Usage:
|
||||||
// rotate_points2d(pts, ang, [cp]);
|
// rotate_points2d(pts, a, [cp]);
|
||||||
// Description:
|
// Description:
|
||||||
// Rotates each 2D point in an array by a given amount, around an optional centerpoint.
|
// Rotates each 2D point in an array by a given amount, around an optional centerpoint.
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// pts = List of 3D points to rotate.
|
// 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]`
|
// cp = 2D Centerpoint to rotate around. Default: `[0,0]`
|
||||||
function rotate_points2d(pts, ang, cp=[0,0]) =
|
function rotate_points2d(pts, a, cp=[0,0]) =
|
||||||
approx(ang,0)? pts :
|
approx(a,0)? pts :
|
||||||
let(
|
let(
|
||||||
m = affine2d_zrot(ang)
|
cp = point2d(cp),
|
||||||
) [for (pt = pts) m*point3d(pt-cp)+cp];
|
pts = path2d(pts),
|
||||||
|
m = affine2d_zrot(a)
|
||||||
|
) [for (pt = pts) point2d(m*concat(pt-cp, [1])+cp)];
|
||||||
|
|
||||||
|
|
||||||
// Function: rotate_points3d()
|
// 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 :
|
(is_undef(from) && (a==0 || a==[0,0,0]))? pts :
|
||||||
let (
|
let (
|
||||||
from = is_undef(from)? undef : (from / norm(from)),
|
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 (
|
let (
|
||||||
mrot = reverse? (
|
mrot = reverse? (
|
||||||
!is_undef(from)? (
|
!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),
|
ang = vector_angle(from, to),
|
||||||
v = vector_axis(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)
|
affine3d_rot_by_axis(v, ang) * affine3d_rot_by_axis(from, a)
|
||||||
) : !is_undef(v)? (
|
) : !is_undef(v)? (
|
||||||
affine3d_rot_by_axis(v, a)
|
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)
|
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