polyline3d.scad
1 /** 2 * polyline3d.scad 3 * 4 * @copyright Justin Lin, 2017 5 * @license https://opensource.org/licenses/lgpl-3.0.html 6 * 7 * @see https://openhome.cc/eGossip/OpenSCAD/lib3x-polyline3d.html 8 * 9 **/ 10 11 use <line3d.scad> 12 13 module polyline3d(points, diameter, startingStyle = "CAP_CIRCLE", endingStyle = "CAP_CIRCLE") { 14 leng_pts = len(points); 15 16 s_styles = [startingStyle, "CAP_BUTT"]; 17 e_styles = ["CAP_SPHERE", endingStyle]; 18 default_styles = ["CAP_SPHERE", "CAP_BUTT"]; 19 20 module line_segment(index) { 21 styles = index == 1 ? s_styles : 22 index == leng_pts - 1 ? e_styles : 23 default_styles; 24 25 p1 = points[index - 1]; 26 p2 = points[index]; 27 p1Style = styles[0]; 28 p2Style = styles[1]; 29 30 line3d(p1, p2, diameter, 31 p1Style = p1Style, p2Style = p2Style); 32 } 33 34 if(leng_pts == 2) { 35 line3d(points[0], points[1], diameter, startingStyle, endingStyle); 36 } 37 else { 38 for(i = [1:leng_pts - 1]) { 39 line_segment(i); 40 } 41 } 42 }