Example #1
0
    def _intersectLineArc(self, arc):
        #AB = self.B
        #a  = AB.length2()
        a = self.AB[0]**2 + self.AB[1]**2
        if a < EPS2: return None, None

        #CA = self.start-arc.center
        #b  = 2.0*AB*CA
        #c  = CA.length2() - arc.radius**2
        CAx = self.start[0] - arc.center[0]
        CAy = self.start[1] - arc.center[1]
        b = 2.0 * (self.AB[0] * CAx + self.AB[1] * CAy)

        #c  = CAx**2 + CAy**2 - arc.radius**2
        if abs(CAx) < abs(CAy):
            c = CAy**2 + (CAx + arc.radius) * (CAx - arc.radius)
        else:
            c = CAx**2 + (CAy + arc.radius) * (CAy - arc.radius)

        t1, t2 = quadratic(b / a, c / a)
        if t1 is None: return None, None
        if t1 < -EPS or t1 > 1.0 + EPS:
            P1 = None
        elif t1 <= EPS:
            P1 = Vector(self.start)
        elif t1 >= 1.0 - EPS:
            P1 = Vector(self.end)
        else:
            #P1 = AB*t1 + self.start
            P1 = Vector(self.AB[0] * t1 + self.start[0],
                        self.AB[1] * t1 + self.start[1])
        if P1 and not arc._insideArc(P1): P1 = None

        if t2 < -EPS or t2 > 1.0 + EPS:
            P2 = None
        elif t2 <= EPS:
            P2 = Vector(self.start)
        elif t2 >= 1.0 - EPS:
            P2 = Vector(self.end)
        else:
            #P2 = AB*t2 + self.start
            P2 = Vector(self.AB[0] * t2 + self.start[0],
                        self.AB[1] * t2 + self.start[1])
        if P2 and not arc._insideArc(P2): P2 = None

        # force P1 to have always the solution if any
        if P1 is None: return P2, None
        return P1, P2
Example #2
0
    def _intersectLineArc(self, arc):
        # AB = self.B
        # a  = AB.length2()
        a = self.AB[0] ** 2 + self.AB[1] ** 2
        if a < EPS2:
            return None, None

        # CA = self.start-arc.center
        # b  = 2.0*AB*CA
        # c  = CA.length2() - arc.radius**2
        CAx = self.start[0] - arc.center[0]
        CAy = self.start[1] - arc.center[1]
        b = 2.0 * (self.AB[0] * CAx + self.AB[1] * CAy)

        # c  = CAx**2 + CAy**2 - arc.radius**2
        if abs(CAx) < abs(CAy):
            c = CAy ** 2 + (CAx + arc.radius) * (CAx - arc.radius)
        else:
            c = CAx ** 2 + (CAy + arc.radius) * (CAy - arc.radius)

        t1, t2 = quadratic(b / a, c / a)
        if t1 is None:
            return None, None
        if t1 < -EPS or t1 > 1.0 + EPS:
            P1 = None
        elif t1 <= EPS:
            P1 = Vector(self.start)
        elif t1 >= 1.0 - EPS:
            P1 = Vector(self.end)
        else:
            # P1 = AB*t1 + self.start
            P1 = Vector(self.AB[0] * t1 + self.start[0], self.AB[1] * t1 + self.start[1])
        if P1 and not arc._insideArc(P1):
            P1 = None

        if t2 < -EPS or t2 > 1.0 + EPS:
            P2 = None
        elif t2 <= EPS:
            P2 = Vector(self.start)
        elif t2 >= 1.0 - EPS:
            P2 = Vector(self.end)
        else:
            # P2 = AB*t2 + self.start
            P2 = Vector(self.AB[0] * t2 + self.start[0], self.AB[1] * t2 + self.start[1])
        if P2 and not arc._insideArc(P2):
            P2 = None
        return P1, P2
Example #3
0
    def _intersectLineArc(self, arc):
        #AB = self.B
        #a  = AB.length2()
        a = self.AB[0]**2 + self.AB[1]**2
        if a < EPS2: return None, None

        #CA = self.start-arc.center
        #b  = 2.0*AB*CA
        #c  = CA.length2() - arc.radius**2
        CAx = self.start[0] - arc.center[0]
        CAy = self.start[1] - arc.center[1]
        b = 2.0 * (self.AB[0] * CAx + self.AB[1] * CAy)
        c = CAx**2 + CAy**2 - arc.radius**2

        t1, t2 = quadratic(b / a, c / a)
        if t1 is None: return None, None
        if t1 < -EPS or t1 > 1.0 + EPS:
            P1 = None
        elif t1 <= EPS:
            P1 = self.start
        elif t1 >= 1.0 - EPS:
            P1 = self.end
        else:
            #P1 = AB*t1 + self.start
            P1 = Vector(self.AB[0] * t1 + self.start[0],
                        self.AB[1] * t1 + self.start[1])
        if P1 and not arc._insideArc(P1): P1 = None

        if t2 < -EPS or t2 > 1.0 + EPS:
            P2 = None
        elif t2 <= EPS:
            P2 = self.start
        elif t2 >= 1.0 - EPS:
            P2 = self.end
        else:
            #P2 = AB*t2 + self.start
            P2 = Vector(self.AB[0] * t2 + self.start[0],
                        self.AB[1] * t2 + self.start[1])
        if P2 and not arc._insideArc(P2): P2 = None
        return P1, P2