Raw File
correct_orientation_triangles.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[newt] = correct_orientation_triangles(p, oldt)

	% INPUT
	% p			List of P1 nodes
	% oldt		List of P1 triangles to be corrected
	%
	% OUTPUT
	% newt		List of P1 triangles with corrected orientation

	newt = oldt;
	nt = size(newt,2);
	for i=1:nt
		v1 = p(:,oldt(1,i));
		v2 = p(:,oldt(2,i));
		v3 = p(:,oldt(3,i));
		dett = v1(1)*v2(2)-v2(1)*v1(2) + v2(1)*v3(2)-v3(1)*v2(2) + v3(1)*v1(2)-v1(1)*v3(2);
		if (dett < 0.)
			newt(1,i) = oldt(2,i);
			newt(2,i) = oldt(1,i);
			fprintf('Needed to correct the orientation of triangle %d\n', i);
		end
	end

end
back to top