def intersectLine(self, pt1, pt2): q = pt1 s = pt2 - pt1 intersections = [] for seg in self.segments: r = seg[1] a = (q - seg[0]) b = r.cross(s) if _epsilonEquals(b, 0): pass else: t = a.cross(s) / b u = a.cross(r) / b if t >= 0 and t <= 1 and u >= 0 and u <= 1 and seg[0] + r*t == q + s*u: return True return False
def intersectLine(pt1, pt2, ptA, ptB): q = pt1 s = pt2 - pt1 intersections = [] r = ptB - ptA a = (q - ptA) b = r.cross(s) if _epsilonEquals(b, 0): pass else: t = a.cross(s) / b u = a.cross(r) / b if t >= 0 and t <= 1 and u >= 0 and u <= 1: point = q + u * s #self.canvas.create_oval(point[0] - 2, point[1] - 2, point[0] + 2, point[1] + 2) return True return False
def intersect(self, pt, angle, maxLen): q = pt s = Pt(maxLen, 0.0).rotate(angle) intersections = [] for seg in self.segments: r = seg[1] a = (q - seg[0]) b = r.cross(s) if _epsilonEquals(b, 0): pass else: t = a.cross(s) / b u = a.cross(r) / b if t >= 0 and t <= 1 and u >= 0 and u <= 1 and seg[0] + r*t == q + s*u: intersections.append(q + s*u) if len(intersections) == 0: return None else: return min(intersections, key=lambda p: p.dist(pt))