File Exchange

image thumbnail

Compute normal vectors of 2.5D triangulation

version (2.25 KB) by David Gingras
That function compute the normal vectors of a 2.5D triangulation.

1 Download

Updated 05 May 2009

View Version History

View License

It could be useful to know the normal vectors of a surface. The function provided is able to take a 2.5D unrestricted triangulation (Delaunay or not) which define a 3D surface and computes the normal vectors of each cell. It is possible to compute vectors at the center cells or at vertices.

Inputs :
"XYZ" is the coordinate of the vertex of the triangulation (nx3 matrix).
"TRI" is the list of triangles which contain indexes of XYZ (mx3 matrix).
"strPosition" is the position where the normal is computed. It
could be 'center-cells' for a computation on the center of each
triangle or could be 'vertices' and the vectors are computed at
vertices with respect to the neighbor cells (string).

Outputs :
"NormalVx", "NormalVy" and "NormalVz" are the component of
normal vectors (normalized to 1).
"PosVx", "PosVy" and "PosVz" is the positions of each vector.

Note :
if strPosition == 'center-cells', then the dimension of each
output are mx1.
if strPosition == 'vertices', then the dimension of each
output are nx1.

All cells have to be enumerated clockwise or counter-clock.

Example :

TRI = delaunay(X,Y);
[NormalVx NormalVy NormalVz PosVx PosVy PosVz]=computeNormalVectorTriangulation([X Y Z],TRI,'vertices');

quiver3(PosVx,PosVy, PosVz, NormalVx, NormalVy, NormalVz), axis equal
hold on

David Gingras, February 2009

Cite As

David Gingras (2021). Compute normal vectors of 2.5D triangulation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

xiyu li


[X Y] = meshgrid(1:n, 1:n);
[X Y Z] = peaks(n);
a = delaunay(X(:),Y(:));
A = [X(a(:,1)) Y(a(:,1)) Z(a(:,1))];
B = [X(a(:,2)) Y(a(:,2)) Z(a(:,2))];
C = [X(a(:,3)) Y(a(:,3)) Z(a(:,3))];
facets.C = (A+B+C)/3;
B = B-A;
C = C-A;
M = cross(B, C, 2);
L = sqrt(sum(M.^2,2)) + 10e-20;
facets.N = M./repmat(L,1,3);
facets.S = 0.5*L;

Edward Bender

Worked perfectly the first time. A+!

Gozde Unal

very nice, thanks.

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

Community Treasure Hunt

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

Start Hunting!