-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesktopAppVersion.py
87 lines (63 loc) · 2.18 KB
/
DesktopAppVersion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import csv
from pathlib import Path
import math
values = []
coords = []
fileInput = input('Enter a file: ') # This will be your csv file of coords
filepath = Path(fileInput) # This will be the filepath to your coords
distanceConstant = float(input('Enter a distance constant: '))
with open(f'{filepath}', encoding='utf-8-sig') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
values.append(row)
for i in range(0, len(values)):
val = values[i]
val = list(map(float, val))
coords.append(val)
def distance(a, b):
return math.sqrt(((b[1] - a[1]) ** 2) + (b[0] - a[0]) ** 2)
def NSect(n, array):
xCoords = []
yCoords = []
i = (array[1][0] - array[0][0]) / n
j = (array[1][1] - array[0][1]) / n
for a in range(1, n):
xCoords.append(array[0][0] + i * a)
yCoords.append(array[0][1] + j * a)
return list(map(list, zip(xCoords, yCoords)))
def twoCoordGetter(array):
twoCoords = []
for i in range(0, len(array) - 1):
twoCoords.append([array[i], array[i + 1]])
return twoCoords
def PrintCoords1(array, n):
vals = []
for i in range(0, len(array) - 1):
for element in NSect(n, twoCoordGetter(coords)[i]):
vals.append(element)
return vals
def PrintCoords2(array, n):
vals = []
for i in range(0, len(array) - 1):
for element in NSect(n, twoCoordGetter(array)[i]):
vals.append(element)
vals.insert(0, array[0])
vals.insert(len(vals), array[len(array) - 1])
return vals
def NGenerator(d):
n = 2
while distance(PrintCoords1(coords, n)[(int(len(PrintCoords1(coords, n)) / 2) - 1)],
PrintCoords1(coords, n)[int(len(PrintCoords1(coords, n)) / 2)]) >= d:
n = n + 1
return n
def CoordsFinal():
n = NGenerator(distanceConstant)
a = PrintCoords2(coords, n)
b = PrintCoords2(a, n)
return PrintCoords2(b, n)
def FileWriter(array):
print("Outputted data to Output.csv")
f = open("Output.csv", "w")
return f.write(str(array).replace('], [', '\n').replace(', ', ',')[2:-2])
FileWriter(CoordsFinal())
# You can run the funtion on itself as many times as you want in def CoordsFinal()