mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Fixed rotate_points3d(from,to)
This commit is contained in:
parent
d1a9d98033
commit
a4c4738f80
1 changed files with 30 additions and 16 deletions
46
math.scad
46
math.scad
|
@ -941,25 +941,38 @@ function rotate_points2d(pts, ang, cp=[0,0]) = let(
|
||||||
// from = If given, the vector to rotate something from. Used with `to`.
|
// from = If given, the vector to rotate something from. Used with `to`.
|
||||||
// to = If given, the vector to rotate something to. Used with `from`.
|
// to = If given, the vector to rotate something to. Used with `from`.
|
||||||
// reverse = If true, performs an exactly reversed rotation.
|
// reverse = If true, performs an exactly reversed rotation.
|
||||||
function rotate_points3d(pts, v=[0,0,0], cp=[0,0,0], axis=undef, from=undef, to=undef, reverse=false) =
|
function rotate_points3d(pts, v=0, cp=[0,0,0], axis=undef, from=undef, to=undef, reverse=false) =
|
||||||
let(
|
let(
|
||||||
dummy = assertion(is_def(from)==is_def(to), "`from` and `to` must be given together."),
|
dummy = assertion(is_def(from)==is_def(to), "`from` and `to` must be given together."),
|
||||||
mrot = reverse? (
|
mrot = reverse? (
|
||||||
is_def(from)? let (
|
is_def(from)? (
|
||||||
ang = vector_angle(from, to),
|
let (
|
||||||
axis = vector_axis(from, to)
|
ang = vector_angle(from, to),
|
||||||
) matrix4_rot_by_axis(from, -v) * matrix4_rot_by_axis(axis, -ang) :
|
axis = vector_axis(from, to)
|
||||||
is_def(axis)? matrix4_rot_by_axis(axis, -v) :
|
)
|
||||||
is_scalar(v)? matrix4_zrot(-v) :
|
matrix4_rot_by_axis(from, -v) * matrix4_rot_by_axis(axis, -ang)
|
||||||
matrix4_xrot(-v.x) * matrix4_yrot(-v.y) * matrix4_zrot(-v.z)
|
) : is_def(axis)? (
|
||||||
|
matrix4_rot_by_axis(axis, -v)
|
||||||
|
) : is_scalar(v)? (
|
||||||
|
matrix4_zrot(-v)
|
||||||
|
) : (
|
||||||
|
matrix4_xrot(-v.x) * matrix4_yrot(-v.y) * matrix4_zrot(-v.z)
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
is_def(from)? let (
|
is_def(from)? (
|
||||||
ang = vector_angle(from, to),
|
let (
|
||||||
axis = vector_axis(from, to)
|
ang = vector_angle(from, to),
|
||||||
) matrix4_rot_by_axis(axis, ang) * matrix4_rot_by_axis(from, v) :
|
axis = vector_axis(from, to)
|
||||||
is_def(axis)? matrix4_rot_by_axis(axis, v) :
|
)
|
||||||
is_scalar(v)? matrix4_zrot(v) :
|
echo(axis=axis, ang=ang, v=v)
|
||||||
matrix4_zrot(v.z) * matrix4_yrot(v.y) * matrix4_xrot(v.x)
|
matrix4_rot_by_axis(axis, ang) * matrix4_rot_by_axis(from, v)
|
||||||
|
) : is_def(axis)? (
|
||||||
|
matrix4_rot_by_axis(axis, v)
|
||||||
|
) : is_scalar(v)? (
|
||||||
|
matrix4_zrot(v)
|
||||||
|
) : (
|
||||||
|
matrix4_zrot(v.z) * matrix4_yrot(v.y) * matrix4_xrot(v.x)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
m = matrix4_translate(cp) * mrot * matrix4_translate(-cp)
|
m = matrix4_translate(cp) * mrot * matrix4_translate(-cp)
|
||||||
) [for (pt = pts) point3d(m*concat(point3d(pt),[1]))];
|
) [for (pt = pts) point3d(m*concat(point3d(pt),[1]))];
|
||||||
|
@ -1286,7 +1299,8 @@ function matrix4_zrot(ang) = assert(ang!=undef) [
|
||||||
function matrix4_rot_by_axis(u, ang) = let(
|
function matrix4_rot_by_axis(u, ang) = let(
|
||||||
u = normalize(u),
|
u = normalize(u),
|
||||||
c = cos(ang),
|
c = cos(ang),
|
||||||
c2 = 1-c, s = sin(ang)
|
c2 = 1-c,
|
||||||
|
s = sin(ang)
|
||||||
) [
|
) [
|
||||||
[u[0]*u[0]*c2+c , u[0]*u[1]*c2-u[2]*s, u[0]*u[2]*c2+u[1]*s, 0],
|
[u[0]*u[0]*c2+c , u[0]*u[1]*c2-u[2]*s, u[0]*u[2]*c2+u[1]*s, 0],
|
||||||
[u[1]*u[0]*c2+u[2]*s, u[1]*u[1]*c2+c , u[1]*u[2]*c2-u[0]*s, 0],
|
[u[1]*u[0]*c2+u[2]*s, u[1]*u[1]*c2+c , u[1]*u[2]*c2-u[0]*s, 0],
|
||||||
|
|
Loading…
Reference in a new issue