Matlab functions    from  BioméCardio    

 
   otsu
polydeg   

polycenter

Area and centroid of polygon

Contents

Download

polycenter.m

Syntax

   [A,Cx,Cy] = polycenter(x,y)
   [A,Cx,Cy] = polycenter(x,y,dim)

Description

[area,Cx,Cy] = polycenter(x,y) returns the area and the centroid coordinates of the polygon specified by the vertices in the vectors x and y. If x and y are matrices of the same size, then polycenter returns the centroid and area of polygons defined by the columns x and y. If x and y are arrays, polycenter returns the centroid and area of the polygons in the first non-singleton dimension of x and y.

polycenter is an extended version of polyarea.

The polygon edges must not intersect. If they do, polycenter returns the values of the difference between the clockwise encircled parts and the counterclockwise ones. As with polyarea, the absolute value is used for the area.

[area,Cx,Cy] = polycenter(x,y,dim) returns the centroid and area of the polygons specified by the vertices in the dimension dim.

Example

Create a pentagon and determine its area and center:

x0 = rand(1); y0 = rand(1);
L = linspace(0,2.*pi,6);
xv = cos(L)' + x0; yv = sin(L)' + y0;
xv = [xv ; xv(1)]; yv = [yv ; yv(1)];
[A,cx,cy] = polycenter(xv,yv);
plot(xv,yv,cx,cy,'k+')
title(['Area = ' num2str(A)]), axis equal

Information

Centroid on Wikipedia

See also

polyarea

About the author

Damien Garcia, Eng., Ph.D.
Assistant professor, Department of radiology
CRCHUM, University of Montreal Hospital
Montreal, QC, Canada
Damien.Garcia.REMOVE-THIS@BiomeCardio.com

www.biomecardio.com