display surface normal using quiver3

4 ビュー (過去 30 日間)
MK
MK 2017 年 3 月 5 日
コメント済み: MK 2017 年 3 月 12 日
I have an MxN matrix Z after some processing, and wanted to retrieve the surface normals (as well as view it on a plot)
I've tried surfnorm(Z), but since it had looked pretty messy I thought of simply using quiver3, with the surface normals from the return value of surfnorm. Since the documentation states that quiver3(x,y,z,u,v,n) usage is such that the (u, v, n) vectors would be at location(x,y,z), I tried the following:
% I checked that surf(Z) and surf(X, Y, Z) gave the same plot
X = zeros(M, N);
Y = zeros(M, N);
for k = 1:M
X(k, :) = k;
end
for k = 1:N
Y(:, k) = k;
end
[U, V, W] = surfnorm(Z);
quiver3(X, Y, Z, U, V, W);
but I simply got a "cylindrical" vector plot (seemingly as if the origin of the vectors are the same (center of cylinder)). I tried with different Z matrices but the quiver3 plot was always similar looking.
Am I understanding any of the functions wrong? Would really appreciate some help.
surf result:
surfnorm result:
quiver3 result:

採用された回答

Rahul Kalampattel
Rahul Kalampattel 2017 年 3 月 6 日
編集済み: Rahul Kalampattel 2017 年 3 月 6 日
1. Use
[U,V,W] = surfnorm(X,Y,Z);
instead of
[U,V,W] = surfnorm(Z);
This will make sure that the quiver3 vectors are mapped to the right coordinates.
2. If you look at the last plot, the X/Y axes scales are 14 orders of magnitude larger than in your surf and surfnorm plots. The vectors from quiver3 are too long, which gives the illusion of a cylindrical plot. This might be fixed after step 1, but if not you can rescale them using
quiver3(X,Y,Z,U,V,W,0.5); % Half scale
  4 件のコメント
Rahul Kalampattel
Rahul Kalampattel 2017 年 3 月 7 日
Also I'm not sure exactly what you want as far as having different coloured vectors in different directions goes, but this is one way to do it.
hold on
% Vectors with positive U are blue, the rest are red
quiver3(X,Y,Z,(U>=0).*U,(U>=0).*V,(U>=0).*W)
quiver3(X,Y,Z,(U<0).*U,(U<0).*V,(U<0).*W, 'color', 'r')
MK
MK 2017 年 3 月 12 日
Yes I saw the documentation as well. But since my vectors had a range of 0-1, I thought they would not have been upscaled, so I did not notice the magnification.
Regarding the colour, I was thinking more that the corresponding (u,v,w) vectors would give the (r,g,b) colours, since the range of (u,v,w) was 0-1. For now though, I have actually done away with the colour display since the vectors (after downscaling) are really small, and direction less clear. I'm actually now just working with the values instead.
By the way, thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by