Home > matGeom > polygons2d > steinerPoint.m

steinerPoint

PURPOSE ^

STEINERPOINT Compute steiner point (weighted centroid) of a polygon.

SYNOPSIS ^

function pt = steinerPoint(varargin)

DESCRIPTION ^

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 % E-mail: david.legland@inrae.fr
0018 % Created: 2004-11-11
0019 % Copyright 2004-2024 INRA - TPV URPOI - BIA IMASTE
0020 
0021 if nargin==1
0022     var = varargin{1};
0023     px = var(:,1);
0024     py = var(:,2);
0025 elseif nargin==2
0026     px = varargin{1};
0027     py = varargin{2};
0028 end
0029 
0030 % Algorithme P. Bourke
0031 sx = 0;
0032 sy = 0;
0033 N = length(px);
0034 for i=1:N-1
0035     sx = sx + (px(i)+px(i+1))*(px(i)*py(i+1) - px(i+1)*py(i));
0036     sy = sy + (py(i)+py(i+1))*(px(i)*py(i+1) - px(i+1)*py(i));
0037 end
0038 sx = sx + (px(N)+px(1))*(px(N)*py(1) - px(1)*py(N));
0039 sy = sy + (py(N)+py(1))*(px(N)*py(1) - px(1)*py(N));
0040 
0041 pt = [sx sy]/6/polygonArea(px, py);

Generated on Thu 21-Nov-2024 11:30:22 by m2html © 2003-2022