Exemplo n.º 1
0
    def _generate_spiral(self, is_dragging=False):
        """
        Generate a spiral curve
        """

        _key = ''

        _start = Vector(self.pi_nodes[0].point)
        _pi = Vector(self.pi_nodes[1].point)
        _end = Vector(self.pi_nodes[2].point)

        if not self.curve.get('StartRadius') \
            or self.curve['StartRadius'] == math.inf:

            _key = 'EndRadius'
            _end = self.curve['End']

            #first curve uses the start point.
            #otherwise, calculate a point halfway in between.
            if _start.is_end_node:

                _start = _pi.sub(
                    Vector(_pi.sub(_start)).multiply(
                        _start.distanceToPoint(_pi) / 2.0
                    )
                )

        else:

            _key = 'StartRadius'
            _start = self.curve['Start']

            #last curve uses the end point.
            #otherwise, calculate a point halfway between.
            if _start.is_end_node:

                _end = _pi.add(
                    Vector(_end.sub(_pi)).multiply(
                        _end.distanceToPoint(_pi) / 2.0)
                )

        _curve = {
            'PI': _pi,
            'Start': _start,
            'End': _end,
            _key: self.curve[_key]
        }

        _curve = spiral.solve_unk_length(_curve)

        #re-render the last known good points if an error occurs
        if _curve['TanShort'] <= 0.0 or _curve['TanLong'] <= 0.0:
            _curve = self.curve

        self.curve = _curve

        return spiral.get_points(self.curve)
Exemplo n.º 2
0
def extend_two_points(
    p1: FreeCAD.Vector,
    p2: FreeCAD.Vector,
    length: float = 4000,
) -> tuple:
    xs = p1.x
    xe = p2.x
    ys = p1.y
    ye = p2.y
    delta_x = xe - xs
    d = p1.distanceToPoint(p2)
    if delta_x == 0:
        dx = 0
        dy = length
        new_start_point = p1.add(FreeCAD.Vector(dx, -dy, 0))
        new_d = new_start_point.distanceToPoint(p2)
        if new_d > d:
            new_end_point = p2.add(FreeCAD.Vector(dx, dy, 0))
        else:
            new_start_point = p1.add(FreeCAD.Vector(dx, dy, 0))
            new_end_point = p2.add(FreeCAD.Vector(dx, -dy, 0))
    else:
        equation = get_line_equation(p1, p2)
        m = (ye - ys) / (xe - xs)
        dx = length / math.sqrt(1 + m**2)
        x = p2.x + dx
        y = eval(equation)
        dist = math.sqrt((x - p1.x)**2 + (y - p1.y)**2)
        if dist > d:
            new_end_point = FreeCAD.Vector(x, y, p2.z)
            x = p1.x - dx
            y = eval(equation)
            new_start_point = FreeCAD.Vector(x, y, p1.z)
        else:
            x = p2.x - dx
            y = eval(equation)
            new_end_point = FreeCAD.Vector(x, y, p2.z)
            x = p1.x + dx
            y = eval(equation)
            new_start_point = FreeCAD.Vector(x, y, p1.z)
    return new_start_point, new_end_point