路径上绘制法线或者切线向量箭头,如何绘制matlab代码

%绘制规划路径(如果找到)
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
    
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值