From: <jpi...@us...> - 2011-10-04 00:06:40
|
Revision: 8670 http://octave.svn.sourceforge.net/octave/?rev=8670&view=rev Author: jpicarbajal Date: 2011-10-04 00:06:32 +0000 (Tue, 04 Oct 2011) Log Message: ----------- geometry. Adapting matGeom - angles Done! Modified Paths: -------------- trunk/octave-forge/main/geometry/geom2d/inst/vectorAngle.m Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/angleDiff.m trunk/octave-forge/main/geometry/geom2d/inst/angleSort.m trunk/octave-forge/main/geometry/geom2d/inst/angles2d.m trunk/octave-forge/main/geometry/geom2d/inst/createLine.m trunk/octave-forge/main/geometry/geom2d/inst/deg2rad.m trunk/octave-forge/main/geometry/geom2d/inst/edgeAngle.m trunk/octave-forge/main/geometry/geom2d/inst/lineAngle.m trunk/octave-forge/main/geometry/geom2d/inst/rad2deg.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testAngleSort.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateLine.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLineAngle.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/test_angleDiff.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleDiff.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleSort.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angles2d.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/deg2rad.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeAngle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lineAngle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/rad2deg.m Copied: trunk/octave-forge/main/geometry/geom2d/inst/angleDiff.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleDiff.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/angleDiff.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/angleDiff.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,76 @@ +%% Copyright (c) 2011, INRA +%% 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{dif} =} angleDiff (@var{angle1}, @var{angle2}) +%% ANGLEDIFF Difference between two angles +%% +%% Computes the signed angular difference between two angles in radians. +%% The result is comprised between -PI and +PI. +%% +%% Example +%% A = angleDiff(-pi/4, pi/4) +%% A = +%% 1.5708 % equal to pi/2 +%% A = angleDiff(pi/4, -pi/4) +%% A = +%% -1.5708 % equal to -pi/2 +%% +%% @seealso{angles2d, angleAbsDiff} +%% @end deftypefn + +function dif = angleDiff(angle1, angle2) + + % first, normalization + angle1 = normalizeAngle(angle1); + angle2 = normalizeAngle(angle2); + + % compute difference and normalize in [-pi pi] + dif = normalizeAngle(angle2 - angle1, 0); +endfunction + +%!test +%! dif = angleDiff(0, pi/2); +%! assert (pi/2, dif, 1e-6); + +%!test +%! dif = angleDiff(pi/2, 0); +%! assert (-pi/2, dif, 1e-6); + +%!test +%! dif = angleDiff(0, 3*pi/2); +%! assert (-pi/2, dif, 1e-6); + +%!test +%! dif = angleDiff(3*pi/2, 0); +%! assert (pi/2, dif, 1e-6); Copied: trunk/octave-forge/main/geometry/geom2d/inst/angleSort.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleSort.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/angleSort.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/angleSort.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,106 @@ +%% 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} {varargout =} angleSort (@var{pts}, varargin) +%% ANGLESORT Sort points in the plane according to their angle to origin +%% +%% +%% PTS2 = angleSort(PTS); +%% Computes angle of points with origin, and sort points with increasing +%% angles in Counter-Clockwise direction. +%% +%% PTS2 = angleSort(PTS, PTS0); +%% Computes angles between each point of PTS and PT0, which can be +%% different from origin. +%% +%% PTS2 = angleSort(..., THETA0); +%% Specifies the starting angle for sorting. +%% +%% [PTS2, I] = angleSort(...); +%% Also returns in I the indices of PTS, such that PTS2 = PTS(I, :); +%% +%% @seealso{points2d, angles2d, angle2points, normalizeAngle} +%% @end deftypefn + +function varargout = angleSort(pts, varargin) + + % default values + pt0 = [0 0]; + theta0 = 0; + + if length(varargin)==1 + var = varargin{1}; + if size(var, 2)==1 + % specify angle + theta0 = var; + else + pt0 = var; + end + elseif length(varargin)==2 + pt0 = varargin{1}; + theta0 = varargin{2}; + end + + + n = size(pts, 1); + pts2 = pts - repmat(pt0, [n 1]); + angle = lineAngle([zeros(n, 2) pts2]); + angle = mod(angle - theta0 + 2*pi, 2*pi); + + [dummy, I] = sort(angle); + + % format output + if nargout<2 + varargout{1} = pts(I, :); + elseif nargout==2 + varargout{1} = pts(I, :); + varargout{2} = I; + end + +endfunction + +%!shared p1,p2,p3,p4,pts,center +%! p1 = [0 0]; +%! p2 = [10 0]; +%! p3 = [10 10]; +%! p4 = [0 10]; +%! pts = [p1;p2;p3;p4]; +%! center = [5 5]; + +%!test +%! expected = pts([3 4 1 2], :); +%! assert (expected, angleSort (pts, center), 1e-6); + +%!assert (pts, angleSort (pts, center, -pi), 1e-6); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/angles2d.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angles2d.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/angles2d.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/angles2d.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,54 @@ +%% 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} angles2d () +%% ANGLES2D Description of functions for manipulating angles +%% +%% Angles are normalized in an interval of width 2*PI. Most geom2d +%% functions return results in the [0 2*pi] interval, but it can be +%% convenient to consider the [-pi pi] interval as well. See the +%% normalizeAngle function to switch between conventions. +%% +%% Angles are usually oriented. The default orientation is the CCW +%% (Counter-Clockwise) orientation. +%% +%% @seealso{angle2Points, angle3Points, angleAbsDiff, normalizeAngle, vectorAngle, +%% angleDiff, angleSort, lineAngle, edgeAngle, deg2rad, rad2deg} +%% @end deftypefn + +function angles2d + + help('angles2d'); + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/createLine.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createLine.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,163 @@ +%% 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} =} createLine(varargin) +%% CREATELINE Create a straight line from 2 points, or from other inputs +%% +%% Line is represented in a parametric form : [x0 y0 dx dy] +%% x = x0 + t*dx +%% y = y0 + t*dy; +%% +%% +%% L = createLine(p1, p2); +%% Returns the line going through the two given points. +%% +%% L = createLine(x0, y0, dx, dy); +%% Returns the line going through point (x0, y0) and with direction +%% vector(dx, dy). +%% +%% L = createLine(LINE); +%% where LINE is an array of 4 values, creates the line going through the +%% point (LINE(1) LINE(2)), and with direction given by vector (LINE(3) +%% LINE(4)). +%% +%% L = createLine(THETA); +%% Create a polar line originated at (0,0) and with angle THETA. +%% +%% L = createLine(RHO, THETA); +%% Create a polar line with normal theta, and with min distance to origin +%% equal to rho. rho can be negative, in this case, the line is the same +%% as with CREATELINE(-rho, theta+pi), but the orientation is different. +%% +%% +%% Note: in all cases, parameters can be vertical arrays of the same +%% dimension. The result is then an array of lines, of dimensions [N*4]. +%% +%% NOTE : A line can also be represented with a 1*5 array : +%% [x0 y0 dx dy t]. +%% whith 't' being one of the following : +%% - t=0 : line is a singleton (x0,y0) +%% - t=1 : line is an edge segment, between points (x0,y0) and (x0+dx, +%% y0+dy). +%% - t=Inf : line is a Ray, originated from (x0,y0) and going to infinity +%% in the direction(dx,dy). +%% - t=-Inf : line is a Ray, originated from (x0,y0) and going to infinity +%% in the direction(-dx,-dy). +%% - t=NaN : line is a real straight line, and contains all points +%% verifying the above equation. +%% This seems us a convenient way to represent uniformly all kind of lines +%% (including edges, rays, and even point). +%% +%% NOTE2 : Any line object can be represented using a 1x6 array : +%% [x0 y0 dx dy t0 t1] +%% the first 4 parameters define the supporting line, +%% t0 represent the position of the first point on the line, +%% and t1 the position of the last point. +%% * for edges : t0 = 0, and t1=1 +%% * for straight lines : t0 = -inf, t1=inf +%% * for rays : t0=0, t1=inf (or t0=-inf,t1=0 for inverted ray). +%% I propose to call these objects 'lineArc' +%% +%% @seealso{lines2d, createEdge, createRay} +%% @end deftypefn + +function line = createLine(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. + line = var; + elseif size(var, 2)==1 + % 1 parameter : angle of the line, going through origin. + line = [zeros(size(var)) zeros(size(var)) 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 : + % - line angle and signed distance to origin. + % - 2 points, then 2 arrays of 1*2 double. + v1 = varargin{1}; + v2 = varargin{2}; + if size(v1, 2)==1 + % first param is angle of line, and second param is signed distance + % to origin. + line = [v1.*cos(v2) v1.*sin(v2) -sin(v2) cos(v2)]; + else + % first input parameter is first point, and second input is the + % second point. + line = [v1(:,1), v1(:,2), v2(:,1)-v1(:,1), v2(:,2)-v1(:,2)]; + 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}; + line = [p(:,1) p(:,2) varargin{2} varargin{3}]; + + elseif length(varargin)==4 + % 4 input parameters : + % they are x0, y0 (point belongng to line) and dx, dy (direction vector + % of the line). + % All parameters should have the same size. + line = [varargin{1} varargin{2} varargin{3} varargin{4}]; + else + error('Wrong number of arguments in ''createLine'' '); + end + +endfunction + +%!test +%! p1 = [1 1]; +%! p2 = [2 3]; +%! lin = createLine(p1, p2); +%! assert (p1, lin(1,1:2), 1e-6); +%! assert (p2-p1, lin(1,3:4), 1e-6); + +%!test +%! p1 = [1 1;1 1]; +%! p2 = [2 3;2 4]; +%! lin = createLine(p1, p2); +%! assert (2, size(lin, 1)); +%! assert (p1, lin(:,1:2), 1e-6); +%! assert (p2-p1, lin(:,3:4), 1e-6); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/deg2rad.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/deg2rad.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/deg2rad.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/deg2rad.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,58 @@ +%% Copyright (c) 2011, INRA +%% 2004-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{rad} =} deg2rad(@var{deg}) +%% DEG2RAD Convert angle from degrees to radians +%% +%% Usage: +%% R = deg2rad(D) +%% convert an angle in degrees to an angle in radians. +%% +%% Example +%% deg2rad(180) % gives pi +%% ans = +%% 3.1416 +%% deg2rad(60) % gives pi/3 +%% ans = +%% 1.0472 +%% +%% @seealso{angles2d, rad2deg} +%% @end deftypefn + +function rad = deg2rad(deg) + + rad = deg*pi/180; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/edgeAngle.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeAngle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/edgeAngle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/edgeAngle.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,61 @@ +%% 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{theta} =} edgeAngle(@var{edge}) +%% EDGEANGLE Return angle of edge +%% +%% A = edgeAngle(EDGE) +%% Returns the angle between horizontal, right-axis and the edge EDGE. +%% Angle is given in radians, between 0 and 2*pi, in counter-clockwise +%% direction. +%% Notation for edge is [x1 y1 x2 y2] (coordinates of starting and ending +%% points). +%% +%% Example +%% p1 = [10 20]; +%% p2 = [30 40]; +%% rad2deg(edgeAngle([p1 p2])) +%% ans = +%% 45 +%% +%% @seealso{edges2d, angles2d, edgeAngle, lineAngle, edgeLength} +%% @end deftypefn + +function theta = edgeAngle(edge) + + line = createLine(edge(:,1:2), edge(:,3:4)); + theta = lineAngle(line); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/lineAngle.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lineAngle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/lineAngle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/lineAngle.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,105 @@ +%% 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{theta} =} lineAngle(varargin) +%% LINEANGLE Computes angle between two straight lines +%% +%% A = lineAngle(LINE); +%% Returns the angle between horizontal, right-axis and the given line. +%% Angle is fiven in radians, between 0 and 2*pi, in counter-clockwise +%% direction. +%% +%% A = lineAngle(LINE1, LINE2); +%% Returns the directed angle between the two lines. Angle is given in +%% radians between 0 and 2*pi, in counter-clockwise direction. +%% +%% @seealso{lines2d, angles2d, createLine, normalizeAngle} +%% @end deftypefn + +function theta = lineAngle(varargin) + + nargs = length(varargin); + if nargs == 1 + % angle of one line with horizontal + line = varargin{1}; + theta = mod(atan2(line(:,4), line(:,3)) + 2*pi, 2*pi); + + elseif nargs==2 + % angle between two lines + theta1 = lineAngle(varargin{1}); + theta2 = lineAngle(varargin{2}); + theta = mod(bsxfun(@minus, theta2, theta1)+2*pi, 2*pi); + end + +endfunction + +% horizontal +%!test +%! line1 = createLine([2 3 1 0]); +%! assert (lineAngle(line1), 0, 1e-6); + +%!test +%! line1 = createLine([2 3 0 1]); +%! assert (lineAngle(line1), pi/2, 1e-6); + +%!test +%! line1 = createLine([2 3 1 1]); +%! assert (lineAngle(line1), pi/4, 1e-6); + +%!test +%! line1 = createLine([2 3 5 -1]); +%! assert (lineAngle(line1), mod(atan2(-1, 5)+2*pi, 2*pi), 1e-6); + +%!test +%! line1 = createLine([2 3 5000 -1000]); +%! assert (lineAngle(line1), mod(atan2(-1, 5)+2*pi, 2*pi), 1e-6); + +%!test +%! line1 = createLine([2 3 -1 0]); +%! assert (lineAngle(line1), pi, 1e-6); + +% test lineAngle with two parameters : angle between 2 lines +% check for 2 orthogonal lines +%!test +%! line1 = createLine([1 3 1 0]); +%! line2 = createLine([-2 -1 0 1]); +%! assert (lineAngle(line1, line2), pi/2, 1e-6); +%! assert (lineAngle(line2, line1), 3*pi/2, 1e-6); + +% check for 2 orthogonal lines, with very different parametrizations +%!test +%! line1 = createLine([1 3 1 1]); +%! line2 = createLine([-2 -1 -1000 1000]); +%! assert (lineAngle(line1, line2), pi/2, 1e-6); +%! assert (lineAngle(line2, line1), 3*pi/2, 1e-6); Copied: trunk/octave-forge/main/geometry/geom2d/inst/rad2deg.m (from rev 8665, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/rad2deg.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/rad2deg.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/rad2deg.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -0,0 +1,58 @@ +%% Copyright (c) 2011, INRA +%% 2004-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{deg} =} rad2deg(@var{rad}) +% RAD2DEG Convert angle from radians to degrees +% +% Usage: +% R = rad2deg(D) +% convert an angle in radians to angle in degrees +% +% Example: +% rad2deg(pi) +% ans = +% 180 +% rad2deg(pi/3) +% ans = +% 60 +%% +%% @seealso{angles2d, deg2rad} +%% @end deftypefn + +function deg = rad2deg(rad) + + deg = rad*180/pi; + +endfunction + Modified: trunk/octave-forge/main/geometry/geom2d/inst/vectorAngle.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/vectorAngle.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/geom2d/inst/vectorAngle.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -33,7 +33,7 @@ %% -*- texinfo -*- %% @deftypefn {Function File} {@var{alpha} =} vectorAngle (@var{v1}) -%%VECTORANGLE Angle of a vector, or between 2 vectors +%% VECTORANGLE Angle of a vector, or between 2 vectors %% %% A = vectorAngle(V); %% Returns angle between Ox axis and vector direction, in Counter @@ -194,28 +194,28 @@ %!test %! vecs = [1 0;0 1;0 -1;1 1;1 -1]; %! angs = [0;pi/2;-pi/2;pi/4;-pi/4]; -%! assert(angs, vectorAngle(vecs, 0)); +%! assert(angs, vectorAngle(vecs, 0), 1e-6); %!test %! v1 = [1 0]; %! v2 = [0 1]; %! ang = pi /2 ; -%! assert(ang, vectorAngle(v1, v2)); +%! assert(ang, vectorAngle(v1, v2), 1e-6); %!test %! v1 = [1 0]; %! v2 = [0 1; 0 1; 1 1; -1 1]; %! ang = [pi / 2 ;pi / 2 ;pi / 4 ; 3 * pi / 4]; -%! assert(ang, vectorAngle(v1, v2)); +%! assert(ang, vectorAngle(v1, v2), 1e-6); %!test %! v1 = [0 1; 0 1; 1 1; -1 1]; %! v2 = [-1 0]; %! ang = [pi / 2 ;pi / 2 ; 3 * pi / 4 ; pi / 4]; -%! assert(ang, vectorAngle(v1, v2)); +%! assert(ang, vectorAngle(v1, v2), 1e-6); %!test %! v1 = [1 0; 0 1; 1 1; -1 1]; %! v2 = [0 1; 1 0; -1 1; -1 0]; %! ang = [pi / 2 ;3 * pi / 2 ;pi / 2 ; pi / 4]; -%! assert(ang, vectorAngle(v1, v2)); +%! assert(ang, vectorAngle(v1, v2), 1e-6); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testAngleSort.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testAngleSort.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testAngleSort.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,39 +0,0 @@ -function test_suite = testAngleSort(varargin) -%TESTCLIPLINE One-line description here, please. -% output = testAngleSort(input) -% -% Example -% testAngleSort -% -% 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 testSimple - -p1 = [0 0]; -p2 = [10 0]; -p3 = [10 10]; -p4 = [0 10]; -pts = [p1;p2;p3;p4]; -center = [5 5]; -expected = pts([3 4 1 2], :); -assertElementsAlmostEqual(expected, angleSort(pts, center)); - -function testSimpleWithAngle - -p1 = [0 0]; -p2 = [10 0]; -p3 = [10 10]; -p4 = [0 10]; -pts = [p1;p2;p3;p4]; -center = [5 5]; -assertElementsAlmostEqual(pts, angleSort(pts, center, -pi)); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateLine.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateLine.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,38 +0,0 @@ -function test_suite = testCreateLine(varargin) -%testCreateLine One-line description here, please. -% output = testCreateLine(input) -% -% Example -% testCreateLine -% -% 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 testCreateLine2Points - -p1 = [1 1]; -p2 = [2 3]; -line = createLine(p1, p2); - -assertElementsAlmostEqual(p1, line(1,1:2)); -assertElementsAlmostEqual(p2-p1, line(1,3:4)); - -function testCreateLine2Arrays - -p1 = [1 1;1 1]; -p2 = [2 3;2 4]; -line = createLine(p1, p2); - -assertEqual(2, size(line, 1)); -assertElementsAlmostEqual(p1, line(:,1:2)); -assertElementsAlmostEqual(p2-p1, line(:,3:4)); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLineAngle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLineAngle.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testLineAngle.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,60 +0,0 @@ -function test_suite = testLineAngle(varargin) %#ok<STOUT> -%TESTLINEANGLE One-line description here, please. -% output = testLineAngle(input) -% -% Example -% testLineAngle -% -% 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 testLineAngle1 %#ok<*DEFNU> -% test lineAngle with one parameter - -% horizontal -line1 = createLine([2 3 1 0]); -assertElementsAlmostEqual(lineAngle(line1), 0); - -line1 = createLine([2 3 0 1]); -assertElementsAlmostEqual(lineAngle(line1), pi/2); - -line1 = createLine([2 3 1 1]); -assertElementsAlmostEqual(lineAngle(line1), pi/4); - -line1 = createLine([2 3 5 -1]); -assertElementsAlmostEqual(lineAngle(line1), mod(atan2(-1, 5)+2*pi, 2*pi)); - -line1 = createLine([2 3 5000 -1000]); -assertElementsAlmostEqual(lineAngle(line1), mod(atan2(-1, 5)+2*pi, 2*pi)); - -line1 = createLine([2 3 -1 0]); -assertElementsAlmostEqual(lineAngle(line1), pi); - - - -function testLineAngle2 -% test lineAngle with two parameters : angle between 2 lines - -% check for 2 orthogonal lines -line1 = createLine([1 3 1 0]); -line2 = createLine([-2 -1 0 1]); -assertElementsAlmostEqual(lineAngle(line1, line2), pi/2); -assertElementsAlmostEqual(lineAngle(line2, line1), 3*pi/2); - - -% check for 2 orthogonal lines, with very different parametrizations -line1 = createLine([1 3 1 1]); -line2 = createLine([-2 -1 -1000 1000]); -assertElementsAlmostEqual(lineAngle(line1, line2), pi/2); -assertElementsAlmostEqual(lineAngle(line2, line1), 3*pi/2); - - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/test_angleDiff.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/test_angleDiff.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/test_angleDiff.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,34 +0,0 @@ -function test_suite = test_angleDiff(varargin) %#ok<STOUT> -%TEST_ANGLEDIFF Test case for the file angleDiff -% -% Test case for the file angleDiff - -% Example -% test_angleDiff -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2011-07-27, using Matlab 7.9.0.529 (R2009b) -% Copyright 2011 INRA - Cepia Software Platform. - -initTestSuite; - -function test_Simple %#ok<*DEFNU> -% simple tests - - -dif = angleDiff(0, pi/2); -assertAlmostEqual(pi/2, dif); - -dif = angleDiff(pi/2, 0); -assertAlmostEqual(-pi/2, dif); - -dif = angleDiff(0, 3*pi/2); -assertAlmostEqual(-pi/2, dif); - -dif = angleDiff(3*pi/2, 0); -assertAlmostEqual(pi/2, dif); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleDiff.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleDiff.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleDiff.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,63 +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 dif = angleDiff(angle1, angle2) -%ANGLEDIFF Difference between two angles -% -% Computes the signed angular difference between two angles in radians. -% The result is comprised between -PI and +PI. -% -% Example -% A = angleDiff(-pi/4, pi/4) -% A = -% 1.5708 % equal to pi/2 -% A = angleDiff(pi/4, -pi/4) -% A = -% -1.5708 % equal to -pi/2 -% -% See also -% angles2d, angleAbsDiff -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2011-07-27, using Matlab 7.9.0.529 (R2009b) -% Copyright 2011 INRA - Cepia Software Platform. - -% first, normalization -angle1 = normalizeAngle(angle1); -angle2 = normalizeAngle(angle2); - -% compute difference and normalize in [-pi pi] -dif = normalizeAngle(angle2 - angle1, 0); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleSort.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleSort.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angleSort.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,99 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = angleSort(pts, varargin) -%ANGLESORT Sort points in the plane according to their angle to origin -% -% -% PTS2 = angleSort(PTS); -% Computes angle of points with origin, and sort points with increasing -% angles in Counter-Clockwise direction. -% -% PTS2 = angleSort(PTS, PTS0); -% Computes angles between each point of PTS and PT0, which can be -% different from origin. -% -% PTS2 = angleSort(..., THETA0); -% Specifies the starting angle for sorting. -% -% [PTS2, I] = angleSort(...); -% Also returns in I the indices of PTS, such that PTS2 = PTS(I, :); -% -% See Also: -% points2d, angles2d, angle2points, normalizeAngle -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2005-11-24 -% Copyright 2010 INRA - Cepia Software Platform. - - -% HISTORY : - -% default values -pt0 = [0 0]; -theta0 = 0; - -if length(varargin)==1 - var = varargin{1}; - if size(var, 2)==1 - % specify angle - theta0 = var; - else - pt0 = var; - end -elseif length(varargin)==2 - pt0 = varargin{1}; - theta0 = varargin{2}; -end - - -n = size(pts, 1); -pts2 = pts - repmat(pt0, [n 1]); -angle = lineAngle([zeros(n, 2) pts2]); -angle = mod(angle - theta0 + 2*pi, 2*pi); - -[dummy, I] = sort(angle); - -% format output -if nargout<2 - varargout{1} = pts(I, :); -elseif nargout==2 - varargout{1} = pts(I, :); - varargout{2} = I; -end - - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angles2d.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angles2d.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/angles2d.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,58 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function angles2d -%ANGLES2D Description of functions for manipulating angles -% -% Angles are normalized in an interval of width 2*PI. Most geom2d -% functions return results in the [0 2*pi] interval, but it can be -% convenient to consider the [-pi pi] interval as well. See the -% normalizeAngle function to switch between conventions. -% -% Angles are usually oriented. The default orientation is the CCW -% (Counter-Clockwise) orientation. -% -% See also: -% normalizeAngle, angleDiff, angleAbsDiff, angleSort -% angle2Points, angle3Points, vectorAngle, lineAngle, edgeAngle -% deg2rad, rad2deg -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-03-31, using Matlab 7.4.0.287 (R2007a) -% Copyright 2010 INRA - Cepia Software Platform. - - -help('angles2d'); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createLine.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createLine.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,156 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function line = createLine(varargin) -%CREATELINE Create a straight line from 2 points, or from other inputs -% -% Line is represented in a parametric form : [x0 y0 dx dy] -% x = x0 + t*dx -% y = y0 + t*dy; -% -% -% L = createLine(p1, p2); -% Returns the line going through the two given points. -% -% L = createLine(x0, y0, dx, dy); -% Returns the line going through point (x0, y0) and with direction -% vector(dx, dy). -% -% L = createLine(LINE); -% where LINE is an array of 4 values, creates the line going through the -% point (LINE(1) LINE(2)), and with direction given by vector (LINE(3) -% LINE(4)). -% -% L = createLine(THETA); -% Create a polar line originated at (0,0) and with angle THETA. -% -% L = createLine(RHO, THETA); -% Create a polar line with normal theta, and with min distance to origin -% equal to rho. rho can be negative, in this case, the line is the same -% as with CREATELINE(-rho, theta+pi), but the orientation is different. -% -% -% Note: in all cases, parameters can be vertical arrays of the same -% dimension. The result is then an array of lines, of dimensions [N*4]. -% -% -% See also: -% lines2d, createEdge, createRay -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY : -% 18/02/2004 : add more possibilities to create lines (4 parameters, -% all param in a single tab, and point + dx + dy. -% Also add support for creation of arrays of lines. - -% NOTE : A line can also be represented with a 1*5 array : -% [x0 y0 dx dy t]. -% whith 't' being one of the following : -% - t=0 : line is a singleton (x0,y0) -% - t=1 : line is an edge segment, between points (x0,y0) and (x0+dx, -% y0+dy). -% - t=Inf : line is a Ray, originated from (x0,y0) and going to infinity -% in the direction(dx,dy). -% - t=-Inf : line is a Ray, originated from (x0,y0) and going to infinity -% in the direction(-dx,-dy). -% - t=NaN : line is a real straight line, and contains all points -% verifying the above equation. -% This seems us a convenient way to represent uniformly all kind of lines -% (including edges, rays, and even point). -% - -% NOTE2 : Any line object can be represented using a 1x6 array : -% [x0 y0 dx dy t0 t1] -% the first 4 parameters define the supporting line, -% t0 represent the position of the first point on the line, -% and t1 the position of the last point. -% * for edges : t0 = 0, and t1=1 -% * for straight lines : t0 = -inf, t1=inf -% * for rays : t0=0, t1=inf (or t0=-inf,t1=0 for inverted ray). -% I propose to call these objects 'lineArc' - -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. - line = var; - elseif size(var, 2)==1 - % 1 parameter : angle of the line, going through origin. - line = [zeros(size(var)) zeros(size(var)) 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 : - % - line angle and signed distance to origin. - % - 2 points, then 2 arrays of 1*2 double. - v1 = varargin{1}; - v2 = varargin{2}; - if size(v1, 2)==1 - % first param is angle of line, and second param is signed distance - % to origin. - line = [v1.*cos(v2) v1.*sin(v2) -sin(v2) cos(v2)]; - else - % first input parameter is first point, and second input is the - % second point. - line = [v1(:,1), v1(:,2), v2(:,1)-v1(:,1), v2(:,2)-v1(:,2)]; - 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}; - line = [p(:,1) p(:,2) varargin{2} varargin{3}]; - -elseif length(varargin)==4 - % 4 input parameters : - % they are x0, y0 (point belongng to line) and dx, dy (direction vector - % of the line). - % All parameters should have the same size. - line = [varargin{1} varargin{2} varargin{3} varargin{4}]; -else - error('Wrong number of arguments in ''createLine'' '); -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/deg2rad.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/deg2rad.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/deg2rad.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,59 +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 rad = deg2rad(deg) -%DEG2RAD Convert angle from degrees to radians -% -% Usage: -% R = deg2rad(D) -% convert an angle in degrees to an angle in radians. -% -% Example -% deg2rad(180) % gives pi -% ans = -% 3.1416 -% deg2rad(60) % gives pi/3 -% ans = -% 1.0472 -% -% See Also -% angles2d, rad2deg -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 09/12/2004. -% - -rad = deg*pi/180; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeAngle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeAngle.m 2011-10-03 23:43:30 UTC (rev 8669) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeAngle.m 2011-10-04 00:06:32 UTC (rev 8670) @@ -1,62 +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 theta = edgeAngle(edge) -%EDGEANGLE Return angle of edge -% -% A = edgeAngle(EDGE) -% Returns the angle between horizontal, right-axis and the edge EDGE. -% Angle is given in radians, between 0 and 2*pi, in counter-clockwise -% direction. -% Notation for edge is [x1 y1 x2 y2] (coordinates of starting and ending -% points). -% -% Example -% p1 = [10 20]; -% p2 = [30 40]; -% rad2deg(edgeAngle([p1 p2])) -% ans = -% 45 -% -% See also -% edges2d, angles2d, edgeAngle, lineAngle, edgeLength -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 06/04/2003. -% - -line = createLine(edge(:,1:2), edge(:,3:4)); -theta = lineAngle(line); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lineAngle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lineAngle.m 2011-10... [truncated message content] |