module section(points){ //points[0] must have its points ordered clockwise assert(len(points) == 2, "section is formed between exactly two polygons"); assert(len(points[0]) == len(points[1]), "polygons need to have the same number of vertices"); assert(len(points[0])>2, "polygons need to have at least 3 sides"); n = len(points[0]); points_new = concat(points[0], points[1]); faces = concat([[for(i = [0 : 1 : n-1]) i]], concat([[for(i = [1 : n]) (2*n)-i]], concat( [for(i = [0 : n-2]) [i+1, i, n+i, n+i+1]], [[0,n-1,(2*n)-1,n]]))); polyhedron(points = points_new, faces = faces, convexity = 10); } module extrusion(points){ assert(len(points)>1, "extrusion is formed between at least two polygons"); for(i = [0 : len(points)-2]) section([points[i],points[i+1]]); } module bezier_extrude(ctrl, shape, steps = 512){ B_0 = ctrl[0]; B_1 = 3*((-1)*ctrl[0] + ctrl[1]); B_2 = 3*(ctrl[0] - 2*ctrl[1] + ctrl[2]); B_3 = (-1)*ctrl[0] + 3*(ctrl[1] - ctrl[2]) + ctrl[3]; function bezier(t) = B_0 + t*B_1 + (t^2)*B_2 + (t^3)*B_3; Bd_0 = 3*((-1)*ctrl[0] + ctrl[1]); Bd_1 = 6*(ctrl[0] - 2*ctrl[1] + ctrl[2]); Bd_2 = 3*((-1)*ctrl[0] + 3*(ctrl[1] - ctrl[2]) + ctrl[3]); Bn_0 = [Bd_0.y,-Bd_0.x]; Bn_1 = [Bd_1.y,-Bd_1.x]; Bn_2 = [Bd_2.y,-Bd_2.x]; function normal(t) = Bn_0 + t*Bn_1 + (t^2)*Bn_2; slices = [for(i = [0 : steps]) let (t = i/steps, p = bezier(t), normal = normal(t), n = normal/norm(normal)) [for (v = shape) [p.x+(n.x * v.x),p.y+(n.y * v.x), v.y]]]; extrusion(slices); } shape = [[0,0.5],[0.8,0],[-0.5,-1],[-0.8,0]]; ctrl = [[0,0],[0,10],[10,0],[10,10]]; bezier_extrude(ctrl = ctrl, shape = shape); //extrusion([[[0,0,0],[0,1,0],[0,1,1],[0,0,1]],[[1,0,0],[1,1,0],[1,1,1],[1,0,1]],[[2,0,1],[2,1,1],[2,1,2],[2,0,2]]]);