【问题标题】:The mArrow3 function in Matlab behaves weirdMatlab 中的 mArrow3 函数行为怪异
【发布时间】:2017-03-20 14:32:57
【问题描述】:

正如您在图片中看到的,我正在使用 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
  • 这是一个函数,可以显示平面的方向。在这种情况下,红色箭头。
  • 奇怪的意思是,正如你在图片中看到的,Vx 的宽度不同于 Vy 和 Vz。我不知道为什么,因为设置是一样的。
  • 不是内置函数。它在哪里?见:minimal reproducible example

标签: matlab matlab-figure figure


【解决方案1】:

根据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 blockset 传递的不是'color''stemWidth''tipWidth' 的属性。如果它们不是patch 对象的有效属性,set 将抛出一个错误,该错误被捕获并显示以防止函数完全出错。如果你查看Patch properties,你会看到'lineWidth' is a valid property,所以set 不会出错。但是,它控制补丁边缘的宽度,我猜这不是您真正想要调整的属性。

【讨论】:

  • 使用 stemWidth 代替 lineWidth 使箭头消失,只显示文本。
  • 可能是因为 2 大约是 0.08% 您最小轴范围的大小。您需要将它们标准化为您的坐标轴。
  • 效果更好,我用了数字 10 而不是 2,但它看起来是扁平的,不是 3D,而且在所有情况下长度都不相同。有时圆锥只出现合并而线条不出现。
  • 总之,它的行为并不总是一样的。
  • 鉴于您的轴不统一,您将需要单独操作参数或提出提供所需视觉效果的规范化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
  • 2015-11-19
  • 2016-01-26
  • 2011-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多