File Exchange

image thumbnail

Patch Normals

version 1.0.0.0 (14.5 KB) by Dirk-Jan Kroon
Calculates the normal vectors of a triangulated mesh (patch)

15 Downloads

Updated 02 Jun 2009

View License

This function calculates the normal vectors of a triangulated mesh such as used by the Matlab function patch.

It first calculates the normal vectors of all faces, and after that calculates the vertex normals from the face normals weighted by the angles of the faces.

The function is both implemented as a normal Matlab function and as a mex file in c-code (much faster)

Try the example ...

Comments and Ratings (10)

does it work only for triangles?

Serge

simplified version:

function N = patchnormals(FV)
%Vertex normals of a triangulated mesh, area weighted, left-hand-rule
% N = patchnormals(FV) -struct with fields, faces Nx3 and vertices Mx3
%N: vertex normals as Mx3

%face corners index
A = FV.faces(:,1);
B = FV.faces(:,2);
C = FV.faces(:,3);

%face normals
n = cross(FV.vertices(A,:)-FV.vertices(B,:),FV.vertices(C,:)-FV.vertices(A,:)); %area weighted

%vertice normals
N = zeros(size(FV.vertices)); %init vertix normals
for i = 1:size(FV.faces,1) %step through faces (a vertex can be reference any number of times)
N(A(i),:) = N(A(i),:)+n(i,:); %sum face normals
N(B(i),:) = N(B(i),:)+n(i,:);
N(C(i),:) = N(C(i),:)+n(i,:);
end

Anka Chan

Hello!Thank you for sharing your work!
I wonder that whether the center arrangement of face vextex is required? Do you check if them was clockwise or counterclockwise?

Alireza

Thanks for this coding. It is working well. But sir, I just want to ask, is it able to calculate the Thickness of a 3D mesh perfectly?

I am looking for your reply!

Thanks

Vedpal Singh

Thank you for your source code. But, i dont succeed to patch the different normal in some 3D mesh image. In fact, i was succeed to use you source code to have the normal vector of any facet but i don't succeed to patch him like the figure presented.
Can someone help me please how i can patch the differents normal in my 3D mesh image.

Thank you for your source code. But, i dont succeed to patch the different normal in some 3D mesh image. In fact, i was succeed to use you source code to have the normal vector of any facet but i don't succeed to patch him like the figure presented.
Can someone help me please how i can patch the differents normal in my 3D mesh image.

works like a charm, thank you!

I was halfway through writing this very function, when I thought... 'I wonder whether this has been done'...

Glad I checked!

This is flawless, as far as I can tell (so far I've compiled and run the example).

Cheers Dirk-Jan :)

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Compute STL Vertex Normals