Guest User

Untitled

a guest
Jul 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. 300.754178236262248 103.453277023380423 0,276.62980277988612 90.123295023340319 0,269.345711570634421 103.319531391674346 0,293.447811515317824 116.649513392506364 0,300.754178236262248 103.453277023380423 0
  2.  
  3. import math
  4.  
  5. def calc(x1, y1, x2, y2):
  6. dist = math.sqrt((x2-x1)**2 + (y2-y1)**2)
  7. return dist
  8.  
  9. li = []
  10. res = []
  11. with open("/Users/jin/points.txt") as filestream:
  12. for line in filestream:
  13. temp = line.split(",") #splits by the comma in a single list
  14.  
  15. for i in temp:
  16. temp = i.split(" ") #splits by spaces to individual lists of points
  17. li.append(temp) #list of lists containing each point
  18. # for item in li:
  19. # x1 = item[1]
  20. # y1 = item[0]
  21.  
  22. # for item in li:
  23. # for pt in item:
  24. # print pt
  25.  
  26. for index in range(len(li)-1):
  27. one = li[index]
  28. two = li[index+1]
  29. x1 = float(one[0])
  30. y1 = float(one[1])
  31. x2 = float(two[0])
  32. y2 = float(two[1])
  33. res.append(calc(x1, y1, x2, y2))
  34. print res
Add Comment
Please, Sign In to add comment