diff --git a/src/experimental/convex_hull.scad b/src/experimental/convex_hull.scad index 23d83d74..7a8a55dd 100644 --- a/src/experimental/convex_hull.scad +++ b/src/experimental/convex_hull.scad @@ -1,11 +1,28 @@ -use ; +use ; +use ; +use ; -function convex_hull(points) = - let( - sorted = _convex_hull_sort_by_xy(points), - leng = len(sorted), - lwr_ch = _convex_hull_lower_chain(sorted, leng, [], 0, 0), - leng_lwr_ch = len(lwr_ch), - chain = _convex_hull_upper_chain(sorted, lwr_ch, leng_lwr_ch, leng_lwr_ch + 1, leng - 2) - ) - [for(i = [0:len(chain) - 2]) chain[i]]; \ No newline at end of file +pt_nums = 50; +width = 1; +points = [for(i = [0:pt_nums - 1]) rands(-50, 50, 2)]; + +intersection() { + for(line = voronoi_lines(points)) { + hull_polyline2d( + line, + width = width, + $fn = 4 + ); + } + hull() + #for(p = points) { + translate(p) + circle(.5); + } +} + +hull_pts = convex_hull(points); +hull_polyline2d( + concat(hull_pts, [hull_pts[0]]), + width = width, $fn = 4 +); \ No newline at end of file