24小时热门版块排行榜    

查看: 1684  |  回复: 1

JESLoooo

新虫 (初入文坛)

[求助] matlab中quiver3和surfnorm的问题 已有1人参与

代码是matlab quiver3函数中的一个例子。输出的图中蓝色矢量是quiver3的结果。然后红色线是另外画的,是surfnorm(x,y,z)的结果。不明白为什么会不一样,surfnorm不就是画出曲面法线的函数么?

matlab中quiver3和surfnorm的问题
91ef76c6a7efce1b1efcfc13a651f3deb58f6517.jpg


matlab中quiver3和surfnorm的问题-1
c2fdfc039245d688176e857dadc27d1ed31b24fe.jpg
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

pdl9527

专家顾问 (小有名气)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
jjdg: 金币+2, 感谢参与 2017-04-05 16:16:49
JESLoooo: 金币+8, ★★★★★最佳答案 2017-04-05 22:50:21
简单点说是横宽比的问题,两次绘图的横宽比不同所以导致视觉上的不一致,以下是转载的解释。

https://nl.mathworks.com/matlabcentral/answers/100252-why-do-the-surface-norms-calculated-by-surfnorm-and-quiver3-not-coincide-in-matlab-6-5-r13

This is the correct behavior. A unit vector only displays orientation information. The orientation needs to be scaled if the aspect ratio is not the basic [1 1 1] as is in the case of an arbitrary plot. Another way to see this is to think of a line going from [0,1] to [1,1]. Imagine plotting the line in different aspect ratios–the unit vector would have to change to stay normal.

To correct the perceived misalignment with SURFNORM and QUIVER3, you can set both the DataAspectRatio and PlotBoxAspectRatio properties of the Axes Object as shown in the following example code:
CODE:
function question_35
clear;clc
[X,Y] = meshgrid(-2:0.25:2,-1:0.2:1);
Z = X.* exp(-X.^2 - Y.^2);
[U,V,W] = surfnorm(X,Y,Z);
quiver3(X,Y,Z,U,V,W,0.5);
hold on
surf(X,Y,Z);
set(gca,'DataAspectRatio',[1 1 1]);% set data aspect ratio
set(gca,'PlotBoxAspectRatio',[1 1 1]);% set plot box aspect ratio
surfnorm(X,Y,Z);
hold off

2楼2017-04-05 16:11:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 JESLoooo 的主题更新
信息提示
请填处理意见