-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheRoad.py
executable file
·65 lines (51 loc) · 1.47 KB
/
TheRoad.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
import csv
from math import sqrt,pow
import sys
#set Variables
if(len(sys.argv)<4):
exit
inputfile = open(sys.argv[1])
N= float(sys.argv[2])
lenght=float(sys.argv[3])
#End
pointer = csv.reader(inputfile, delimiter=',')
points = []
for i in pointer:
points.append(i)
distanceList = []
#Finding Distance
for i in range(len(points)-1):
# print(points[i+1])
coor1 = points[i]
coor2 = points[i+1]
dis = sqrt(pow((float(coor2[0]) - float(coor1[0])),2)+pow((float(coor2[1]) - float(coor1[1])), 2))
distanceList.append(dis)
output=open('length.csv', 'wb')
writer = csv.writer(output)
output=open('section.csv', 'wb')
writer2 = csv.writer(output)
currentp=-lenght;
i=0;
while(i<(len(points)-1)):
currentp=lenght+currentp;
if(currentp>distanceList[i]):
currentp=currentp-distanceList[i];
i = i+1
if(i>(len(points)-2)):
break;
# finding points after lenght
x3 = float(float(points[i+1][0]) - float(points[i][0]))
y3 = float(float(points[i+1][1]) - float(points[i][1]))
u = float(sqrt(float(pow(x3, 2)) + float(pow(y3, 2))))
x31 = (float(x3/u) * currentp) + float(points[i][0])
y31 = (float(y3/u) * currentp) + float(points[i][1])
s=[str(x31),str(y31)]
writer.writerow(s)
P1x = x31 + (N/2)*y3/u
P1y = y31 - (N/2)*x3/u
P2x = x31 - (N/2)*y3/u
P2y = y31 + (N/2)*x3/u
#Section points
s=[str(P1x),str(P1y)]
writer2.writerow(s)
writer2.writerow([str(P2x),str(P2y)])