From 441d73393550eea7735b95da01adf680d56a3eb4 Mon Sep 17 00:00:00 2001 From: spirkelmann Date: Fri, 13 Sep 2019 17:17:05 +0200 Subject: [PATCH] added code for generation of jigsaw puzzle piece on svg line --- prototype/circles.py | 97 +++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 23 deletions(-) diff --git a/prototype/circles.py b/prototype/circles.py index 84be1b8..f4cbffb 100644 --- a/prototype/circles.py +++ b/prototype/circles.py @@ -5,7 +5,7 @@ import operator # scale in inkscape # 1 unit = 0.283 mm -scale = 1000.0/282.222 +svg_scale = 1000.0/282.222 def svg_circle(id, name, c, r): # create circle object in svg notation @@ -48,12 +48,12 @@ def svg_puzzle(p, size, angle): p4 = p - size * v1 # convert to svg units - p1 *= scale - p2 *= scale - p3 *= scale - p4 *= scale + p1 *= svg_scale + p2 *= svg_scale + p3 *= svg_scale + p4 *= svg_scale - radius_scaled = 1.25 * size * scale + radius_scaled = 1.25 * size * svg_scale text = [' 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 *= svg_scale + p2 *= svg_scale + p3 *= svg_scale + p4 *= svg_scale + start *= svg_scale + end *= svg_scale + + radius_scaled = 1.25 * size * svg_scale + + text = [' \n'.format(linewidth, start[0], start[1], p1[0], p1[1], p2[0], p2[1], radius_scaled, radius_scaled, + p3[0], p3[1], p4[0], p4[1], end[0], end[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 @@ -74,13 +126,13 @@ def svg_half_circle(id, name, c, r, angle, orientation_flag=1): # compute starting point v = np.array([np.cos(angle), np.sin(angle)]) begin = c + r * v # in millimeters - begin *= scale # in svg units + begin *= svg_scale # in svg units # compute end point end = c - r * v # in millimeters - end *= scale # in svg units + end *= svg_scale # in svg units - radius_scaled = r * scale # radius in svg units + radius_scaled = r * svg_scale # radius in svg units text = ['