mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-29 17:50:06 +02:00
Removed translate_points(), scale_points(), rotate_points2d() and rotate_points3d()
This commit is contained in:
119
coords.scad
119
coords.scad
@@ -100,121 +100,6 @@ function path4d(points, fill=0) =
|
||||
result + repeat(addition, len(result));
|
||||
|
||||
|
||||
// Function: translate_points()
|
||||
// Usage:
|
||||
// translate_points(pts, v);
|
||||
// Description:
|
||||
// Moves each point in an array by a given amount.
|
||||
// Arguments:
|
||||
// pts = List of points to translate.
|
||||
// v = Amount to translate points by.
|
||||
function translate_points(pts, v=[0,0,0]) =
|
||||
pts==[]? [] : let(
|
||||
v=point3d(v)
|
||||
) [for (pt = pts) pt+v];
|
||||
|
||||
|
||||
// Function: scale_points()
|
||||
// Usage:
|
||||
// scale_points(pts, v, [cp]);
|
||||
// Description:
|
||||
// Scales each point in an array by a given amount, around a given centerpoint.
|
||||
// Arguments:
|
||||
// pts = List of points to scale.
|
||||
// v = A vector with a scaling factor for each axis.
|
||||
// cp = Centerpoint to scale around.
|
||||
function scale_points(pts, v=[1,1,1], cp=[0,0,0]) =
|
||||
pts==[]? [] : let(
|
||||
cp = point3d(cp),
|
||||
v = point3d(v,fill=1)
|
||||
) [for (pt = pts) vmul(pt-cp,v)+cp];
|
||||
|
||||
|
||||
// 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
|
||||
|
||||
// Function: polar_to_xy()
|
||||
@@ -289,7 +174,7 @@ function project_plane(point, a, b, c) =
|
||||
v = unit(c-a),
|
||||
n = unit(cross(u,v)),
|
||||
w = unit(cross(n,u)),
|
||||
relpoint = is_vector(point)? (point-a) : translate_points(point,-a)
|
||||
relpoint = is_vector(point)? (point-a) : move(-a,p=point)
|
||||
) relpoint * transpose([w,u]);
|
||||
|
||||
|
||||
@@ -320,7 +205,7 @@ function lift_plane(point, a, b, c) =
|
||||
n = unit(cross(u,v)),
|
||||
w = unit(cross(n,u)),
|
||||
remapped = point*[w,u]
|
||||
) is_vector(remapped)? (a+remapped) : translate_points(remapped,a);
|
||||
) is_vector(remapped)? (a+remapped) : move(a,p=remapped);
|
||||
|
||||
|
||||
// Function: cylindrical_to_xyz()
|
||||
|
Reference in New Issue
Block a user