Matlab 中的 mArrow3 函数表现怪异

The mArrow3 function in Matlab behaves weird

如图所示,我正在使用 mArrow3 函数来显示平面的方向。 但是,有时任何飞镖都会表现得很奇怪。

我使用的代码:

drawnow;
xExt = abs(diff(get(gca, 'XLim')));
yExt = abs(diff(get(gca, 'YLim')));
zExt = abs(diff(get(gca, 'ZLim')));
mArrow3([0 0 0],[xExt / 1, 0, 0], 'lineWidth', 2,'color','red','facealpha',  0.1);
mArrow3([0 0 0],[0, yExt / 1, 0], 'lineWidth',  2,'color','red','facealpha',0.1);
mArrow3([0 0 0],[0, 0, zExt / 1], 'lineWidth',  2,'color','red','facealpha',0.1);


text(xExt, 0, 0, 'Vx','FontSize',12);  
text(0, yExt, 0, 'Vy','FontSize',12); 
text(0, 0, zExt, 'Vz','FontSize',12);

你能给我一些关于这个问题的提示吗?

根据 mArrow3 (MATLAB FEX) 的内联文档,控制行外观的三个属性是:

% properties: 'color':      color according to MATLAB specification
%                           (see MATLAB help item 'ColorSpec')
%             'stemWidth':  width of the line
%             'tipWidth':   width of the cone 

如您所见,'lineWidth' 不是这些选项之一。要了解为什么会出现上述行为,您可以查看函数定义,看看如果这些值未在函数调用中传递会发生什么情况:

%% default parameters
if ~exist('stemWidth','var')
    ax = axis;
    if numel(ax)==4
        stemWidth = norm(ax([2 4])-ax([1 3]))/300;
    elseif numel(ax)==6
        stemWidth = norm(ax([2 4 6])-ax([1 3 5]))/300;
    end
end
if ~exist('tipWidth','var')
    tipWidth = 3*stemWidth;
end

如您所见,如果未提供 stemWidthtipWidthmArrow3 将分别根据轴限制和 stemWidth 对它们的值进行标准化。

那么为什么它不抛出错误呢?如果您进一步查看函数定义,您可以查看错误检查:

%% draw
fv.faces = f;
fv.vertices = v;
h = patch(fv);
for propno = 1:numel(propertyNames)
    try
        set(h,propertyNames{propno},propertyValues{propno});
    catch
        disp(lasterr)
    end
end

这样做是使用try/catch block to set the properties you've passed that aren't 'color', 'stemWidth', or 'tipWidth'. If they're not valid properties for the patch object, set will throw an error, which is caught and displayed to keep the function from erroring out completely. If you check out the Patch properties, you'll see that 'lineWidth' is a valid property,所以set不会出错。然而,它控制了补丁边缘的宽度,我猜这不是你真正想要调整的属性。