def collision2Train(train1, train2): train1back = train1.getBack() train2back = train2.getBack() return helper.intersect(train1.x, train1.y, train1back[0], train1back[1], train2.x, train2.y, train2back[0], train2back[1])
def calc_isect_nieve(): intersections = [] seen = [] vs = False hs = False es = False for seg1 in S: if helper.approx_equal(seg1[0][0], seg1[1][0], EPSILON): print('VERTICAL SEG') print('') print('') vs = True if helper.approx_equal(seg1[0][1], seg1[1][1], EPSILON): print('HORIZONTAL SEG') print('') print('') hs = True for seg2 in S: if seg1 is not seg2 and helper.segs_equal(seg1, seg2): print('EQUAL SEGS') print('') print('') es = True if seg1 is not seg2 and (seg2, seg1) not in seen: i = helper.intersect(seg1, seg2) if i: intersections.append((i, [seg1, seg2])) # xpts = [seg1[0][0], seg1[1][0], seg2[0][0], seg2[1][0]] # xpts = sorted(xpts) # if (i[0] <= xpts[2] and i[0] >= xpts[1]: # intersections.append((i, [seg1, seg2])) seen.append((seg1, seg2)) return intersections
def cast(self, wall: Boundary): """ Checks if the ray intersects with a wall, and returns the results :param wall: A boundary to check the intersection with :type wall: Boundary :return: The point where the ray hits the wall, or an empty list if it doesn't :rtype: List[float] """ return hl.intersect( wall.a, wall.b, self.pos, Vector(self.pos.x + self.ang.x, self.pos.y + self.ang.y))
def extend_if_possible(self, facet): # print("Extending...") # Check if any part of the new facet leaves the box for x, y in facet.points: if x < 0 or x > 1 or y < 0 or y > 1: return None # Remove any edges that lie on the boundary new = PartialSolution(self.problem) new.closed_edges = list(self.closed_edges) new.open_edges = list(self.open_edges) new.facets = list(self.facets) fe = facet.make_edges() for e in list(fe): m = e.midpoint if m[0] == 0 or m[0] == 1 or m[1] == 0 or m[1] == 1: fe.remove(e) new.closed_edges.append(e) # Check if any edge of the new facet has an interior inside the existing solution for e in fe: if self.in_interior(e.midpoint): return None # Check if any edge of the new facet intersects badly the existing solution for e in fe: for e2 in self.open_edges: if helper.intersect(e.a, e.b, e2.a, e2.b): return None # For each intersection check if the transforms are consistent, and remove any # finished edges for e in list(fe): for e2 in self.open_edges: if e.a == e2.a: if e.ta != e2.ta: return None if e.a == e2.b: if e.ta != e2.tb: return None if e.b == e2.a: if e.tb != e2.ta: return None if e.b == e2.b: if e.tb != e2.tb: return None if (e.a == e2.a and e.b == e2.b) or (e.a == e2.b and e.b == e2.a): new.open_edges.remove(e2) fe.remove(e) # Add edges to existing lists new.open_edges.extend(fe) new.facets.append(facet) new.targetted_facets = set(self.targetted_facets) new.targetted_facets.add(facet.target) new.area = self.area + facet.area if new.area > 1: # This really shouldn't be necessary :( print ("G") return None # Are we done? if new.is_done(): # Check that there are not any unmatched edges if len(new.open_edges) > 0: # print("Extra edges") return None # we also need to check if there are any target facets we never used for tf in self.problem.skeleton.facets: if tf not in new.targetted_facets: # print(len(new.targetted_facets)) # print(len(self.problem.skeleton.facets)) # print("Missing facets") return None # print(" Successful") return new
def find_new_event(s1, s2, p, q): i = helper.intersect(s1, s2) if i: if helper.compare_by_y(i, p) == 1: if not q.find(i): q.insert(i, [])