Home > matGeom > polygons2d > convexification.m

convexification

PURPOSE ^

CONVEXIFICATION Compute the convexification of a polygon.

SYNOPSIS ^

function co = convexification(varargin)

DESCRIPTION ^

CONVEXIFICATION Compute the convexification of a polygon.

   CO = convexification(H)
   Creates convexification from support function. Support function is
   supposed to be uniformly distributed over [0 2pi].

   CO = convexification(POLYGON)
   Computes support function of the polygon, then the corresponding
   convexification.

   CO = convexification(POLYGON, N)
   Uses N points for convexification computation. Note that the number of
   points of CO can be lower than N.
   
   CAUTION: The result will be valid only for convex polygons.

   See also
   polygons2d, supportFunction

 ---------
 author: David Legland
 created the 12/01/2005.
 Copyright 2010 INRA - Cepia Software Platform.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function co = convexification(varargin)
0002 %CONVEXIFICATION Compute the convexification of a polygon.
0003 %
0004 %   CO = convexification(H)
0005 %   Creates convexification from support function. Support function is
0006 %   supposed to be uniformly distributed over [0 2pi].
0007 %
0008 %   CO = convexification(POLYGON)
0009 %   Computes support function of the polygon, then the corresponding
0010 %   convexification.
0011 %
0012 %   CO = convexification(POLYGON, N)
0013 %   Uses N points for convexification computation. Note that the number of
0014 %   points of CO can be lower than N.
0015 %
0016 %   CAUTION: The result will be valid only for convex polygons.
0017 %
0018 %   See also
0019 %   polygons2d, supportFunction
0020 %
0021 % ---------
0022 % author: David Legland
0023 % created the 12/01/2005.
0024 % Copyright 2010 INRA - Cepia Software Platform.
0025 %
0026 
0027 %   HISTORY
0028 %   13/06/2007: clean up code
0029 
0030 if ~isempty(varargin)>0
0031     var = varargin{1};
0032     if size(var, 2)==1
0033         h = var;
0034     else
0035         poly = var;
0036         N = 128;
0037         if length(varargin)>1
0038             N = varargin{2};
0039         end
0040         h = supportFunction(poly, N);
0041     end
0042 else
0043     error('not enough input arguments');
0044 end
0045 
0046 N   = length(h);
0047 u   = (0:2*pi/N:2*pi*(1-1/N))';
0048 v   = [cos(u) sin(u)].*[h h];
0049 
0050 i1  = 1:N;
0051 i2  = [2:N 1];
0052 i3  = [3:N 1 2];
0053 
0054 circ = zeros(N, 4);
0055 for i=1:N
0056     circ(i, 1:4) = createDirectedCircle(v(i1(i),:), v(i2(i),:), v(i3(i), :));
0057 end
0058 
0059 % remove non direct-oriented circles
0060 circ = circ(circ(:,4)==0, :);
0061 
0062 % keep only circles seen several times
0063 dp = diff(circ(:,1:2));
0064 dp = sum(dp.*dp, 2);
0065 ind1 = [1; find(dp<1e-10)+1];
0066 circ = circ(ind1, :);
0067 
0068 % keep only one instance of each circle
0069 dp = diff(circ(:,1:2));
0070 dp = sum(dp.*dp, 2);
0071 ind = [1; find(dp>1e-10)+1];
0072 co = 2*circ(ind, 1:2);
0073 
0074 % eventually remove the last point if it is the same as the first one
0075 if distancePoints(co(1,:), co(end, :))<1e-10 && size(co, 1)>1
0076     co = co(1:end-1,:);
0077 end
0078 
0079

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019