tidied up / removed sqrt
This commit is contained in:
1 parent
3bf7c83bd5
commit
d2256630be
3 files changed
+32
-5
No files matched your search
@@ -20,4 +20,4 @@ There are various settings you can change in config.py. Most notably, you must s
|
||||
|
||||
zTravel is the height it will move to before traveling to the next stroke
|
||||
|
||||
zDraw should be the height at which the pen will make contact with the paper
|
||||
zDraw should be the heiggit at which the pen will make contact with the paper
|
||||
+15
-3
@@ -3,7 +3,7 @@ from datetime import datetime as dt
|
||||
from utils import *
|
||||
|
||||
|
||||
def get_distance(a, b, sq=True):
|
||||
def get_distance(a, b, sq=False):
|
||||
x1, y1 = a[0], a[1]
|
||||
x2, y2 = b[0], b[1]
|
||||
|
||||
@@ -15,7 +15,18 @@ def get_distance(a, b, sq=True):
|
||||
return x * x + y * y
|
||||
|
||||
|
||||
def optimise_path(shapes, sq=True):
|
||||
def get_total_distance(shapes):
|
||||
|
||||
total_distance = 0
|
||||
last = shapes.pop(0)[-1]
|
||||
|
||||
for i in shapes:
|
||||
total_distance += get_distance(i[0], last, sq=True)
|
||||
|
||||
return total_distance
|
||||
|
||||
|
||||
def optimise_path(shapes, sq=False):
|
||||
|
||||
t1 = dt.now()
|
||||
new_order = []
|
||||
@@ -48,4 +59,5 @@ def optimise_path(shapes, sq=True):
|
||||
shapes.remove(selection)
|
||||
|
||||
timer(t1, "optimizing ")
|
||||
return new_order
|
||||
return new_order
|
||||
|
||||
+16
-1
@@ -7,7 +7,7 @@ from shapes import point_generator
|
||||
from config import *
|
||||
import re
|
||||
from datetime import datetime as dt
|
||||
from optimise import optimise_path
|
||||
from optimise import optimise_path, get_total_distance
|
||||
from utils import *
|
||||
|
||||
debug = False
|
||||
@@ -116,11 +116,26 @@ def main(file_path, output):
|
||||
|
||||
shapes = get_shapes(file_path)
|
||||
|
||||
|
||||
|
||||
if optimise:
|
||||
|
||||
pre_distance = get_total_distance(shapes)
|
||||
|
||||
print("unoptimised distance: ", get_total_distance(shapes))
|
||||
|
||||
new_order = optimise_path(shapes)
|
||||
|
||||
post_distance = get_total_distance(new_order)
|
||||
|
||||
print("unoptimised distance: ", pre_distance)
|
||||
print("optimised distance ", post_distance)
|
||||
print("factor: ", post_distance / pre_distance)
|
||||
|
||||
commands = shapes_2_gcode(new_order)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
|
||||
commands = shapes_2_gcode(shapes)
|
||||
|
||||
Reference in new issue
Block a user