1 Star 0 Fork 3

木头/monte-carlo-AGV

forked from 朱洪君/monte-carlo-AGV 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
draw.py 4.02 KB
一键复制 编辑 原始数据 按行查看 历史
朱洪君 提交于 2021-03-18 16:26 . 1.0版本
import matplotlib.pyplot as plt
from gl import MAPSIZE
from change import switch_to_xy,ro2xy
import math
def DRAW_MAP(): # 绘制地图
# 绘制地图
x = range(0, 21, 1)
y = range(0, 21, 1)
plt.xticks(x, x)
plt.yticks(y, y)
# plt.style.use('ggplot') # bmh seaborn classic ggplot grayscale
for i in range(MAPSIZE.shape[0]):
for j in range(MAPSIZE.shape[1]):
plt.plot([0, MAPSIZE.shape[0]], [j, j], 'gray', linewidth=0.1)
plt.plot([i, i], [0, MAPSIZE.shape[1]], 'gray', linewidth=0.1)
#绘制箭头的方法 plt.annotate('', xy=(0.5, 0.5), xytext=(0.5, 1.5),
# arrowprops=dict(facecolor='black',arrowstyle="->", connectionstyle="arc3"))
tmpx = [i, i + 1]
tmpy1 = j
tmpy2 = j + 1
if MAPSIZE[i][j] == 0:
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='white')
elif MAPSIZE[i][j] == 1:
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='red')
elif MAPSIZE[i][j] == 2:
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='red')
elif MAPSIZE[i][j] == 3:
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='green')
elif MAPSIZE[i][j] == 4:
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='yellow')
elif MAPSIZE[i][j] == 5:
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='black')
# for i in range(len(SCHE_PLAN)):
# [tmpx1,tmpy1]=switch_to_xy(SCHE_PLAN[i][0])
# [tmpx1,tmpy1]=[tmpx1+0.2,tmpy1+0.2]
# tmpy2=tmpy1+0.6
# tmpx2=tmpx1+0.6
# tmpx=[tmpx1,tmpx2]
# plt.fill_between(tmpx,tmpy1,tmpy2,facecolor='blue')
plt.plot([0, MAPSIZE.shape[0]], [MAPSIZE.shape[1], MAPSIZE.shape[1]], 'gray')
plt.plot([MAPSIZE.shape[0], MAPSIZE.shape[0]], [0, MAPSIZE.shape[1]], 'gray')
# plt.show()
def DRAW_PATH_BY_TREE(tree):
DRAW_MAP()
for i in range(len(tree)):
[tmpx1, tmpy1] = switch_to_xy(tree[i].location)
[tmpx1, tmpy1] = [tmpx1 + 0.2, tmpy1 + 0.2]
tmpy2 = tmpy1 + 0.6
tmpx2 = tmpx1 + 0.6
tmpx = [tmpx1, tmpx2]
# if tree[i].AGV==0:
# plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='blue')
# if tree[i].AGV==1:
# plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='gray')
# if tree[i].AGV==2:
# plt.fill_between(tmpx, tmpy1, tmpy2, facecolor='purple')
plot_path(tree[i])
def rotate_arrow(treenode,color):
[x, y] = switch_to_xy(treenode.location)
[xflag,yflag] = ro2xy(treenode.rotation)
if xflag==1:
plt.annotate('', xy=(x + 1, y + 0.5), xytext=(x, y + 0.5),
arrowprops=dict(color=color, arrowstyle="->", connectionstyle="arc3"))
if xflag==-1:
plt.annotate('', xy=(x, y + 0.5), xytext=(x+1, y + 0.5),
arrowprops=dict(color=color, arrowstyle="->", connectionstyle="arc3"))
if yflag==1:
plt.annotate('', xy=(x + 0.5, y + 1), xytext=(x+ 0.5, y ),
arrowprops=dict(color=color, arrowstyle="->", connectionstyle="arc3"))
if yflag==-1:
plt.annotate('', xy=(x + 0.5, y ), xytext=(x+ 0.5, y + 1),
arrowprops=dict(color=color, arrowstyle="->", connectionstyle="arc3"))
def plot_path(self):
if len(self.children) != 0:
for i in range(len(self.children)):
plot_path(self.children[i])
if self.AGV==0:
rotate_arrow(self,'blue')
if self.AGV == 1:
rotate_arrow(self, 'gray')
if self.AGV == 2:
rotate_arrow(self,'purple')
return 0
else:
if self.AGV == 0:
rotate_arrow(self, 'blue')
if self.AGV == 1:
rotate_arrow(self, 'gray')
if self.AGV == 2:
rotate_arrow(self, 'purple')
return 0
def plot_AGV(location,color):
[x,y]=switch_to_xy(location)
tmpx=[x+0.2,x+0.8]
tmpy1=y+0.2
tmpy2=tmpy1+0.8
plt.fill_between(tmpx, tmpy1, tmpy2, facecolor=color)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jetingman/monte-carlo-AGV.git
git@gitee.com:jetingman/monte-carlo-AGV.git
jetingman
monte-carlo-AGV
monte-carlo-AGV
master

搜索帮助