module line(point1, point2, width = 1, cap_round = true) { angle = 90 - atan((point2[1] - point1[1]) / (point2[0] - point1[0])); offset_x = 0.5 * width * cos(angle); offset_y = 0.5 * width * sin(angle); offset1 = [-offset_x, offset_y]; offset2 = [offset_x, -offset_y]; if(cap_round) { translate(point1) circle(d = width, $fn = 24); translate(point2) circle(d = width, $fn = 24); } polygon(points=[ point1 + offset1, point2 + offset1, point2 + offset2, point1 + offset2 ]); } module polyline(points, width = 1) { module polyline_inner(points, index) { if(index < len(points)) { line(points[index - 1], points[index], width); polyline_inner(points, index + 1); } } polyline_inner(points, 1); } module spiral(points, d, width, n_loop, i=0) { j = i * 4; if (i+1==n_loop) { points2 = concat(points, [[points[j][0]+d, points[j][1]+1.5*d]]); union()polyline(points2, width); } else { points2 = concat(points, [[points[j][0]+d, points[j][1]+d], [points[j+1][0]-d, points[j+1][1]+d], [points[j+2][0]-d, points[j+2][1]-d], [points[j+3][0]+d, points[j+2][1]-d]]); spiral(points2, d, width, n_loop, i+1); } } w = 60; h = 40; width = 1.3; d = width+0.5; n_loop = 6; points = [[-d, 0],[w, 0],[w,h],[0,h]]; spiral(points, d, width, n_loop); polyline([[-10, 0], [0, 0]], width=width); polyline([[-10, 1.2*d], [-1.2*d, 1.2*d]], width=width);