tri_arc_path.scad
1 use <__comm__/__frags.scad> 2 use <angle_between.scad> 3 use <triangle/tri_circumcenter.scad> 4 use <ptf/ptf_rotate.scad> 5 use <util/reverse.scad> 6 use <experimental/tri_is_ccw.scad> 7 8 function _tri_arc_ct_clk(shape_pts) = 9 let( 10 c = tri_circumcenter(shape_pts), 11 v0 = shape_pts[0] - c, 12 v2 = shape_pts[2] - c, 13 r = norm(v0), 14 v0_a = atan2(v0[1], v0[0]), 15 a = angle_between(v0, v2, ccw = true), 16 a_step = a / __frags(r) 17 ) 18 [for(a = [0:a_step:a]) c + ptf_rotate([r * cos(a), r * sin(a)], v0_a)]; 19 20 function tri_arc_path(shape_pts) = 21 tri_is_ccw(shape_pts) ? 22 _tri_arc_ct_clk(shape_pts) : 23 reverse(_tri_arc_ct_clk(reverse(shape_pts))); 24 25 /* 26 use <experimental/tri_arc_path.scad> 27 28 use <util/zip.scad> 29 use <hull_polyline2d.scad> 30 31 $fn = 24; 32 pts = zip([rands(0, 20, 3), rands(0, 20, 3)]); 33 34 hull_polyline2d(tri_arc_path(pts)); 35 #for(i = [0:len(pts) - 1]) { 36 translate(pts[i]) 37 sphere(1); 38 translate(pts[i]) 39 text(str(i), 2); 40 } 41 */