From 81413584add0c13205de3071853d23246e6082a0 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 20 Jun 2021 15:29:01 +0800 Subject: [PATCH] add direction param --- src/surface/sf_thicken.scad | 40 +++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/surface/sf_thicken.scad b/src/surface/sf_thicken.scad index d6833f17..9053edf8 100644 --- a/src/surface/sf_thicken.scad +++ b/src/surface/sf_thicken.scad @@ -1,7 +1,7 @@ use ; use ; -module sf_thicken(points, thickness, slicing = "SLASH") { +module sf_thicken(points, thickness, direction = undef, slicing = "SLASH") { function tri_normal(tri) = let(v = cross(tri[2] - tri[0], tri[1] - tri[0])) v / norm(v); @@ -26,20 +26,30 @@ module sf_thicken(points, thickness, slicing = "SLASH") { ) sum(normals) / len(normals); - vertex_normals = [ - for(y = [0:len(points) - 1]) - [ - for(x = [0:len(points[0]) - 1]) - vertex_normal(points, x, y) - ] - ]; - - - half_thickness = thickness / 2; - surface_top = points + half_thickness * vertex_normals; - surface_bottom = points - half_thickness * vertex_normals; - - sf_solidify(surface_top, surface_bottom, slicing); + if(direction == undef) { + vertex_normals = [ + for(y = [0:len(points) - 1]) + [ + for(x = [0:len(points[0]) - 1]) + vertex_normal(points, x, y) + ] + ]; + half_thickness = thickness / 2; + surface_top = points + half_thickness * vertex_normals; + surface_bottom = points - half_thickness * vertex_normals; + sf_solidify(surface_top, surface_bottom, slicing); + } + else { + dir_v = direction / norm(direction); + sf = points + thickness * [ + for(y = [0:len(points) - 1]) + [ + for(x = [0:len(points[0]) - 1]) + dir_v + ] + ]; + sf_solidify(points, sf, slicing); + } } /*