Beispiel #1
0
    def offset_path(self, step_over):
        # TODO Sort Edges to ensure they're in order.

        if step_over == 0:
            return self

        segs = self.get_segments()
        segmentgroup = SegmentGroup()

        for i in range(len(segs)):
            seg = segs[i]
            if seg.bulge != 0:

                if seg.bulge > 0:
                    # get normal from end point to centre
                    start_normal = seg.start.normalise_to(
                        seg.get_centre_point())
                    end_normal = seg.end.normalise_to(seg.get_centre_point())
                    # get point in the direction of the normal with magnitude of step_over
                    pt1 = start_normal.multiply(step_over)
                    pt2 = end_normal.multiply(step_over)
                    # get the new start and end points
                    new_start = seg.start.add(pt1)
                    new_end = seg.end.add(pt2)
                    rad = seg.get_radius() - step_over
                else:
                    # get normal from the centre to the end points
                    start_normal = seg.get_centre_point().normalise_to(
                        seg.start)
                    end_normal = seg.get_centre_point().normalise_to(seg.end)
                    # get point in the direction of the normal with magnitude of step_over
                    pt1 = start_normal.multiply(step_over)
                    pt2 = end_normal.multiply(step_over)
                    # get the new start and end points
                    new_start = pt1.add(seg.start)
                    new_end = pt2.add(seg.end)
                    rad = seg.get_radius() + step_over

                segment = Segment(new_start, new_end)
                segment.derive_bulge(seg, rad)

            if seg.bulge == 0:
                normal = seg.start.normalise_to(seg.end).rotate(-90)
                pt = normal.multiply(step_over)
                segment = Segment(pt.add(seg.start), pt.add(seg.end))

            segmentgroup.add_segment(segment)

        segmentgroup.join_segments()
        return segmentgroup
Beispiel #2
0
    def join_segments(self):
        """join segments of the segmentgroup"""

        segments = self.get_segments()
        segmentgroupOut = SegmentGroup()

        for i in range(len(segments)):

            pt1 = segments[i].start
            pt2 = segments[i].end

            if i != 0:
                seg1 = segments[i - 1]
                intersect, pt = seg1.intersect(segments[i], extend=True)
                if intersect:
                    if type(pt) is list:
                        pt = pt1.nearest(pt)
                    pt1 = pt

            if i != len(segments) - 1:
                seg2 = segments[i + 1]
                intersect2, pt = seg2.intersect(segments[i], extend=True)
                if intersect2:
                    if type(pt) is list:
                        pt = pt2.nearest(pt)
                    pt2 = pt

            if pt1 and pt2:
                if segments[i].bulge != 0:
                    rad = segments[i].get_centre_point().distance_to(pt1)
                    nseg = Segment(pt1, pt2)
                    nseg.derive_bulge(segments[i], rad)
                    segmentgroupOut.add_segment(nseg)
                else:
                    segmentgroupOut.add_segment(Segment(pt1, pt2))
            else:
                # No Intersections found. Return the segment in its current state
                segmentgroupOut.add_segment(segments[i])

        self.segments = segmentgroupOut.get_segments()
        self.clean_offset_path()
Beispiel #3
0
    def remove_the_groove(self, stock_z_min, tool, allow_grooving=False):
        segments = self.get_segments()
        segs_out = SegmentGroup()
        index = 0

        while index < len(segments):
            seg = segments[index]
            next_index = False
            pt1 = seg.start
            pt2 = seg.end
            pt = None

            # TO DO: Tidy this mess

            if seg.bulge > 0:
                segAng = round(math.degrees(seg.get_angle()), 5)
                # get angle tangent to the start point
                startPtAng = round(
                    pt1.angle_to(seg.get_centre_point()) - 90, 5)
                if startPtAng >= tool.get_tool_cutting_angle():
                    if startPtAng + segAng <= 270:
                        segs_out.add_segment(seg)
                else:
                    ang = tool.get_tool_cutting_angle()
                    # calculate the length required to project the point to the centreline
                    length = abs(pt1.X / math.cos(math.radians(ang - 90)))
                    proj_pt = pt1.project(ang, length)
                    projseg = Segment(pt1, proj_pt)
                    intersect, pts = projseg.intersect(segments[index])
                    if intersect and allow_grooving:
                        # add the intersecting line to the segment_group
                        new_seg = Segment(pt1, pts[0])
                        segs_out.add_segment(new_seg)
                        # add the remainder of the arc to the segment_group
                        remaining_seg = Segment(pts[0], pt2)
                        remaining_seg.derive_bulge(seg)
                        segs_out.add_segment(remaining_seg)
                    else:
                        if seg.start.angle_to(seg.end) <= 180:
                            seg = Segment(pt1, pt2)
                            segs_out.add_segment(seg)
                        else:
                            pt = seg.start
                            next_index, pt = self.find_next_good_edge(
                                index, stock_z_min, tool, allow_grooving, pt)

            if seg.bulge < 0:
                # Limit the arc movement to the X extents or the tangent at the max tool angle if allow_grooving
                angle_limit = 270 if allow_grooving is False else tool.get_tool_cutting_angle(
                ) + 90
                if seg.get_centre_point().angle_to(pt2) >= angle_limit:
                    segs_out.add_segment(seg)
                else:
                    rad = seg.get_radius()
                    if not allow_grooving:
                        # define a point vertically down on the x axis.
                        x = seg.get_centre_point().X - rad
                        y = seg.get_centre_point().Y
                        z = seg.get_centre_point().Z
                        pt = Point(x, y, z)
                    else:
                        # project a point from the centre of the arc along the angle limit to the radius
                        pt = seg.get_centre_point().project(angle_limit, rad)

                    nseg = Segment(pt1, pt)
                    nseg.derive_bulge(seg, rad)
                    segs_out.add_segment(nseg)

                    pt1 = pt
                    next_index, pt = self.find_next_good_edge(
                        index, stock_z_min, tool, allow_grooving, pt)

            elif seg.bulge == 0:
                if pt1.angle_to(pt2) < tool.get_tool_cutting_angle():
                    next_index, pt = self.find_next_good_edge(
                        index, stock_z_min, tool, allow_grooving)
                else:
                    segs_out.add_segment(seg)

            if next_index is False and pt is not None:
                seg = Segment(pt1, pt)
                segs_out.add_segment(seg)
                break
            if next_index is not False and next_index != index:
                seg = Segment(pt1, pt)
                segs_out.add_segment(seg)

                next_pt1 = pt
                next_pt2 = segments[next_index].end
                seg = Segment(next_pt1, next_pt2)
                seg.derive_bulge(segments[next_index])
                segs_out.add_segment(seg)

                next_index += 1
                index = next_index
                continue

            index += 1
        segs_out.merge_segments()
        return segs_out