From f206de4a1a753b9400235faef5c295a0c3a70342 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 22 Feb 2020 09:59:31 +0800 Subject: [PATCH] add convex_intersection --- .../_impl/_convex_intersection_impl.scad | 12 ++++++++++++ src/experimental/convex_intersection.scad | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/experimental/_impl/_convex_intersection_impl.scad create mode 100644 src/experimental/convex_intersection.scad diff --git a/src/experimental/_impl/_convex_intersection_impl.scad b/src/experimental/_impl/_convex_intersection_impl.scad new file mode 100644 index 00000000..731dcad6 --- /dev/null +++ b/src/experimental/_impl/_convex_intersection_impl.scad @@ -0,0 +1,12 @@ +use ; + +function _intersection_ps(shape, line_pts, epsilon) = + let( + leng = len(shape), + pts = concat(shape, [shape[0]]) + ) + [ + for(i = [0:leng - 1]) + let(p = intersection_p(line_pts, [pts[i], pts[i + 1]], epsilon = epsilon)) + if(p != []) p + ]; \ No newline at end of file diff --git a/src/experimental/convex_intersection.scad b/src/experimental/convex_intersection.scad new file mode 100644 index 00000000..f3311815 --- /dev/null +++ b/src/experimental/convex_intersection.scad @@ -0,0 +1,17 @@ + +use ; +use ; +use ; + +function convex_intersection(shape1, shape2, epsilon = 0.0001) = + let( + leng = len(shape1), + pts = concat(shape1, [shape1[0]]) + ) + convex_ct_clk_order( + concat( + [for(p = shape1) if(in_shape(shape2, p, include_edge = true)) p], + [for(p = shape2) if(in_shape(shape1, p, include_edge = true)) p], + [for(i = [0:leng - 1]) each _intersection_ps(shape2, [pts[i], pts[i + 1]], epsilon)] + ) + ); \ No newline at end of file