diff --git a/regions.scad b/regions.scad index 6777abbc..c51120c3 100644 --- a/regions.scad +++ b/regions.scad @@ -381,82 +381,6 @@ function region_parts(region) = // Section: Region Extrusion and VNFs -function _path_path_closest_vertices(path1,path2) = - let( - dists = [for (i=idx(path1)) let(j=closest_point(path1[i],path2)) [j,norm(path2[j]-path1[i])]], - i1 = min_index(subindex(dists,1)), - i2 = dists[i1][0] - ) [dists[i1][1], i1, i2]; - - -function _join_paths_at_vertices(path1,path2,v1,v2) = - let( - repeat_start = !approx(path1[v1],path2[v2]), - path1 = clockwise_polygon(polygon_shift(path1,v1)), - path2 = ccw_polygon(polygon_shift(path2,v2)) - ) - [ - each path1, - if (repeat_start) path1[0], - each path2, - if (repeat_start) path2[0], - ]; - - -// Given a region that is connected and has its outer border in region[0], -// produces a polygon with the same points that has overlapping connected paths -// to join internal holes to the outer border. Output is a single path. -function _cleave_connected_region(region) = - len(region)==0? [] : - len(region)<=1? clockwise_polygon(region[0]) : - let( - dists = [ - for (i=[1:1:len(region)-1]) - _path_path_closest_vertices(region[0],region[i]) - ], - idxi = min_index(subindex(dists,0)), - newoline = _join_paths_at_vertices( - region[0], region[idxi+1], - dists[idxi][1], dists[idxi][2] - ) - ) len(region)==2? clockwise_polygon(newoline) : - let( - orgn = [ - newoline, - for (i=idx(region)) - if (i>0 && i!=idxi+1) - region[i] - ] - ) - assert(len(orgn)0 && i!=idxi+1) + region[i] + ] + ) + assert(len(orgn) pivot) li ] ) + concat( _indicator_sort(lesser ,imin,pivot-1), + search(pivot,l,1) ? 1 : 0 , + _indicator_sort(greater,pivot+1,imax) ) ; + + // Function: vnf_triangulate() // Usage: // vnf2 = vnf_triangulate(vnf); // Description: -// Triangulates faces in the VNF that have more than 3 vertices. +// Triangulates faces in the VNF that have more than 3 vertices. +// Example: +// include +// vnf = zrot(33,regular_polyhedron_info("vnf", "dodecahedron", side=12)); +// vnf_polyhedron(vnf); +// triangulated = vnf_triangulate(vnf); +// color("red")vnf_wireframe(triangulated,width=.3); function vnf_triangulate(vnf) = let( - vnf = is_vnf_list(vnf)? vnf_merge(vnf) : vnf, verts = vnf[0], faces = [for (face=vnf[1]) each len(face)==3 ? [face] : polygon_triangulate(verts, face)] @@ -709,7 +832,7 @@ function vnf_halfspace(plane, vnf, closed=true) = let( M = project_plane(plane), faceregion = [for(path=newpaths) path2d(apply(M,select(newvert,path)))], - facevnf = region_faces(faceregion,transform=rot_inverse(M),reverse=true) + facevnf = vnf_from_region(faceregion,transform=rot_inverse(M),reverse=true) ) vnf_merge([[newvert, faces_edges_vertices[0]], facevnf]);