//畫出agv空間 for (int i = 0; i < agvs.size(); i++) { if (i < paths.size() && !paths[i].empty() ) { Node *next_node = paths[i][0]; QColor color(128, 138, 135); QPen pen(color, 14); painter.setPen(pen); QPoint start(agvs[i].current_x*25+200+nodeSize/2, (agvs[i].current_y+1)*25+50+nodeSize/2); QPoint end(next_node->x* 25 + 200 +nodeSize/2, (next_node->y+1)* 25 + 50 +nodeSize/2); painter.drawLine(start, end); }},修改爲會順澤下一個坐標的方向,根據agv的current坐標向前面加1
时间: 2024-03-09 07:44:25 浏览: 63
以下是修改后的代码:
```
//画出agv空间
for (int i = 0; i < agvs.size(); i++) {
if (i < paths.size() && !paths[i].empty()) {
Node *next_node = paths[i][0];
QColor color(128, 138, 135);
QPen pen(color, 14);
painter.setPen(pen);
QPoint start(agvs[i].current_x*25+200+nodeSize/2, (agvs[i].current_y+1)*25+50+nodeSize/2);
QPoint end;
if (agvs[i].current_x == next_node->x && next_node->y > agvs[i].current_y) {
end.setX(next_node->x*25+200+nodeSize/2);
end.setY((next_node->y+1)*25+50+nodeSize/2);
} else if (agvs[i].current_x == next_node->x && next_node->y < agvs[i].current_y) {
end.setX(next_node->x*25+200+nodeSize/2);
end.setY((next_node->y)*25+50+nodeSize/2);
} else if (agvs[i].current_y == next_node->y && next_node->x > agvs[i].current_x) {
end.setX((next_node->x)*25+200+nodeSize/2);
end.setY((next_node->y+1)*25+50+nodeSize/2);
} else if (agvs[i].current_y == next_node->y && next_node->x < agvs[i].current_x) {
end.setX((next_node->x+1)*25+200+nodeSize/2);
end.setY((next_node->y+1)*25+50+nodeSize/2);
}
painter.drawLine(start, end);
}
}
```
这个修改后的代码会根据 AGV 的 current 坐标向前面加1,来画出从当前坐标到下一个坐标的连线。如果下一个坐标在 AGV 的当前坐标的右边,那么就会向右画出连线;如果下一个坐标在 AGV 的当前坐标的左边,那么就会向左画出连线;如果下一个坐标在 AGV 的当前坐标的上面,那么就会向上画出连线;如果下一个坐标在 AGV 的当前坐标的下面,那么就会向下画出连线。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)