mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-09-03 11:02:51 +02:00
Merge branch 'master' into master
This commit is contained in:
84
coords.scad
84
coords.scad
@@ -100,90 +100,6 @@ function path4d(points, fill=0) =
|
||||
result + repeat(addition, len(result));
|
||||
|
||||
|
||||
// Function: rotate_points2d()
|
||||
// Usage:
|
||||
// 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.
|
||||
// a = Angle to rotate by.
|
||||
// cp = 2D Centerpoint to rotate around. Default: `[0,0]`
|
||||
function rotate_points2d(pts, a, cp=[0,0]) =
|
||||
approx(a,0)? pts :
|
||||
let(
|
||||
cp = point2d(cp),
|
||||
pts = path2d(pts),
|
||||
m = affine2d_zrot(a)
|
||||
) [for (pt = pts) point2d(m*concat(pt-cp, [1])+cp)];
|
||||
|
||||
|
||||
// Function: rotate_points3d()
|
||||
// Usage:
|
||||
// rotate_points3d(pts, a, [cp], [reverse]);
|
||||
// rotate_points3d(pts, a, v, [cp], [reverse]);
|
||||
// rotate_points3d(pts, from, to, [a], [cp], [reverse]);
|
||||
// Description:
|
||||
// Rotates each 3D point in an array by a given amount, around a given centerpoint.
|
||||
// Arguments:
|
||||
// pts = List of points to rotate.
|
||||
// a = Rotation angle(s) in degrees.
|
||||
// v = If given, axis vector to rotate around.
|
||||
// cp = Centerpoint to rotate around.
|
||||
// from = If given, the vector to rotate something from. Used with `to`.
|
||||
// to = If given, the vector to rotate something to. Used with `from`.
|
||||
// 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.")
|
||||
(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)),
|
||||
cp = point3d(cp),
|
||||
pts2 = path3d(pts)
|
||||
)
|
||||
(!is_undef(from) && approx(from,to) && (a==0 || a == [0,0,0]))? pts2 :
|
||||
let (
|
||||
mrot = reverse? (
|
||||
!is_undef(from)? (
|
||||
assert(norm(from)>0, "The from argument cannot equal [0,0] or [0,0,0]")
|
||||
assert(norm(to)>0, "The to argument cannot equal [0,0] or [0,0,0]")
|
||||
let (
|
||||
ang = vector_angle(from, to),
|
||||
v = vector_axis(from, to)
|
||||
)
|
||||
affine3d_rot_by_axis(from, -a) * affine3d_rot_by_axis(v, -ang)
|
||||
) : !is_undef(v)? (
|
||||
affine3d_rot_by_axis(v, -a)
|
||||
) : is_num(a)? (
|
||||
affine3d_zrot(-a)
|
||||
) : (
|
||||
affine3d_xrot(-a.x) * affine3d_yrot(-a.y) * affine3d_zrot(-a.z)
|
||||
)
|
||||
) : (
|
||||
!is_undef(from)? (
|
||||
assert(norm(from)>0, "The from argument cannot equal [0,0] or [0,0,0]")
|
||||
assert(norm(to)>0, "The to argument cannot equal [0,0] or [0,0,0]")
|
||||
let (
|
||||
from = from / norm(from),
|
||||
to = to / norm(from),
|
||||
ang = vector_angle(from, to),
|
||||
v = vector_axis(from, to)
|
||||
)
|
||||
affine3d_rot_by_axis(v, ang) * affine3d_rot_by_axis(from, a)
|
||||
) : !is_undef(v)? (
|
||||
affine3d_rot_by_axis(v, a)
|
||||
) : is_num(a)? (
|
||||
affine3d_zrot(a)
|
||||
) : (
|
||||
affine3d_zrot(a.z) * affine3d_yrot(a.y) * affine3d_xrot(a.x)
|
||||
)
|
||||
),
|
||||
m = affine3d_translate(cp) * mrot * affine3d_translate(-cp)
|
||||
)
|
||||
[for (pt = pts2) point3d(m*concat(pt, fill=1))];
|
||||
|
||||
|
||||
|
||||
// Section: Coordinate Systems
|
||||
|
||||
|
Reference in New Issue
Block a user