How to obtain normals from faces?
Show older comments
Hello, I would like to know if there is a way to obtain the normals of some given Faces. The Faces are defined by an stl file. I am using Matlab R2012b. Thank you for your help!
Answers (1)
The easy way would be to use the triangulation class, or since we're pre-R2013a, use TriRep(). The following example was tested in R2009b.
unzip saddleblock.stl.zip % needed for the forum
% you got F,V data in MATLAB somehow.
% this is from FEX #51200 and was available in early 2015,
% so it's period-correct, or at least plausible.
[V F] = stlRead('saddleblock.stl');
% since we're in R2012b, we're using TriRep().
% after R2013a, we can just use triangulation().
T = TriRep(F,V);
fn = faceNormals(T);
c = incenters(T);
% display it all
patch('faces',F,'vertices',V,'facecolor','w','edgecolor','k'); hold on
quiver3(c(:,1),c(:,2),c(:,3),fn(:,1),fn(:,2),fn(:,3),'linewidth',2);
view(3); camlight; view(10,33)
axis equal; grid on
xlabel('X'); ylabel('Y'); zlabel('Z')
Categories
Find more on STL (STereoLithography) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!