STEINERPOINT Compute steiner point (weighted centroid) of a polygon. PT = steinerPoint(POINTS); PT = steinerPoint(PTX, PTY); Computes steiner point of a polygon defined by POINTS. POINTS is a [N*2] array of double. The steiner point is computed the same way as the polygon centroid, except that a weight depending on the angle is given to each vertex. See also: polygons2d, polygonArea, polygonCentroid, drawPolygon --------- author : David Legland INRA - TPV URPOI - BIA IMASTE created the 11/11/2004.
0001 function pt = steinerPoint(varargin) 0002 %STEINERPOINT Compute steiner point (weighted centroid) of a polygon. 0003 % 0004 % PT = steinerPoint(POINTS); 0005 % PT = steinerPoint(PTX, PTY); 0006 % Computes steiner point of a polygon defined by POINTS. POINTS is a 0007 % [N*2] array of double. 0008 % 0009 % The steiner point is computed the same way as the polygon centroid, 0010 % except that a weight depending on the angle is given to each vertex. 0011 % 0012 % See also: 0013 % polygons2d, polygonArea, polygonCentroid, drawPolygon 0014 % 0015 % --------- 0016 % author : David Legland 0017 % INRA - TPV URPOI - BIA IMASTE 0018 % created the 11/11/2004. 0019 % 0020 0021 0022 if nargin==1 0023 var = varargin{1}; 0024 px = var(:,1); 0025 py = var(:,2); 0026 elseif nargin==2 0027 px = varargin{1}; 0028 py = varargin{2}; 0029 end 0030 0031 % Algorithme P. Bourke 0032 sx = 0; 0033 sy = 0; 0034 N = length(px); 0035 for i=1:N-1 0036 sx = sx + (px(i)+px(i+1))*(px(i)*py(i+1) - px(i+1)*py(i)); 0037 sy = sy + (py(i)+py(i+1))*(px(i)*py(i+1) - px(i+1)*py(i)); 0038 end 0039 sx = sx + (px(N)+px(1))*(px(N)*py(1) - px(1)*py(N)); 0040 sy = sy + (py(N)+py(1))*(px(N)*py(1) - px(1)*py(N)); 0041 0042 pt = [sx sy]/6/polygonArea(px, py);