diff --git a/src/along_with.scad b/src/along_with.scad index ac0fde78..11c95bc9 100644 --- a/src/along_with.scad +++ b/src/along_with.scad @@ -61,16 +61,14 @@ module along_with(points, angles, twist = 0, scale = 1.0, method = "AXIS_ANGLE") leng_rot_matrice_minus_one = leng_rot_matrice - 1, leng_rot_matrice_minus_two = leng_rot_matrice - 2 ) - leng_rot_matrice == 0 ? [identity_matrix] : ( - leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] : ( - i == leng_rot_matrice_minus_two ? - [ - rot_matrice[leng_rot_matrice_minus_one], - rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one] - ] - : axis_angle_cumulated_rot_matrice_sub(i, rot_matrice) - ) - ); + leng_rot_matrice == 0 ? [identity_matrix] : + leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] : + i == leng_rot_matrice_minus_two ? + [ + rot_matrice[leng_rot_matrice_minus_one], + rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one] + ] + : axis_angle_cumulated_rot_matrice_sub(i, rot_matrice); function axis_angle_cumulated_rot_matrice_sub(i, rot_matrice) = let( diff --git a/src/path_extrude.scad b/src/path_extrude.scad index 93d9f62e..36fefe36 100644 --- a/src/path_extrude.scad +++ b/src/path_extrude.scad @@ -10,8 +10,9 @@ use <__comm__/__to3d.scad>; use <__comm__/__angy_angz.scad>; -use ; use ; +use ; +use ; use ; module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false, method = "AXIS_ANGLE") { @@ -20,18 +21,13 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = len_path_pts = len(pth_pts); len_path_pts_minus_one = len_path_pts - 1; + + m_rot_90_0_n90 = m_rotation([90, 0, -90]); module axis_angle_path_extrude() { twist_step_a = twist / len_path_pts; - - function scale_pts(pts, s) = - [ - for(p = pts) [p.x * s.x, p.y * s.y, p.z * s.z] - ]; function translate_pts(pts, t) = [for(p = pts) p + t]; - - function rotate_pts(pts, a, v) = [for(p = pts) ptf_rotate(p, a, v)]; scale_step_vt = is_num(scale) ? let(s = (scale - 1) / len_path_pts_minus_one) [s, s, s] : @@ -72,16 +68,15 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = ]; function cumulated_rot_matrice(i) = - leng_rot_matrice == 0 ? [identity_matrix] : ( - leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] : - ( - i == leng_rot_matrice_minus_two ? - [ - rot_matrice[leng_rot_matrice_minus_one], - rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one] - ] - : cumulated_rot_matrice_sub(i)) - ); + leng_rot_matrice == 0 ? [identity_matrix] : + leng_rot_matrice == 1 ? [rot_matrice[0], identity_matrix] : + i == leng_rot_matrice_minus_two ? + [ + rot_matrice[leng_rot_matrice_minus_one], + rot_matrice[leng_rot_matrice_minus_two] * rot_matrice[leng_rot_matrice_minus_one] + ] + : + cumulated_rot_matrice_sub(i); function cumulated_rot_matrice_sub(i) = let( @@ -93,17 +88,19 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = cumu_rot_matrice = cumulated_rot_matrice(0); + // get all sections function init_section(a, s) = - let(angleyz = __angy_angz(pth_pts[0], pth_pts[1])) - rotate_pts( - rotate_pts( - rotate_pts( - scale_pts(sh_pts, s), a - ), [90, 0, -90] - ), [0, -angleyz[0], angleyz[1]] - ); + let( + angleyz = __angy_angz(pth_pts[0], pth_pts[1]), + transform_m = m_rotation([0, -angleyz[0], angleyz[1]]) * m_rot_90_0_n90 * m_rotation(a) * m_scaling(s) + ) + [ + for(p = sh_pts) + let(transformed = transform_m * [each p, 1]) + [transformed.x, transformed.y, transformed.z] + ]; function local_rotate_section(j, init_a, init_s) = j == 0 ? @@ -112,8 +109,6 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = function local_rotate_section_sub(j, init_a, init_s) = let( - vt0 = pth_pts[j] - pth_pts[j - 1], - vt1 = pth_pts[j + 1] - pth_pts[j], ms = cumu_rot_matrice[j - 1], ms0 = ms[0], ms1 = ms[1], @@ -164,20 +159,20 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = function section(p1, p2, i) = let( - length = norm(p1 - p2), angy_angz = __angy_angz(p1, p2), ay = -angy_angz[0], - az = angy_angz[1] + az = angy_angz[1], + transform_m = m_translation(p1) * + m_rotation([0, ay, az]) * + m_translation([i == 0 ? 0 : norm(p1 - p2), 0, 0]) * + m_rot_90_0_n90 * + m_rotation(twist_step * i) * + m_scaling([1 + scale_step_vt.x * i, 1 + scale_step_vt.y * i, 1]) ) [ for(p = sh_pts) - let(scaled_p = [p.x * (1 + scale_step_vt.x * i), p.y * (1 + scale_step_vt.y * i), p.z]) - ptf_rotate( - ptf_rotate( - ptf_rotate(scaled_p, twist_step * i), [90, 0, -90] - ) + [i == 0 ? 0 : length, 0, 0], - [0, ay, az] - ) + p1 + let(transformed = transform_m * [each p, 1]) + [transformed.x, transformed.y, transformed.z] ]; path_extrude_inner = diff --git a/src/ptf/_impl/_ptf_rotate_impl.scad b/src/ptf/_impl/_ptf_rotate_impl.scad index d4ada998..9d047442 100644 --- a/src/ptf/_impl/_ptf_rotate_impl.scad +++ b/src/ptf/_impl/_ptf_rotate_impl.scad @@ -26,10 +26,10 @@ function _q_rotate_p_3d(p, a, v) = 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 + p * [ + [1 - yy - zz, yx + wz, zx - wy], + [yx - wz, 1 - xx - zz, zy + wx], + [zx + wy, zy - wx, 1 - xx - yy] ]; function _rotx(pt, a) = diff --git a/src/shape_circle.scad b/src/shape_circle.scad index ed0b466b..5ee5de01 100644 --- a/src/shape_circle.scad +++ b/src/shape_circle.scad @@ -16,8 +16,4 @@ function shape_circle(radius, n) = step_a = 360 / _frags, end = (is_undef(n) || n > _frags) ? _frags - 1: n - 1 ) - [ - for(i = [0:end]) - let(a = i * step_a) - [radius * cos(a), radius * sin(a)] - ]; + [for(a = [0:step_a:end * step_a]) [radius * cos(a), radius * sin(a)]]; diff --git a/src/shape_cyclicpolygon.scad b/src/shape_cyclicpolygon.scad index ae8f67f7..5c46ccc0 100644 --- a/src/shape_cyclicpolygon.scad +++ b/src/shape_cyclicpolygon.scad @@ -20,14 +20,14 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) = corner_circle_center = circle_r - corner_r / sin(corner_a / 2), first_corner = [ for( - pt = __pie_for_rounding( - corner_r, - -half_corner_circle_a, - half_corner_circle_a, - __frags(corner_r) * corner_circle_a / 360 - ) - ) - [pt.x + corner_circle_center, pt.y] + pt = __pie_for_rounding( + corner_r, + -half_corner_circle_a, + half_corner_circle_a, + __frags(corner_r) * corner_circle_a / 360 + ) + ) + [pt.x + corner_circle_center, pt.y] ] ) @@ -35,15 +35,12 @@ function shape_cyclicpolygon(sides, circle_r, corner_r) = first_corner, [ for(side = 1; side < sides; side = side + 1) - for(pt = first_corner) - let( - a = frag_a * side, - sina = sin(a), - cosa = cos(a) - ) - [ - pt.x * cosa - pt.y * sina, - pt.x * sina + pt.y * cosa - ] + let( + a = frag_a * side, + sina = sin(a), + cosa = cos(a) + ) + // for(pt = first_corner) [pt.x * cosa - pt.y * sina, pt.x * sina + pt.y * cosa] + each first_corner * [[cosa, sina], [-sina, cosa]] ] ); \ No newline at end of file