From: <jpi...@us...> - 2011-10-06 21:42:03
|
Revision: 8695 http://octave.svn.sourceforge.net/octave/?rev=8695&view=rev Author: jpicarbajal Date: 2011-10-06 21:41:54 +0000 (Thu, 06 Oct 2011) Log Message: ----------- geometry. Finish adding boxes and clips Modified Paths: -------------- trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/clipRay.m trunk/octave-forge/main/geometry/geom2d/inst/intersectBoxes.m trunk/octave-forge/main/geometry/geom2d/inst/intersectLines.m trunk/octave-forge/main/geometry/geom2d/inst/linePosition.m trunk/octave-forge/main/geometry/geom2d/inst/mergeBoxes.m trunk/octave-forge/main/geometry/geom2d/inst/randomPointInBox.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testClipRay.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectBoxes.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectLines.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLinePosition.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMergeBoxes.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipRay.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectBoxes.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLines.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/linePosition.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/mergeBoxes.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/randomPointInBox.m Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/INDEX 2011-10-06 21:41:54 UTC (rev 8695) @@ -14,6 +14,12 @@ rad2deg vectorAngle cbezier2poly + boxes2d + clipEdge + clipLine + clipPoints + drawBezierCurve + drawBox Input svgload svgnormalize Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-06 21:41:54 UTC (rev 8695) @@ -32,9 +32,16 @@ vectorAngle.m =============================================================================== -geometry-1.2 Release Date: 2011-10-xx Release Manager: Juan Pablo Carbajal +geometry-1.1.1 Release Date: 2011-10-xx Release Manager: Juan Pablo Carbajal =============================================================================== -* Continue to add geom2d from matGeom +* Continue to add geom2d from matGeom (boxes and clips) cbezier2poly.m + boxes2d.m + clipEdge.m + clipLine.m + clipPoints.m + drawBezierCurve.m + drawBox.m + =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/clipRay.m (from rev 8692, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipRay.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/clipRay.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/clipRay.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -0,0 +1,172 @@ +%% 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{edge} @var{inside}] =} clipRay (@var{ray}, @var{box}) +%% Clip a ray with a box. +%% +%% @var{ray} is a straight ray given as a 4 element row vector: [x0 y0 dx dy], +%% with (x0 y0) being the origin of the ray and (dx dy) its direction +%% vector, @var{box} is the clipping box, given by its extreme coordinates: +%% [xmin xmax ymin ymax]. +%% The result is given as an edge, defined by the coordinates of its 2 +%% extreme points: [x1 y1 x2 y2]. +%% If the ray does not intersect the box, [NaN NaN NaN NaN] is returned. +%% +%% Function works also if @var{ray} is a Nx4 array, if @var{box} is a Nx4 array, or +%% if both @var{ray} and @var{box} are Nx4 arrays. In these cases, @var{edge} is a Nx4 +%% array. +%% +%% @seealso{rays2d, boxes2d, edges2d, clipLine, drawRay} +%% @end deftypefn + +function [edge isInside] = clipRay(ray, bb) + + % adjust size of two input arguments + if size(ray, 1)==1 + ray = repmat(ray, size(bb, 1), 1); + elseif size(bb, 1)==1 + bb = repmat(bb, size(ray, 1), 1); + elseif size(ray, 1) != size(bb, 1) + error('bad sizes for input'); + end + + % first compute clipping of supporting line + edge = clipLine(ray, bb); + + % detectes valid edges (edges outside box are all NaN) + inds = find(isfinite(edge(:, 1))); + + % compute position of edge extremities relative to the ray + pos1 = linePosition(edge(inds,1:2), ray(inds,:)); + pos2 = linePosition(edge(inds,3:4), ray(inds,:)); + + % if first point is before ray origin, replace by origin + edge(inds(pos1<0), 1:2) = ray(inds(pos1<0), 1:2); + + % if last point of edge is before origin, set all edge to NaN + edge(inds(pos2<0), :) = NaN; + + % eventually returns result about inside or outside + if nargout>1 + isInside = isfinite(edge(:,1)); + end + +endfunction + +%!shared bb +%! bb = [0 100 0 100]; + +%!test % inside +%! origin = [30 40]; +%! direction = [10 0]; +%! ray = [origin direction]; +%! expected = [30 40 100 40]; +%! assert (expected, clipRay(ray, bb), 1e-6); + +%!test % outside +%! origin = [30 140]; +%! direction = [10 0]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % line inside, but ray outside +%! origin = [130 40]; +%! direction = [10 0]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % inside +%! origin = [30 40]; +%! direction = [-10 0]; +%! ray = [origin direction]; +%! expected = [30 40 0 40]; +%! assert (expected, clipRay(ray, bb), 1e-6); + +%!test % outside +%! origin = [30 140]; +%! direction = [-10 0]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % line inside, but ray outside +%! origin = [-30 40]; +%! direction = [-10 0]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % inside +%! origin = [30 40]; +%! direction = [0 10]; +%! ray = [origin direction]; +%! expected = [30 40 30 100]; +%! assert (expected, clipRay(ray, bb), 1e-6); + +%!test % outside +%! origin = [130 40]; +%! direction = [0 10]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % line inside, but ray outside +%! origin = [30 140]; +%! direction = [0 10]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % inside +%! origin = [30 40]; +%! direction = [0 -10]; +%! ray = [origin direction]; +%! expected = [30 40 30 0]; +%! assert (expected, clipRay(ray, bb), 1e-6); + +%!test % outside +%! origin = [130 40]; +%! direction = [0 -10]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test % line inside, but ray outside +%! origin = [30 -40]; +%! direction = [0 -10]; +%! ray = [origin direction]; +%! assert (sum(isnan(clipRay(ray, bb)))==4); + +%!test +%! origins = [30 40;30 40;30 140;130 40]; +%! directions = [10 0;0 10;10 0;0 10]; +%! rays = [origins directions]; +%! expected = [30 40 100 40;30 40 30 100;NaN NaN NaN NaN;NaN NaN NaN NaN]; +%! clipped = clipRay(rays, bb); +%! assert (expected, clipped, 1e-6); Copied: trunk/octave-forge/main/geometry/geom2d/inst/intersectBoxes.m (from rev 8687, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectBoxes.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/intersectBoxes.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/intersectBoxes.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -0,0 +1,76 @@ +%% 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{box} =} intersectBoxes (@var{box1}, @var{box2}) +%% Intersection of two bounding boxes. +%% +%% Example +%% +%% @example +%% box1 = [5 20 5 30]; +%% box2 = [0 15 0 15]; +%% intersectBoxes(box1, box2) +%% ans = +%% 5 15 5 15 +%% @end example +%% +%% @seealso{boxes2d, drawBox, mergeBoxes} +%% @end deftypefn + +function bb = intersectBoxes(box1, box2) + + % unify sizes of data + if size(box1,1) == 1 + box1 = repmat(box1, size(box2,1), 1); + elseif size(box2, 1) == 1 + box2 = repmat(box2, size(box1,1), 1); + elseif size(box1,1) != size(box2,1) + error('geom2d:Error',"Bad size for inputs.\n"); + end + + % compute extreme coords + mini = min(box1(:,[2 4]), box2(:,[2 4])); + maxi = max(box1(:,[1 3]), box2(:,[1 3])); + + % concatenate result into a new box structure + bb = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2)]; + +endfunction + +%!test +%! box1 = [5 20 10 25]; +%! box2 = [0 15 15 20]; +%! res = [5 15 15 20]; +%! bb = intersectBoxes(box1, box2); +%! assert (res, bb, 1e-6); Copied: trunk/octave-forge/main/geometry/geom2d/inst/intersectLines.m (from rev 8687, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLines.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/intersectLines.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/intersectLines.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -0,0 +1,178 @@ +%% 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{point} =} intersectLines (@var{line1}, @var{line2}) +%% @deftypefnx {Function File} {@var{point} =} intersectLines (@var{line1}, @var{line2},@var{eps}) +%% Return all intersection points of N lines in 2D. +%% +%% Returns the intersection point of lines @var{line1} and @var{line2}. +%% @var{line1} and @var{line2} are [1*4] +%% arrays, containing parametric representation of each line (in the form +%% [x0 y0 dx dy], see @code{createLine} for details). +%% +%% In case of colinear lines, returns [Inf Inf]. +%% In case of parallel but not colinear lines, returns [NaN NaN]. +%% +%% If each input is [N*4] array, the result is a [N*2] array containing +%% intersections of each couple of lines. +%% If one of the input has N rows and the other 1 row, the result is a +%% [N*2] array. +%% +%% A third input argument specifies the tolerance for detecting parallel lines. +%% Default is 1e-14. +%% +%% Example +%% +%% @example +%% line1 = createLine([0 0], [10 10]); +%% line2 = createLine([0 10], [10 0]); +%% point = intersectLines(line1, line2) +%% point = +%% 5 5 +%% @end example +%% +%% @seealso{lines2d, edges2d, intersectEdges, intersectLineEdge, intersectLineCircle} +%% @end deftypefn + +function point = intersectLines(line1, line2, varargin) + + % extreact tolerance + tol = 1e-14; + if !isempty(varargin) + tol = varargin{1}; + end + + x1 = line1(:,1); + y1 = line1(:,2); + dx1 = line1(:,3); + dy1 = line1(:,4); + + x2 = line2(:,1); + y2 = line2(:,2); + dx2 = line2(:,3); + dy2 = line2(:,4); + + N1 = length(x1); + N2 = length(x2); + + % indices of parallel lines + par = abs(dx1.*dy2 - dx2.*dy1) < tol; + + % indices of colinear lines + col = abs((x2-x1) .* dy1 - (y2-y1) .* dx1) < tol & par ; + + x0(col) = Inf; + y0(col) = Inf; + x0(par & !col) = NaN; + y0(par & !col) = NaN; + + i = !par; + + % compute intersection points + if N1==N2 + x0(i) = ((y2(i)-y1(i)).*dx1(i).*dx2(i) + x1(i).*dy1(i).*dx2(i) - x2(i).*dy2(i).*dx1(i)) ./ ... + (dx2(i).*dy1(i)-dx1(i).*dy2(i)) ; + y0(i) = ((x2(i)-x1(i)).*dy1(i).*dy2(i) + y1(i).*dx1(i).*dy2(i) - y2(i).*dx2(i).*dy1(i)) ./ ... + (dx1(i).*dy2(i)-dx2(i).*dy1(i)) ; + + elseif N1==1 + x0(i) = ((y2(i)-y1).*dx1.*dx2(i) + x1.*dy1.*dx2(i) - x2(i).*dy2(i).*dx1) ./ ... + (dx2(i).*dy1-dx1.*dy2(i)) ; + y0(i) = ((x2(i)-x1).*dy1.*dy2(i) + y1.*dx1.*dy2(i) - y2(i).*dx2(i).*dy1) ./ ... + (dx1.*dy2(i)-dx2(i).*dy1) ; + + elseif N2==1 + x0(i) = ((y2-y1(i)).*dx1(i).*dx2 + x1(i).*dy1(i).*dx2 - x2.*dy2.*dx1(i)) ./ ... + (dx2.*dy1(i)-dx1(i).*dy2) ; + y0(i) = ((x2-x1(i)).*dy1(i).*dy2 + y1(i).*dx1(i).*dy2 - y2.*dx2.*dy1(i)) ./ ... + (dx1(i).*dy2-dx2.*dy1(i)) ; + + else + % formattage a rajouter + x0(i) = ((y2(i)-y1(i)).*dx1(i).*dx2(i) + x1(i).*dy1(i).*dx2(i) - x2(i).*dy2(i).*dx1(i)) ./ ... + (dx2(i).*dy1(i)-dx1(i).*dy2(i)) ; + y0(i) = ((x2(i)-x1(i)).*dy1(i).*dy2(i) + y1(i).*dx1(i).*dy2(i) - y2(i).*dx2(i).*dy1(i)) ./ ... + (dx1(i).*dy2(i)-dx2(i).*dy1(i)) ; + end + + % concatenate result + point = [x0' y0']; + +endfunction + +%!test % basic test with two orthogonal lines +%! line1 = [3 1 0 1]; +%! line2 = [1 4 1 0]; +%! assert (intersectLines(line1, line2), [3 4], 1e-6); + +%!test % orthognal diagonal lines +%! line1 = [0 0 3 2]; +%! line2 = [5 -1 4 -6]; +%! assert (intersectLines(line1, line2), [3 2], 1e-6); + +%!test % one diagonal and one horizontal line +%! line1 = [10 2 25 0]; +%! line2 = [5 -1 4 -6]; +%! assert (intersectLines(line1, line2), [3 2], 1e-6); + +%!test % check for dx and dy very big compared to other line +%! line1 = [3 1 0 1000]; +%! line2 = [1 4 -14 0]; +%! assert (intersectLines(line1, line2), [3 4], 1e-6); + +%!test +%! line1 = [2 0 20000 30000]; +%! line2 = [1 6 1 -1]; +%! assert (intersectLines(line1, line2), [4 3], 1e-6); + +%!test +%! line1 = [3 1 0 1]; +%! line2 = repmat([1 4 1 0], 5, 1); +%! res = repmat([3 4], 5, 1); +%! inters = intersectLines(line1, line2); +%! assert (res, inters, 1e-6); + +%!test +%! line1 = repmat([3 1 0 1], 5, 1); +%! line2 = [1 4 1 0]; +%! res = repmat([3 4], 5, 1); +%! inters = intersectLines(line1, line2); +%! assert (res, inters, 1e-6); + +%!test +%! line1 = repmat([3 1 0 1], 5, 1); +%! line2 = repmat([1 4 1 0], 5, 1); +%! res = repmat([3 4], 5, 1); +%! inters = intersectLines(line1, line2); +%! assert (res, inters, 1e-6); Copied: trunk/octave-forge/main/geometry/geom2d/inst/linePosition.m (from rev 8687, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/linePosition.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/linePosition.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/linePosition.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -0,0 +1,139 @@ +%% 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 PUR@var{pos}E +%% 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 +%% @var{pos}SIBILITY 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{pos} =} linePosition (@var{point}, @var{line}) +%% Position of a point on a line. +%% +%% Computes position of point @var{point} on the line @var{line}, relative to origin +%% point and direction vector of the line. +%% @var{line} has the form [x0 y0 dx dy], +%% @var{point} has the form [x y], and is assumed to belong to line. +%% +%% If @var{line} is an array of NL lines, return NL positions, corresponding to +%% each line. +%% +%% If @var{point} is an array of NP points, return NP positions, corresponding +%% to each point. +%% +%% If @var{point} is an array of NP points and @var{line}S is an array of NL lines, +%% return an array of [NP NL] position, corresponding to each couple +%% point-line. +%% +%% Example +%% +%% @example +%% line = createLine([10 30], [30 90]); +%% linePosition([20 60], line) +%% ans = +%% .5 +%% @end example +%% +%% @seealso{lines2d, createLine, projPointOnLine, isPointOnLine} +%% @end deftypefn + +function d = linePosition(point, lin) + + % number of inputs + Nl = size(lin, 1); + Np = size(point, 1); + + if Np == Nl + % if both inputs have the same size, no problem + dxl = lin(:, 3); + dyl = lin(:, 4); + dxp = point(:, 1) - lin(:, 1); + dyp = point(:, 2) - lin(:, 2); + + elseif Np == 1 + % one point, several lines + dxl = lin(:, 3); + dyl = lin(:, 4); + dxp = point(ones(Nl, 1), 1) - lin(:, 1); + dyp = point(ones(Nl, 1), 2) - lin(:, 2); + + elseif Nl == 1 + % one lin, several points + dxl = lin(ones(Np, 1), 3); + dyl = lin(ones(Np, 1), 4); + dxp = point(:, 1) - lin(1); + dyp = point(:, 2) - lin(2); + + else + % expand one of the array to have the same size + dxl = repmat(lin(:,3)', Np, 1); + dyl = repmat(lin(:,4)', Np, 1); + dxp = repmat(point(:,1), 1, Nl) - repmat(lin(:,1)', Np, 1); + dyp = repmat(point(:,2), 1, Nl) - repmat(lin(:,2)', Np, 1); + end + + % compute position + d = (dxp.*dxl + dyp.*dyl) ./ (dxl.^2 + dyl.^2); + +endfunction + +%!demo +%! point = [20 60;10 30;25 75]; +%! lin = createLine([10 30], [30 90]); +%! pos = linePosition(point, lin) +%! +%! plot(point(:,1),point(:,2),'ok'); +%! hold on +%! drawLine(lin,'color','r'); +%! plot(lin(1)+lin(3)*pos,lin(2)+lin(4)*pos,'xb') +%! hold off + +%!test +%! point = [20 60]; +%! lin = createLine([10 30], [30 90]); +%! res = .5; +%! pos = linePosition(point, lin); +%! assert (res, pos); + +%!test +%! point = [20 60;10 30;25 75]; +%! lin = createLine([10 30], [30 90]); +%! res = [.5; 0; .75]; +%! pos = linePosition(point, lin); +%! assert (res, pos); + +%!test +%! point = [20 60]; +%! lin1 = createLine([10 30], [30 90]); +%! lin2 = createLine([0 0], [20 60]); +%! lin3 = createLine([20 60], [40 120]); +%! lines = [lin1;lin2;lin3]; +%! res = [.5; 1; 0]; +%! pos = linePosition(point, lines); +%! assert (res, pos); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/mergeBoxes.m (from rev 8687, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/mergeBoxes.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/mergeBoxes.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/mergeBoxes.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -0,0 +1,77 @@ +%% 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{box} =} mergeBoxes (@var{box1}, @var{box2}) +%% Merge two boxes, by computing their greatest extent. +%% +% Example +%% +%% @example +%% box1 = [5 20 5 30]; +%% box2 = [0 15 0 15]; +%% mergeBoxes(box1, box2) +%% ans = +%% 0 20 0 30 +%% @end example +%% +%% @seealso{boxes2d, drawBox, intersectBoxes} +%% @end deftypefn + +function bb = mergeBoxes(box1, box2) + + % unify sizes of data + if size(box1,1) == 1 + box1 = repmat(box1, size(box2,1), 1); + elseif size(box2, 1) == 1 + box2 = repmat(box2, size(box1,1), 1); + elseif size(box1,1) != size(box2,1) + error('geom2d:Error', 'Bad size for inputs'); + end + + % compute extreme coords + mini = min(box1(:,[1 3]), box2(:,[1 3])); + maxi = max(box1(:,[2 4]), box2(:,[2 4])); + + % concatenate result into a new box structure + bb = [mini(:,1) maxi(:,1) mini(:,2) maxi(:,2)]; + +endfunction + +%!test +%! box1 = [5 20 10 25]; +%! box2 = [0 15 15 20]; +%! res = [0 20 10 25]; +%! bb = mergeBoxes(box1, box2); +%! assert (res, bb, 1e-6); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/randomPointInBox.m (from rev 8687, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/randomPointInBox.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/randomPointInBox.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/randomPointInBox.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -0,0 +1,85 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{points} =} randomPointInBox (@var{box}) +%% @deftypefnx {Function File} {@var{points} =} randomPointInBox (@var{box}, @var{n}) +%% Generate random points within a box. +%% +%% Generate a random point within the box @var{box}. The result is a 1-by-2 row +%% vector. If @var{n} is given, generates @var{n} points. The result is a +%% @var{n}-by-2 array. +%% +%% Example +%% +%% @example +%% % draw points within a box +%% box = [10 80 20 60]; +%% pts = randomPointInBox(box, 500); +%% figure(1); clf; hold on; +%% drawBox(box); +%% drawPoint(pts, '.'); +%% axis('equal'); +%% axis([0 100 0 100]); +%% @end example +%% +%% @seealso{edges2d, boxes2d, clipLine} +%% @end deftypefn + +function points = randomPointInBox(box, N=1, varargin) + + % extract box bounds + xmin = box(1); + xmax = box(2); + ymin = box(3); + ymax = box(4); + + % compute size of box + dx = xmax - xmin; + dy = ymax - ymin; + + % compute point coordinates + points = [rand(N, 1)*dx+xmin , rand(N, 1)*dy+ymin]; + +endfunction + +%!demo +%! % draw points within a box +%! bb = [10 80 20 60]; +%! pts = randomPointInBox(bb, 500); +%! figure(1); clf; hold on; +%! drawBox(bb); +%! drawPoint(pts, '.'); +%! axis equal +%! axis([0 100 0 100]); + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testClipRay.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testClipRay.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testClipRay.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,131 +0,0 @@ -function test_suite = testClipRay(varargin) -% Tests the function 'clipRay' -% output = testClipRay(input) -% -% Example -% testClipRay -% -% 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 testRightSide -% test edges totally inside window, possibly touching edges - -% a basic bounding box -box = [0 100 0 100]; - -% inside -origin = [30 40]; -direction = [10 0]; -ray = [origin direction]; -expected = [30 40 100 40]; -assertElementsAlmostEqual(expected, clipRay(ray, box)); - -% outside -origin = [30 140]; -direction = [10 0]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - -% line inside, but ray outside -origin = [130 40]; -direction = [10 0]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - -function testLeftSide -% test edges totally inside window, possibly touching edges - -% a basic bounding box -box = [0 100 0 100]; - -% inside -origin = [30 40]; -direction = [-10 0]; -ray = [origin direction]; -expected = [30 40 0 40]; -assertElementsAlmostEqual(expected, clipRay(ray, box)); - -% outside -origin = [30 140]; -direction = [-10 0]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - -% line inside, but ray outside -origin = [-30 40]; -direction = [-10 0]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - - -function testUpSide -% test edges totally inside window, possibly touching edges - -box = [0 100 0 100]; - -% inside -origin = [30 40]; -direction = [0 10]; -ray = [origin direction]; -expected = [30 40 30 100]; -assertElementsAlmostEqual(expected, clipRay(ray, box)); - -% outside -origin = [130 40]; -direction = [0 10]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - -% line inside, but ray outside -origin = [30 140]; -direction = [0 10]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - - -function testDownSide -% test edges totally inside window, possibly touching edges - -box = [0 100 0 100]; - -% inside -origin = [30 40]; -direction = [0 -10]; -ray = [origin direction]; -expected = [30 40 30 0]; -assertElementsAlmostEqual(expected, clipRay(ray, box)); - -% outside -origin = [130 40]; -direction = [0 -10]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - -% line inside, but ray outside -origin = [30 -40]; -direction = [0 -10]; -ray = [origin direction]; -assertTrue(sum(isnan(clipRay(ray, box)))==4); - - -function testArray -% test with an array of rays and a box - -box = [0 100 0 100]; - -origins = [30 40;30 40;30 140;130 40]; -directions = [10 0;0 10;10 0;0 10]; -rays = [origins directions]; -expected = [30 40 100 40;30 40 30 100;NaN NaN NaN NaN;NaN NaN NaN NaN]; -clipped = clipRay(rays, box); -assertElementsAlmostEqual(expected, clipped); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectBoxes.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectBoxes.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectBoxes.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,26 +0,0 @@ -function test_suite = testIntersectBoxes(varargin) %#ok<STOUT> -%testIntersectBoxes One-line description here, please. -% -% output = testIntersectBoxes(input) -% -% Example -% testIntersectBoxes -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-08-06, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - - -initTestSuite; - -function testBasic %#ok<*DEFNU> -box1 = [5 20 10 25]; -box2 = [0 15 15 20]; -exp = [5 15 15 20]; -box = intersectBoxes(box1, box2); -assertElementsAlmostEqual(exp, box); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectLines.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectLines.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIntersectLines.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,76 +0,0 @@ -function test_suite = testIntersectLines(varargin) %#ok<STOUT> -%TESTINTERSECTLINES One-line description here, please. -% output = testIntersectLines(input) -% -% Example -% testIntersectLines -% -% 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 testOrthogonal %#ok<*DEFNU> -% basic test with two orthogonal lines -line1 = [3 1 0 1]; -line2 = [1 4 1 0]; -assertElementsAlmostEqual(intersectLines(line1, line2), [3 4]); - -function testOrthogonalDiagonals -% orthognal diagonal lines -line1 = [0 0 3 2]; -line2 = [5 -1 4 -6]; -assertElementsAlmostEqual(intersectLines(line1, line2), [3 2]); - -function testDiagonalHorizontal -% one diagonal and one horizontal line -line1 = [10 2 25 0]; -line2 = [5 -1 4 -6]; -assertElementsAlmostEqual(intersectLines(line1, line2), [3 2]); - -function testBigDerivative -% check for dx and dy very big compared to other line -line1 = [3 1 0 1000]; -line2 = [1 4 -14 0]; -assertElementsAlmostEqual(intersectLines(line1, line2), [3 4]); - -line1 = [2 0 20000 30000]; -line2 = [1 6 1 -1]; -assertElementsAlmostEqual(intersectLines(line1, line2), [4 3]); - -function testSingleArray - -line1 = [3 1 0 1]; -line2 = repmat([1 4 1 0], 5, 1); -exp = repmat([3 4], 5, 1); - -inters = intersectLines(line1, line2); -assertElementsAlmostEqual(exp, inters); - - -function testArraySingle - -line1 = repmat([3 1 0 1], 5, 1); -line2 = [1 4 1 0]; -exp = repmat([3 4], 5, 1); - -inters = intersectLines(line1, line2); -assertElementsAlmostEqual(exp, inters); - - -function testArrayArray - -line1 = repmat([3 1 0 1], 5, 1); -line2 = repmat([1 4 1 0], 5, 1); -exp = repmat([3 4], 5, 1); - -inters = intersectLines(line1, line2); -assertElementsAlmostEqual(exp, inters); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLinePosition.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLinePosition.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLinePosition.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,55 +0,0 @@ -function test_suite = testLinePosition(varargin) %#ok<STOUT> -%TESTLINEPOSITION One-line description here, please. -% -% output = testLinePosition(input) -% -% Example -% testLinePosition -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2011-06-15, using Matlab 7.9.0.529 (R2009b) -% Copyright 2011 INRA - Cepia Software Platform. - - -initTestSuite; - -function testBasic %#ok<*DEFNU> - -point = [20 60]; -line = createLine([10 30], [30 90]); - -exp = .5; -pos = linePosition(point, line); - -assertEqual(exp, pos); - - -function testPointArray - -point = [20 60;10 30;25 75]; -line = createLine([10 30], [30 90]); - -exp = [.5; 0; .75]; -pos = linePosition(point, line); - -assertEqual(exp, pos); - - -function testLineArray - -point = [20 60]; -line1 = createLine([10 30], [30 90]); -line2 = createLine([0 0], [20 60]); -line3 = createLine([20 60], [40 120]); -lines = [line1;line2;line3]; - -exp = [.5; 1; 0]; -pos = linePosition(point, lines); - -assertEqual(exp, pos); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMergeBoxes.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMergeBoxes.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMergeBoxes.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,26 +0,0 @@ -function test_suite = testMergeBoxes(varargin) %#ok<*STOUT> -%testMergeBoxes One-line description here, please. -% -% output = testMergeBoxes(input) -% -% Example -% testMergeBoxes -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-08-06, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - - -initTestSuite; - -function testBasic %#ok<*DEFNU> -box1 = [5 20 10 25]; -box2 = [0 15 15 20]; -exp = [0 20 10 25]; -box = mergeBoxes(box1, box2); -assertElementsAlmostEqual(exp, box); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipRay.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipRay.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipRay.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,86 +0,0 @@ -%% 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{edge} @var{inside}] =} clipRay (@var{ray}, @var{box}) -%% Clip a ray with a box. -%% -%% @var{ray} is a straight ray given as a 4 element row vector: [x0 y0 dx dy], -%% with (x0 y0) being the origin of the ray and (dx dy) its direction -%% vector, @var{box} is the clipping box, given by its extreme coordinates: -%% [xmin xmax ymin ymax]. -%% The result is given as an edge, defined by the coordinates of its 2 -%% extreme points: [x1 y1 x2 y2]. -%% If the ray does not intersect the box, [NaN NaN NaN NaN] is returned. -%% -%% Function works also if @var{ray} is a Nx4 array, if @var{box} is a Nx4 array, or -%% if both @var{ray} and @var{box} are Nx4 arrays. In these cases, @var{edge} is a Nx4 -%% array. -%% -%% @seealso{rays2d, boxes2d, edges2d, clipLine, drawRay} -%% @end deftypefn - -function [edge isInside] = clipRay(ray, box) - - % adjust size of two input arguments - if size(ray, 1)==1 - ray = repmat(ray, size(box, 1), 1); - elseif size(box, 1)==1 - box = repmat(box, size(ray, 1), 1); - elseif size(ray, 1) != size(box, 1) - error('bad sizes for input'); - end - - % first compute clipping of supporting line - edge = clipLine(ray, box); - - % detectes valid edges (edges outside box are all NaN) - inds = find(isfinite(edge(:, 1))); - - % compute position of edge extremities relative to the ray - pos1 = linePosition(edge(inds,1:2), ray(inds,:)); - pos2 = linePosition(edge(inds,3:4), ray(inds,:)); - - % if first point is before ray origin, replace by origin - edge(inds(pos1<0), 1:2) = ray(inds(pos1<0), 1:2); - - % if last point of edge is before origin, set all edge to NaN - edge(inds(pos2<0), :) = NaN; - - % eventually returns result about inside or outside - if nargout>1 - isInside = isfinite(edge(:,1)); - end - -endfunction - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectBoxes.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectBoxes.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectBoxes.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,71 +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 box = intersectBoxes(box1, box2) -%INTERSECTBOXES Intersection of two bounding boxes -% -% RES = intersectBoxes(BOX1, BOX2) -% -% Example -% box1 = [5 20 5 30]; -% box2 = [0 15 0 15]; -% intersectBoxes(box1, box2) -% ans = -% 5 15 5 15 -% -% See also -% boxes2d, drawBox, mergeBoxes -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - -% unify sizes of data -if size(box1,1) == 1 - box1 = repmat(box1, size(box2,1), 1); -elseif size(box2, 1) == 1 - box2 = repmat(box2, size(box1,1), 1); -elseif size(box1,1) ~= size(box2,1) - error('Bad size for inputs'); -end - -% compute extreme coords -mini = min(box1(:,[2 4]), box2(:,[2 4])); -maxi = max(box1(:,[1 3]), box2(:,[1 3])); - -% concatenate result into a new box structure -box = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2)]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLines.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLines.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLines.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,135 +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 = intersectLines(line1, line2, varargin) -%INTERSECTLINES Return all intersection points of N lines in 2D -% -% PT = intersectLines(L1, L2); -% returns the intersection point of lines L1 and L2. L1 and L2 are [1*4] -% arrays, containing parametric representation of each line (in the form -% [x0 y0 dx dy], see 'createLine' for details). -% -% In case of colinear lines, returns [Inf Inf]. -% In case of parallel but not colinear lines, returns [NaN NaN]. -% -% If each input is [N*4] array, the result is a [N*2] array containing -% intersections of each couple of lines. -% If one of the input has N rows and the other 1 row, the result is a -% [N*2] array. -% -% PT = intersectLines(L1, L2, EPS); -% Specifies the tolerance for detecting parallel lines. Default is 1e-14. -% -% Example -% line1 = createLine([0 0], [10 10]); -% line2 = createLine([0 10], [10 0]); -% point = intersectLines(line1, line2) -% point = -% 5 5 -% -% See also -% lines2d, edges2d, intersectEdges, intersectLineEdge -% intersectLineCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 19/02/2004 add support for multiple lines. -% 08/03/2007 update doc - -% extreact tolerance -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -x1 = line1(:,1); -y1 = line1(:,2); -dx1 = line1(:,3); -dy1 = line1(:,4); - -x2 = line2(:,1); -y2 = line2(:,2); -dx2 = line2(:,3); -dy2 = line2(:,4); - -N1 = length(x1); -N2 = length(x2); - -% indices of parallel lines -par = abs(dx1.*dy2 - dx2.*dy1) < tol; - -% indices of colinear lines -col = abs((x2-x1) .* dy1 - (y2-y1) .* dx1) < tol & par ; - -x0(col) = Inf; -y0(col) = Inf; -x0(par & ~col) = NaN; -y0(par & ~col) = NaN; - -i = ~par; - -% compute intersection points -if N1==N2 - x0(i) = ((y2(i)-y1(i)).*dx1(i).*dx2(i) + x1(i).*dy1(i).*dx2(i) - x2(i).*dy2(i).*dx1(i)) ./ ... - (dx2(i).*dy1(i)-dx1(i).*dy2(i)) ; - y0(i) = ((x2(i)-x1(i)).*dy1(i).*dy2(i) + y1(i).*dx1(i).*dy2(i) - y2(i).*dx2(i).*dy1(i)) ./ ... - (dx1(i).*dy2(i)-dx2(i).*dy1(i)) ; - -elseif N1==1 - x0(i) = ((y2(i)-y1).*dx1.*dx2(i) + x1.*dy1.*dx2(i) - x2(i).*dy2(i).*dx1) ./ ... - (dx2(i).*dy1-dx1.*dy2(i)) ; - y0(i) = ((x2(i)-x1).*dy1.*dy2(i) + y1.*dx1.*dy2(i) - y2(i).*dx2(i).*dy1) ./ ... - (dx1.*dy2(i)-dx2(i).*dy1) ; - -elseif N2==1 - x0(i) = ((y2-y1(i)).*dx1(i).*dx2 + x1(i).*dy1(i).*dx2 - x2.*dy2.*dx1(i)) ./ ... - (dx2.*dy1(i)-dx1(i).*dy2) ; - y0(i) = ((x2-x1(i)).*dy1(i).*dy2 + y1(i).*dx1(i).*dy2 - y2.*dx2.*dy1(i)) ./ ... - (dx1(i).*dy2-dx2.*dy1(i)) ; - -else - % formattage a rajouter - x0(i) = ((y2(i)-y1(i)).*dx1(i).*dx2(i) + x1(i).*dy1(i).*dx2(i) - x2(i).*dy2(i).*dx1(i)) ./ ... - (dx2(i).*dy1(i)-dx1(i).*dy2(i)) ; - y0(i) = ((x2(i)-x1(i)).*dy1(i).*dy2(i) + y1(i).*dx1(i).*dy2(i) - y2(i).*dx2(i).*dy1(i)) ./ ... - (dx1(i).*dy2(i)-dx2(i).*dy1(i)) ; -end - -% concatenate result -point = [x0' y0']; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/linePosition.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/linePosition.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/linePosition.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,112 +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 d = linePosition(point, line) -%LINEPOSITION Position of a point on a line -% -% POS = linePosition(POINT, LINE); -% Computes position of point POINT on the line LINE, relative to origin -% point and direction vector of the line. -% LINE has the form [x0 y0 dx dy], -% POINT has the form [x y], and is assumed to belong to line. -% -% POS = linePosition(POINT, LINES); -% If LINES is an array of NL lines, return NL positions, corresponding to -% each line. -% -% POS = linePosition(POINTS, LINE); -% If POINTS is an array of NP points, return NP positions, corresponding -% to each point. -% -% POS = linePosition(POINTS, LINES); -% If POINTS is an array of NP points and LINES is an array of NL lines, -% return an array of [NP NL] position, corresponding to each couple -% point-line. -% -% Example -% line = createLine([10 30], [30 90]); -% linePosition([20 60], line) -% ans = -% .5 -% -% See also: -% lines2d, createLine, projPointOnLine, isPointOnLine -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 25/05/2004. -% - -% HISTORY -% 2005-07-07 manage multiple input -% 2011-06-15 avoid the use of repmat when possible - -% number of inputs -Nl = size(line, 1); -Np = size(point, 1); - -if Np == Nl - % if both inputs have the same size, no problem - dxl = line(:, 3); - dyl = line(:, 4); - dxp = point(:, 1) - line(:, 1); - dyp = point(:, 2) - line(:, 2); - -elseif Np == 1 - % one point, several lines - dxl = line(:, 3); - dyl = line(:, 4); - dxp = point(ones(Nl, 1), 1) - line(:, 1); - dyp = point(ones(Nl, 1), 2) - line(:, 2); - -elseif Nl == 1 - % one line, several points - dxl = line(ones(Np, 1), 3); - dyl = line(ones(Np, 1), 4); - dxp = point(:, 1) - line(1); - dyp = point(:, 2) - line(2); - -else - % expand one of the array to have the same size - dxl = repmat(line(:,3)', Np, 1); - dyl = repmat(line(:,4)', Np, 1); - dxp = repmat(point(:,1), 1, Nl) - repmat(line(:,1)', Np, 1); - dyp = repmat(point(:,2), 1, Nl) - repmat(line(:,2)', Np, 1); -end - -% compute position -d = (dxp.*dxl + dyp.*dyl) ./ (dxl.^2 + dyl.^2); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/mergeBoxes.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/mergeBoxes.m 2011-10-06 21:37:42 UTC (rev 8694) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/mergeBoxes.m 2011-10-06 21:41:54 UTC (rev 8695) @@ -1,72 +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 box = mergeBoxes(box1, box2) -%MERGEBOXES Merge two boxes, by computing their greatest extent -% -% BOX = mergeBoxes(BOX1, BOX2); -% -% Example -% box1 = [5 20 5 30]; -% box2 = [0 15 0 15]; -% mergeBoxes(box1, box2) -% ans = -% 0 20 0 30 -% -% -% See also -% boxes2d, drawBox, intersectBoxes -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - -% unify sizes of data -if size(box1,1) == 1 - box1 = repmat(box1, size(box2,1), 1); -elseif size(box2, 1) =... [truncated message content] |