-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathmeshreorient.m
29 lines (27 loc) · 900 Bytes
/
meshreorient.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function [newelem, evol, idx] = meshreorient(node, elem)
%
% [newelem, evol, idx]=meshreorient(node,elem)
%
% reorder nodes in a surface or tetrahedral mesh to ensure all
% elements are oriented consistently
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2010/05/05
%
% input:
% node: list of nodes
% elem: list of elements (each row are indices of nodes of each element)
% idx: indices of the elements there had negative volume
%
% output:
% newelem: the element list with consistent ordering
% evol: the signed element volume before reorientation
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
% calculate the canonical volume of the element (can be a 2D or 3D)
evol = elemvolume(node, elem, 'signed');
% make sure all elements are positive in volume
idx = find(evol < 0);
elem(idx, [end - 1, end]) = elem(idx, [end, end - 1]);
newelem = elem;