From: <jpi...@us...> - 2011-10-16 20:55:57
|
Revision: 8757 http://octave.svn.sourceforge.net/octave/?rev=8757&view=rev Author: jpicarbajal Date: 2011-10-16 20:55:49 +0000 (Sun, 16 Oct 2011) Log Message: ----------- geometry. Adding rest of create* functions 2 to go Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m trunk/octave-forge/main/geometry/geom2d/inst/private/ trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m Copied: trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,123 @@ +%% 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{circle} = } createCircle (@var{p1}, @var{p2}, @var{p3}) +%% @deftypefnx {Function File} {@var{circle} = } createCircle (@var{p1}, @var{p2}) +%% Create a circle from 2 or 3 points. +%% +%% Creates the circle passing through the 3 given points. +%% C is a 1x3 array of the form: [XC YX R]. +%% +%% When two points are given, creates the circle whith center @var{p1} and passing +%% throuh the point @var{p2}. +%% +%% Works also when input are point arrays the same size, in this case the +%% result has as many lines as the point arrays. +%% +%% Example +%% +%% @example +%% % Draw a circle passing through 3 points. +%% p1 = [10 15]; +%% p2 = [15 20]; +%% p3 = [10 25]; +%% circle = createCircle(p1, p2, p3); +%% figure; hold on; axis equal; axis([0 50 0 50]); +%% drawPoint([p1 ; p2; p3]); +%% drawCircle(circle); +%% @end example +%% +%% @seealso{circles2d, createDirectedCircle} +%% @end deftypefn + +function circle = createCircle(varargin) + + if nargin == 2 + % inputs are the center and a point on the circle + p1 = varargin{1}; + p2 = varargin{2}; + x0 = p1(:,1); + y0 = p1(:,2); + r = hypot((p2(:,1)-x0), (p2(:,2)-y0)); + + elseif nargin == 3 + % inputs are three points on the circle + p1 = varargin{1}; + p2 = varargin{2}; + p3 = varargin{3}; + + % compute circle center + line1 = medianLine(p1, p2); + line2 = medianLine(p1, p3); + point = intersectLines(line1, line2); + x0 = point(:, 1); + y0 = point(:, 2); + + % circle radius + r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); + end + + % create array for returning result + circle = [x0 y0 r]; + +endfunction + +%!test +%! p1 = [10 15]; +%! p2 = [15 20]; +%! p3 = [10 25]; +%! exp = [10 20 5]; +%! circle = createCircle(p1, p2, p3); +%! assertEqual(exp, circle); +%! circle = createCircle(p3, p1, p2); +%! assertEqual(exp, circle); +%! circle = createCircle(p2, p3, p1); +%! assertEqual(exp, circle); + +%!test +%! p1 = [10 15]; +%! p2 = [15 20]; +%! p3 = [10 25]; +%! exp = [10 20 5]; +%! p1 = [p1; p1+10; p1+20; p1-5]; +%! p2 = [p2; p2+10; p2+20; p2-5]; +%! p3 = [p3; p3+10; p3+20; p3-5]; +%! exp = repmat(exp, 4, 1) + [0 0 0;10 10 0;20 20 0;-5 -5 0]; +%! circle = createCircle(p1, p2, p3); +%! assertEqual(exp, circle); +%! circle = createCircle(p3, p1, p2); +%! assertEqual(exp, circle); +%! circle = createCircle(p2, p3, p1); +%! assertEqual(exp, circle); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,92 @@ +%% Copyright (c) 2011, INRA +%% 2005-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{circle} = } createDirectedCircle (@var{p1}, @var{p2}, @var{p3}) +%% @deftypefnx {Function File} {@var{circle} = } createDirectedCircle (@var{p1}, @var{p2}) +%% Create a circle from 2 or 3 points. +%% +%% Creates the circle passing through the 3 given points. +%% C is a 1x4 array of the form: [XC YX R INV]. +%% +%% When two points are given, creates the circle whith center @var{p1} and passing +%% throuh the point @var{p2}. +%% +%% Works also when input are point arrays the same size, in this case the +%% result has as many lines as the point arrays. +%% +%% Example +%% +%% +%% @seealso{circles2d, createCircle} +%% @end deftypefn + +function circle = createDirectedCircle(varargin) + + if nargin == 2 + % inputs are the center and a point on the circle + p1 = varargin{1}; + p2 = varargin{2}; + x0 = (p1(:,1) + p2(:,1))/2; + y0 = (p1(:,2) + p2(:,2))/2; + r = hypot((p2(:,1)-p1(:,1)), (p2(:,2)-p1(:,2)))/2; + + % circle is direct by default + d = 0; + + elseif nargin == 3 + % inputs are three points on the circle + p1 = varargin{1}; + p2 = varargin{2}; + p3 = varargin{3}; + + % compute circle center + line1 = medianLine(p1, p2); + line2 = medianLine(p1, p3); + center = intersectLines(line1, line2); + x0 = center(:, 1); + y0 = center(:, 2); + + % circle radius + r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); + + % compute circle orientation + angle = angle3Points(p1, center, p2) + angle3Points(p2, center, p3); + d = angle>2*pi; + end + + + circle = [x0 y0 r d]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,121 @@ +%% 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{edge} = } createEdge (@var{p1}, @var{p2}) +%% @deftypefnx {Function File} {@var{edge} = } createEdge (@var{x0}, @var{y0}, @var{dx}, @var{dy}) +%% @deftypefnx {Function File} {@var{edge} = } createEdge (@var{param}) +%% @deftypefnx {Function File} {@var{edge} = } createEdge (@var{line}, @var{d}) +%% Create an edge between two points, or from a line. +%% +%% The internal format for edge representation is given by coordinates of +%% two points : [x1 y1 x2 y2]. +%% This function can serve as a line to edge converter. +%% +%% +%% Returns the edge between the two given points @var{p1} and @var{p2}. +%% +%% Returns the edge going through point (@var{x0}, @var{y0}) and with direction +%% vector (@var{dx},@var{dy}). +%% +%% When @var{param} is an array of 4 values, creates the edge going through the +%% point (param(1) param(2)), and with direction vector given by +%% (param(3) param(4)). +%% +%% When @var{line} is given, creates the edge contained in @var{line}, with same +%% direction and start point, but with length given by @var{d}. +%% +%% +%% Note: in all cases, parameters can be vertical arrays of the same +%% dimension. The result is then an array of edges, of dimensions [N*4]. +%% +%% @seealso{edges2d, lines2d, drawEdge, clipEdge} +%% @end deftypefn + +function edge = createEdge(varargin) + + if length(varargin)==1 + % Only one input parameter. It can be : + % - line angle + % - array of four parameters + % TODO : add control for arrays of lines. + var = varargin{1}; + + if size(var, 2)==4 + % 4 parameters of the line in a single array. + %edge = var; + edge = zeros(size(var)); + edge(:, 1:2) = var(:,1:2); + edge(:, 3:4) = edge(:, 1:2)+var(:,3:4); + elseif size(var, 2)==1 + % 1 parameter : angle of the line, going through origin. + edge = [zeros(size(var,1)) zeros(size(var,1)) cos(var) sin(var)]; + else + error('wrong number of dimension for arg1 : can be 1 or 4'); + end + + elseif length(varargin)==2 + % 2 input parameters. They can be : + % - 2 points, then 2 arrays of 1*2 double, + % - a line, and a distance. + v1 = varargin{1}; + v2 = varargin{2}; + if size(v1, 2)==2 + % first input parameter is first point, and second input is the + % second point. + %edge = [v1(:,1), v1(:,2), v2(:,1), v2(:,2)]; + edge = [v1 v2]; + else + % first input parameter is a line, and second one a distance. + angle = atan2(v1(:,4), v1(:,3)); + edge = [v1(:,1), v1(:,2), v1(:,1)+v2.*cos(angle), v1(:,2)+v2.*sin(angle)]; + end + + elseif length(varargin)==3 + % 3 input parameters : + % first one is a point belonging to the line, + % second and third ones are direction vector of the line (dx and dy). + p = varargin{1}; + edge = [p(:,1) p(:,2) p(:,1)+varargin{2} p(:,2)+varargin{3}]; + + elseif length(varargin)==4 + % 4 input parameters : + % they are x0, y0 (point belonging to line) and dx, dy (direction + % vector of the line). + % All parameters should have the same size. + edge = [varargin{1} varargin{2} varargin{1}+varargin{3} varargin{2}+varargin{4}]; + else + error('Wrong number of arguments in ''createLine'' '); + end + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,137 @@ +%% 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{line} = } medianLine (@var{p1}, @var{p2}) +%% @deftypefnx {Function File} {@var{line} = } medianLine (@var{pts}) +%% @deftypefnx {Function File} {@var{line} = } medianLine (@var{edge}) +%% Create a median line between two points. +%% +%% Create the median line of points @var{p1} and @var{p2}, that is the line containing +%% all points located at equal distance of @var{p1} and @var{p2}. +%% +%% Creates the median line of 2 points, given as a 2*2 array @var{pts}. Array has +%% the form: +%% [ [ x1 y1 ] ; [ x2 y2 ] ] +%% +%% Creates the median of the @var{edge}. @var{edge} is a 1*4 array, containing [X1 Y1] +%% coordinates of first point, and [X2 Y2], the coordinates of the second +%% point. +%% +%% Example +%% +%% @example +%% % Draw the median line of two points +%% P1 = [10 20]; +%% P2 = [30 50]; +%% med = medianLine(P1, P2); +%% figure; axis square; axis([0 100 0 100]); +%% drawEdge([P1 P2], 'linewidth', 2, 'color', 'k'); +%% drawLine(med) +%% +%% % Draw the median line of an edge +%% P1 = [50 60]; +%% P2 = [80 30]; +%% edge = createEdge(P1, P2); +%% figure; axis square; axis([0 100 0 100]); +%% drawEdge(edge, 'linewidth', 2) +%% med = medianLine(edge); +%% drawLine(med) +%% @end example +%% +%% @seealso{lines2d, createLine, orthogonalLine} +%% @end deftypefn + +function lin = medianLine(varargin) + + nargs = length(varargin); + x0 = 0; + y0 = 0; + dx = 0; + dy = 0; + + if nargs == 1 + tab = varargin{1}; + if size(tab, 2)==2 + % input is an array of two points + x0 = tab(1,1); + y0 = tab(1,2); + dx = tab(2,1)-x0; + dy = tab(2,2)-y0; + else + % input is an edge + x0 = tab(:, 1); + y0 = tab(:, 2); + dx = tab(:, 3) - tab(:, 1); + dy = tab(:, 4) - tab(:, 2); + end + + elseif nargs==2 + % input is given as two points, or two point arrays + p1 = varargin{1}; + p2 = varargin{2}; + x0 = p1(:, 1); + y0 = p1(:, 2); + dx = bsxfun(@minus, p2(:, 1), x0); + dy = bsxfun(@minus, p2(:, 2), y0); + + else + error('Too many input arguments'); + end + + % compute median using middle point of the edge, and the direction vector + % rotated by 90 degrees counter-clockwise + lin = [bsxfun(@plus, x0, dx/2), bsxfun(@plus, y0, dy/2), -dy, dx]; + +endfunction + +%!test +%! p1 = [0 0]; +%! p2 = [10 0]; +%! exp = [5 0 0 10]; +%! lin = medianLine(p1, p2); +%! assertElementsAlmostEqual(exp, lin); + +%!test +%! p1 = [0 0]; +%! p2 = [10 0]; +%! exp = [5 0 0 10]; +%! lin = medianLine([p1 p2]); +%! assertElementsAlmostEqual(exp, lin); + +%!test +%! p1 = [0 0; 10 10]; +%! p2 = [10 0;10 20]; +%! exp = [5 0 0 10; 10 15 -10 0]; +%! lin = medianLine(p1, p2); +%! assertElementsAlmostEqual(exp, lin); Added: trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,26 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {} assertAlmostEqual () +%% Wrapper. Not documented. +%% +%% @end deftypefn + +function assertAlmostEqual(a,b) + + assert(b,a,1e-6); + +endfunction Added: trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,26 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {} assertEqual () +%% Wrapper. Not documented. +%% +%% @end deftypefn + +function assertEqual(a,b) + + assert(b,a); + +endfunction Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,56 +0,0 @@ -function test_suite = testCreateCircle(varargin) %#ok<STOUT> -% One-line description here, please. -% output = testMidPoint(input) -% -% Example -% testMidPoint -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -initTestSuite; - -function test_threePoints %#ok<*DEFNU> - -p1 = [10 15]; -p2 = [15 20]; -p3 = [10 25]; -exp = [10 20 5]; - -circle = createCircle(p1, p2, p3); -assertEqual(exp, circle); - -circle = createCircle(p3, p1, p2); -assertEqual(exp, circle); - -circle = createCircle(p2, p3, p1); -assertEqual(exp, circle); - - -function test_threeArrays %#ok<*DEFNU> - -p1 = [10 15]; -p2 = [15 20]; -p3 = [10 25]; -exp = [10 20 5]; - -p1 = [p1; p1+10; p1+20; p1-5]; -p2 = [p2; p2+10; p2+20; p2-5]; -p3 = [p3; p3+10; p3+20; p3-5]; - -exp = repmat(exp, 4, 1) + [0 0 0;10 10 0;20 20 0;-5 -5 0]; - -circle = createCircle(p1, p2, p3); -assertEqual(exp, circle); - -circle = createCircle(p3, p1, p2); -assertEqual(exp, circle); - -circle = createCircle(p2, p3, p1); -assertEqual(exp, circle); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,47 +0,0 @@ -function test_suite = testMedianLine(varargin) %#ok<STOUT> -%TESTMEDIANLINE One-line description here, please. -% output = testMedianLine(input) -% -% Example -% testMedianLine -% -% 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 testTwoPoints %#ok<*DEFNU> -% test with 2 points - -p1 = [0 0]; -p2 = [10 0]; -exp = [5 0 0 10]; -line = medianLine(p1, p2); -assertElementsAlmostEqual(exp, line); - -function testEdge -% test with an edge as input - -p1 = [0 0]; -p2 = [10 0]; -exp = [5 0 0 10]; -line = medianLine([p1 p2]); -assertElementsAlmostEqual(exp, line); - -function testTwoPointArrays %#ok<*DEFNU> -% test with 2 points - -p1 = [0 0; 10 10]; -p2 = [10 0;10 20]; - -exp = [5 0 0 10; 10 15 -10 0]; - -line = medianLine(p1, p2); -assertElementsAlmostEqual(exp, line); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,94 +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 circle = createCircle(varargin) -%CREATECIRCLE Create a circle from 2 or 3 points -% -% C = createCircle(P1, P2, P3); -% Creates the circle passing through the 3 given points. -% C is a 1*3 array of the form: [XC YX R]. -% -% C = createCircle(P1, P2); -% Creates the circle whith center P1 and passing throuh the point P2. -% -% Works also when input are point arrays the same size, in this case the -% result has as many lines as the point arrays. -% -% Example -% % Draw a circle passing through 3 points. -% p1 = [10 15]; -% p2 = [15 20]; -% p3 = [10 25]; -% circle = createCircle(p1, p2, p3); -% figure; hold on; axis equal; axis([0 50 0 50]); -% drawPoint([p1 ; p2; p3]); -% drawCircle(circle); -% -% See also: -% circles2d, createDirectedCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - - -if nargin == 2 - % inputs are the center and a point on the circle - p1 = varargin{1}; - p2 = varargin{2}; - x0 = p1(:,1); - y0 = p1(:,2); - r = hypot((p2(:,1)-x0), (p2(:,2)-y0)); - -elseif nargin == 3 - % inputs are three points on the circle - p1 = varargin{1}; - p2 = varargin{2}; - p3 = varargin{3}; - - % compute circle center - line1 = medianLine(p1, p2); - line2 = medianLine(p1, p3); - point = intersectLines(line1, line2); - x0 = point(:, 1); - y0 = point(:, 2); - - % circle radius - r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); -end - -% create array for returning result -circle = [x0 y0 r]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,92 +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 circle = createDirectedCircle(varargin) -%CREATEDIRECTEDCIRCLE Create a directed circle -% -% C = createDirectedCircle(P1, P2, P3); -% Creates a circle going through the given points. -% C is a 1*4 array of the form: [XC YC R INV]. -% The last parameter is set to 1 if the points are located in clockwise -% order on the circle. -% -% C = createDirectedCircle(P1, P2); -% Creates the circle whith center P1 and passing throuh the point P2. -% -% Works also when input are point arrays the same size, in this case the -% result has as many lines as the point arrays. -% -% See also: -% circles2d, createCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 12/01/2005. -% - -if nargin == 2 - % inputs are the center and a point on the circle - p1 = varargin{1}; - p2 = varargin{2}; - x0 = (p1(:,1) + p2(:,1))/2; - y0 = (p1(:,2) + p2(:,2))/2; - r = hypot((p2(:,1)-p1(:,1)), (p2(:,2)-p1(:,2)))/2; - - % circle is direct by default - d = 0; - -elseif nargin == 3 - % inputs are three points on the circle - p1 = varargin{1}; - p2 = varargin{2}; - p3 = varargin{3}; - - % compute circle center - line1 = medianLine(p1, p2); - line2 = medianLine(p1, p3); - center = intersectLines(line1, line2); - x0 = center(:, 1); - y0 = center(:, 2); - - % circle radius - r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); - - % compute circle orientation - angle = angle3Points(p1, center, p2) + angle3Points(p2, center, p3); - d = angle>2*pi; -end - - -circle = [x0 y0 r d]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,130 +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 edge = createEdge(varargin) -%CREATEEDGE Create an edge between two points, or from a line -% -% The internal format for edge representation is given by coordinates of -% two points : [x1 y1 x2 y2]. -% This function can serve as a line to edge converter. -% -% -% E = createEdge(P1, P2); -% Returns the edge between the two given points P1 and P2. -% -% E = createEdge(x0, y0, dx, dy); -% Returns the edge going through point (x0, y0) and with direction -% vector (dx,dy). -% -% E = createEdge(param); -% where param is an array of 4 values, creates the edge going through the -% point (param(1) param(2)), and with direction vector given by -% (param(3) param(4)). -% -% E = createEdge(LINE, D); -% create the edge contained in LINE, with same direction and start point, -% but with length given by D. -% -% -% Note: in all cases, parameters can be vertical arrays of the same -% dimension. The result is then an array of edges, of dimensions [N*4]. -% -% -% See also: -% edges2d, lines2d, drawEdge, clipEdge -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY : -% 18/02/2004 : add more possibilities to create edges, not only from 2 -% points. Also add support for arrays. -% 31/03/2004 : convert to [P1 P2] format - -if length(varargin)==1 - % Only one input parameter. It can be : - % - line angle - % - array of four parameters - % TODO : add control for arrays of lines. - var = varargin{1}; - - if size(var, 2)==4 - % 4 parameters of the line in a single array. - %edge = var; - edge = zeros(size(var)); - edge(:, 1:2) = var(:,1:2); - edge(:, 3:4) = edge(:, 1:2)+var(:,3:4); - elseif size(var, 2)==1 - % 1 parameter : angle of the line, going through origin. - edge = [zeros(size(var,1)) zeros(size(var,1)) cos(var) sin(var)]; - else - error('wrong number of dimension for arg1 : can be 1 or 4'); - end - -elseif length(varargin)==2 - % 2 input parameters. They can be : - % - 2 points, then 2 arrays of 1*2 double, - % - a line, and a distance. - v1 = varargin{1}; - v2 = varargin{2}; - if size(v1, 2)==2 - % first input parameter is first point, and second input is the - % second point. - %edge = [v1(:,1), v1(:,2), v2(:,1), v2(:,2)]; - edge = [v1 v2]; - else - % first input parameter is a line, and second one a distance. - angle = atan2(v1(:,4), v1(:,3)); - edge = [v1(:,1), v1(:,2), v1(:,1)+v2.*cos(angle), v1(:,2)+v2.*sin(angle)]; - end - -elseif length(varargin)==3 - % 3 input parameters : - % first one is a point belonging to the line, - % second and third ones are direction vector of the line (dx and dy). - p = varargin{1}; - edge = [p(:,1) p(:,2) p(:,1)+varargin{2} p(:,2)+varargin{3}]; - -elseif length(varargin)==4 - % 4 input parameters : - % they are x0, y0 (point belonging to line) and dx, dy (direction - % vector of the line). - % All parameters should have the same size. - edge = [varargin{1} varargin{2} varargin{1}+varargin{3} varargin{2}+varargin{4}]; -else - error('Wrong number of arguments in ''createLine'' '); -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,120 +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 line = medianLine(varargin) -%MEDIANLINE Create a median line between two points -% -% L = medianLine(P1, P2); -% Create the median line of points P1 and P2, that is the line containing -% all points located at equal distance of P1 and P2. -% -% L = medianLine(PTS); -% Creates the median line of 2 points, given as a 2*2 array. Array has -% the form: -% [ [ x1 y1 ] ; [ x2 y2 ] ] -% -% L = medianLine(EDGE); -% Creates the median of the edge. Edge is a 1*4 array, containing [X1 Y1] -% coordinates of first point, and [X2 Y2], the coordinates of the second -% point. -% -% Example -% % Draw the median line of two points -% P1 = [10 20]; -% P2 = [30 50]; -% med = medianLine(P1, P2); -% figure; axis square; axis([0 100 0 100]); -% drawEdge([P1 P2], 'linewidth', 2, 'color', 'k'); -% drawLine(med) -% -% % Draw the median line of an edge -% P1 = [50 60]; -% P2 = [80 30]; -% edge = createEdge(P1, P2); -% figure; axis square; axis([0 100 0 100]); -% drawEdge(edge, 'linewidth', 2) -% med = medianLine(edge); -% drawLine(med) -% -% -% See also: -% lines2d, createLine, orthogonalLine -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% history -% 2010-08-06 vectorize and change behaviour for N-by-4 inputs - -nargs = length(varargin); -x0 = 0; -y0 = 0; -dx = 0; -dy = 0; - -if nargs == 1 - tab = varargin{1}; - if size(tab, 2)==2 - % input is an array of two points - x0 = tab(1,1); - y0 = tab(1,2); - dx = tab(2,1)-x0; - dy = tab(2,2)-y0; - else - % input is an edge - x0 = tab(:, 1); - y0 = tab(:, 2); - dx = tab(:, 3) - tab(:, 1); - dy = tab(:, 4) - tab(:, 2); - end - -elseif nargs==2 - % input is given as two points, or two point arrays - p1 = varargin{1}; - p2 = varargin{2}; - x0 = p1(:, 1); - y0 = p1(:, 2); - dx = bsxfun(@minus, p2(:, 1), x0); - dy = bsxfun(@minus, p2(:, 2), y0); - -else - error('Too many input arguments'); -end - -% compute median using middle point of the edge, and the direction vector -% rotated by 90 degrees counter-clockwise -line = [bsxfun(@plus, x0, dx/2), bsxfun(@plus, y0, dy/2), -dy, dx]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |