def segmentAngleXY(self,
                       prevCommand,
                       currCommand,
                       endpos=False,
                       currentZ=0):
        '''returns in the starting angle in radians for a Path command.
        requires the previous command in order to calculate arcs correctly
        if endpos = True, return the angle at the end of the segment.'''

        global arccommands
        if currCommand.Name in arccommands:
            arcLoc = FreeCAD.Vector((prevCommand.x + currCommand.I),
                                    (prevCommand.y + currCommand.J), currentZ)
            if endpos is True:
                radvector = arcLoc.sub(currCommand.Placement.Base
                                       )  #Calculate vector at start of arc
            else:
                radvector = arcLoc.sub(prevCommand.Placement.Base
                                       )  #Calculate vector at end of arc

            v1 = radvector.cross(FreeCAD.Vector(0, 0, 1))
            if currCommand.Name in ["G2", "G02"]:
                v1 = D.rotate2D(v1, math.radians(180))
        else:
            v1 = currCommand.Placement.Base.sub(
                prevCommand.Placement.Base)  #Straight segments are easy

        myAngle = D.angle(v1, FreeCAD.Base.Vector(1, 0, 0),
                          FreeCAD.Base.Vector(0, 0, -1))
        return myAngle
    def getIncidentAngle(self, queue):
        global currLocation
        '''returns in the incident angle in radians between the current and previous moves'''
        # get the vector of the last move
        if queue[1].Name in arccommands:
            print queue
            print currLocation
            arcLoc = FreeCAD.Base.Vector(queue[2].X + queue[1].I, queue[2].Y + queue[1].J, currLocation['Z'])
            radvector = queue[1].Placement.Base.sub(arcLoc)  # vector of chord from center to point
            # vector of line perp to chord.
            v1 = radvector.cross(FreeCAD.Base.Vector(0, 0, 1))
        else:
            v1 = queue[1].Placement.Base.sub(queue[2].Placement.Base)

        # get the vector of the current move
        if queue[0].Name in arccommands:
            arcLoc = FreeCAD.Base.Vector((queue[1].x + queue[0].I), (queue[1].y + queue[0].J), currLocation['Z'])
            radvector = queue[1].Placement.Base.sub(arcLoc)  # calculate arcangle

            v2 = radvector.cross(FreeCAD.Base.Vector(0, 0, 1))

            # if switching between G2 and G3, reverse orientation
            if queue[1].Name in arccommands:
                if queue[0].Name != queue[1].Name:
                    v2 = D.rotate2D(v2, math.radians(180))
        else:
            v2 = queue[0].Placement.Base.sub(queue[1].Placement.Base)

        incident_angle = D.angle(v1, v2, FreeCAD.Base.Vector(0, 0, -1))
        return incident_angle
    def segmentAngleXY(self, prevCommand, currCommand, endpos=False, currentZ=0):
        '''returns in the starting angle in radians for a Path command.
        requires the previous command in order to calculate arcs correctly
        if endpos = True, return the angle at the end of the segment.'''

        global arccommands
        if currCommand.Name in arccommands:
            arcLoc = FreeCAD.Vector((prevCommand.x + currCommand.I), (prevCommand.y + currCommand.J), currentZ)
            if endpos is True:
                radvector = arcLoc.sub(currCommand.Placement.Base)  # Calculate vector at start of arc
            else:
                radvector = arcLoc.sub(prevCommand.Placement.Base)  # Calculate vector at end of arc

            v1 = radvector.cross(FreeCAD.Vector(0, 0, 1))
            if currCommand.Name in ["G2", "G02"]:
                v1 = D.rotate2D(v1, math.radians(180))
        else:
            v1 = currCommand.Placement.Base.sub(prevCommand.Placement.Base)  # Straight segments are easy

        myAngle = D.angle(v1, FreeCAD.Base.Vector(1, 0, 0), FreeCAD.Base.Vector(0, 0, -1))
        return myAngle
示例#4
0
    def getIncidentAngle(self, queue):
        global currLocation
        '''returns in the incident angle in radians between the current and previous moves'''
        # get the vector of the last move
        if queue[1].Name in arccommands:
            print queue
            print currLocation
            arcLoc = FreeCAD.Base.Vector(queue[2].X + queue[1].I,
                                         queue[2].Y + queue[1].J,
                                         currLocation['Z'])
            radvector = queue[1].Placement.Base.sub(
                arcLoc)  # vector of chord from center to point
            # vector of line perp to chord.
            v1 = radvector.cross(FreeCAD.Base.Vector(0, 0, 1))
        else:
            v1 = queue[1].Placement.Base.sub(queue[2].Placement.Base)

        # get the vector of the current move
        if queue[0].Name in arccommands:
            arcLoc = FreeCAD.Base.Vector((queue[1].x + queue[0].I),
                                         (queue[1].y + queue[0].J),
                                         currLocation['Z'])
            radvector = queue[1].Placement.Base.sub(
                arcLoc)  # calculate arcangle

            v2 = radvector.cross(FreeCAD.Base.Vector(0, 0, 1))

            # if switching between G2 and G3, reverse orientation
            if queue[1].Name in arccommands:
                if queue[0].Name != queue[1].Name:
                    v2 = D.rotate2D(v2, math.radians(180))
        else:
            v2 = queue[0].Placement.Base.sub(queue[1].Placement.Base)

        incident_angle = D.angle(v1, v2, FreeCAD.Base.Vector(0, 0, -1))
        return incident_angle