added generation of jigsaw puzzle shape

master
Simon Pirkelmann 2019-09-13 08:44:31 +02:00
parent 42c5f92ece
commit d59117c101
1 changed files with 51 additions and 2 deletions

View File

@ -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 = [' <path \n '
' id="path666" \n '
' style="fill:none;stroke:#ff0000;stroke-width:1.60000002" \n'
' d="M {} {} L {} {} A {} {} 0 1 0 {} {} L {} {}"'
' />\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):