16 views (last 30 days)
Show older comments
MK on 5 Mar 2017
Commented: MK on 12 Mar 2017
Accepted Answer: Rahul Kalampattel
Open in MATLAB Online
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:
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Rahul Kalampattel on 6 Mar 2017
Edited: Rahul Kalampattel on 6 Mar 2017
Open in MATLAB Online
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
3. If the two plots still aren't matching, this answer might help: https://au.mathworks.com/matlabcentral/answers/100252-why-do-the-surface-norms-calculated-by-surfnorm-and-quiver3-not-coincide-in-matlab-6-5-r13?s_tid=answers_rc1-1_p1_MLT
4 Comments Show 2 older commentsHide 2 older comments
Show 2 older commentsHide 2 older comments
MK on 7 Mar 2017
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/328149-display-surface-normal-using-quiver3#comment_434701
Hey, thanks for your answer. The issue here really was the scale (both surfnorm(Z) and surfnorm(X,Y,Z) returned the same values for the matrices U,V,W).
Did not notice until you pointed it out, but as the scale was many magnitudes larger, I set the scale in quiver3(x,y,z,u,v,w, scale) the same orders of magnitude smaller. Tried on a different image and its actually showing a proper figure now. I'll still need to figure about changing the color with the U,V,W direction to make it clearer though. Thanks.
surf result:
surfnorm result:
quiver3 result:
On another note, would you happen to know how the scaling is done in the quiver3 plot ? I had actually assumed that the size of the vector would be given by the values in my U, V and W matrices.. Also did not see any mention about the 'default' vector scale in the quiver3 documentation..
Rahul Kalampattel on 7 Mar 2017
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/328149-display-surface-normal-using-quiver3#comment_434710
U,V and W do specify the lengths of each vector, but by default the result is autoscaled.
From the documentation, "The quiver3 function automatically scales the vectors to prevent overlapping based on the distance between them".
You can turn this off by setting the scale parameter to 0, but it might be a bit messy.
Rahul Kalampattel on 7 Mar 2017
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/328149-display-surface-normal-using-quiver3#comment_434715
Open in MATLAB Online
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 on 12 Mar 2017
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/328149-display-surface-normal-using-quiver3#comment_436317
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!
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Categories
MATLABGraphicsFormatting and Annotation3-D Scene ControlLighting, Transparency, and Shading
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Tags
- quiver3
- surfnorm
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office