display surface normal using quiver3

조회 수: 7 (최근 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 CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by