addMinkowskiVrep

PURPOSE ^

calculate the Minkowski sum of two polytopes in V-representation

SYNOPSIS ^

function vrepSum = addMinkowskiVrep(vrepOne , vrepTwo, zerotol, reduce)

DESCRIPTION ^

 calculate the Minkowski sum of two polytopes in V-representation

 Syntax: vrepSum = addMinkowskiVrep(vrepOne, vrepTwo)
   or    vrepSum = addMinkowskiVrep(vrepOne, vrepTwo, zerotol)
   or    vrepSum = addMinkowskiVrep(vrepOne, vrepTwo, zerotol, reduce)

 The parameter zerotol applies for scaleVrep only, which is used for
   the reduction to extreme points (see below). Default: see elkZerotol.

 Consider that cddlib applies an additional zerotol that is stored in the 
   function zerotolCddlib during initialization of this library 
   (buildCddlib).
 
 The parameter reduce lets you decide whether the points that are
   generated for the sum are reduced to the set of extreme points. Chosing
   reduce=0 to switch this reduction off may increase performance,
   dependent on subsequent operations, e.g. if you perform a polytope
   conversion afterwards where this reduction happens automatically. 
   Default: 1 (on).

 See also: convertPolytope, obtainPolytope, addMinkowskiPolytope

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vrepSum = addMinkowskiVrep(vrepOne , vrepTwo, zerotol, reduce)
0002 % calculate the Minkowski sum of two polytopes in V-representation
0003 %
0004 % Syntax: vrepSum = addMinkowskiVrep(vrepOne, vrepTwo)
0005 %   or    vrepSum = addMinkowskiVrep(vrepOne, vrepTwo, zerotol)
0006 %   or    vrepSum = addMinkowskiVrep(vrepOne, vrepTwo, zerotol, reduce)
0007 %
0008 % The parameter zerotol applies for scaleVrep only, which is used for
0009 %   the reduction to extreme points (see below). Default: see elkZerotol.
0010 %
0011 % Consider that cddlib applies an additional zerotol that is stored in the
0012 %   function zerotolCddlib during initialization of this library
0013 %   (buildCddlib).
0014 %
0015 % The parameter reduce lets you decide whether the points that are
0016 %   generated for the sum are reduced to the set of extreme points. Chosing
0017 %   reduce=0 to switch this reduction off may increase performance,
0018 %   dependent on subsequent operations, e.g. if you perform a polytope
0019 %   conversion afterwards where this reduction happens automatically.
0020 %   Default: 1 (on).
0021 %
0022 % See also: convertPolytope, obtainPolytope, addMinkowskiPolytope
0023 
0024 % The elk-library: convex geometry applied to crystallization modeling.
0025 %   Copyright (C) 2012 Alexander Reinhold
0026 %
0027 % This program is free software: you can redistribute it and/or modify it
0028 %   under the terms of the GNU General Public License as published by the
0029 %   Free Software Foundation, either version 3 of the License, or (at your
0030 %   option) any later version.
0031 %
0032 % This program is distributed in the hope that it will be useful, but
0033 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0034 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0035 %   General Public License for more details.
0036 %
0037 % You should have received a copy of the GNU General Public License along
0038 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0039 
0040 %% Input handling
0041 if ~exist('zerotol', 'var')
0042     zerotol = elkZerotol;
0043 end
0044 
0045 if ~exist('reduce', 'var')
0046     reduce = 1;
0047 end
0048 
0049 if size(vrepOne.V, 2) ~= size(vrepTwo.V, 2);
0050     error('elk:polytope:wrongType', ...
0051         'both summands must have the same dimension');
0052 end
0053 
0054 %% Determine some sizes
0055 mOne = size(vrepOne.V, 1);
0056 mTwo = size(vrepTwo.V, 1);
0057 dim = size(vrepOne.V, 2);
0058 mResult = mOne*mTwo;
0059 
0060 %% Construct a matrix filled repetedly with vrepOne
0061 % This vector already has the size of the non-reduced result.
0062 vrepSum.V = zeros(mOne * mTwo, dim);
0063 for iRow = 1:mTwo
0064     vrepSum.V((1:mOne) + (iRow-1)*mOne,:) = vrepOne.V;
0065 end
0066 
0067 %% Add vrepTwo
0068 for iRow = 1:mOne
0069     mThisRowVector = (1:mOne:mResult) + (iRow-1);
0070     vrepSum.V(mThisRowVector,:) = vrepSum.V(mThisRowVector,:) + vrepTwo.V;
0071 end
0072 
0073 %% Calculate convex hull and eliminate unused points
0074 if reduce
0075     [vrepSum, scale, x0] = scaleVrep(vrepSum, zerotol);
0076     vrepSum = reduceVrep(vrepSum);
0077     vrepSum = stretchVrep(vrepSum, scale);
0078     vrepSum = moveVrep(vrepSum, x0);
0079 end

Generated on Sat 18-Jul-2015 16:45:31 by m2html © 2005