diff --git a/src/cross_sections.scad b/src/cross_sections.scad index ba4d9534..9ffc361a 100644 --- a/src/cross_sections.scad +++ b/src/cross_sections.scad @@ -8,8 +8,6 @@ * **/ -use <__comm__/__to3d.scad>; - use ; use ; use ; @@ -17,24 +15,35 @@ use ; function cross_sections(shape_pts, path_pts, angles, twist = 0, scale = 1.0) = let( len_path_pts_minus_one = len(path_pts) - 1, - sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) __to3d(p)], - pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)], - scale_step_vt = is_num(scale) ? - [(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] : - [(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one], - twist_step = twist / len_path_pts_minus_one + sh_pts = len(shape_pts[0]) == 3 ? [for(p = shape_pts) [each p, 1]] : [for(p = shape_pts) [each p, 0, 1]], + pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) [each p, 0]] + ) + twist == 0 && scale == 1.0 ? + [ + for(i = [0:len_path_pts_minus_one]) + let(transform_m = m_translation(pth_pts[i]) * m_rotation(angles[i])) + [ + for(p = sh_pts) + let(transformed = transform_m * p) + [transformed.x, transformed.y, transformed.z] + ] + ] : + let( + twist_step = twist / len_path_pts_minus_one, + scale_step_vt = (is_num(scale) ? let(s = scale - 1) [s, s, 0] : ([each scale, 0] - [1, 1, 0])) / len_path_pts_minus_one, + one_s = [1, 1, 1] ) [ - for(i = 0; i <= len_path_pts_minus_one; i = i + 1) + for(i = [0:len_path_pts_minus_one]) let( transform_m = m_translation(pth_pts[i]) * m_rotation(angles[i]) * m_rotation(twist_step * i) * - m_scaling([1 + scale_step_vt.x * i, 1 + scale_step_vt.y * i, 1]) + m_scaling(scale_step_vt * i + one_s) ) [ for(p = sh_pts) - let(transformed = transform_m * [each p, 1]) + let(transformed = transform_m * p) [transformed.x, transformed.y, transformed.z] ] ];