File Exchange

image thumbnail

polygeom.m

version 1.4.0.0 (54.1 KB) by H.J. Sommer
POLYGEOM computes area, centroid location, area moments of inertia and perimeter of closed polygons.

34 Downloads

Updated 09 Dec 2016

View License

POLYGEOM computes area, centroid location, area moments of inertia and perimeter of closed polygons.
This function is useful for bending/torsion stress analyses, area centroids of models for wind tunnel testing, rotational inertia for dynamics and blob analysis for image processing.

Comments and Ratings (37)

Hongbo Zhao

Thank you for this code.
I was wondering if the angles of the principal inertia moments could be state in counterclockwise format, starting at positive X axis direction (from 0 to 180º). If you want this, just add the following code below line 91 of polygeom.m:
%
ang1 = ang1+(ang1 < 0)*pi;
ang2 = ang2+(ang2 < 0)*pi;
%

Ryan Baxley

Ajay Goyal

Function polygeom.
Helpe me please the units are in [m] or [cm].

Wonderfully well written code! I do have a few general questions though. Why take the mean of the coordinate points? The comment says it improves accuracy, but how exactly? Also, most theoretical area approximations used integrals. How do the summations suffice for these integrals? Just curious.

Ali Torabi

points have to be in neighbouring/sequential. cannot be in random order. use convhull() if in random order.

Trevor W

lufei

lufei

very good

sue142857

Thank you so much! It works very fine. I learned about new commands. I would like to know about the references for the Ixx Iyy formulas. Here is a more simple formula in Steger's paper. I'm not sure why the area(a) is in denominator but despite this value it is the same result.

Take a look in formula 36 at http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.29.8765&rep=rep1&type=pdf

Here is a the same example

clear; clc;
x = [ 2.000 0.500 4.830 6.330 ]';
y = [ 4.000 6.598 9.098 6.500 ]';

[ x, ns ] = shiftdim( x );
[ y, ns ] = shiftdim( y );
[ n, c ] = size( x );

xime1 = x([n 1:n-1]);
yime1 = y([n 1:n-1]);

a = 1/2*sum(xime1.*y-x.*yime1);
Ixx = 1/12*sum((yime1.^2+yime1.*y+y.^2).*(xime1.*y-x.*yime1));
Iyy = 1/12*sum((xime1.^2+xime1.*x+x.^2).*(xime1.*y-x.*yime1));
if (a<0) a=-a; Ixx=-Ixx; Iyy=-Iyy; end

Does it also work for an arbitrarily shaped form?

charlie

Excellent program.

Question: Is J = Iuu + Ivv valid only for circular cross sections?

Excellent function, a real time saver

Raghuram, the correct answer is given if you reorder your vertices so they are given clockwise around the outside of the polygon, rather than just specified randomly, e.g,

% Your vertices
% x = [1.0000 0.5000 0.8333 0.5694];
% y = [1.0000 0.1667 0.5000 0.5694] ;

% reordered moving clockwise around the polygon from (0.5, 0.1667)

xy = [0.5, 0.1667;
0.8333, 0.5;
1, 1;
0.5694, 0.5694; ];

x = xy(:,1);
y = xy(:,2);

for i = 1:numel(x)-1
line(x(i:i+1), y(i:i+1), [0,0], 'Color', 'b');
hold on
end

line([x(end), x(1)], [y(end), y(1)], [0,0], 'Color', 'b');

[ geom, iner, cpmo ] = polygeom( x, y )

plot(geom(2), geom(3), '+r')

hold off

Raghuram

The outputs are erroneous for the following input:
x = [1.0000 0.5000 0.8333 0.5694]
y = [1.0000 0.1667 0.5000 0.5694]
The centroid is computed as (0.8801,1.1496) which is outside the parallelogram formed by the input points.

This prog is wonderful, just what I needed. If you have time please improve it to handle the third dimension!!

Xu

Xu

Can't download ZIP instead of m file only?

Alice Huang

Pooya S

Nice package

Jim Price

Yes, yes, yes --- this is an extremely useful and well-done script. Should be a part of the regular Matlab so that users can most easily find it. Thank You!!

Alfonso Rojas

Very useful program, clean and well-commented code. Tried it with Matlab
v 7.0.1 (R14), and it works fine. Excellent.

Chinmay Pangarkar

Super!!! I get all geometry of my arbitrary cells using this code. Thank you H.J. Sommer!!

Thor I. Fossen

Excellent program. Should be standard in Matlab. I have used it compute the centroids for wind and current projected areas as welll as other things:)

Finlay Scott

Very useful for getting the perimeter of cyclic predator-prey ecological systems

Elvis Dieguez

Excellent program! Saved me lots of time trying to calculate the area surveyed by a moving wheeled sensor system.

Updates

1.4.0.0

16.12.09

1.3.0.0

Documentation updated 16.12.09

1.2.0.0

derivation and test routine added to ZIP on 08.11.30

1.0.0.0

ZIP includes boundary integral equations and how to handle holes.

Provides positive area for CW or CCW vertex sequence.

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags