diff --git a/prototype/circles.py b/prototype/circles.py index 8159d15..9ca6600 100644 --- a/prototype/circles.py +++ b/prototype/circles.py @@ -3,6 +3,9 @@ import matplotlib.pyplot as plt import math import operator +# scale in inkscape +# 1 unit = 0.283 mm +scale = 1000.0/282.222 def svg_circle(id, name, c, r): # create circle object in svg notation @@ -16,6 +19,40 @@ def svg_circle(id, name, c, r): return text +def svg_half_circle(id, name, c, r, angle): + # draws half a circle centered at c with radius r + # angle specifies how the half circle should be rotated + # for the default angle of zero, it draws the top half of the circle + + # convert angle to radians + angle = angle/360.0 * 2.0 * np.pi + + # compute starting point + v = np.array([np.cos(angle), np.sin(angle)]) + begin = c + r * v # in millimeters + begin *= scale # in pixel units + + # compute end point + end = c - r * v # in millimeters + end *= scale # in pixel units + + radius_scaled = r * scale + + text = [' \n ' + ' \n' + ' \n' + ' \n'.format(begin[0], begin[1], radius_scaled, radius_scaled, 0, end[0], end[1])] + + return text + def svg_rectangle(id, name, c, width, heigth, angle): x = np.sqrt(c[0]**2 + c[1]**2) - width/2 @@ -194,7 +231,7 @@ class PlateLayout: # compute coordinates and various measurements for fixed radii of plate and tubes self.target_plate_radius = 160.0 self.target_center_hole_radius = 7.5 - self.target_radius_1 = 50.2 + self.target_radius_1 = 50.5 self.target_radius_2 = 20.0 teeth = 200 @@ -430,20 +467,28 @@ class PlateLayout: text = svg_circle(0, 'plate', (0,0), self.target_plate_radius) f_lines = f_lines + text + output_all = False + if output_all: + N = len(self.tube_1_coords.items()) + else: + N = 1 + # output big circles as svg - for k, c in self.tube_1_coords.items(): - text = svg_circle(k, 'big circle', c, self.target_radius_1) + for k, c in self.tube_1_coords.items()[0:N]: + #text = svg_circle(k, 'big circle', c, self.target_radius_1) + angle = self.tube_1_angles[k] + text = svg_half_circle(k, 'big circle', c, self.target_radius_1, angle) f_lines = f_lines + text pass # output small circles as svg - for k, c in self.tube_2_coords.items(): + for k, c in self.tube_2_coords.items()[0:N]: text = svg_circle(k, 'small circle', c, self.target_radius_2) f_lines = f_lines + text pass # gear markings for big cirlces and small circles - for k, c in self.tube_1_tangents.items(): + for k, c in self.tube_1_tangents.items()[0:N]: circle_midpoint = self.tube_1_coords[k] v = np.array(c[0]) - np.array(circle_midpoint) v = v/np.linalg.norm(v) @@ -457,7 +502,7 @@ class PlateLayout: f_lines = f_lines + text pass - for k, c in self.tube_2_tangents.items(): + for k, c in self.tube_2_tangents.items()[0:N]: circle_midpoint = self.tube_2_coords[k] v = np.array(c[0]) - np.array(circle_midpoint) v = v/np.linalg.norm(v) @@ -472,19 +517,19 @@ class PlateLayout: pass # output cuts for big circles - for k, c in self.tube_1_cuts.items(): + for k, c in self.tube_1_cuts.items()[0:N]: text = svg_rectangle(k, 'cut', c['center'], c['length'], c['width'], c['angle_deg']) f_lines = f_lines + text pass # output cuts for small circles - for k, c in self.tube_2_cuts.items(): + for k, c in self.tube_2_cuts.items()[0:N]: text = svg_rectangle(k, 'cut', c['center'], c['length'], c['width'], c['angle_deg']) f_lines = f_lines + text pass # lines for manufacturing out of multiple pieces - for k, a in self.tube_1_angles.items(): + for k, a in self.tube_1_angles.items()[0:N]: a = a/360.0 * 2.0 * np.pi r1 = np.linalg.norm(np.array(self.tube_1_coords[k])) - self.target_radius_1 vunit = np.array([np.cos(a), np.sin(a)])