From: <jpi...@us...> - 2011-10-13 17:08:02
|
Revision: 8738 http://octave.svn.sourceforge.net/octave/?rev=8738&view=rev Author: jpicarbajal Date: 2011-10-13 17:07:54 +0000 (Thu, 13 Oct 2011) Log Message: ----------- geometry. Finish with points2d Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/drawPoint.m trunk/octave-forge/main/geometry/geom2d/inst/isCounterClockwise.m trunk/octave-forge/main/geometry/geom2d/inst/minDistancePoints.m trunk/octave-forge/main/geometry/geom2d/inst/pointOnLine.m trunk/octave-forge/main/geometry/geom2d/inst/points2d.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsCounterClockwise.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMinDistancePoints.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isCounterClockwise.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/minDistancePoints.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/pointOnLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/points2d.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:07:54 UTC (rev 8738) @@ -87,5 +87,7 @@ transformLine.m centroid.m distancePoints.m + midPoint.m + polarPoint.m =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawPoint.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawPoint.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawPoint.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -0,0 +1,91 @@ +%% 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{h} = } drawPoint (@var{x}, @var{y}) +%% @deftypefnx {Function File} {@var{h} = } drawPoint (@var{coord}) +%% @deftypefnx {Function File} {@var{h} = } drawPoint (@dots{}, @var{opt}) +%% Draw the point on the axis. +% +% Draws points defined by coordinates @var{x} and @var{y}Y. +% @var{x} and @var{y} should be array the same size. Coordinates can be +% packed coordinates in a single [N*2] array @var{coord}. Options @var{opt} +% are passed to the @code{plot} function. +% +% @seealso{points2d, clipPoints} +% +%% @end deftypefn + +function varargout = drawPoint(varargin) + + % process input arguments + var = varargin{1}; + if size(var, 2)==1 + % points stored in separate arrays + px = varargin{1}; + py = varargin{2}; + varargin(1:2) = []; + else + % points packed in one array + px = var(:, 1); + py = var(:, 2); + varargin(1) = []; + end + + % ensure we have column vectors + px = px(:); + py = py(:); + + % default drawing options, but keep specified options if it has the form of + % a bundled string + if length(varargin)~=1 + varargin = [{'linestyle', 'none', 'marker', 'o', 'color', 'b'}, varargin]; + end + + % plot the points, using specified drawing options + h = plot(px(:), py(:), varargin{:}); + + % process output arguments + if nargout>0 + varargout{1}=h; + end + +endfunction + +%!demo +%! drawPoint(10, 10); + +%!demo +%! t = linspace(0, 2*pi, 20)'; +%! drawPoint([5*cos(t)+10 3*sin(t)+10], 'r+'); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/isCounterClockwise.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isCounterClockwise.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isCounterClockwise.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isCounterClockwise.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -0,0 +1,156 @@ +%% Copyright (c) 2011, INRA +%% 2010-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{ccw} = } isCounterClockwise (@var{p1}, @var{p2}, @var{p3}) +%% @deftypefnx {Function File} {@var{ccw} = } isCounterClockwise (@var{p1}, @var{p2}, @var{p3},@var{tol}) +%% Compute relative orientation of 3 points +%% +%% Computes the orientation of the 3 points. The returns is: +%% +1 if the path @var{p1}-> @var{p2}-> @var{p3} turns Counter-Clockwise (i.e., the point @var{p3} +%% is located "on the left" of the line @var{p1}- @var{p2}) +%% -1 if the path turns Clockwise (i.e., the point @var{p3} lies "on the right" +%% of the line @var{p1}- @var{p2}) +%% 0 if the point @var{p3} is located on the line segment [ @var{p1} @var{p2}]. +%% +%% This function can be used in more complicated algorithms: detection of +%% line segment intersections, convex hulls, point in triangle... +%% +%% @var{ccw} = isCounterClockwise( @var{p1}, @var{p2}, @var{p3}, EPS); +%% Specifies the threshold used for detecting colinearity of the 3 points. +%% Default value is 1e-12 (absolute). +%% +%% Example +%% +%% @example +%% isCounterClockwise([0 0], [10 0], [10 10]) +%% ans = +%% 1 +%% isCounterClockwise([0 0], [0 10], [10 10]) +%% ans = +%% -1 +%% isCounterClockwise([0 0], [10 0], [5 0]) +%% ans = +%% 0 +%% @end example +%% +%% @seealso{points2d, isPointOnLine, isPointInTriangle} +%% @end deftypefn + +function res = isCounterClockwise(p1, p2, p3, varargin) + + % get threshold value + eps = 1e-12; + if ~isempty(varargin) + eps = varargin{1}; + end + + % ensure all data have same size + np = max([size(p1, 1) size(p2, 1) size(p3,1)]); + if np > 1 + if size(p1,1) == 1 + p1 = repmat(p1, np, 1); + end + if size(p2,1) == 1 + p2 = repmat(p2, np, 1); + end + if size(p3,1) == 1 + p3 = repmat(p3, np, 1); + end + end + + % init with 0 + res = zeros(np, 1); + + % extract vector coordinates + x0 = p1(:, 1); + y0 = p1(:, 2); + dx1 = p2(:, 1) - x0; + dy1 = p2(:, 2) - y0; + dx2 = p3(:, 1) - x0; + dy2 = p3(:, 2) - y0; + + % check non colinear cases + res(dx1 .* dy2 > dy1 .* dx2) = 1; + res(dx1 .* dy2 < dy1 .* dx2) = -1; + + % case of colinear points + ind = abs(dx1 .* dy2 - dy1 .* dx2) < eps; + res(ind( (dx1(ind) .* dx2(ind) < 0) | (dy1(ind) .* dy2(ind) < 0) )) = -1; + res(ind( hypot(dx1(ind), dy1(ind)) < hypot(dx2(ind), dy2(ind)) )) = 1; + +endfunction + +%!shared p0,pu,pd,pl,pr +%! p0 = [2, 3]; % center point +%! pu = [2, 4]; % up point +%! pd = [2, 2]; % down point +%! pl = [1, 3]; % left point +%! pr = [3, 3]; % right point + +%!assert (+1, isCounterClockwise(pl, p0, pu)); +%!assert (+1, isCounterClockwise(pd, p0, pl)); +%!assert (+1, isCounterClockwise(pr, p0, pd)); +%!assert (+1, isCounterClockwise(pu, p0, pr)); + +% turn 90° right => return -1 +%!assert (-1, isCounterClockwise(pl, p0, pd)); +%!assert (-1, isCounterClockwise(pd, p0, pr)); +%!assert (-1, isCounterClockwise(pr, p0, pu)); +%!assert (-1, isCounterClockwise(pu, p0, pl)); + +%!test % turn 90° left => return +1 +%! pts1 = [pl;pd;pr;pu;pl;pd;pr;pu]; +%! pts2 = [p0;p0;p0;p0;p0;p0;p0;p0]; +%! pts3 = [pu;pl;pd;pr;pd;pr;pu;pl]; +%! expected = [1;1;1;1;-1;-1;-1;-1]; +%! result = isCounterClockwise(pts1, pts2, pts3); +%! assert (result, expected, 1e-6); + +% aligned with p0-p1-p2 => return +1 +%!assert (+1, isCounterClockwise(pl, p0, pr)); +%!assert (+1, isCounterClockwise(pu, p0, pd)); +%!assert (+1, isCounterClockwise(pr, p0, pl)); +%!assert (+1, isCounterClockwise(pd, p0, pu)); + +% aligned ]ith p0-p2-p1 => return 0 +%!assert (0, isCounterClockwise(pl, pr, p0)); +%!assert (0, isCounterClockwise(pu, pd, p0)); +%!assert (0, isCounterClockwise(pr, pl, p0)); +%!assert (0, isCounterClockwise(pd, pu, p0)); + +% aligned with p1-p0-p2 => return -1 +%!assert (-1, isCounterClockwise(p0, pl, pr)); +%!assert (-1, isCounterClockwise(p0, pu, pd)); +%!assert (-1, isCounterClockwise(p0, pr, pl)); +%!assert (-1, isCounterClockwise(p0, pr, pl)); Copied: trunk/octave-forge/main/geometry/geom2d/inst/minDistancePoints.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/minDistancePoints.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/minDistancePoints.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/minDistancePoints.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -0,0 +1,280 @@ +%% 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{dist} = } minDistancePoints (@var{pts}) +%% @deftypefnx {Function File} {@var{dist} = } minDistancePoints (@var{pts1},@var{pts2}) +%% @deftypefnx {Function File} {@var{dist} = } minDistancePoints (@dots{},@var{norm}) +%% @deftypefnx {Function File} {[@var{dist} @var{i} @var{j}] = } minDistancePoints (@var{pts1}, @var{pts2}, @dots{}) +%% @deftypefnx {Function File} {[@var{dist} @var{j}] = } minDistancePoints (@var{pts1}, @var{pts2}, @dots{}) +%% Minimal distance between several points. +%% +%% Returns the minimum distance between all couple of points in @var{pts}. var{pts} is +%% an array of [NxND] values, N being the number of points and ND the +%% dimension of the points. +%% +%% Computes for each point in @var{pts1} the minimal distance to every point of +%% @var{pts2}. @var{pts1} and @var{pts2} are [NxD] arrays, where N is the number of points, +%% and D is the dimension. Dimension must be the same for both arrays, but +%% number of points can be different. +%% The result is an array the same length as @var{pts1}. +%% +%% When @var{norm} is provided, it uses a user-specified norm. @var{norm}=2 means euclidean norm (the default), +%% @var{norm}=1 is the Manhattan (or "taxi-driver") distance. +%% Increasing @var{norm} growing up reduces the minimal distance, with a limit +%% to the biggest coordinate difference among dimensions. +%% +%% +%% Returns indices I and J of the 2 points which are the closest. @var{dist} +%% verifies relation: +%% @var{dist} = distancePoints(@var{pts}(@var{i},:), @var{pts}(@var{j},:)); +%% +%% If only 2 output arguments are given, it returns the indices of points which are the closest. J has the +%% same size as @var{dist}. for each I It verifies the relation : +%% @var{dist}(I) = distancePoints(@var{pts1}(I,:), @var{pts2}(@var{J},:)); +%% +%% +%% Examples: +%% +%% @example +%% % minimal distance between random planar points +%% points = rand(20,2)*100; +%% minDist = minDistancePoints(points); +%% +%% % minimal distance between random space points +%% points = rand(30,3)*100; +%% [minDist ind1 ind2] = minDistancePoints(points); +%% minDist +%% distancePoints(points(ind1, :), points(ind2, :)) +%% % results should be the same +%% +%% % minimal distance between 2 sets of points +%% points1 = rand(30,2)*100; +%% points2 = rand(30,2)*100; +%% [minDists inds] = minDistancePoints(points1, points2); +%% minDists(10) +%% distancePoints(points1(10, :), points2(inds(10), :)) +%% % results should be the same +%% @end example +%% +%% @seealso{points2d, distancePoints} +%% @end deftypefn + +function varargout = minDistancePoints(p1, varargin) + + %% Initialisations + + % default norm (euclidean) + n = 2; + + % flag for processing of all points + allPoints = false; + + % process input variables + if isempty(varargin) + % specify only one array of points, not the norm + p2 = p1; + + elseif length(varargin)==1 + var = varargin{1}; + if length(var)>1 + % specify two arrays of points + p2 = var; + allPoints = true; + else + % specify array of points and the norm + n = var; + p2 = p1; + end + + else + % specify two array of points and the norm + p2 = varargin{1}; + n = varargin{2}; + allPoints = true; + end + + + % number of points in each array + n1 = size(p1, 1); + n2 = size(p2, 1); + + % dimension of points + d = size(p1, 2); + + + %% Computation of distances + + % allocate memory + dist = zeros(n1, n2); + + % different behaviour depending on the norm used + if n==2 + % Compute euclidian distance. this is the default case + % Compute difference of coordinate for each pair of point ([n1*n2] array) + % and for each dimension. -> dist is a [n1*n2] array. + % in 2D: dist = dx.*dx + dy.*dy; + for i=1:d + dist = dist + (repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1])).^2; + end + + % compute minimal distance: + if ~allPoints + % either on all couple of points + mat = repmat((1:n1)', [1 n1]); + ind = mat < mat'; + [minSqDist ind] = min(dist(ind)); + else + % or for each point of P1 + [minSqDist ind] = min(dist, [], 2); + end + + % convert squared distance to distance + minDist = sqrt(minSqDist); + elseif n==inf + % infinite norm corresponds to maximum absolute value of differences + % in 2D: dist = max(abs(dx) + max(abs(dy)); + for i=1:d + dist = max(dist, abs(p1(:,i)-p2(:,i))); + end + else + % compute distance using the specified norm. + % in 2D: dist = power(abs(dx), n) + power(abs(dy), n); + for i=1:d + dist = dist + power((abs(repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1]))), n); + end + + % compute minimal distance + if ~allPoints + % either on all couple of points + mat = repmat((1:n1)', [1 n1]); + ind = mat < mat'; + [minSqDist ind] = min(dist(ind)); + else + % or for each point of P1 + [minSqDist ind] = min(dist, [], 2); + end + + % convert squared distance to distance + minDist = power(minSqDist, 1/n); + end + + + + if ~allPoints + % convert index in array to row ad column subindices. + % This uses the fact that index are sorted in a triangular matrix, + % with the last index of each column being a so-called triangular + % number + ind2 = ceil((-1+sqrt(8*ind+1))/2); + ind1 = ind - ind2*(ind2-1)/2; + ind2 = ind2 + 1; + end + + + %% format output parameters + + % format output depending on number of asked parameters + if nargout<=1 + varargout{1} = minDist; + elseif nargout==2 + % If two arrays are asked, 'ind' is an array of indices, one for each + % point in var{pts}1, corresponding to the result in minDist + varargout{1} = minDist; + varargout{2} = ind; + elseif nargout==3 + % If only one array is asked, minDist is a scalar, ind1 and ind2 are 2 + % indices corresponding to the closest points. + varargout{1} = minDist; + varargout{2} = ind1; + varargout{3} = ind2; + end + +endfunction + +%!test +%! pts = [50 10;40 60;30 30;20 0;10 60;10 30;0 10]; +%! assert (minDistancePoints(pts), 20); + +%!test +%! pts = [10 10;25 5;20 20;30 20;10 30]; +%! [dist ind1 ind2] = minDistancePoints(pts); +%! assert (10, dist, 1e-6); +%! assert (3, ind1, 1e-6); +%! assert (4, ind2, 1e-6); + +%!test +%! pts = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; +%! assert (minDistancePoints([40 50], pts), 10*sqrt(5), 1e-6); +%! assert (minDistancePoints([25 30], pts), 5*sqrt(5), 1e-6); +%! assert (minDistancePoints([30 40], pts), 10, 1e-6); +%! assert (minDistancePoints([20 40], pts), 0, 1e-6); + +%!test +%! pts1 = [40 50;25 30;40 20]; +%! pts2 = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; +%! res = [10*sqrt(5);5*sqrt(5);10]; +%! assert (minDistancePoints(pts1, pts2), res, 1e-6); + +%!test +%! pts = [50 10;40 60;40 30;20 0;10 60;10 30;0 10]; +%! assert (minDistancePoints(pts, 1), 30, 1e-6); +%! assert (minDistancePoints(pts, 100), 20, 1e-6); + +%!test +%! pts = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; +%! assert (minDistancePoints([40 50], pts, 2), 10*sqrt(5), 1e-6); +%! assert (minDistancePoints([25 30], pts, 2), 5*sqrt(5), 1e-6); +%! assert (minDistancePoints([30 40], pts, 2), 10, 1e-6); +%! assert (minDistancePoints([20 40], pts, 2), 0, 1e-6); +%! assert (minDistancePoints([40 50], pts, 1), 30, 1e-6); +%! assert (minDistancePoints([25 30], pts, 1), 15, 1e-6); +%! assert (minDistancePoints([30 40], pts, 1), 10, 1e-6); +%! assert (minDistancePoints([20 40], pts, 1), 0, 1e-6); + +%!test +%! pts1 = [40 50;25 30;40 20]; +%! pts2 = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; +%! res1 = [10*sqrt(5);5*sqrt(5);10]; +%! assert (minDistancePoints(pts1, pts2, 2), res1, 1e-6); +%! res2 = [30;15;10]; +%! assert (minDistancePoints(pts1, pts2, 1), res2); + +%!test +%! pts1 = [40 50;20 30;40 20]; +%! pts2 = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; +%! dists0 = [10*sqrt(5);10;10]; +%! inds1 = [3;3;4]; +%! [minDists inds] = minDistancePoints(pts1, pts2); +%! assert (dists0, minDists); +%! assert (inds1, inds); Copied: trunk/octave-forge/main/geometry/geom2d/inst/pointOnLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/pointOnLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/pointOnLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/pointOnLine.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -0,0 +1,53 @@ +%% 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{point} = } pointOnLine (@var{line}, @var{d}) +%% Create a point on a line at a given position on the line. +%% +%% Creates the point belonging to the line @var{line}, and located at the +%% distance @var{d} from the line origin. +%% @var{line} has the form [x0 y0 dx dy]. +%% @var{line} and @var{d} should have the same number N of rows. The result will have +%% N rows and 2 column (x and y positions). +%% +%% @seealso{lines2d, points2d, onLine, onLine, linePosition} +%% @end deftypefn + +function point = pointOnLine(lin, pos) + + ang = lineAngle(lin); + point = [lin(:,1) + pos .* cos(ang), lin(:,2) + pos .* sin(ang)]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/points2d.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/points2d.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/points2d.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/points2d.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -0,0 +1,60 @@ +%% Copyright (c) 2011, INRA +%% 2008-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} points2d () +%% Description of functions operating on points. +%% +%% A point is defined by its two cartesian coordinate, put into a row +%% vector of 2 elements: +%% P = [x y]; +%% +%% Several points are stores in a matrix with two columns, one for the +%% x-coordinate, one for the y-coordinate. +%% PTS = [x1 y1 ; x2 y2 ; x3 y3]; +%% +%% Example +%% P = [5 6]; +%% +%% @seealso{centroid, midPoint, polarPoint, pointOnLine +%% isCounterClockwise, angle2Points, angle3Points, angleSort +%% distancePoints, minDistancePoints +%% transformPoint, clipPoints, drawPoint} +%% @end deftypefn + +function points2d + + help('points2d'); + +endfunction + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsCounterClockwise.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsCounterClockwise.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsCounterClockwise.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,103 +0,0 @@ -function test_suite = testIsCounterClockwise -%test orientation of 3 points -% output = testEq(input) -% -% Example -% testEq -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-04-03, 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 testCcwTurnLeft -% turn 90\xB0 left => return +1 - -p0 = [2, 3]; % center point -pu = [2, 4]; % up point -pd = [2, 2]; % down point -pl = [1, 3]; % left point -pr = [3, 3]; % right point - -assertEqual(isCounterClockwise(pl, p0, pu), +1); -assertEqual(isCounterClockwise(pd, p0, pl), +1); -assertEqual(isCounterClockwise(pr, p0, pd), +1); -assertEqual(isCounterClockwise(pu, p0, pr), +1); - -function testCcwTurnRight -% turn 90\xB0 right => return -1 - -p0 = [2, 3]; % center point -pu = [2, 4]; % up point -pd = [2, 2]; % down point -pl = [1, 3]; % left point -pr = [3, 3]; % right point - -assertEqual(isCounterClockwise(pl, p0, pd), -1); -assertEqual(isCounterClockwise(pd, p0, pr), -1); -assertEqual(isCounterClockwise(pr, p0, pu), -1); -assertEqual(isCounterClockwise(pu, p0, pl), -1); - -function testCcwTurnLeftArray -% turn 90\xB0 left => return +1 - -p0 = [2, 3]; % center point -pu = [2, 4]; % up point -pd = [2, 2]; % down point -pl = [1, 3]; % left point -pr = [3, 3]; % right point - -pts1 = [pl;pd;pr;pu;pl;pd;pr;pu]; -pts2 = [p0;p0;p0;p0;p0;p0;p0;p0]; -pts3 = [pu;pl;pd;pr;pd;pr;pu;pl]; -expected = [1;1;1;1;-1;-1;-1;-1]; -result = isCounterClockwise(pts1, pts2, pts3); -assertElementsAlmostEqual(expected, result); - -function testCcwCol1 -% aligned with p0-p1-p2 => return +1 - -p0 = [2, 3]; % center point -pu = [2, 4]; % up point -pd = [2, 2]; % down point -pl = [1, 3]; % left point -pr = [3, 3]; % right point - -assertEqual(isCounterClockwise(pl, p0, pr), +1); -assertEqual(isCounterClockwise(pu, p0, pd), +1); -assertEqual(isCounterClockwise(pr, p0, pl), +1); -assertEqual(isCounterClockwise(pd, p0, pu), +1); - -function testCcwCol0 -% aligned ]ith p0-p2-p1 => return 0 -p0 = [2, 3]; % center point -pu = [2, 4]; % up point -pd = [2, 2]; % down point -pl = [1, 3]; % left point -pr = [3, 3]; % right point - -assertEqual(isCounterClockwise(pl, pr, p0), 0); -assertEqual(isCounterClockwise(pu, pd, p0), 0); -assertEqual(isCounterClockwise(pr, pl, p0), 0); -assertEqual(isCounterClockwise(pd, pu, p0), 0); - -function testCcwColM1 -% aligned with p1-p0-p2 => return -1 -p0 = [2, 3]; % center point -pu = [2, 4]; % up point -pd = [2, 2]; % down point -pl = [1, 3]; % left point -pr = [3, 3]; % right point - -assertEqual(isCounterClockwise(p0, pl, pr), -1); -assertEqual(isCounterClockwise(p0, pu, pd), -1); -assertEqual(isCounterClockwise(p0, pr, pl), -1); -assertEqual(isCounterClockwise(p0, pd, pu), -1); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMinDistancePoints.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMinDistancePoints.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMinDistancePoints.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,89 +0,0 @@ -function test_suite = testMinDistancePoints(varargin) -%TESTMINDISTANCEPOINTS One-line description here, please. -% output = testMinDistancePoints(input) -% -% Example -% testMinDistancePoints -% -% 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 testArray - -pts = [50 10;40 60;30 30;20 0;10 60;10 30;0 10]; -assertElementsAlmostEqual(minDistancePoints(pts), 20); - -function testArrayIndInd - -pts = [10 10;25 5;20 20;30 20;10 30]; -[dist ind1 ind2] = minDistancePoints(pts); -assertAlmostEqual(10, dist); -assertAlmostEqual(3, ind1); -assertAlmostEqual(4, ind2); - - -function testPointArray - -pts = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; -assertElementsAlmostEqual(minDistancePoints([40 50], pts), 10*sqrt(5)); -assertElementsAlmostEqual(minDistancePoints([25 30], pts), 5*sqrt(5)); -assertElementsAlmostEqual(minDistancePoints([30 40], pts), 10); -assertElementsAlmostEqual(minDistancePoints([20 40], pts), 0); - -function testArrayArray - -pts1 = [40 50;25 30;40 20]; -pts2 = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; -res = [10*sqrt(5);5*sqrt(5);10]; -assertElementsAlmostEqual(minDistancePoints(pts1, pts2), res); - - - -function testArrayNorm - -pts = [50 10;40 60;40 30;20 0;10 60;10 30;0 10]; -assertElementsAlmostEqual(minDistancePoints(pts, 1), 30); -assertElementsAlmostEqual(minDistancePoints(pts, 100), 20); - - -function testPointArrayNorm - -pts = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; -assertElementsAlmostEqual(minDistancePoints([40 50], pts, 2), 10*sqrt(5)); -assertElementsAlmostEqual(minDistancePoints([25 30], pts, 2), 5*sqrt(5)); -assertElementsAlmostEqual(minDistancePoints([30 40], pts, 2), 10); -assertElementsAlmostEqual(minDistancePoints([20 40], pts, 2), 0); -assertElementsAlmostEqual(minDistancePoints([40 50], pts, 1), 30); -assertElementsAlmostEqual(minDistancePoints([25 30], pts, 1), 15); -assertElementsAlmostEqual(minDistancePoints([30 40], pts, 1), 10); -assertElementsAlmostEqual(minDistancePoints([20 40], pts, 1), 0); - -function testArrayArrayNorm - -pts1 = [40 50;25 30;40 20]; -pts2 = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; -res1 = [10*sqrt(5);5*sqrt(5);10]; -assertElementsAlmostEqual(minDistancePoints(pts1, pts2, 2), res1); - -res2 = [30;15;10]; -assertElementsAlmostEqual(minDistancePoints(pts1, pts2, 1), res2); - -function testArrayArrayIndices - -pts1 = [40 50;20 30;40 20]; -pts2 = [0 80;10 60;20 40;30 20;40 0;0 0;100 0;0 100;0 -10;-10 -20]; -dists0 = [10*sqrt(5);10;10]; -inds1 = [3;3;4]; -[minDists inds] = minDistancePoints(pts1, pts2); -assertElementsAlmostEqual(dists0, minDists); -assertElementsAlmostEqual(inds1, inds); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawPoint.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,103 +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 varargout = drawPoint(varargin) -%DRAWPOINT Draw the point on the axis. -% -% drawPoint(X, Y); -% Draws points defined by coordinates X and Y. -% X and Y should be array the same size. -% -% drawPoint(COORD); -% Packs coordinates in a single [N*2] array. -% -% drawPoint(..., OPT); -% Draws each point with given option. OPT is a series of arguments pairs -% compatible with 'plot' model. -% -% -% H = drawPoint(...) also return a handle to each of the drawn points. -% -% Example -% drawPoint(10, 10); -% -% t = linspace(0, 2*pi, 20)'; -% drawPoint([5*cos(t)+10 3*sin(t)+10], 'r+'); -% -% See also -% points2d, clipPoints -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 23/02/2004 add more documentation. Manage different kind of inputs. -% Does not draw points outside visible area. -% 26/02/2007 update processing of input arguments. -% 30/04/2009 remove clipping of points (use clipPoints if necessary) - -% process input arguments -var = varargin{1}; -if size(var, 2)==1 - % points stored in separate arrays - px = varargin{1}; - py = varargin{2}; - varargin(1:2) = []; -else - % points packed in one array - px = var(:, 1); - py = var(:, 2); - varargin(1) = []; -end - -% ensure we have column vectors -px = px(:); -py = py(:); - -% default drawing options, but keep specified options if it has the form of -% a bundled string -if length(varargin)~=1 - varargin = [{'linestyle', 'none', 'marker', 'o', 'color', 'b'}, varargin]; -end - -% plot the points, using specified drawing options -h = plot(px(:), py(:), varargin{:}); - -% process output arguments -if nargout>0 - varargout{1}=h; -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isCounterClockwise.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isCounterClockwise.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isCounterClockwise.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,119 +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 res = isCounterClockwise(p1, p2, p3, varargin) -%ISCOUNTERCLOCKWISE Compute relative orientation of 3 points -% -% CCW = isCounterClockwise(P1, P2, P3); -% Computes the orientation of the 3 points. The returns is: -% +1 if the path P1->P2->P3 turns Counter-Clockwise (i.e., the point P3 -% is located "on the left" of the line P1-P2) -% -1 if the path turns Clockwise (i.e., the point P3 lies "on the right" -% of the line P1-P2) -% 0 if the point P3 is located on the line segment [P1 P2]. -% -% This function can be used in more complicated algorithms: detection of -% line segment intersections, convex hulls, point in triangle... -% -% CCW = isCounterClockwise(P1, P2, P3, EPS); -% Specifies the threshold used for detecting colinearity of the 3 points. -% Default value is 1e-12 (absolute). -% -% Example -% isCounterClockwise([0 0], [10 0], [10 10]) -% ans = -% 1 -% isCounterClockwise([0 0], [0 10], [10 10]) -% ans = -% -1 -% isCounterClockwise([0 0], [10 0], [5 0]) -% ans = -% 0 -% -% See also -% points2d, isPointOnLine, isPointInTriangle -% -% References -% Algorithm adapated from Sedgewick's book. -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-04-09 -% Copyright 2011 INRA - Cepia Software Platform. - - -% HISTORY -% 2011-05-16 change variable names, add support for point arrays - - -% get threshold value -eps = 1e-12; -if ~isempty(varargin) - eps = varargin{1}; -end - -% ensure all data have same size -np = max([size(p1, 1) size(p2, 1) size(p3,1)]); -if np > 1 - if size(p1,1) == 1 - p1 = repmat(p1, np, 1); - end - if size(p2,1) == 1 - p2 = repmat(p2, np, 1); - end - if size(p3,1) == 1 - p3 = repmat(p3, np, 1); - end -end - -% init with 0 -res = zeros(np, 1); - -% extract vector coordinates -x0 = p1(:, 1); -y0 = p1(:, 2); -dx1 = p2(:, 1) - x0; -dy1 = p2(:, 2) - y0; -dx2 = p3(:, 1) - x0; -dy2 = p3(:, 2) - y0; - -% check non colinear cases -res(dx1 .* dy2 > dy1 .* dx2) = 1; -res(dx1 .* dy2 < dy1 .* dx2) = -1; - -% case of colinear points -ind = abs(dx1 .* dy2 - dy1 .* dx2) < eps; -res(ind( (dx1(ind) .* dx2(ind) < 0) | (dy1(ind) .* dy2(ind) < 0) )) = -1; -res(ind( hypot(dx1(ind), dy1(ind)) < hypot(dx2(ind), dy2(ind)) )) = 1; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/minDistancePoints.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/minDistancePoints.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/minDistancePoints.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,235 +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 varargout = minDistancePoints(p1, varargin) -%MINDISTANCEPOINTS Minimal distance between several points -% -% DIST = minDistancePoints(PTS) -% Returns the minimum distance between all couple of points in PTS. PTS is -% an array of [NxND] values, N being the number of points and ND the -% dimension of the points. -% -% DIST = minDistancePoints(PTS1, PTS2) -% Computes for each point in PTS1 the minimal distance to every point of -% PTS2. PTS1 and PTS2 are [NxD] arrays, where N is the number of points, -% and D is the dimension. Dimension must be the same for both arrays, but -% number of points can be different. -% The result is an array the same length as PTS1. -% -% -% DIST = minDistancePoints(..., NORM) -% Uses a user-specified norm. NORM=2 means euclidean norm (the default), -% NORM=1 is the Manhattan (or "taxi-driver") distance. -% Increasing NORM growing up reduces the minimal distance, with a limit -% to the biggest coordinate difference among dimensions. -% -% -% [DIST I J] = minDistancePoints(PTS) -% Returns indices I and J of the 2 points which are the closest. DIST -% verifies relation: -% DIST = distancePoints(PTS(I,:), PTS(J,:)); -% -% [DIST J] = minDistancePoints(PTS1, PTS2, ...) -% Also returns the indices of points which are the closest. J has the -% same size as DIST. It verifies relation : -% DIST(I) = distancePoints(PTS1(I,:), PTS2(J,:)); -% -% -% Examples: -% % minimal distance between random planar points -% points = rand(20,2)*100; -% minDist = minDistancePoints(points); -% -% % minimal distance between random space points -% points = rand(30,3)*100; -% [minDist ind1 ind2] = minDistancePoints(points); -% minDist -% distancePoints(points(ind1, :), points(ind2, :)) -% % results should be the same -% -% % minimal distance between 2 sets of points -% points1 = rand(30,2)*100; -% points2 = rand(30,2)*100; -% [minDists inds] = minDistancePoints(points1, points2); -% minDists(10) -% distancePoints(points1(10, :), points2(inds(10), :)) -% % results should be the same -% -% See Also -% points2d, distancePoints -% -% --------- -% author: David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 15/06/2004. -% - -% HISTORY: -% 22/06/2005 compute sqrt only at the end (faster), and change behaviour -% for 2 inputs: compute min distance for each point in PTS1. -% Also add support for different norms. -% 15/08/2005 make difference when 1 array or 2 arrays of points -% 25/10/2006 also returns indices of closest points -% 30/10/2006 generalize to points of any dimension -% 28/08/2007 code cleanup, add comments and help - - -%% Initialisations - -% default norm (euclidean) -n = 2; - -% flag for processing of all points -allPoints = false; - -% process input variables -if isempty(varargin) - % specify only one array of points, not the norm - p2 = p1; - -elseif length(varargin)==1 - var = varargin{1}; - if length(var)>1 - % specify two arrays of points - p2 = var; - allPoints = true; - else - % specify array of points and the norm - n = var; - p2 = p1; - end - -else - % specify two array of points and the norm - p2 = varargin{1}; - n = varargin{2}; - allPoints = true; -end - - -% number of points in each array -n1 = size(p1, 1); -n2 = size(p2, 1); - -% dimension of points -d = size(p1, 2); - - -%% Computation of distances - -% allocate memory -dist = zeros(n1, n2); - -% different behaviour depending on the norm used -if n==2 - % Compute euclidian distance. this is the default case - % Compute difference of coordinate for each pair of point ([n1*n2] array) - % and for each dimension. -> dist is a [n1*n2] array. - % in 2D: dist = dx.*dx + dy.*dy; - for i=1:d - dist = dist + (repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1])).^2; - end - - % compute minimal distance: - if ~allPoints - % either on all couple of points - mat = repmat((1:n1)', [1 n1]); - ind = mat < mat'; - [minSqDist ind] = min(dist(ind)); - else - % or for each point of P1 - [minSqDist ind] = min(dist, [], 2); - end - - % convert squared distance to distance - minDist = sqrt(minSqDist); -elseif n==inf - % infinite norm corresponds to maximum absolute value of differences - % in 2D: dist = max(abs(dx) + max(abs(dy)); - for i=1:d - dist = max(dist, abs(p1(:,i)-p2(:,i))); - end -else - % compute distance using the specified norm. - % in 2D: dist = power(abs(dx), n) + power(abs(dy), n); - for i=1:d - dist = dist + power((abs(repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1]))), n); - end - - % compute minimal distance - if ~allPoints - % either on all couple of points - mat = repmat((1:n1)', [1 n1]); - ind = mat < mat'; - [minSqDist ind] = min(dist(ind)); - else - % or for each point of P1 - [minSqDist ind] = min(dist, [], 2); - end - - % convert squared distance to distance - minDist = power(minSqDist, 1/n); -end - - - -if ~allPoints - % convert index in array to row ad column subindices. - % This uses the fact that index are sorted in a triangular matrix, - % with the last index of each column being a so-called triangular - % number - ind2 = ceil((-1+sqrt(8*ind+1))/2); - ind1 = ind - ind2*(ind2-1)/2; - ind2 = ind2 + 1; -end - - -%% format output parameters - -% format output depending on number of asked parameters -if nargout<=1 - varargout{1} = minDist; -elseif nargout==2 - % If two arrays are asked, 'ind' is an array of indices, one for each - % point in PTS1, corresponding to the result in minDist - varargout{1} = minDist; - varargout{2} = ind; -elseif nargout==3 - % If only one array is asked, minDist is a scalar, ind1 and ind2 are 2 - % indices corresponding to the closest points. - varargout{1} = minDist; - varargout{2} = ind1; - varargout{3} = ind2; -end - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/pointOnLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/pointOnLine.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/pointOnLine.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,58 +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 point = pointOnLine(line, pos) -%POINTONLINE Create a point on a line at a given position on the line -% -% P = pointOnLine(LINE, POS); -% Creates the point belonging to the line LINE, and located at the -% distance D from the line origin. -% LINE has the form [x0 y0 dx dy]. -% LINE and D should have the same number N of rows. The result will have -% N rows ans 2 column (x and y positions). -% -% See also: -% lines2d, points2d, onLine, onLine, linePosition -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 07/04/2004. -% - - -angle = lineAngle(line); -point = [line(:,1) + pos .* cos(angle), line(:,2) + pos .* sin(angle)]; - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/points2d.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/points2d.m 2011-10-13 07:43:26 UTC (rev 8737) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/points2d.m 2011-10-13 17:07:54 UTC (rev 8738) @@ -1,61 +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 points2d -%POINTS2D Description of functions operating on points -% -% A point is defined by its two cartesian coordinate, put into a row -% vector of 2 elements: -% P = [x y]; -% -% Several points are stores in a matrix with two columns, one for the -% x-coordinate, one for the y-coordinate. -% PTS = [x1 y1 ; x2 y2 ; x3 y3]; -% -% Example -% P = [5 6]; -% -% See also: -% centroid, midPoint, polarPoint, pointOnLine -% isCounterClockwise, angle2Points, angle3Points, angleSort -% distancePoints, minDistancePoints -% transformPoint, clipPoints, drawPoint -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) -% Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. - -help('points2d'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |