已知长宽和中心点,求四个角坐标和转换机代码,用仿真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)

strapi v4版本建立与users_permissions联系的注意实现

在strapi v4中最好不要直接建立一个collection与users_permissions的联系。在strapi v4版本中建立了一个逻辑:如果一个用户没有权限对某个collection做'find'操作。那么该用户也无法间接的对该collection做任意操作。

在v4版本的@strapi/utils/lib/sanitize/visitors/remove-restricted-relations.js文件建立了一套逻辑。在所有间接写操作中,如果用户对被写的那个collection 没有'find'权限,那么这个间接写操作,将会被移除。

我们显然不希望用户可以对users_permissions这么重要集合有那么高的读权限。因此,如果我们非要建立一个集合和用户的关系时,可以仅仅保存用户id即可。不需要建立集合的联系。如果是考虑到性能的话,可以再建立一个集合,用来优化。

写一个函数求出已知队列数值最大值

a = [1.2,26,-3,-1,684,'sfggh',"896",412,'asdf']
k = 'x'
for v in a:
    #if(isinstance(v,int) or isinstance(v,float)):
    try:
        v1 = float(v)
        if(k == 'x'):
            k = v1
        else:
            if(v1 > k):
                k = v1
    except Exception as err:
        print('错误信息:',err)
if(k == 'x'):
    print('找不到最大值')
else:
    print('最大值为',k)

#找最大值
~                                                                                                                       ~                                   

vim配置

vim的配置对于经常使用的人来说非常重要,针对于个人习惯我们通常都要配置vim。

配置位置

linux下vim配置文件一般是~/.vimrc

window下vim配置文件是C:/Program File X86/Vim/_vimrc

配置编码

配置编码尤其对于windows用户来说非常重要。我们常常需要配置utf-8。常见的配置方法如下:

set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

配置缩进

有时候为了便于编辑我们经常需要配置一个tab转化成几个空格啊这种问题。常见的配置命令如下:

set tabstop=2
set shiftwidth=2
set expandtab

配置undo和备份文件位置

一般情况下,vim会在文件编辑时将生成的备份文件和undo文件放在文件的同一目录位置。但有时候,这个属性会导致很多问题。例如有的系统会对源代码所在文件位置做检索之类和文件名匹配的操作。那些多出来的备份文件和undo文件等就会产生干扰。配置这些文件的位置命令如下:

set backupdir=~/.vimbackup
set undodir=~/.vimundo

这两个命令会把相应文件存放在~/.vimbackup和~/.vimundo下。要注意,这两个目录需要存在,否则就会无效。

windows下推荐的配置文件

set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set tabstop=2
set expandtab
set shiftwidth=2
set backupdir=~/.vimbackup//,/var/tmp//,/tmp//,.
set undodir=~/.vimundo
set directory=~/.vimswp

vim的插件可以给vim添加很多新功能

以下这篇文档描述的非常经典

https://pragmaticpineapple.com/ultimate-vim-typescript-setup/

以下3个插件对于前端开发者很有用

计算几何学中几个典型的问题

多边形直骨架问题 straight skeleton problem

https://github.com/Botffy/polyskel/blob/master/doc/StraightSkeletonImplementation.pdf

凸多边形包围问题 convex hull problem

多边形相互关系问题

monotone 在曲线中的概念

在很多计算几何学的问题或者几何引擎的应用中都会monotone curve的概念。直接翻译成中文可以是“单调曲线”。但这样翻译有时候经常会误导九年义务教育的中国学者。这里的"单调"不是指的“单调递增”或者“单调递减”。"monotone curve"相关的定义可以参照下面的几句话:

A smooth plane curve containing no special points will be called a curve with monotone curvature, or a monotone curve. 来自这里

A continuous curve C in R 2 is called x-monotone, if every vertical line intersects it at a single point at most. 来自这里

2d arrangements 问题

对于一个空间内的所有的几何对象最安排和整理的算法。其基本思想是给一个空间内插入很多几何对象。例如点,曲线等。然后2d arrangements的算法就是用一套规则来安排整理和管理这些几何对象。这些安排的机制包括:

  1. 把所有非x-monotone的曲线分割成x-monotone的曲线线段
  2. 把所有互相相交的曲线都相互分割
  3. 给每一段曲线建立halfEdge机制
  4. 建立顶点和边,边与边,边与面,面与顶点等的关联关系

建立好这些数据结构或机制以后,基于这个几何安排,我们就可以做基于几何元素的各种检索应用,或者像可视性判断等基于几何性质的应用。

Delaunay triangulation 和Voronoi diagram的问题

Delaunay triangulationvoronoi diagram是一组点集成对存在两个图。其中简单地说delaunay triangulation是一种对点集做三角化的运算,这种三角化的运算能够最大化三角形集合中的最小夹角。而voronoi diagram能够根据点集对空间进行一次分割。每个点所确定的一块区域内所有的点到该点的距离比到其他任何一个点的距离都近。

FreeCAD中几何元素类型的适配误差

FreeCAD是基于opencascade的。对于一些几何元素的提取时,偶尔会产生一些误差。例如,把线段判断成更广义的BSplineCurve, 把圆锥面判断成更广义的旋转面等等。本文将对这些可能存在的偏差做一些记录。

  1. 线段识别为BSplineCurve, 此时虽然是BSplineCurve,但是该曲线所属边只有2个顶点。这种情况下,如果对线段类型要求严格,则需要对其进行纠正。

需要擅长于使用pyke中的in规则

前面在pyke引擎的总结文章中多次提到pyke是为了寻找一个集合中的组合方式而构建的推理引擎。在一种方式里,我们可以通过kfb文件或者_assert,add_universal_fact等方法去声明很多事实。但在构建一些规则的时候,我们需要一个模式去在一些其他方式构建的集合中去遍历。例如我们需要某一个对象遍历从0到10之间所有的数字,来检验一些规则。在这种情况下,我们就需要使用$pattern in python_iterable这样的方式来创建遍历集合了。使用规则示例如下:

test
        use test($pair)
        when
                $first in [0,1,2,3,4]
                $second in ['a', 'b', 'c']
                $pair = str($first) + '_' + $second


测试结果:(with engine.prove_goal(<rule_base>.test($pair)) as gen: ....)

result: {'pair': '0_a'}
result: {'pair': '0_b'}
result: {'pair': '0_c'}
result: {'pair': '1_a'}
result: {'pair': '1_b'}
result: {'pair': '1_c'}
result: {'pair': '2_a'}
result: {'pair': '2_b'}
result: {'pair': '2_c'}
result: {'pair': '3_a'}
result: {'pair': '3_b'}
result: {'pair': '3_c'}
result: {'pair': '4_a'}
result: {'pair': '4_b'}
result: {'pair': '4_c'}