POLYGONSECONDAREAMOMENTS Compute second-order area moments of a polygon. [IXX, IYY, IXY] = polygonSecondAreaMoments(POLY) Compute the second-order inertia moments of a polygon. The polygon is specified by the N-by-2 list of vertex coordinates. Example polygonSecondAreaMoments References * http://paulbourke.net/geometry/polygonmesh/ * https://en.wikipedia.org/wiki/Second_moment_of_area See also polygons2d, polygonEquivalentEllipse, polygonArea, polygonCentroid
0001 function [Ixx, Iyy, Ixy] = polygonSecondAreaMoments(poly) 0002 %POLYGONSECONDAREAMOMENTS Compute second-order area moments of a polygon. 0003 % 0004 % [IXX, IYY, IXY] = polygonSecondAreaMoments(POLY) 0005 % Compute the second-order inertia moments of a polygon. The polygon is 0006 % specified by the N-by-2 list of vertex coordinates. 0007 % 0008 % Example 0009 % polygonSecondAreaMoments 0010 % 0011 % References 0012 % * http://paulbourke.net/geometry/polygonmesh/ 0013 % * https://en.wikipedia.org/wiki/Second_moment_of_area 0014 % 0015 % See also 0016 % polygons2d, polygonEquivalentEllipse, polygonArea, polygonCentroid 0017 0018 % ------ 0019 % Author: David Legland 0020 % e-mail: david.legland@inra.fr 0021 % Created: 2017-09-08, using Matlab 9.1.0.441655 (R2016b) 0022 % Copyright 2017 INRA - Cepia Software Platform. 0023 0024 % get vertex coordinates, and recenter polygon 0025 centroid = polygonCentroid(poly); 0026 px = poly(:,1) - centroid(1); 0027 py = poly(:,2) - centroid(2); 0028 0029 % vertex indices 0030 N = length(px); 0031 iNext = [2:N 1]; 0032 0033 % compute twice signed area of each triangle 0034 common = px .* py(iNext) - px(iNext) .* py; 0035 0036 % compute each term 0037 Ixx = sum( (py.^2 + py .* py(iNext) + py(iNext).^2) .* common) / 12; 0038 Iyy = sum( (px.^2 + px .* px(iNext) + px(iNext).^2) .* common) / 12; 0039 Ixy = sum( ... 0040 (px .* py(iNext) + 2 * px .* py + 2 * px(iNext) .* py(iNext) ... 0041 + px(iNext) .* py ) .* common) / 24;