%绘制规划路径(如果找到)
if ~isempty(patha)
plot(patha(:,1), patha(:,2), 'g-', 'LineWidth', 2); % 原始路径(绿色)
plot(patha(:,1), patha(:,2), 'b.', 'MarkerSize',12); % 路径节点(蓝色圆点)
% 方向箭头(品红色)
step = 5; % 每隔4个点取一个箭头
% 动态调整step以避免越界
total_points = size(patha, 1);
if total_points < 2
warning('路径点不足,无法计算方向');
else
step = min(step, floor(total_points / 2)); % 确保至少有两个点
arrow_x = patha(1:step:end, 1);
arrow_y = patha(1:step:end, 2);
% 计算方向向量
if size(patha, 2) >= 3
directions = patha(1:step:end, 3);
else
dx = diff(patha(:,1));
dy = diff(patha(:,2));
directions = atan2(dy, dx);
directions = directions(1:numel(arrow_x)); % 对齐索引
end
u = cos(directions);
v = sin(directions);
quiver(arrow_x, arrow_y, u, v, 0.2, 'Color', 'm', 'DisplayName', 'Direction');
end