Example #1
0
    def __init__(self, box1, box2, boxdists=[0,0]):

        self.box1 = box1
        self.box2 = box2

        connector_pt.__init__(self,
            [path.normsubpath([path.normline_pt(self.box1.center[0], self.box1.center[1],
                                                self.box2.center[0], self.box2.center[1])], closed=0)])

        self.omitends(box1, box2)
        self.shortenpath(boxdists)
Example #2
0
    def __init__(self, box1, box2, relangle=45,
                 absbulge=None, relbulge=None, boxdists=[0,0]):

        # the deviation of arc from the straight line can be specified:
        # 1. By an angle between a straight line and the arc
        #    This angle is measured at the centers of the box.
        # 2. By the largest normal distance between line and arc: absbulge
        #    or, equivalently, by the bulge relative to the length of the
        #    straight line from center to center.
        # Only one can be used.

        self.box1 = box1
        self.box2 = box2

        tangent = (self.box2.center[0] - self.box1.center[0],
                   self.box2.center[1] - self.box1.center[1])
        distance = hypot(*tangent)
        tangent = tangent[0] / distance, tangent[1] / distance

        if relbulge is not None or absbulge is not None:
            # usage of bulge overrides the relangle parameter
            bulge = 0
            if absbulge is not None:
                bulge += absbulge
            if relbulge is not None:
                bulge += relbulge*distance
        else:
            # otherwise use relangle, which should be present
            bulge = 0.5 * distance * math.tan(0.5*radians(relangle))

        if abs(bulge) < normpath._epsilon:
            # fallback solution for too straight arcs
            connector_pt.__init__(self,
                [path.normsubpath([path.normline_pt(*(self.box1.center+self.box2.center))], closed=0)])
        else:
            radius = abs(0.5 * (bulge + 0.25 * distance**2 / bulge))
            centerdist = mathutils.sign(bulge) * (radius - abs(bulge))
            center = (0.5 * (self.box1.center[0] + self.box2.center[0]) + tangent[1]*centerdist,
                      0.5 * (self.box1.center[1] + self.box2.center[1]) - tangent[0]*centerdist)
            angle1 = atan2(self.box1.center[1] - center[1], self.box1.center[0] - center[0])
            angle2 = atan2(self.box2.center[1] - center[1], self.box2.center[0] - center[0])

            if bulge > 0:
                connectorpath = path.path(path.moveto_pt(*self.box1.center),
                                          path.arcn_pt(center[0], center[1], radius, degrees(angle1), degrees(angle2)))
                connector_pt.__init__(self, connectorpath.normpath().normsubpaths)
            else:
                connectorpath = path.path(path.moveto_pt(*self.box1.center),
                                          path.arc_pt(center[0], center[1], radius, degrees(angle1), degrees(angle2)))
                connector_pt.__init__(self, connectorpath.normpath().normsubpaths)

        self.omitends(box1, box2)
        self.shortenpath(boxdists)
Example #3
0
    def __init__(self, box1, box2,
                 relangle1=45, relangle2=45,
                 absangle1=None, absangle2=None,
                 absbulge=0, relbulge=0.39, boxdists=[0,0]):

        # The deviation of the curve from a straight line can be specified:
        # A. By an angle at each center
        #    These angles are either absolute angles with origin at the positive x-axis
        #    or the relative angle with origin at the straight connection line
        # B. By the (expected) largest normal distance between line and arc: absbulge
        #    and/or by the (expected) bulge relative to the length of the
        #    straight line from center to center.
        # Here, we need both informations.
        #
        # a curve with relbulge=0.39 and relangle1,2=45 leads
        # approximately to the arc with angle=45

        self.box1 = box1
        self.box2 = box2

        rel = (self.box2.center[0] - self.box1.center[0],
               self.box2.center[1] - self.box1.center[1])
        distance = hypot(*rel)
        # absolute angle of the straight connection
        dangle = atan2(rel[1], rel[0])

        # calculate the armlength and absolute angles for the control points:
        # absolute and relative bulges are added
        bulge = abs(distance*relbulge + absbulge)

        if absangle1 is not None:
            angle1 = radians(absangle1)
        else:
            angle1 = dangle + radians(relangle1)
        if absangle2 is not None:
            angle2 = radians(absangle2)
        else:
            angle2 = dangle + radians(relangle2)

        # get the control points
        control1 = (cos(angle1), sin(angle1))
        control2 = (cos(angle2), sin(angle2))
        control1 = (self.box1.center[0] + control1[0] * bulge, self.box1.center[1] + control1[1] * bulge)
        control2 = (self.box2.center[0] - control2[0] * bulge, self.box2.center[1] - control2[1] * bulge)

        connector_pt.__init__(self,
               [path.normsubpath([path.normcurve_pt(*(self.box1.center +
                                                   control1 +
                                                   control2 + self.box2.center))], 0)])

        self.omitends(box1, box2)
        self.shortenpath(boxdists)