Raw File
normals.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is part of NS2DDV.                                                      %
%                                                                                   %
% Copyright(C) 2011-2018    C. Calgaro  (caterina.calgaro@math.univ-lille1.fr)      %
%                           E. Creusé   (emmanuel.creuse@math.univ-lille1.fr)       %
%                           T. Goudon   (thierry.goudon@inria.fr)                   %
%                           A. Mouton   (alexandre.mouton@math.univ-lille1.fr)      %
%                                                                                   %
% NS2DDV is free software: you can redistribute it and/or modify it under the terms %
% of the GNU General Public License as published by the Free Software Foundation,   %
% either version 3 of the License, or (at your option) any later version.           %
%                                                                                   %
% NS2DDV is distributed in the hope that it will be useful, but WITHOUT ANY         %
% WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   %
% PARTICULAR PURPOSE. See the GNU General Public License for more details.          %
%                                                                                   %
% You should have received a copy of the GNU General Public License along with      %
% NS2DDV. If not, see <http://www.gnu.org/licenses/>.                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[edges_normal_sign, edges_non_unit_normals, edges_length] = normals(MESH)

	% INPUT
	% MESH						An incomplete mesh metadata
	%
	% OUTPUT
	% edges_normal_sign			Positive or negative number according to MESH.e1full(i,k) > MESH.e1full(i,k+1)
	% edges_non_unit_normals	Coordinates of non-unit normal vector to edges
	% edges_length				Edges length

	edges_normal_sign = zeros(3,MESH.nt1);
	for ie = 1:MESH.nt1   % loop on triangles
		for ia = 1:3     % loop on the 3 edges of each triangle
			iap  = mod(ia ,3)+1;
			iapp = mod(iap,3)+1;
			is1  = MESH.t1(iap ,ie);
			is2  = MESH.t1(iapp,ie); 
			if is1 < is2
				edges_normal_sign(ia,ie) = -1;
			else
				edges_normal_sign(ia,ie) = 1;
			end
		end 
	end

	edges_non_unit_normals = zeros(2,MESH.ne1full);
	edges_length = zeros(1,MESH.ne1full);
	for ia =1:MESH.ne1full
		is1 = MESH.e1full(1,ia);
		is2 = MESH.e1full(2,ia);
		if is1 < is2
			edges_non_unit_normals(1,ia) = MESH.p1(2,is1)-MESH.p1(2,is2);
			edges_non_unit_normals(2,ia) = MESH.p1(1,is2)-MESH.p1(1,is1);
		else
			edges_non_unit_normals(1,ia) = MESH.p1(2,is2)-MESH.p1(2,is1);
			edges_non_unit_normals(2,ia) = MESH.p1(1,is1)-MESH.p1(1,is2);
		end        
		edges_length(ia) = sqrt(edges_non_unit_normals(1,ia)^2+edges_non_unit_normals(2,ia)^2);
	end

end
back to top