Code covered by the BSD License  

Highlights from
3D Crouzeix-Raviart mortar finite element method

image thumbnail
from 3D Crouzeix-Raviart mortar finite element method by Jan Valdman
Implementation of 3D Crouzeix-Raviart mortar finite element

[x_center, y_center, area]=center_polygon(x,y)
function [x_center, y_center, area]=center_polygon(x,y)
x=[x; x(1)]; %closing up the polygon
y=[y; y(1)];

area=0;
x_center=0;
y_center=0;
for i=1:size(x,1)-1
    area=area+x(i)*y(i+1)-x(i+1)*y(i);
    x_center=x_center+(x(i)+x(i+1))*(x(i)*y(i+1)-x(i+1)*y(i));
    y_center=y_center+(y(i)+y(i+1))*(x(i)*y(i+1)-x(i+1)*y(i));    
end
area=area/2;    %this area can be negative, do not make it abs value, otherwise the center point is not correct!
x_center=x_center/area/6;
y_center=y_center/area/6;
area=abs(area);

Contact us at files@mathworks.com