Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ole AKA Ole Lennart Kek AKA Olon
- # Luca AKA Lucie Laura Bau
- # Mats AKA Hosen Oskar Madds
- # libarys
- import urllib.request
- print("lelek ein easteregg")
- class Main(object):
- def __init__(self):
- # Import Data for the Triangles
- input = urllib.request.urlopen("https://www.bwinf.de/fileadmin/user_upload/dreiecke1.txt").read() \
- .decode('UTF-8').splitlines()
- # Save Line Quantity
- lineQuantity = input.pop(0)
- self.lines = []
- self.triangles = []
- i = 0
- for line in input:
- i = i + 1
- self.lines += [Line(line.split(" "), index=i)]
- def calculateIntersection(self, l1, l2):
- print("Trying", l1.get_index(), l2.get_index())
- intersectionPoint = None
- px1 = l1.positionVector[0]
- py1 = l1.positionVector[1]
- dx1 = l1.directionVector[0]
- dy1 = l1.directionVector[1]
- px2 = l2.positionVector[0]
- py2 = l2.positionVector[1]
- dx2 = l2.directionVector[0]
- dy2 = l2.directionVector[1]
- if (l1.positionVector1 == l2.positionVector or l1.positionVector1 == l2.positionVector1):
- intersectionPoint = l1.positionVector1
- return intersectionPoint
- elif (l1.positionVector == l2.positionVector or l1.positionVector == l2.positionVector1):
- intersectionPoint = l1.positionVector
- return intersectionPoint
- elif (dx1 != 0 and dy1 != 0):
- t = ((dx1 * (py2 - py1)) - (dy1 * (px2 - px1))) / ((dy1 * dx2) - (dx1 * dy2))
- xPoint = px2 + (t * dx2)
- yPoint = py2 + (t * dy2)
- print('used t for getting intersection ')
- elif (dx2 != 0 and dy2 != 0):
- s = ((dx2 * (py1 - py2)) - (dy2 * (px1 - px2))) / ((dy2 * dx1) - (dx2 * dy1))
- xPoint = px1 + (s * dx1)
- yPoint = py1 + (s * dy1)
- print("used s for getting intersection")
- else:
- # print('HOUSTON, WE GOT A PROBLEM, LEEEEEEEEEEEEEEEEEEEL!')
- # print(l1.geometries, l2.geometries)
- return intersectionPoint
- if (min([l1.geometries[0], l1.geometries[2]]) <= xPoint <= max([l1.geometries[0], l1.geometries[2]])
- and min([l2.geometries[0], l2.geometries[2]]) <= xPoint <= max(
- [l2.geometries[0], l2.geometries[2]])):
- # print("yeaaaaaaaaaaaaaaaaaaaaaaaah!")
- # print(l1.geometries, l2.geometries)
- intersectionPoint = [xPoint, yPoint]
- else:
- print("leeeeeeeeeeeeeeeeelekolekek!")
- print(l1.geometries, l2.geometries)
- print(xPoint)
- pass
- # print(intersectionPoint)
- return intersectionPoint
- def checkForTriangles(self):
- self.getIntersections()
- counter = 0
- doublecounter = 0
- for i in self.lines:
- for primaryIntersection in i.intersections:
- for secondaryIntersection in primaryIntersection.line.intersections:
- for tertiaryIntersection in secondaryIntersection.line.intersections:
- if (tertiaryIntersection.line == i):
- # triangle = [primaryIntersection.index,secondaryIntersection.index, tertiaryIntersection.index]
- triangle = Triangle([primaryIntersection.index, secondaryIntersection.index,
- tertiaryIntersection.index].sort(),
- [primaryIntersection.position, secondaryIntersection.position,
- i.intersections.position])
- # print("unsorted triangle array:", triangle)
- # print("sorted triangle array:",triangle)
- for x in self.triangles:
- if triangle.index != x.index:
- print("jo")
- else:
- print("kek")
- # if triangle.index not in self.triangles.index:
- # self.triangles += triangle
- # counter += 1
- # else:
- # print("Gabs schon du keker fatzke")
- # doublecounter = doublecounter + 1
- # print("Nächster bitte, du kleiner remmud keleL! Heil Christian Lindner ~Ole, da wo der kek wohnt. LOOOOOOOOOOOOOOL!")
- print(counter)
- print(doublecounter)
- print(self.triangles)
- def getIntersections(self):
- clonedLines = list(self.lines)
- for l1 in self.lines:
- for l2 in clonedLines:
- if l1 != l2:
- x = self.calculateIntersection(l1, l2)
- if x != None:
- l1.intersections += [Intersection(l2, x)]
- l2.intersections += [Intersection(l1, x)]
- print([[[l1.geometries, l2.geometries], x]])
- clonedLines.remove(l1)
- # print(self.intersections)
- class Line(object):
- def __init__(self, g, index=-1):
- self.geometries = [float(g[0]), float(g[1]), float(g[2]), float(g[3])]
- # self.intersections = []
- self.index = index
- self.directionVector = [(self.geometries[0] - self.geometries[2]), (self.geometries[1] - self.geometries[3])]
- self.positionVector = [self.geometries[0], self.geometries[1]]
- self.positionVector1 = [self.geometries[2], self.geometries[3]]
- self.intersections = []
- def get_index(self):
- return self.index
- class Intersection(object):
- def __init__(self, line, position):
- self.line = line
- self.position = position
- class Triangle(object):
- def __init__(self, index, positions):
- self.index = index # Plural
- self.positions = positions
- m = Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement