moveBndToCenterOfMass

PURPOSE ^

correct boundary so that the origin is the center of mass

SYNOPSIS ^

function bnd = moveBndToCenterOfMass(bnd)

DESCRIPTION ^

 correct boundary so that the origin is the center of mass

 this operation assumes that the origin is in the polytope (no negative
   point distances).

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function bnd = moveBndToCenterOfMass(bnd)
0002 % correct boundary so that the origin is the center of mass
0003 %
0004 % this operation assumes that the origin is in the polytope (no negative
0005 %   point distances).
0006 
0007 % The elk-library: convex geometry applied to crystallization modeling.
0008 %   Copyright (C) 2013 Alexander Reinhold
0009 %
0010 % This program is free software: you can redistribute it and/or modify it
0011 %   under the terms of the GNU General Public License as published by the
0012 %   Free Software Foundation, either version 3 of the License, or (at your
0013 %   option) any later version.
0014 %
0015 % This program is distributed in the hope that it will be useful, but
0016 %   WITHOUT ANY WARRANTY; without even the implied warranty of
0017 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0018 %   General Public License for more details.
0019 %
0020 % You should have received a copy of the GNU General Public License along
0021 %   with this program.  If not, see <http://www.gnu.org/licenses/>.
0022 
0023 % the center of each circle section:
0024 circleSectionCenterMatrix = 0.5*computeNormalFromAngle(bnd.polarAngle).*...
0025     [bnd.polarDistance;bnd.polarDistance];
0026 % the area of each circle section:
0027 circleSectionAreaVector = (bnd.polarDistance.^2.*bnd.polarBinSize)/2;
0028 % center weighted by section area, summed up and divided by total area:
0029 massCenter = sum(circleSectionCenterMatrix .* ...
0030     [circleSectionAreaVector; circleSectionAreaVector], 2) / ...
0031     sum(circleSectionAreaVector);
0032 % massCenter = massCenter + [5;0];
0033 
0034 % correct bnd
0035 newCart = bsxfun(@plus, [bnd.cartX; bnd.cartY], -1*massCenter);
0036 bnd.cartX = newCart(1,:);
0037 bnd.cartY = newCart(2,:);
0038 bnd.centerPointOriginal = bnd.centerPointOriginal - 1*massCenter;
0039 bnd.centerPointMean = -1*massCenter;
0040 % create polar data
0041 [bnd.polarAngle bnd.polarDistance] = convertCartToPolar(...
0042     bnd.cartX, bnd.cartY);
0043 % sort data
0044 [bnd.polarAngle bnd.polarDistance, permutationVector] = ...
0045     standardizePolar(bnd.polarAngle, bnd.polarDistance);
0046 bnd.cartX = bnd.cartX(permutationVector);
0047 bnd.cartY = bnd.cartY(permutationVector);
0048

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