function [meshelenew] = rghthand(meshele,meshnod)
% meshelenew = rghthand(meshele,meshnod);
% This cleans up the meshele to make sure that all triangles
% are specified by the right hand rule.
% It also removes degenerate elements with only two or one
% distinct nodes. (or three colinear points)
disp(['rghthand: FAST Right Hand check on the mesh element matrix'])

XY = meshnod(:,2) + i*meshnod(:,3);
V1 = XY(meshele(:,2))-XY(meshele(:,3));
V2 = XY(meshele(:,3))-XY(meshele(:,4));
hand = imag(V1.*conj(V2));
% negative is righthanded, positive is lefthanded
lefth = find(hand>0);
meshele(lefth,3:4) = meshele(lefth,4:-1:3);

% eliminate the degenerate ones
good = find(abs(hand)>0.000001);

meshelenew = meshele(good,:);
meshelenew(:,1) = [1:length(good)]';

