scaleVrep

PURPOSE ^

scale polytope to reasonable size and position

SYNOPSIS ^

function [vrep, scale, x0] = scaleVrep(vrep, zerotol, flagIsometric)

DESCRIPTION ^

 scale polytope to reasonable size and position

 Syntax: [vrep, scale, x0] = scaleVrep(vrep)
   or    [vrep, scale, x0] = scaleVrep(vrep, zerotol)

 The bounding box of the polytope is calculated. The polytope is then 
   first moved and secondly stretched so that the bounding box of this
   polytop equals the cube [-1, 1]^n. In a second step the polytope is
   moved so that the mean fits the origin.

 Stretching values become large, when a polytope is flat and well aligned 
   with one of the coordinate axes. Zerotol relates to the flatness a
   polytope can have before stretching in that direction is disabled.
   Default: see elkZerotol.

 With scaleVrep(.., flagIsometric), the polytope can be scaled
   isometrically (equally in all dimensions). This is usually required for
   measure calculations. Default: 0

 The polytope is scaled back to original by:
   originalVrep = stretchVrep(scaledVrep, scale);
   originalVrep = moveVrep(originalVrep, x0);

 See also: convertVrepToHrep, scaleHrep, reduceVrepDimension, reduceVrep

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [vrep, scale, x0] = scaleVrep(vrep, zerotol, flagIsometric)
0002 % scale polytope to reasonable size and position
0003 %
0004 % Syntax: [vrep, scale, x0] = scaleVrep(vrep)
0005 %   or    [vrep, scale, x0] = scaleVrep(vrep, zerotol)
0006 %
0007 % The bounding box of the polytope is calculated. The polytope is then
0008 %   first moved and secondly stretched so that the bounding box of this
0009 %   polytop equals the cube [-1, 1]^n. In a second step the polytope is
0010 %   moved so that the mean fits the origin.
0011 %
0012 % Stretching values become large, when a polytope is flat and well aligned
0013 %   with one of the coordinate axes. Zerotol relates to the flatness a
0014 %   polytope can have before stretching in that direction is disabled.
0015 %   Default: see elkZerotol.
0016 %
0017 % With scaleVrep(.., flagIsometric), the polytope can be scaled
0018 %   isometrically (equally in all dimensions). This is usually required for
0019 %   measure calculations. Default: 0
0020 %
0021 % The polytope is scaled back to original by:
0022 %   originalVrep = stretchVrep(scaledVrep, scale);
0023 %   originalVrep = moveVrep(originalVrep, x0);
0024 %
0025 % See also: convertVrepToHrep, scaleHrep, reduceVrepDimension, reduceVrep
0026 
0027 % The elk-library: convex geometry applied to crystallization modeling.
0028 %   Copyright (C) 2012 Alexander Reinhold
0029 %
0030 % This program is free software: you can redistribute it and/or modify it
0031 %   under the terms of the GNU General Public License as published by the
0032 %   Free Software Foundation, either version 3 of the License, or (at your
0033 %   option) any later version.
0034 %
0035 % This program is distributed in the hope that it will be useful, but
0036 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0037 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0038 %   General Public License for more details.
0039 %
0040 % You should have received a copy of the GNU General Public License along
0041 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0042 
0043 %% Input
0044 if ~exist('zerotol', 'var') || isempty(zerotol)
0045     zerotol = elkZerotol;
0046 end
0047 if ~exist('flagIsometric', 'var')
0048     flagIsometric = 0;
0049 end
0050 if isempty(vrep.V)
0051     scale = 1;
0052     x0 = ones(size(vrep.V, 2), 1);
0053     return
0054 end
0055 
0056 %% Gather bounding box
0057 dim = size(vrep.V, 2);
0058 minPos = ones(1, dim);
0059 maxPos = ones(1, dim);
0060 for iDim = 1:dim
0061     minPos(iDim) = min(vrep.V(:, iDim));
0062     maxPos(iDim) = max(vrep.V(:, iDim));
0063 end
0064 
0065 %% Determine scaling coefficients
0066 if flagIsometric
0067     % the center of the bounding box
0068     x0 = (maxPos + minPos)/2;
0069     % the size of the bounding box (but as it is scaled to the box [-1, 1]^dim
0070     %   the scaling factor is only half of the original size
0071     scale = 0.5*(maxPos - minPos);
0072     scale = max(scale);
0073 else
0074     % the center of the bounding box
0075     x0 = mean(vrep.V, 1);
0076     % the size of the bounding box (but as it is scaled to the box [-1, 1]^dim
0077     %   the scaling factor is only half of the original size
0078     scale = 0.5*(maxPos - minPos);
0079     scale(abs(scale) < 0.5*zerotol) = 1;
0080 end
0081 %% Scale polytope
0082 vrep = moveVrep(vrep, -1*x0);
0083 vrep = stretchVrep(vrep, 1./scale, zeros(1, dim));

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