From 87052bb1723dc58e7b060e32b475a376897f1d91 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 29 Apr 2019 15:26:50 +0800 Subject: [PATCH] required by path_extrude --- src/rotate_p.scad | 50 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/rotate_p.scad b/src/rotate_p.scad index fb91f02d..7480cfcb 100644 --- a/src/rotate_p.scad +++ b/src/rotate_p.scad @@ -14,6 +14,37 @@ include <__private__/__to2d.scad>; include <__private__/__to3d.scad>; + +function _q_rotate_p_3d(p, a, v) = + let( + half_a = a / 2, + axis = v / norm(v), + s = sin(half_a), + x = s * axis[0], + y = s * axis[1], + z = s * axis[2], + w = cos(half_a), + + x2 = x + x, + y2 = y + y, + z2 = z + z, + + xx = x * x2, + yx = y * x2, + yy = y * y2, + zx = z * x2, + zy = z * y2, + zz = z * z2, + wx = w * x2, + wy = w * y2, + wz = w * z2 + ) + [ + [1 - yy - zz, yx - wz, zx + wy] * p, + [yx + wz, 1 - xx - zz, zy - wx] * p, + [zx - wy, zy + wx, 1 - xx - yy] * p + ]; + function _rotx(pt, a) = let(cosa = cos(a), sina = sin(a)) [ @@ -48,10 +79,21 @@ function to_avect(a) = ) ); -function rotate_p(point, a) = +function _rotate_p(p, a) = let(angle = to_avect(a)) - len(point) == 3 ? - _rotate_p_3d(point, angle) : + len(p) == 3 ? + _rotate_p_3d(p, angle) : __to2d( - _rotate_p_3d(__to3d(point), angle) + _rotate_p_3d(__to3d(p), angle) ); + + +function _q_rotate_p(p, a, v) = + len(p) == 3 ? + _q_rotate_p_3d(p, a, v) : + __to2d( + _q_rotate_p_3d(__to3d(p), a, v) + ); + +function rotate_p(point, a, v) = + v == undef ? _rotate_p(point, a) : _q_rotate_p(point, a, v);