added code for truncating plate gear path to segment

master
Simon Pirkelmann 2019-09-13 18:08:48 +02:00
parent 7d828f5fbf
commit 903fbdba07
1 changed files with 28 additions and 6 deletions

View File

@ -138,7 +138,7 @@ def svg_half_circle(id, name, c, r, angle, orientation_flag=1):
text = [' <path \n '
' id="path666" \n '
' style="fill:none;stroke:#ff0000;stroke-width:0.60000002" \n'
' style="fill:none;stroke:#000000;stroke-width:0.60000002" \n'
' d="M {} {} A {} {} 0 {} {} {} {}"'
' />\n'.format(begin[0], begin[1], radius_scaled, radius_scaled, orientation_flag, orientation_flag,
end[0], end[1])]
@ -151,7 +151,7 @@ def svg_arc(p1, p2, r, large_arc, sweep):
radius_scaled = r * svg_scale
text = [' <path \n '
' id="path666" \n '
' style="fill:none;stroke:#ff0000;stroke-width:0.60000002" \n'
' style="fill:none;stroke:#000000;stroke-width:0.60000002" \n'
' d="M {} {} A {} {} 0 {} {} {} {}"'
' />\n'.format(begin[0], begin[1], radius_scaled, radius_scaled, large_arc, sweep,
end[0], end[1])]
@ -589,7 +589,7 @@ class PlateLayout:
def output_segment(self, f_lines, k):
# k = which segment?
k_next = (k + 1) % 5
k_next = (k + 1) % self.N
# center hole
a = self.tube_1_angles[k]
@ -679,8 +679,6 @@ class PlateLayout:
#text = svg_line(p3, p4, 0.1)
f_lines = f_lines + text
outer_point_1 = p4
# segment border (left)
a = self.tube_1_angles[k_next]
a = a / 360.0 * 2.0 * np.pi
@ -700,7 +698,14 @@ class PlateLayout:
text = svg_line_puzzle(p3, p4)
f_lines = f_lines + text
outer_point_2 = p4
r_pitch_minus_module = self.target_plate_radius - self.plate_module
a1 = (self.tube_1_angles[k] - 0.9) / 360.0 * 2.0 * np.pi
vunit1 = np.array([np.cos(a1), np.sin(a1)])
outer_point_1 = vunit1 * r_pitch_minus_module
a2 = (self.tube_1_angles[k_next] - 0.9) / 360.0 * 2.0 * np.pi
vunit2 = np.array([np.cos(a2), np.sin(a2)])
outer_point_2 = vunit2 * r_pitch_minus_module
# truncate gear path
for j in range(len(f_lines)):
@ -724,6 +729,23 @@ class PlateLayout:
dist_1 = [np.linalg.norm(c - outer_point_1 * svg_scale) for c in coordinates]
dist_2 = [np.linalg.norm(c - outer_point_2 * svg_scale) for c in coordinates]
min_dist_index_1 = np.argmin(dist_1)
min_dist_index_2 = np.argmin(dist_2)
if min_dist_index_2 > min_dist_index_1:
coordinates = coordinates[min_dist_index_1:min_dist_index_2+1]
else:
coordinates = coordinates[min_dist_index_1:] + coordinates[0:min_dist_index_2]
print("TODO: check this")
coordinates_data_raw_new = "".join(['{},{} '.format(c[0], c[1]) for c in coordinates])
gear_data_new = gear_data[0:index_start] + "M " + coordinates_data_raw_new + gear_data[index_end+1:]
f_lines[j] = gear_data_new
# find minimum distance and keep only points between the two distances
# problem: does not consider manual rotation of the plate
# -> rotate points outer_point_1 and outer_point_2 before computing the distance