已知长宽和中心点,求四个角坐标和转换机代码,用仿真CNC把长方形面积挖出来

def createPocket(width,length,toolDiameter,center):
resultPoints = []
while(min(width, length) > toolDiameter):
width = width - toolDiameter/2
length = length - toolDiameter/2
currentPoints = biankuan(length, width, center)
resultPoints = resultPoints + currentPoints
p = [i for i in resultPoints[0]]
p[2] = p[2]+20
p = [p]
i = [i for i in resultPoints[-1]]
i[2] = i[2]+20
i = [i]
gCode0 = moveTool2(0, p)
gCode1 = moveTool2(1, resultPoints)
gCode2 = moveTool2(0, i)
gcode = gCode0 + '\n' + gCode1 + '\n' + gCode2
return gcode

def getGcode(method,k):
    x = 'X'
    y = 'Y'
    z = 'Z'
    g00 = 'G00 '
    g01 = 'G01 '
    if(method == 0):
        result = g00
    elif(method == 1):
        result = g01 
    if(k[0] != None):
        result += x + str(k[0]) + ' '
    if(k[1] != None):
        result += y + str(k[1]) + ' '
    if(k[2] != None):
        result += z + str(k[2]) + ' '
    return result
    


def moveTool2(method,polygon):
    if(method != 0 and method != 1):
        print('cuowu de canshu')
#        raise()
        return
    c = []
    result = ''
    for k in polygon:
        #根据坐标得到G代码
        #tp = g00 + ' ' + x + str(k[0]) + ' ' + y + str(k[1]) + ' ' + z + str(k[2])
        tp = getGcode(method,k)
        c.append(tp)
        #result += tp + '\n'
    #print(c)
    return '\n'.join(c)
    #return result
# points = [[35, 35 , 25], [35,150,25], [150,150,25],[150,35,25],[35,35,25],[35,35,50]]
# method = 0 输出G00, method = 1输出G01
#points0 = [[0,150,35]]
#points1 = [[0.0, 150.0, 25], [0.0, 0.0, 25], [150.0, 0.0, 25], [150.0, 150.0, 25], [0.0, 150.0, 25]]
#points2 = [[0,0,50],[100,100,60]]


def biankuan(i,w,c):
    a1 = [c[0] - i/2 ,c[1] + w/2 ,c[2]]
    a2 = [c[0] - i/2 ,c[1] - w/2 ,c[2]]
    a3 = [c[0] + i/2 ,c[1] - w/2 ,c[2]]
    a4 = [c[0] + i/2 ,c[1] + w/2 ,c[2]]
    b = [a1,a2,a3,a4,a1]
    return b
#points1 = biankuan(140,140,[70,70,15])
#p = [i for i in resultPoints[0]]
#p[2] = p[2]+20
#p = [p]
#i = [i for i in resultPoints[-1]]
#i[2] = i[2]+20
#i = [i]
#print(p,i)


def min(x, y):
    if(x < y):
        return x
    else:
        return y

##width = 140
#length = 140
#toolDiameter = 5
#center = [75, 70, 15]

#resultPoints = []
#while(min(width, length) > toolDiameter):
   # width = width - toolDiameter/2
   # length = length - toolDiameter/2
   # currentPoints = biankuan(length, width, center)
   # resultPoints = resultPoints + currentPoints
    #print(w, l)
    
#gCode0 = moveTool2(0, p)
#gCode1 = moveTool2(1, resultPoints)
#gCode2 = moveTool2(0, i)
#print(gCode0)
#print(gCode1)
#print(gCode2)

def createPocket(width,length,toolDiameter,center):
    resultPoints = []
    while(min(width, length) > toolDiameter):
        width = width - toolDiameter/2
        length = length - toolDiameter/2
        currentPoints = biankuan(length, width, center)
        resultPoints = resultPoints + currentPoints
    p = [i for i in resultPoints[0]]
    p[2] = p[2]+20
    p = [p]
    i = [i for i in resultPoints[-1]]
    i[2] = i[2]+20
    i = [i]
    gCode0 = moveTool2(0, p)
    gCode1 = moveTool2(1, resultPoints)
    gCode2 = moveTool2(0, i)
    gcode = gCode0 + '\n' + gCode1 + '\n' + gCode2
    return gcode

gcode = createPocket(140, 140, 10, [70, 70, 15])
print(gcode)
def createpocket(width,length,toolDiameter,center):
    resultPoints = []
    while(min(width, length) > toolDiameter):
        width = width - toolDiameter/2
        length = length - toolDiameter/2
        currentPoints = biankuan(length, width, center)
        resultPoints = resultPoints + currentPoints
    p = [i for i in resultPoints[0]]
    p[2] = p[2]+20
    p = [p]
    i = [i for i in resultPoints[-1]]
    i[2] = i[2]+20
    i = [i]
    gCode0 = moveTool2(0, p)
    gCode1 = moveTool2(1, resultPoints)
    gCode2 = moveTool2(0, i)
    bkzb = gCode0 + '\n' + gCode1 + '\n' + gCode2
    return bkzb
gcode = createPocket(140, 140, 10, [70, 70, 15])
print(gcode)

发表评论

邮箱地址不会被公开。 必填项已用*标注