//畫出路綫 if (i < paths.size() && paths[i].size() > 1 && paths[i][0] != nullptr) { QPainterPath path; path.moveTo(paths[i][0]->x, paths[i][0]->y); for (int k = 1; k < paths[i].size(); k++) { if (paths[i][k] != nullptr) { path.lineTo(paths[i][k]->x, paths[i][k]->y); } } if (!path.isEmpty()) { QPainter painter(this); if (painter.isActive()) { painter.setPen(QPen(Qt::red, 2)); painter.drawPath(path); } } },修改代碼:循環所有的agv,畫出path的路徑
时间: 2023-12-21 10:03:18 浏览: 64
JAVA源码最短路径算法实现k-shortest-paths
可以尝试以下修改代码:
```
for (int i = 0; i < agvs.size(); i++) {
//畫出路綫
if (i < paths.size() && paths[i].size() > 1 && paths[i][0] != nullptr) {
QPainterPath path;
path.moveTo(paths[i][0]->x, paths[i][0]->y);
for (int k = 1; k < paths[i].size(); k++) {
if (paths[i][k] != nullptr) {
path.lineTo(paths[i][k]->x, paths[i][k]->y);
}
}
if (!path.isEmpty()) {
QPainter painter(this);
if (painter.isActive()) {
painter.setPen(QPen(Qt::red, 2));
painter.drawPath(path);
}
}
}
}
```
这样就会循环所有的 agv,画出每个 agv 对应的路径。
阅读全文