Created
August 18, 2015 04:17
-
-
Save hyperair/07290f032ea2b3243d66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import sys | |
| import math | |
| import re | |
| import collections | |
| import os | |
| filament_diameter = 1.75; | |
| layer_height = float(os.getenv('layer_height', 0.2)) | |
| point = collections.namedtuple('point', ['x', 'y', 'e']) | |
| area = math.pi * (filament_diameter ** 2) / 4 | |
| def parse_coord(line): | |
| coord_regex = r'([^ ]+)' | |
| x = float(re.search('X' + coord_regex, line).group(1)) | |
| y = float(re.search('Y' + coord_regex, line).group(1)) | |
| e = float(re.search('E' + coord_regex, line).group(1)) | |
| return point(x, y, e) | |
| def distance(p1, p2): | |
| return math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2) | |
| def extrusion_width(p1, p2): | |
| dist = distance(p1, p2) | |
| volume = area * abs(p1.e - p2.e) | |
| diameter = layer_height | |
| circle_area = (diameter ** 2) * math.pi / 4 | |
| extrusion_crosssection_area = volume / dist | |
| rectangular_width = ((extrusion_crosssection_area - circle_area) / | |
| layer_height) | |
| return diameter + rectangular_width | |
| line1 = sys.stdin.readline().strip() | |
| line2 = sys.stdin.readline().strip() | |
| point1 = parse_coord(line1) | |
| point2 = parse_coord(line2) | |
| print extrusion_width(point1, point2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment