|
@@ -43,6 +43,7 @@ def getDoorBeginAndModuleUsePointDistince(x0,y0,width,height,x,y):
|
|
|
includePoints.append((x0+width/2,y0-height/2))
|
|
|
drawLines(includePoints)
|
|
|
# 获取点到长方形指定点的最短距离,默认点在长方形下方
|
|
|
+# x0,y0为矩形中点,xy为起始点,x1,y1为终点
|
|
|
def getMovePath(x0,y0,width,height,x,y,x1,y1):
|
|
|
points = [(x,y),(x0-width/2,y0-height/2),(x0-width/2,y0+height/2),(x0+width/2,y0-height/2),(x0+width/2,y0+height/2),(x0,y0),(x1,y1)]
|
|
|
drawPoints(points)
|
|
@@ -73,7 +74,103 @@ def getMovePath(x0,y0,width,height,x,y,x1,y1):
|
|
|
else:
|
|
|
includePoints.append((x0-width/2,y0-height/2))
|
|
|
includePoints.append((x1,y1))
|
|
|
+ # drawLines(includePoints)
|
|
|
+ return includePoints
|
|
|
+# 获取点到长方形指定点的最短距离
|
|
|
+# x0,y0为矩形中点,xy为起始点,x1,y1为终点
|
|
|
+def getMovePath2(x0,y0,width,height,x,y,x1,y1):
|
|
|
+ includePoints = [(x,y)]
|
|
|
+ bottom = y0-height/2
|
|
|
+ right = x0+width/2
|
|
|
+ top = y0+height/2
|
|
|
+ left = x0-width/2
|
|
|
+ points = [(x,y),(left,bottom),(left,top),(right,bottom),(right,top),(x0,y0),(x1,y1)]
|
|
|
+ drawPoints(points)
|
|
|
+ # 终点在模块最上边
|
|
|
+ if y1 == top:
|
|
|
+ if y>=top:
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x<=left:
|
|
|
+ includePoints.append((left,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x>=right:
|
|
|
+ includePoints.append((right,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x+x1<=2*x0:
|
|
|
+ includePoints.append((left,bottom))
|
|
|
+ includePoints.append((left,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ else:
|
|
|
+ includePoints.append((right,bottom))
|
|
|
+ includePoints.append((right,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y1 == bottom:
|
|
|
+ if y<=bottom:
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x<=left:
|
|
|
+ includePoints.append((left,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x>=right:
|
|
|
+ includePoints.append((right,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x+x1<=2*x0:
|
|
|
+ includePoints.append((left,top))
|
|
|
+ includePoints.append((left,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ else:
|
|
|
+ includePoints.append((right,top))
|
|
|
+ includePoints.append((right,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif x1 == left:
|
|
|
+ if x<=left:
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y>=top:
|
|
|
+ includePoints.append((left,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y<=bottom:
|
|
|
+ includePoints.append((left,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y+y1<=2*y0:
|
|
|
+ includePoints.append((right,bottom))
|
|
|
+ includePoints.append((left,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ else:
|
|
|
+ includePoints.append((right,top))
|
|
|
+ includePoints.append((left,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ else:
|
|
|
+ if x>=right:
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y>=top:
|
|
|
+ includePoints.append((right,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y<=bottom:
|
|
|
+ includePoints.append((right,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ elif y+y1<=2*y0:
|
|
|
+ includePoints.append((left,bottom))
|
|
|
+ includePoints.append((right,bottom))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ else:
|
|
|
+ includePoints.append((left,top))
|
|
|
+ includePoints.append((right,top))
|
|
|
+ includePoints.append((x1,y1))
|
|
|
+ drawLines(includePoints)
|
|
|
+ return includePoints
|
|
|
+# 获取模块可用点到另一个模块使用点间的距离
|
|
|
+def getModuleMovePath(x10,y10,width1,height1,x1,y1,x20,y20,width2,height2,x2,y2):
|
|
|
+ includePoints1 = getMovePath(x10,y10,width1,height1,x2,y2,x1,y1)
|
|
|
+ includePoints2 = getMovePath(x20,y20,width2,height2,x1,y1,x2,y2)
|
|
|
+ includePoints = []
|
|
|
+ for item in range(len(includePoints1)):
|
|
|
+ if(item>0):
|
|
|
+ includePoints.append(includePoints1[item])
|
|
|
+ for item in range(len(includePoints2)):
|
|
|
+ if(item>0):
|
|
|
+ includePoints.insert(0,includePoints2[item])
|
|
|
+ print(includePoints)
|
|
|
drawLines(includePoints)
|
|
|
+ return includePoints
|
|
|
# getDoorBeginAndModuleUsePointDistince(3300,1500,900,600,10,3000)
|
|
|
# getDoorBeginAndModuleUsePointDistince(3300,2800,900,600,1000,3000)
|
|
|
# getDoorBeginAndModuleUsePointDistince(3300,2800,900,600,3100,3800)
|
|
@@ -82,6 +179,13 @@ def getMovePath(x0,y0,width,height,x,y,x1,y1):
|
|
|
# getMovePath(3300,2800,900,600,0,0,2850,2700)
|
|
|
# getMovePath(3300,2800,900,600,3000,0,2850,2700)
|
|
|
# getMovePath(3300,2800,900,600,3300,0,3500,3100)
|
|
|
+
|
|
|
+# getMovePath2(800,700,600,400,2000,2000,800,900)
|
|
|
+# getMovePath2(800,700,600,400,300,800,800,900)
|
|
|
+# getMovePath2(800,700,600,400,2000,0,800,900)
|
|
|
+# getMovePath2(800,700,600,400,1000,100,800,900)
|
|
|
+# getMovePath2(800,700,600,400,600,100,800,900)
|
|
|
+getModuleMovePath(800,700,600,400,900,500,1500,1100,400,800,1700,800)
|
|
|
def testAppend():
|
|
|
score = []
|
|
|
for i in range(100):
|
|
@@ -89,6 +193,6 @@ def testAppend():
|
|
|
s.append(i)
|
|
|
score.append(s)
|
|
|
print(score)
|
|
|
-testAppend()
|
|
|
+# testAppend()
|
|
|
|
|
|
|