From d59117c101241dd164becdd6e19900c02874b7cb Mon Sep 17 00:00:00 2001 From: spirkelmann Date: Fri, 13 Sep 2019 08:44:31 +0200 Subject: [PATCH] added generation of jigsaw puzzle shape --- prototype/circles.py | 53 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/prototype/circles.py b/prototype/circles.py index 19d0c98..84be1b8 100644 --- a/prototype/circles.py +++ b/prototype/circles.py @@ -19,6 +19,50 @@ def svg_circle(id, name, c, r): return text +def svg_puzzle(p, size, angle): + # convert angle to radians + angle = angle / 360.0 * 2.0 * np.pi + + + # compute points + """ + v1 and v2 are orthogonal vectors + + construction of points (starting at p): + + p3 <------ -2 v1 ------ p2 + ^ + | + v2 + | + | + p4 <-- -v1 -- p -- v1 --> p1 + + then between points p2 and p3 with draw an arc + """ + v1 = np.array([np.cos(angle), np.sin(angle)]) + v2 = np.array([v1[1], -v1[0]]) + p1 = p + size * v1 + p2 = p1 + size * v2 + p3 = p2 - 2.0 * size * v1 + p4 = p - size * v1 + + # convert to svg units + p1 *= scale + p2 *= scale + p3 *= scale + p4 *= scale + + radius_scaled = 1.25 * size * scale + + text = [' \n'.format(p1[0], p1[1], p2[0], p2[1], radius_scaled, radius_scaled, p3[0], p3[1], p4[0], p4[1])] + + return text + def svg_half_circle(id, name, c, r, angle, orientation_flag=1): # draws half a circle centered at c with radius r # angle specifies how the half circle should be rotated @@ -601,8 +645,8 @@ class PlateLayout: outer_point_2 = p4 # truncate gear path - for k in range(len(f_lines)): - current_line = f_lines[k] + for j in range(len(f_lines)): + current_line = f_lines[j] if 'd="m ' in current_line: # remove center whole drawn by gear-dev @@ -630,6 +674,11 @@ class PlateLayout: pass #f_lines[k] = gear_data[0:index+1] + gear_data[-2:] + c = self.tube_1_coords[k] + angle = self.tube_1_angles[k] + text = svg_puzzle(c, 4, angle) + f_lines = f_lines + text + return f_lines def output_whole(self, f_lines):