%function [area]=triproperties(p,t)
%
%  area is the area of the triangle(s)
%
%function [area,w0,wx,wy]=triproperties(p,t)
%
%  The canonical area coordinates w of point [x,y] are given by  
%
%    w = (w0 + x * wx +y * wy)/area
%
%  If cp contain the coordinates of the vertices, then [x,y]=cp*w.
%
%  Further if Grad_x(u) is a 1x3 vector
%    <Grad_x(u),Grad_x(v)> 
%    = < Grad_w(u)*[wx,wy] , Grad_w(v)*[wx,wy] > / area^2
%    = Grad_w(u)*[wx,wy]*[wx,wy]'*Grad_w(v)'  / area^2
%    
%
%  (c) j.v.pfaler, May 1st, 1997 


function [area,w0,wx,wy]=triproperties(p,t)

 
k = size(t,2); 
if k==0, area=[];w0=[];wx=[];wy=[];return; end 

p2 = p(:,t([2,3,1],:));	  % starting points of opposite side
p3 = p(:,t([3,1,2],:));	  % ending points of opposite side

     % note that for each triangle there are three vertices. 

w0 = reshape( -p3(1,:).*p2(2,:) + p3(2,:).*p2(1,:) ,3,k) ; 
area = sum(w0); 

if nargout > 1, 
 % dw = reshape( [-y(j),x(j)]*(p2-p3) ,6,k)
 wx = reshape( p2(2,:)-p3(2,:) ,3,k) ;
 wy = reshape(-p2(1,:)+p3(1,:) ,3,k) ;
end





  




