From: <jpi...@us...> - 2011-10-09 18:09:15
|
Revision: 8719 http://octave.svn.sourceforge.net/octave/?rev=8719&view=rev Author: jpicarbajal Date: 2011-10-09 18:09:08 +0000 (Sun, 09 Oct 2011) Log Message: ----------- geometry. Adding points2d Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/centroid.m trunk/octave-forge/main/geometry/geom2d/inst/distancePoints.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCentroid.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDistancePoints.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/centroid.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePoints.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-09 17:01:50 UTC (rev 8718) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-09 18:09:08 UTC (rev 8719) @@ -82,5 +82,8 @@ createTranslation.m transformPoint.m transforms2d.m + fitAffineTransform2d.m + transformEdge.m + transformLine.m =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/centroid.m (from rev 8716, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/centroid.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/centroid.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/centroid.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -0,0 +1,129 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{c} = } centroid (@var{points}) +%% @deftypefnx {Function File} {@var{c} = } centroid (@var{px}, @var{py}) +%% @deftypefnx {Function File} {@var{c} = } centroid (@dots{}, @var{mass}) +%% Compute centroid (center of mass) of a set of points. +%% +%% Computes the ND-dimensional centroid of a set of points. +%% @{points} is an array with as many rows as the number of points, and as +%% many columns as the number of dimensions. +%% @{px} and @{py} are two column vectors containing coordinates of the +%% 2-dimensional points. +%% The result @var{c} is a row vector with ND columns. +%% +%% If @var{mass} is given, computes center of mass of @var{points}, weighted by coefficient @var{mass}. +%% @var{points} is a Np-by-Nd array, @var{mass} is Np-by-1 array, and @var{px} and @var{py} are +%% also both Np-by-1 arrays. +%% +%% Example: +%% +%% @example +%% pts = [2 2;6 1;6 5;2 4]; +%% centroid(pts) +%% ans = +%% 4 3 +%%@end example +%% +%% @seealso{points2d, polygonCentroid} +%% @end deftypefn + +function center = centroid(varargin) + + %% extract input arguments + + % use empty mass by default + mass = []; + + if nargin==1 + % give only array of points + pts = varargin{1}; + + elseif nargin==2 + % either POINTS+MASS or PX+PY + var = varargin{1}; + if size(var, 2)>1 + % arguments are POINTS, and MASS + pts = var; + mass = varargin{2}; + else + % arguments are PX and PY + pts = [var varargin{2}]; + end + + elseif nargin==3 + % arguments are PX, PY, and MASS + pts = [varargin{1} varargin{2}]; + mass = varargin{3}; + end + + %% compute centroid + + if isempty(mass) + % no weight + center = mean(pts); + + else + % format mass to have sum equal to 1, and column format + mass = mass(:)/sum(mass(:)); + + % compute weighted centroid + center = sum(bsxfun(@times, pts, mass), 1); + % equivalent to: + % center = sum(pts .* mass(:, ones(1, size(pts, 2)))); + end + +endfunction + +%!test +%! points = [0 0;10 0;10 10;0 10]; +%! centro = centroid(points); +%! assert ([5 5], centro, 1e-6); + +%!test +%! points = [0 0;10 0;10 10;0 10]; +%! centro = centroid(points(:,1), points(:,2)); +%! assert ([5 5], centro, 1e-6); + +%!test +%! points = [0 0;30 0;30 30;0 30]; +%! centro = centroid(points, [1;1;1;3]); +%! assert ([10 20], centro, 1e-6); + +%!test +%! points = [0 0;30 0;30 30;0 30]; +%! centro = centroid(points(:,1), points(:,2), [1;1;1;3]); +%! assert ([10 20], centro, 1e-6); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/distancePoints.m (from rev 8716, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePoints.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/distancePoints.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/distancePoints.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -0,0 +1,204 @@ +%% Copyright (c) 2011, INRA +%% 2004-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{d} = } distancePoints (@var{p1}, @var{p2}) +%% @deftypefnx {Function File} {@var{d} = } distancePoints (@var{p1}, @var{p2}, @var{norm}) +%% @deftypefnx {Function File} {@var{d} = } distancePoints (@dots{}, 'diag') +%% Compute distance between two points. +%% +%% Returns the Euclidean distance between points @var{p1} and @var{p2}. +%% If @var{p1} and @var{p2} are two arrays of points, result is a N1xN2 array +%% containing distance between each point of @var{p1} and each point of @var{p2}. +%% +%% Is @var{norm} is given, computes distance using the specified norm. @var{norm}=2 corresponds to usual +%% euclidean distance, @var{norm}=1 corresponds to Manhattan distance, @var{norm}=inf +%% is assumed to correspond to maximum difference in coordinate. Other +%% values (>0) can be specified. +%% +%% When 'diag' is given, computes only distances between @var{p1}(i,:) and @var{p2}(i,:). +%% +%% @seealso{points2d, minDistancePoints} +%% @end deftypefn + +function dist = distancePoints(p1, p2, varargin) + + %% Setup options + + % default values + diag = false; + norm = 2; + + % check first argument: norm or diag + if ~isempty(varargin) + var = varargin{1}; + if isnumeric(var) + norm = var; + elseif strncmp('diag', var, 4) + diag = true; + end + varargin(1) = []; + end + + % check last argument: diag + if ~isempty(varargin) + var = varargin{1}; + if strncmp('diag', var, 4) + diag = true; + end + end + + + % number of points in each array and their dimension + n1 = size(p1, 1); + n2 = size(p2, 1); + d = size(p1, 2); + + if diag + % compute distance only for apparied couples of pixels + dist = zeros(n1, 1); + if norm==2 + % Compute euclidian distance. this is the default case + % Compute difference of coordinate for each pair of point + % and for each dimension. -> dist is a [n1*n2] array. + for i=1:d + dist = dist + (p2(:,i)-p1(:,i)).^2; + end + dist = sqrt(dist); + elseif norm==inf + % infinite norm corresponds to maximal difference of coordinate + for i=1:d + dist = max(dist, abs(p2(:,i)-p1(:,i))); + end + else + % compute distance using the specified norm. + for i=1:d + dist = dist + power((abs(p2(:,i)-p1(:,i))), norm); + end + dist = power(dist, 1/norm); + end + else + % compute distance for all couples of pixels + dist = zeros(n1, n2); + if norm==2 + % Compute euclidian distance. this is the default case + % Compute difference of coordinate for each pair of point + % and for each dimension. -> dist is a [n1*n2] array. + for i=1:d + % equivalent to: + % dist = dist + ... + % (repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1])).^2; + dist = dist + (p1(:, i*ones(1, n2))-p2(:, i*ones(n1, 1))').^2; + end + dist = sqrt(dist); + elseif norm==inf + % infinite norm corresponds to maximal difference of coordinate + for i=1:d + dist = max(dist, abs(p1(:, i*ones(1, n2))-p2(:, i*ones(n1, 1))')); + end + else + % compute distance using the specified norm. + for i=1:d + % equivalent to: + % dist = dist + power((abs(repmat(p1(:,i), [1 n2]) - ... + % repmat(p2(:,i)', [n1 1]))), norm); + dist = dist + power((abs(p1(:, i*ones(1, n2))-p2(:, i*ones(n1, 1))')), norm); + end + dist = power(dist, 1/norm); + end + end + +endfunction + +%!shared pt1,pt2,pt3,pt4 +%! pt1 = [10 10]; +%! pt2 = [10 20]; +%! pt3 = [20 20]; +%! pt4 = [20 10]; + +%!assert (distancePoints(pt1, pt2), 10, 1e-6); +%!assert (distancePoints(pt2, pt3), 10, 1e-6); +%!assert (distancePoints(pt1, pt3), 10*sqrt(2), 1e-6); +%!assert (distancePoints(pt1, pt2, 1), 10, 1e-6); +%!assert (distancePoints(pt2, pt3, 1), 10, 1e-6); +%!assert (distancePoints(pt1, pt3, 1), 20, 1e-6); +%!assert (distancePoints(pt1, pt2, inf), 10, 1e-6); +%!assert (distancePoints(pt2, pt3, inf), 10, 1e-6); +%!assert (distancePoints(pt1, pt3, inf), 10, 1e-6); +%!assert (distancePoints(pt1, [pt1; pt2; pt3]), [0 10 10*sqrt(2)], 1e-6); + +%!test +%! array1 = [pt1;pt2;pt3]; +%! array2 = [pt1;pt2;pt3;pt4]; +%! res = [0 10 10*sqrt(2) 10; 10 0 10 10*sqrt(2); 10*sqrt(2) 10 0 10]; +%! assert (distancePoints(array1, array2), res, 1e-6); +%! assert (distancePoints(array2, array2, 'diag'), [0;0;0;0], 1e-6); + +%!test +%! array1 = [pt1;pt2;pt3]; +%! array2 = [pt2;pt3;pt1]; +%! assert (distancePoints(array1, array2, inf, 'diag'), [10;10;10], 1e-6); + +%!shared pt1,pt2,pt3,pt4 +%! pt1 = [10 10 10]; +%! pt2 = [10 20 10]; +%! pt3 = [20 20 10]; +%! pt4 = [20 20 20]; + +%!assert (distancePoints(pt1, pt2), 10, 1e-6); +%!assert (distancePoints(pt2, pt3), 10, 1e-6); +%!assert (distancePoints(pt1, pt3), 10*sqrt(2), 1e-6); +%!assert (distancePoints(pt1, pt4), 10*sqrt(3), 1e-6); +%!assert (distancePoints(pt1, pt2, inf), 10, 1e-6); +%!assert (distancePoints(pt2, pt3, inf), 10, 1e-6); +%!assert (distancePoints(pt1, pt3, inf), 10, 1e-6); +%!assert (distancePoints(pt1, pt4, inf), 10, 1e-6); + + +%!shared pt1,pt2,pt3,pt4 +%! pt1 = [10 10 30]; +%! pt2 = [10 20 30]; +%! pt3 = [20 20 30]; +%! pt4 = [20 20 40]; + +%!assert (distancePoints(pt1, pt2, 1), 10, 1e-6); +%!assert (distancePoints(pt2, pt3, 1), 10, 1e-6); +%!assert (distancePoints(pt1, pt3, 1), 20, 1e-6); +%!assert (distancePoints(pt1, pt4, 1), 30, 1e-6); + +%!test +%! array1 = [pt1;pt2;pt3]; +%! array2 = [pt2;pt3;pt1]; +%! assert (distancePoints(array1, array2, 'diag'), [10;10;10*sqrt(2)], 1e-6); +%! assert (distancePoints(array1, array2, 1, 'diag'), [10;10;20], 1e-6); + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCentroid.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCentroid.m 2011-10-09 17:01:50 UTC (rev 8718) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCentroid.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -1,47 +0,0 @@ -function test_suite = testCentroid(varargin) -%TESTCLIPLINE One-line description here, please. -% output = testCentroid(input) -% -% Example -% testCentroid -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -initTestSuite; - -function testSquareCentroid -% Centroid of 4 points - -points = [0 0;10 0;10 10;0 10]; -centro = centroid(points); -assertElementsAlmostEqual([5 5], centro); - -function testSquareCentroidSeparateCoords -% Centroid of 4 points - -points = [0 0;10 0;10 10;0 10]; -centro = centroid(points(:,1), points(:,2)); -assertElementsAlmostEqual([5 5], centro); - -function testSquareWeightedCentroid -% Centroid of 4 points - -points = [0 0;30 0;30 30;0 30]; -centro = centroid(points, [1;1;1;3]); -assertElementsAlmostEqual([10 20], centro); - - -function testSquareWeightedCentroidSeparateCoords -% Centroid of 4 points - -points = [0 0;30 0;30 30;0 30]; -centro = centroid(points(:,1), points(:,2), [1;1;1;3]); -assertElementsAlmostEqual([10 20], centro); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDistancePoints.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDistancePoints.m 2011-10-09 17:01:50 UTC (rev 8718) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDistancePoints.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -1,165 +0,0 @@ -function test_suite = testDistancePoints(varargin) %#ok<STOUT> -%TESTDISTANCEPOINTS One-line description here, please. -% output = testDistancePoints(input) -% -% Example -% testDistancePoints -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. -% Licensed under the terms of the LGPL, see the file "license.txt" - -initTestSuite; - -function testSingleSingle %#ok<*DEFNU> - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; - -assertElementsAlmostEqual(distancePoints(pt1, pt2), 10); -assertElementsAlmostEqual(distancePoints(pt2, pt3), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt3), 10*sqrt(2)); - -function testSingleSingleNorm1 -% test norm 1, equivalent to sum of absolute differences - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; - -assertElementsAlmostEqual(distancePoints(pt1, pt2, 1), 10); -assertElementsAlmostEqual(distancePoints(pt2, pt3, 1), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt3, 1), 20); - -function testSingleSingleMaxNorm - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; - -assertElementsAlmostEqual(distancePoints(pt1, pt2, inf), 10); -assertElementsAlmostEqual(distancePoints(pt2, pt3, inf), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt3, inf), 10); - -function testSingleSingle3d - -pt1 = [10 10 10]; -pt2 = [10 20 10]; -pt3 = [20 20 10]; -pt4 = [20 20 20]; - -assertElementsAlmostEqual(distancePoints(pt1, pt2), 10); -assertElementsAlmostEqual(distancePoints(pt2, pt3), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt3), 10*sqrt(2)); -assertElementsAlmostEqual(distancePoints(pt1, pt4), 10*sqrt(3)); - - -function testSingleSingle3dNorm1 -% test norm 1, equivalent to sum of absolute differences - -pt1 = [10 10 30]; -pt2 = [10 20 30]; -pt3 = [20 20 30]; -pt4 = [20 20 40]; - -assertElementsAlmostEqual(distancePoints(pt1, pt2, 1), 10); -assertElementsAlmostEqual(distancePoints(pt2, pt3, 1), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt3, 1), 20); -assertElementsAlmostEqual(distancePoints(pt1, pt4, 1), 30); - -function testSingleSingleMaxNorm3d - -pt1 = [10 10 10]; -pt2 = [10 20 10]; -pt3 = [20 20 10]; -pt4 = [20 20 20]; - -assertElementsAlmostEqual(distancePoints(pt1, pt2, inf), 10); -assertElementsAlmostEqual(distancePoints(pt2, pt3, inf), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt3, inf), 10); -assertElementsAlmostEqual(distancePoints(pt1, pt4, inf), 10); - -function testSingleArray - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; - -assertElementsAlmostEqual(... - distancePoints(pt1, [pt1; pt2; pt3]), ... - [0 10 10*sqrt(2)]); - -function testArrayArray - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; -pt4 = [20 10]; - -array1 = [pt1;pt2;pt3]; -array2 = [pt1;pt2;pt3;pt4]; -res = [... - 0 10 10*sqrt(2) 10;... - 10 0 10 10*sqrt(2);... - 10*sqrt(2) 10 0 10]; - -assertElementsAlmostEqual(distancePoints(array1, array2), res); - -function testArrayArrayDiag - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; - -array = [pt1;pt2;pt3]; - -assertElementsAlmostEqual(... - distancePoints(array, array, 'diag'), ... - [0;0;0]); - -function testArrayArray3dDiag - -pt1 = [10 10 30]; -pt2 = [10 20 30]; -pt3 = [10 20 40]; - -array1 = [pt1;pt2;pt3]; -array2 = [pt2;pt3;pt1]; - -assertElementsAlmostEqual(... - distancePoints(array1, array2, 'diag'), ... - [10;10;10*sqrt(2)]); - -function testArrayArray3dNorm1Diag - -pt1 = [10 10 30]; -pt2 = [10 20 30]; -pt3 = [10 20 40]; - -array1 = [pt1;pt2;pt3]; -array2 = [pt2;pt3;pt1]; - -assertElementsAlmostEqual(... - distancePoints(array1, array2, 1, 'diag'), ... - [10;10;20]); - - -function testArrayArrayDiagMaxNorm - -pt1 = [10 10]; -pt2 = [10 20]; -pt3 = [20 20]; - -array1 = [pt1;pt2;pt3]; -array2 = [pt2;pt3;pt1]; - -assertElementsAlmostEqual(... - distancePoints(array1, array2, inf, 'diag'), ... - [10;10;10]); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/centroid.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/centroid.m 2011-10-09 17:01:50 UTC (rev 8718) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/centroid.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -1,116 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function center = centroid(varargin) -%CENTROID Compute centroid (center of mass) of a set of points -% -% PTS = centroid(POINTS) -% PTS = centroid(PTX, PTY) -% Computes the ND-dimensional centroid of a set of points. -% POINTS is an array with as many rows as the number of points, and as -% many columns as the number of dimensions. -% PTX and PTY are two column vectors containing coordinates of the -% 2-dimensional points. -% The result PTS is a row vector with Nd columns. -% -% PTS = centroid(POINTS, MASS) -% PTS = centroid(PTX, PTY, MASS) -% Computes center of mass of POINTS, weighted by coefficient MASS. -% POINTS is a Np-by-Nd array, MASS is Np-by-1 array, and PTX and PTY are -% also both Np-by-1 arrays. -% -% Example: -% pts = [2 2;6 1;6 5;2 4]; -% centroid(pts) -% ans = -% 4 3 -% -% See Also: -% points2d, polygonCentroid -% -% --------- -% Author: David Legland -% e-mail: dav...@gr... -% created the 07/04/2003. -% Copyright 2010 INRA - Cepia Software Platform. -% - -% HISTORY -% 2009-06-22 support for 3D points -% 2010-04-12 fix bug in weighted centroid -% 2010-12-06 update doc - - -%% extract input arguments - -% use empty mass by default -mass = []; - -if nargin==1 - % give only array of points - pts = varargin{1}; - -elseif nargin==2 - % either POINTS+MASS or PX+PY - var = varargin{1}; - if size(var, 2)>1 - % arguments are POINTS, and MASS - pts = var; - mass = varargin{2}; - else - % arguments are PX and PY - pts = [var varargin{2}]; - end - -elseif nargin==3 - % arguments are PX, PY, and MASS - pts = [varargin{1} varargin{2}]; - mass = varargin{3}; -end - -%% compute centroid - -if isempty(mass) - % no weight - center = mean(pts); - -else - % format mass to have sum equal to 1, and column format - mass = mass(:)/sum(mass(:)); - - % compute weighted centroid - center = sum(bsxfun(@times, pts, mass), 1); - % equivalent to: - % center = sum(pts .* mass(:, ones(1, size(pts, 2)))); -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePoints.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePoints.m 2011-10-09 17:01:50 UTC (rev 8718) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePoints.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -1,156 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function dist = distancePoints(p1, p2, varargin) -%DISTANCEPOINTS Compute distance between two points -% -% D = distancePoints(P1, P2) -% Return the Euclidean distance between points P1 and P2. -% -% If P1 and P2 are two arrays of points, result is a N1*N2 array -% containing distance between each point of P1 and each point of P2. -% -% D = distancePoints(P1, P2, NORM) -% Compute distance using the specified norm. NORM=2 corresponds to usual -% euclidean distance, NORM=1 corresponds to Manhattan distance, NORM=inf -% is assumed to correspond to maximum difference in coordinate. Other -% values (>0) can be specified. -% -% D = distancePoints(..., 'diag') -% compute only distances between P1(i,:) and P2(i,:). -% -% See also: -% points2d, minDistancePoints -% -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 24/02/2004. -% - -% HISTORY : -% 25/05/2004: manage 2 array of points -% 07/04/2004: add option for computing only diagonal. -% 30/10/2006: generalize to any dimension, and manage different norms -% 03/01/2007: bug for arbitrary norm, and update doc -% 28/08/2007: fix bug for norms 2 and infinite, in diagonal case - - -%% Setup options - -% default values -diag = false; -norm = 2; - -% check first argument: norm or diag -if ~isempty(varargin) - var = varargin{1}; - if isnumeric(var) - norm = var; - elseif strncmp('diag', var, 4) - diag = true; - end - varargin(1) = []; -end - -% check last argument: diag -if ~isempty(varargin) - var = varargin{1}; - if strncmp('diag', var, 4) - diag = true; - end -end - - -% number of points in each array and their dimension -n1 = size(p1, 1); -n2 = size(p2, 1); -d = size(p1, 2); - -if diag - % compute distance only for apparied couples of pixels - dist = zeros(n1, 1); - if norm==2 - % Compute euclidian distance. this is the default case - % Compute difference of coordinate for each pair of point - % and for each dimension. -> dist is a [n1*n2] array. - for i=1:d - dist = dist + (p2(:,i)-p1(:,i)).^2; - end - dist = sqrt(dist); - elseif norm==inf - % infinite norm corresponds to maximal difference of coordinate - for i=1:d - dist = max(dist, abs(p2(:,i)-p1(:,i))); - end - else - % compute distance using the specified norm. - for i=1:d - dist = dist + power((abs(p2(:,i)-p1(:,i))), norm); - end - dist = power(dist, 1/norm); - end -else - % compute distance for all couples of pixels - dist = zeros(n1, n2); - if norm==2 - % Compute euclidian distance. this is the default case - % Compute difference of coordinate for each pair of point - % and for each dimension. -> dist is a [n1*n2] array. - for i=1:d - % equivalent to: - % dist = dist + ... - % (repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1])).^2; - dist = dist + (p1(:, i*ones(1, n2))-p2(:, i*ones(n1, 1))').^2; - end - dist = sqrt(dist); - elseif norm==inf - % infinite norm corresponds to maximal difference of coordinate - for i=1:d - dist = max(dist, abs(p1(:, i*ones(1, n2))-p2(:, i*ones(n1, 1))')); - end - else - % compute distance using the specified norm. - for i=1:d - % equivalent to: - % dist = dist + power((abs(repmat(p1(:,i), [1 n2]) - ... - % repmat(p2(:,i)', [n1 1]))), norm); - dist = dist + power((abs(p1(:, i*ones(1, n2))-p2(:, i*ones(n1, 1))')), norm); - end - dist = power(dist, 1/norm); - end -end - Modified: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m 2011-10-09 17:01:50 UTC (rev 8718) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m 2011-10-09 18:09:08 UTC (rev 8719) @@ -31,7 +31,6 @@ %% those of the authors and should not be interpreted as representing official %% policies, either expressed or implied, of copyright holder. - function varargout = drawPoint(varargin) %DRAWPOINT Draw the point on the axis. % This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |