Advertisement
Guest User

matsolelucastuff

a guest
Nov 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. # Ole AKA Ole Lennart Kek AKA Olon
  2. # Luca AKA Lucie Laura Bau
  3. # Mats AKA Hosen Oskar Madds
  4.  
  5. # libarys
  6. import urllib.request
  7.  
  8. print("lelek ein easteregg")
  9.  
  10.  
  11. class Main(object):
  12. def __init__(self):
  13. # Import Data for the Triangles
  14. input = urllib.request.urlopen("https://www.bwinf.de/fileadmin/user_upload/dreiecke1.txt").read() \
  15. .decode('UTF-8').splitlines()
  16.  
  17. # Save Line Quantity
  18. lineQuantity = input.pop(0)
  19.  
  20. self.lines = []
  21. self.triangles = []
  22. i = 0
  23. for line in input:
  24. i = i + 1
  25. self.lines += [Line(line.split(" "), index=i)]
  26.  
  27. def calculateIntersection(self, l1, l2):
  28.  
  29. print("Trying", l1.get_index(), l2.get_index())
  30. intersectionPoint = None
  31. px1 = l1.positionVector[0]
  32. py1 = l1.positionVector[1]
  33. dx1 = l1.directionVector[0]
  34. dy1 = l1.directionVector[1]
  35. px2 = l2.positionVector[0]
  36. py2 = l2.positionVector[1]
  37. dx2 = l2.directionVector[0]
  38. dy2 = l2.directionVector[1]
  39. if (l1.positionVector1 == l2.positionVector or l1.positionVector1 == l2.positionVector1):
  40. intersectionPoint = l1.positionVector1
  41. return intersectionPoint
  42. elif (l1.positionVector == l2.positionVector or l1.positionVector == l2.positionVector1):
  43. intersectionPoint = l1.positionVector
  44. return intersectionPoint
  45. elif (dx1 != 0 and dy1 != 0):
  46. t = ((dx1 * (py2 - py1)) - (dy1 * (px2 - px1))) / ((dy1 * dx2) - (dx1 * dy2))
  47. xPoint = px2 + (t * dx2)
  48. yPoint = py2 + (t * dy2)
  49. print('used t for getting intersection ')
  50. elif (dx2 != 0 and dy2 != 0):
  51. s = ((dx2 * (py1 - py2)) - (dy2 * (px1 - px2))) / ((dy2 * dx1) - (dx2 * dy1))
  52. xPoint = px1 + (s * dx1)
  53. yPoint = py1 + (s * dy1)
  54. print("used s for getting intersection")
  55. else:
  56. # print('HOUSTON, WE GOT A PROBLEM, LEEEEEEEEEEEEEEEEEEEL!')
  57. # print(l1.geometries, l2.geometries)
  58. return intersectionPoint
  59. if (min([l1.geometries[0], l1.geometries[2]]) <= xPoint <= max([l1.geometries[0], l1.geometries[2]])
  60. and min([l2.geometries[0], l2.geometries[2]]) <= xPoint <= max(
  61. [l2.geometries[0], l2.geometries[2]])):
  62. # print("yeaaaaaaaaaaaaaaaaaaaaaaaah!")
  63. # print(l1.geometries, l2.geometries)
  64. intersectionPoint = [xPoint, yPoint]
  65. else:
  66. print("leeeeeeeeeeeeeeeeelekolekek!")
  67. print(l1.geometries, l2.geometries)
  68. print(xPoint)
  69. pass
  70. # print(intersectionPoint)
  71.  
  72. return intersectionPoint
  73.  
  74. def checkForTriangles(self):
  75. self.getIntersections()
  76. counter = 0
  77. doublecounter = 0
  78. for i in self.lines:
  79. for primaryIntersection in i.intersections:
  80. for secondaryIntersection in primaryIntersection.line.intersections:
  81. for tertiaryIntersection in secondaryIntersection.line.intersections:
  82. if (tertiaryIntersection.line == i):
  83. # triangle = [primaryIntersection.index,secondaryIntersection.index, tertiaryIntersection.index]
  84. triangle = Triangle([primaryIntersection.index, secondaryIntersection.index,
  85. tertiaryIntersection.index].sort(),
  86. [primaryIntersection.position, secondaryIntersection.position,
  87. i.intersections.position])
  88. # print("unsorted triangle array:", triangle)
  89. # print("sorted triangle array:",triangle)
  90. for x in self.triangles:
  91. if triangle.index != x.index:
  92. print("jo")
  93. else:
  94. print("kek")
  95. # if triangle.index not in self.triangles.index:
  96. # self.triangles += triangle
  97. # counter += 1
  98. # else:
  99. # print("Gabs schon du keker fatzke")
  100. # doublecounter = doublecounter + 1
  101. # print("Nächster bitte, du kleiner remmud keleL! Heil Christian Lindner ~Ole, da wo der kek wohnt. LOOOOOOOOOOOOOOL!")
  102. print(counter)
  103. print(doublecounter)
  104. print(self.triangles)
  105.  
  106. def getIntersections(self):
  107. clonedLines = list(self.lines)
  108. for l1 in self.lines:
  109. for l2 in clonedLines:
  110. if l1 != l2:
  111. x = self.calculateIntersection(l1, l2)
  112. if x != None:
  113. l1.intersections += [Intersection(l2, x)]
  114. l2.intersections += [Intersection(l1, x)]
  115. print([[[l1.geometries, l2.geometries], x]])
  116. clonedLines.remove(l1)
  117. # print(self.intersections)
  118.  
  119.  
  120. class Line(object):
  121. def __init__(self, g, index=-1):
  122. self.geometries = [float(g[0]), float(g[1]), float(g[2]), float(g[3])]
  123. # self.intersections = []
  124. self.index = index
  125. self.directionVector = [(self.geometries[0] - self.geometries[2]), (self.geometries[1] - self.geometries[3])]
  126. self.positionVector = [self.geometries[0], self.geometries[1]]
  127. self.positionVector1 = [self.geometries[2], self.geometries[3]]
  128. self.intersections = []
  129.  
  130. def get_index(self):
  131. return self.index
  132.  
  133.  
  134. class Intersection(object):
  135. def __init__(self, line, position):
  136. self.line = line
  137. self.position = position
  138.  
  139.  
  140. class Triangle(object):
  141. def __init__(self, index, positions):
  142. self.index = index # Plural
  143. self.positions = positions
  144.  
  145.  
  146. m = Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement