From: <jpi...@us...> - 2011-10-13 18:17:49
|
Revision: 8743 http://octave.svn.sourceforge.net/octave/?rev=8743&view=rev Author: jpicarbajal Date: 2011-10-13 18:17:43 +0000 (Thu, 13 Oct 2011) Log Message: ----------- geometry. Missing functions, fixing demo Modified Paths: -------------- trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/doc/NEWS trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/INDEX 2011-10-13 18:17:43 UTC (rev 8743) @@ -37,6 +37,7 @@ isCounterClockwise isParallel isPerpendicular + isPointOnEdge isPointOnRay lineAngle linePosition Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 18:17:43 UTC (rev 8743) @@ -95,4 +95,5 @@ pointOnLine.m points2d.m intersectLineEdge.m + isPointOnEdge.m =============================================================================== Modified: trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -130,7 +130,7 @@ %!demo %! lin = [30 40 10 0]; %! bb = [0 100 0 100]; -%! res = clipLine(line, bb) +%! res = clipLine(lin, bb) %! %! drawBox(bb,'color','k'); %! line(lin([1 3]),lin([2 4]),'color','b'); Copied: trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -0,0 +1,294 @@ +%% 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{b} = } isPointOnEdge (@var{point}, @var{edge}) +%% @deftypefnx {Function File} {@var{b} = } isPointOnEdge (@var{point}, @var{edge}, @var{tol}) +%% @deftypefnx {Function File} {@var{b} = } isPointOnEdge (@var{point}, @var{edgearray}) +%% @deftypefnx {Function File} {@var{b} = } isPointOnEdge (@var{pointarray}, @var{edgearray}) +%% Test if a point belongs to an edge. +% +% with @var{point} being [xp yp], and @var{edge} being [x1 y1 x2 y2], returns TRUE if +% the point is located on the edge, and FALSE otherwise. +% +% Specify an optilonal tolerance value @var{tol}. The tolerance is given as a +% fraction of the norm of the edge direction vector. Default is 1e-14. +% +% When one of the inputs has several rows, return the result of the test +% for each element of the array tested against the single parameter. +% +% When both @var{pointarray} and @var{edgearray} have the same number of rows, +% returns a column vector with the same number of rows. +% When the number of rows are different and both greater than 1, returns +% a Np-by-Ne matrix of booleans, containing the result for each couple of +% point and edge. +% +% @seealso{edges2d, points2d, isPointOnLine} +%% @end deftypefn + +function b = isPointOnEdge(point, edge, varargin) + + % extract computation tolerance + tol = 1e-14; + if ~isempty(varargin) + tol = varargin{1}; + end + + % number of edges and of points + Np = size(point, 1); + Ne = size(edge, 1); + + % adapt size of inputs if needed, and extract elements for computation + if Np == Ne + % When the number of points and edges is the same, the one-to-one test + % will be computed, so there is no need to repeat matrices + dx = edge(:,3) - edge(:,1); + dy = edge(:,4) - edge(:,2); + lx = point(:,1) - edge(:,1); + ly = point(:,2) - edge(:,2); + + elseif Np == 1 + % one point, several edges + dx = edge(:, 3) - edge(:, 1); + dy = edge(:, 4) - edge(:, 2); + lx = point(ones(Ne, 1), 1) - edge(:, 1); + ly = point(ones(Ne, 1), 2) - edge(:, 2); + + elseif Ne == 1 + % several points, one edge + dx = (edge(3) - edge(1)) * ones(Np, 1); + dy = (edge(4) - edge(2)) * ones(Np, 1); + lx = point(:, 1) - edge(1); + ly = point(:, 2) - edge(2); + + else + % Np points and Ne edges: + % Create an array for each parameter, so that the result will be a + % Np-by-Ne matrix of booleans (requires more memory, and uses repmat) + + x0 = repmat(edge(:, 1)', Np, 1); + y0 = repmat(edge(:, 2)', Np, 1); + dx = repmat(edge(:,3)', Np, 1) - x0; + dy = repmat(edge(:,4)', Np, 1) - y0; + + lx = repmat(point(:, 1), 1, Ne) - x0; + ly = repmat(point(:, 2), 1, Ne) - y0; + end + + % test if point is located on supporting line + b1 = (abs(lx.*dy - ly.*dx) ./ hypot(dx, dy)) < tol; + + % compute position of point with respect to edge bounds + % use different tests depending on line angle + ind = abs(dx) > abs(dy); + t = zeros(size(dx)); + t(ind) = lx( ind) ./ dx( ind); + t(~ind) = ly(~ind) ./ dy(~ind); + + % check if point is located between edge bounds + b = t >- tol & t-1 < tol & b1; + +endfunction + +%!shared points, vertices, edges + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test one point and one edge +%! isPointOnEdge(points(1,:), edges(1,:)) +%! isPointOnEdge(points(3,:), edges(1,:)) + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test one point and several edges +%! isPointOnEdge(points(1,:), edges)' + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test several points and one edge +%! isPointOnEdge(points, edges(1,:))' + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test N points and N edges +%! isPointOnEdge(points, edges(1:3,:))' + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test NP points and NE edges +%! isPointOnEdge(points, edges) + +%!test +%! p1 = [10 20]; +%! p2 = [80 20]; +%! edge = [p1 p2]; +%! p0 = [10 20]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [80 20]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [50 20]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 20]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [80.01 20]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [50 21]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [79 19]; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! p1 = [20 10]; +%! p2 = [20 80]; +%! edge = [p1 p2]; +%! p0 = [20 10]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [20 80]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [20 50]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [20 9.99]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [20 80.01]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [21 50]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [19 79]; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! p1 = [10 20]; +%! p2 = [60 70]; +%! edge = [p1 p2]; +%! assert (isPointOnEdge(p1, edge)); +%! assert (isPointOnEdge(p2, edge)); +%! p0 = [11 21]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [59 69]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 19.99]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [60.01 70.01]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [30 50.01]; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! edge = [10 20 80 20; 20 10 20 80; 20 10 60 70]; +%! p0 = [20 20]; +%! assert ([true ; true ; false], isPointOnEdge(p0, edge)); + +%!test +%! k = 1e15; +%! p1 = [10 20]*k; +%! p2 = [60 70]*k; +%! edge = [p1 p2]; +%! assert (isPointOnEdge(p1, edge)); +%! assert (isPointOnEdge(p2, edge)); +%! p0 = [11 21]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [59 69]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 19.99]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [60.01 70.01]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [30 50.01]*k; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! k = 1e-10; +%! p1 = [10 20]*k; +%! p2 = [60 70]*k; +%! edge = [p1 p2]; +%! assert (isPointOnEdge(p1, edge)); +%! assert (isPointOnEdge(p2, edge)); +%! p0 = [11 21]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [59 69]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 19.99]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [60.01 70.01]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [30 50.01]*k; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! p1 = [10 20]; +%! p2 = [80 20]; +%! edge = [p1 p2]; +%! p0 = [10 20; 80 20; 50 20;50 21]; +%! exp = [true;true;true;false]; +%! assert (exp, isPointOnEdge(p0, edge)); + +%!test +%! p1 = [10 20]; +%! p2 = [80 20]; +%! edge = [p1 p2]; +%! p0 = [40 20]; +%! exp = [true;true;true;true]; +%! assert (exp, isPointOnEdge(p0, [edge;edge;edge;edge])); + +%!test +%! edge1 = [10 20 80 20]; +%! edge2 = [30 10 30 80]; +%! edges = [edge1; edge2]; +%! p0 = [40 20;30 90]; +%! exp = [true;false]; +%! assert (exp, isPointOnEdge(p0, edges)); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -1,192 +0,0 @@ -function test_suite = testIsPointOnEdge(varargin) %#ok<STOUT> -%TESTISPOINTONEDGE One-line description here, please. -% -% output = testIsPointOnEdge(input) -% -% Example -% testIsPointOnEdge -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - -initTestSuite; - -function testHoriz %#ok<*DEFNU> - -p1 = [10 20]; -p2 = [80 20]; -edge = [p1 p2]; - -p0 = [10 20]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [80 20]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [50 20]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 20]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [80.01 20]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [50 21]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [79 19]; -assertFalse(isPointOnEdge(p0, edge)); - - -function testVertical %#ok<*DEFNU> - -p1 = [20 10]; -p2 = [20 80]; -edge = [p1 p2]; - -p0 = [20 10]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [20 80]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [20 50]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [20 9.99]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [20 80.01]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [21 50]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [19 79]; -assertFalse(isPointOnEdge(p0, edge)); - -function testDiagonal - -p1 = [10 20]; -p2 = [60 70]; -edge = [p1 p2]; - -assertTrue(isPointOnEdge(p1, edge)); -assertTrue(isPointOnEdge(p2, edge)); - -p0 = [11 21]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [59 69]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 19.99]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [60.01 70.01]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [30 50.01]; -assertFalse(isPointOnEdge(p0, edge)); - - -function testScalarArray - -edge = [10 20 80 20; 20 10 20 80; 20 10 60 70]; -p0 = [20 20]; -assertEqual([true ; true ; false], isPointOnEdge(p0, edge)); - -function testLargeEdge - -k = 1e15; - -p1 = [10 20]*k; -p2 = [60 70]*k; -edge = [p1 p2]; - -assertTrue(isPointOnEdge(p1, edge)); -assertTrue(isPointOnEdge(p2, edge)); - -p0 = [11 21]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [59 69]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 19.99]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [60.01 70.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [30 50.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - - -function testSmallEdge - -k = 1e-10; - -p1 = [10 20]*k; -p2 = [60 70]*k; -edge = [p1 p2]; - -assertTrue(isPointOnEdge(p1, edge)); -assertTrue(isPointOnEdge(p2, edge)); - -p0 = [11 21]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [59 69]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 19.99]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [60.01 70.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [30 50.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - - -function testPointArray - -p1 = [10 20]; -p2 = [80 20]; -edge = [p1 p2]; - -p0 = [10 20; 80 20; 50 20;50 21]; -exp = [true;true;true;false]; -assertEqual(exp, isPointOnEdge(p0, edge)); - - -function testEdgeArray - -p1 = [10 20]; -p2 = [80 20]; -edge = [p1 p2]; - -p0 = [40 20]; -exp = [true;true;true;true]; -assertEqual(exp, isPointOnEdge(p0, [edge;edge;edge;edge])); - - -function testTwoArrays - -edge1 = [10 20 80 20]; -edge2 = [30 10 30 80]; -edges = [edge1; edge2]; - -p0 = [40 20;30 90]; - -exp = [true;false]; -assertEqual(exp, isPointOnEdge(p0, edges)); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -1,181 +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 b = isPointOnEdge(point, edge, varargin) -%ISPOINTONEDGE Test if a point belongs to an edge -% -% Usage -% B = isPointOnEdge(POINT, EDGE) -% B = isPointOnEdge(POINT, EDGE, TOL) -% -% Description -% B = isPointOnEdge(POINT, EDGE) -% with POINT being [xp yp], and EDGE being [x1 y1 x2 y2], returns TRUE if -% the point is located on the edge, and FALSE otherwise. -% -% B = isPointOnEdge(POINT, EDGE, TOL) -% Specify an optilonal tolerance value TOL. The tolerance is given as a -% fraction of the norm of the edge direction vector. Default is 1e-14. -% -% B = isPointOnEdge(POINTARRAY, EDGE) -% B = isPointOnEdge(POINT, EDGEARRAY) -% When one of the inputs has several rows, return the result of the test -% for each element of the array tested against the single parameter. -% -% B = isPointOnEdge(POINTARRAY, EDGEARRAY) -% When both POINTARRAY and EDGEARRAY have the same number of rows, -% returns a column vector with the same number of rows. -% When the number of rows are different and both greater than 1, returns -% a Np-by-Ne matrix of booleans, containing the result for each couple of -% point and edge. -% -% Examples -% % create a point array -% points = [10 10;15 10; 30 10]; -% % create an edge array -% vertices = [10 10;20 10;20 20;10 20]; -% edges = [vertices vertices([2:end 1], :)]; -% -% % Test one point and one edge -% isPointOnEdge(points(1,:), edges(1,:)) -% ans = -% 1 -% isPointOnEdge(points(3,:), edges(1,:)) -% ans = -% 0 -% -% % Test one point and several edges -% isPointOnEdge(points(1,:), edges)' -% ans = -% 1 0 0 1 -% -% % Test several points and one edge -% isPointOnEdge(points, edges(1,:))' -% ans = -% 1 1 0 -% -% % Test N points and N edges -% isPointOnEdge(points, edges(1:3,:))' -% ans = -% 1 0 0 -% -% % Test NP points and NE edges -% isPointOnEdge(points, edges) -% ans = -% 1 0 0 1 -% 1 0 0 0 -% 0 0 0 0 -% -% -% See also -% edges2d, points2d, isPointOnLine -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 11/03/2004 change input format: edge is [x1 y1 x2 y2]. -% 17/01/2005 if test N edges with N points, return N boolean. -% 21/01/2005 normalize test for colinearity, so enhance precision -% 22/05/2009 rename to isPointOnEdge, add psb to specify tolerance -% 26/01/2010 fix bug in precision computation -% 04/10/2010 fix a bug, and clean up code -% 28/10/2010 fix bug to have N results when input is N points and N -% edges, add support for arrays with different numbers of rows, and -% update doc. -% 2011-06-15 rewrites by using less memory, and avoiding repmat when psb - - -% extract computation tolerance -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -% number of edges and of points -Np = size(point, 1); -Ne = size(edge, 1); - -% adapt size of inputs if needed, and extract elements for computation -if Np == Ne - % When the number of points and edges is the same, the one-to-one test - % will be computed, so there is no need to repeat matrices - dx = edge(:,3) - edge(:,1); - dy = edge(:,4) - edge(:,2); - lx = point(:,1) - edge(:,1); - ly = point(:,2) - edge(:,2); - -elseif Np == 1 - % one point, several edges - dx = edge(:, 3) - edge(:, 1); - dy = edge(:, 4) - edge(:, 2); - lx = point(ones(Ne, 1), 1) - edge(:, 1); - ly = point(ones(Ne, 1), 2) - edge(:, 2); - -elseif Ne == 1 - % several points, one edge - dx = (edge(3) - edge(1)) * ones(Np, 1); - dy = (edge(4) - edge(2)) * ones(Np, 1); - lx = point(:, 1) - edge(1); - ly = point(:, 2) - edge(2); - -else - % Np points and Ne edges: - % Create an array for each parameter, so that the result will be a - % Np-by-Ne matrix of booleans (requires more memory, and uses repmat) - - x0 = repmat(edge(:, 1)', Np, 1); - y0 = repmat(edge(:, 2)', Np, 1); - dx = repmat(edge(:,3)', Np, 1) - x0; - dy = repmat(edge(:,4)', Np, 1) - y0; - - lx = repmat(point(:, 1), 1, Ne) - x0; - ly = repmat(point(:, 2), 1, Ne) - y0; -end - -% test if point is located on supporting line -b1 = (abs(lx.*dy - ly.*dx) ./ hypot(dx, dy)) < tol; - -% compute position of point with respect to edge bounds -% use different tests depending on line angle -ind = abs(dx) > abs(dy); -t = zeros(size(dx)); -t(ind) = lx( ind) ./ dx( ind); -t(~ind) = ly(~ind) ./ dy(~ind); - -% check if point is located between edge bounds -b = t >- tol & t-1 < tol & b1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |