function H = gui_comp_h_tet4( id, ix, x)
% H = gui_comp_h_tet4( id, ix, x)
%-----------------------------------------------------------
% compute the heights for the nodes of selected elements
% WZ. Shan, 23/01/09
%-----------------------------------------------------------
% input:
% ix : elem. con. mat. [p1, p2, p3, p4]
% id : indices of selected elements
% nel : number of elements
% x : nodal coordinates, [x, y, z]
% output:
% H : heights [h1, h2, h3, h4]
ix1 = ix( id, :)';
p1 = [2 1 1 1];
p2 = [3 3 2 2];
p3 = [4 4 4 3];
id1 = ix1( p1, :);
id2 = ix1( p2, :);
id3 = ix1( p3, :);
id1 = id1(:);
id2 = id2(:);
id3 = id3(:);
vec1 = x( id2, :) - x( id1, :);
vec2 = x( id3, :) - x( id1, :);
% normals
N = cross( vec1, vec2, 2);
Nnorm = sqrt(N(:, 1).^2 + N(:, 2).^2 + N( :, 3).^2);
N = N./repmat( Nnorm, 1, 3);
% mid point distance
mid = (x( id1, :) + x( id2, :) + x( id3, :))/3;
dmid = x( ix1(:), :) - mid;
% heights
H = abs(dot( N, dmid, 2));
% reshape
H = reshape( H, 4, length(id))';