Mercurial > forge
changeset 8480:0b283ee42f77 octave-forge
geometry. Adapting Matgeom
author | jpicarbajal |
---|---|
date | Mon, 03 Oct 2011 22:36:21 +0000 |
parents | 04d0e323deea |
children | f3f34a387e61 |
files | main/geometry/geom2d/angle2Points.m main/geometry/geom2d/angle3Points.m main/geometry/geom2d/angleAbsDiff.m main/geometry/geom2d/normalizeAngle.m main/geometry/matGeom_raw/Tests/geom2d/testAngle2Points.m main/geometry/matGeom_raw/Tests/geom2d/testAngle3Points.m main/geometry/matGeom_raw/Tests/geom2d/testNormalizeAngle.m main/geometry/matGeom_raw/Tests/geom2d/test_angleAbsDiff.m main/geometry/matGeom_raw/geom2d/angle3Points.m main/geometry/matGeom_raw/geom2d/angleAbsDiff.m main/geometry/matGeom_raw/geom2d/normalizeAngle.m |
diffstat | 11 files changed, 244 insertions(+), 427 deletions(-) [+] |
line wrap: on
line diff
--- a/main/geometry/geom2d/angle2Points.m Mon Oct 03 21:52:47 2011 +0000 +++ b/main/geometry/geom2d/angle2Points.m Mon Oct 03 22:36:21 2011 +0000 @@ -42,7 +42,6 @@ %% Result is always given in radians, between 0 and 2*pi. %% %% @seealso{points2d, angles2d, angle3points, normalizeAngle, vectorAngle} -%% %% @end deftypefn function theta = angle2Points(varargin)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/angle3Points.m Mon Oct 03 22:36:21 2011 +0000 @@ -0,0 +1,82 @@ +%% Copyright (c) 2011, INRA +%% 2004-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% 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{alpha} =} angle3Points (@var{p1}, @var{p2}, @var{p3}) +%% Computes the angle between the points @var{p1}, @var{p2} and @var{p3}. +%% +%% @var{p1}, @var{p2} and @var{p3} are either [1x2] arrays, or [Nx2] arrays, in this case +%% @var{alpha} is a [Nx1] array. The angle computed is the directed angle between line +%% (@var{p2}@var{p1}) and line (@var{p2}@var{p3}). +%% +%% Result is always given in radians, between 0 and 2*pi. +%% +%% @seealso{points2d, angles2d, angle2points} +%% @end deftypefn + +function theta = angle3Points(varargin) + + if length(varargin)==3 + p1 = varargin{1}; + p2 = varargin{2}; + p3 = varargin{3}; + elseif length(varargin)==1 + var = varargin{1}; + p1 = var(1,:); + p2 = var(2,:); + p3 = var(3,:); + end + + % angle line (P2 P1) + theta = lineAngle(createLine(p2, p1), createLine(p2, p3)); + +endfunction + +%!test +%! % all points inside window, possibly touching edges +%! p1 = [10 0]; +%! p2 = [0 0]; +%! p3 = [0 10]; +%! angle_ = angle3Points(p1, p2, p3); +%! assert(pi/2, angle_,1e-6); +%! angle_ = angle3Points([p1; p2; p3]); +%! assert(pi/2, angle_, 1e-6); + +%!test +%! p1 = [10 0; 20 0]; +%! p2 = [0 0;0 0]; +%! p3 = [0 10; 0 20]; +%! angle_ = angle3Points(p1, p2, p3); +%! assert(2, size(angle_, 1)); +%! assert([pi/2;pi/2], angle_, 1e-6); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/angleAbsDiff.m Mon Oct 03 22:36:21 2011 +0000 @@ -0,0 +1,66 @@ +%% Copyright (c) 2011, INRA +%% 2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% 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} =} angleAbsDiff (@var{angle1}, @var{angle2}) +%% Computes the absolute angular difference between two angles in radians. +%% The result is comprised between 0 and pi. +%% +%% @example +%% A = angleAbsDiff(pi/2, pi/3) +%% A = +%% 0.5236 % equal to pi/6 +%% @end example +%% +%% @seealso{angles2d, angleDiff} +%% @end deftypefn + +function dif = angleAbsDiff(angle1, angle2) + + % first, normalization + angle1 = normalizeAngle(angle1); + angle2 = normalizeAngle(angle2); + + % compute difference and normalize + dif = normalizeAngle(angle1 - angle2); + dif = min(dif, 2*pi - dif); + +endfunction + +%!shared xp +%! xp = pi/2; +%!assert (xp, angleAbsDiff (pi/2, 0), 1e-6); +%!assert (xp, angleAbsDiff (0, pi/2), 1e-6); +%!assert (xp, angleAbsDiff (0, 3*pi/2), 1e-6); +%!assert (xp, angleAbsDiff (3*pi/2, 0), 1e-6); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/normalizeAngle.m Mon Oct 03 22:36:21 2011 +0000 @@ -0,0 +1,96 @@ +%% Copyright (c) 2011, INRA +%% 2008-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% 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{alpha2} =} normalizeAngle (@var{alpha}) +%% @deftypefnx {Function File} {@var{alpha2} =} normalizeAngle (@var{alpha}, @var{center}) +%% NORMALIZEANGLE Normalize an angle value within a 2*PI interval +%% +%% ALPHA2 = normalizeAngle(ALPHA); +%% ALPHA2 is the same as ALPHA modulo 2*PI and is positive. +%% +%% ALPHA2 = normalizeAngle(ALPHA, CENTER); +%% Specifies the center of the angle interval. +%% If CENTER==0, the interval is [-pi ; +pi] +%% If CENTER==PI, the interval is [0 ; 2*pi] (default). +%% +%% Example: +%% % normalization between 0 and 2*pi (default) +%% normalizeAngle(5*pi) +%% ans = +%% 3.1416 +%% +%% % normalization between -pi and +pi +%% normalizeAngle(7*pi/2, 0) +%% ans = +%% -1.5708 +%% +%% References +%% Follows the same convention as apache commons library, see: +%% http://commons.apache.org/math/api-2.2/org/apache/commons/math/util/MathUtils.html%% +%% +%% @seealso{vectorAngle, lineAngle} +%% @end deftypefn + +function alpha = normalizeAngle(alpha, varargin) + + center = pi; + if ~isempty(varargin) + center = varargin{1}; + end + + alpha = mod(alpha-center+pi, 2*pi) + center-pi; + +endfunction + +%!assert (pi/2, normalizeAngle (pi/2), 1e-6); +%!assert (pi, normalizeAngle (pi), 1e-6); +%!assert (3*pi/2, normalizeAngle (3*pi/2), 1e-6); +%!assert (pi/2, normalizeAngle (pi/2, pi), 1e-6); +%!assert (pi, normalizeAngle (pi, pi), 1e-6); +%!assert (3*pi/2, normalizeAngle (3*pi/2, pi), 1e-6); + +%!test +%! theta = linspace(0, 2*pi-.1, 100); +%! assert(theta, normalizeAngle (theta), 1e-6); + +%!assert (0, normalizeAngle (0, 0), 1e-6); +%!assert (pi/2, normalizeAngle (pi/2, 0), 1e-6); +%!assert (-pi, normalizeAngle (-pi, 0), 1e-6); +%!assert (-pi/2, normalizeAngle (7*pi/2, 0), 1e-6); + +%!test +%! theta = linspace(-pi+.1, pi-.1, 100); +%! assert(theta, normalizeAngle (theta, 0), 1e-6); + +
--- a/main/geometry/matGeom_raw/Tests/geom2d/testAngle2Points.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -function test_suite = testAngle2Points(varargin) -%TESTCLIPLINE One-line description here, please. -% output = testAngle2Points(input) -% -% Example -% testAngle2Points -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -initTestSuite; - -function testHoriz -% all points inside window, possibly touching edges - -p1 = [0 0]; -p2 = [10 0]; -angle = angle2Points(p1, p2); -assertAlmostEqual(0, angle); - -angle = angle2Points(p2, p1); -assertAlmostEqual(pi, angle); - -function testVert -% all points inside window, possibly touching edges - -p1 = [0 0]; -p2 = [0 10]; -angle = angle2Points(p1, p2); -assertAlmostEqual(pi/2, angle); - -angle = angle2Points(p2, p1); -assertAlmostEqual(3*pi/2, angle); - - -function testMultiMulti -% all points inside window, possibly touching edges - -p1 = [0 0;0 0;0 0;0 0]; -p2 = [10 0;10 10;0 10;-10 10]; -angle = angle2Points(p1, p2); -assertEqual(size(p1, 1), size(angle, 1)); - -res = [0;pi/4;pi/2;3*pi/4]; -assertElementsAlmostEqual(res, angle); - -function testOneMulti -% all points inside window, possibly touching edges - -p1 = [0 0]; -p2 = [10 0;10 10;0 10;-10 10]; -angle = angle2Points(p1, p2); -assertEqual(size(p2, 1), size(angle, 1)); - -res = [0;pi/4;pi/2;3*pi/4]; -assertElementsAlmostEqual(res, angle); -
--- a/main/geometry/matGeom_raw/Tests/geom2d/testAngle3Points.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -function test_suite = testAngle3Points(varargin) -% One-line description here, please. -% output = testAngle3Points(input) -% -% Example -% testAngle3Points -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -initTestSuite; - -function testSimple -% all points inside window, possibly touching edges - -p1 = [10 0]; -p2 = [0 0]; -p3 = [0 10]; -angle = angle3Points(p1, p2, p3); -assertAlmostEqual(pi/2, angle); - - -function testBundledInput -% all points inside window, possibly touching edges - -p1 = [10 0]; -p2 = [0 0]; -p3 = [0 10]; -angle = angle3Points([p1; p2; p3]); -assertAlmostEqual(pi/2, angle); - -function testArray -% all points inside window, possibly touching edges - -p1 = [10 0; 20 0]; -p2 = [0 0;0 0]; -p3 = [0 10; 0 20]; -angle = angle3Points(p1, p2, p3); - -assertEqual(2, size(angle, 1)); -assertElementsAlmostEqual([pi/2;pi/2], angle); -
--- a/main/geometry/matGeom_raw/Tests/geom2d/testNormalizeAngle.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -function test_suite = testNormalizeAngle(varargin) -% One-line description here, please. -% output = testNormalizeAngle(input) -% -% Example -% testAngle2Points -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -initTestSuite; - -function testDefault - -theta = pi/2; -assertAlmostEqual(theta, normalizeAngle(theta)); - -theta = pi; -assertAlmostEqual(theta, normalizeAngle(theta)); - -theta = 3*pi/2; -assertAlmostEqual(theta, normalizeAngle(theta)); - -function testPiCentered - -theta = pi/2; -assertAlmostEqual(theta, normalizeAngle(theta, pi)); - -theta = pi; -assertAlmostEqual(theta, normalizeAngle(theta, pi)); - -theta = 3*pi/2; -assertAlmostEqual(theta, normalizeAngle(theta, pi)); - - -function testVector - -theta = linspace(0, 2*pi-.1, 100); -assertElementsAlmostEqual(theta, normalizeAngle(theta)); - - -function testZeroCentered - -theta = 0; -assertAlmostEqual(theta, normalizeAngle(theta, 0)); - -theta = pi/2; -assertAlmostEqual(theta, normalizeAngle(theta, 0)); - -theta = -pi; -assertAlmostEqual(theta, normalizeAngle(theta, 0)); - -theta = 7*pi/2; -assertAlmostEqual(-pi/2, normalizeAngle(theta, 0)); - -function testVectorZeroCentered - -theta = linspace(-pi+.1, pi-.1, 100); -assertElementsAlmostEqual(theta, normalizeAngle(theta, 0)); - -
--- a/main/geometry/matGeom_raw/Tests/geom2d/test_angleAbsDiff.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -function test_suite = test_angleAbsDiff(varargin) %#ok<STOUT> -%TEST_ANGLEABSDIFF Test case for the file angleAbsDiff -% -% Test case for the file angleDiff - -% Example -% test_angleAbsDiff -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% 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 - -exp = pi/2; - -dif = angleAbsDiff(pi/2, 0); -assertAlmostEqual(exp, dif); - -dif = angleAbsDiff(0, pi/2); -assertAlmostEqual(exp, dif); - -dif = angleAbsDiff(0, 3*pi/2); -assertAlmostEqual(exp, dif); - -dif = angleAbsDiff(3*pi/2, 0); -assertAlmostEqual(exp, dif);
--- a/main/geometry/matGeom_raw/geom2d/angle3Points.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% 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 = angle3Points(varargin) -%ANGLE3POINTS Compute oriented angle made by 3 points -% -% ALPHA = angle3Points(P1, P2, P3); -% Computes the angle between the points P1, P2 and P3. -% Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a -% [N*1] array. The angle computed is the directed angle between line -% (P2P1) and line (P2P3). -% Result is always given in radians, between 0 and 2*pi. -% -% See Also: -% points2d, angles2d, angle2points -% -% -% --------- -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% created the 23/02/2004. -% Copyright 2010 INRA - Cepia Software Platform. - - -% HISTORY : -% 25/09/2005 : enable single parameter - -if length(varargin)==3 - p1 = varargin{1}; - p2 = varargin{2}; - p3 = varargin{3}; -elseif length(varargin)==1 - var = varargin{1}; - p1 = var(1,:); - p2 = var(2,:); - p3 = var(3,:); -end - -% angle line (P2 P1) -theta = lineAngle(createLine(p2, p1), createLine(p2, p3)); -
--- a/main/geometry/matGeom_raw/geom2d/angleAbsDiff.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% 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 = angleAbsDiff(angle1, angle2) -%ANGLEABSDIFF Absolute difference between two angles -% -% AD = angleAbsDiff(ANGLE1, ANGLE2) -% Computes the absolute angular difference between two angles in radians. -% The result is comprised between 0 and PI. -% -% Example -% A = angleAbsDiff(pi/2, pi/3) -% A = -% 0.5236 % equal to pi/6 -% -% See also -% angles2d, angleDiff -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% 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 -dif = normalizeAngle(angle1 - angle2); -dif = min(dif, 2*pi - dif);
--- a/main/geometry/matGeom_raw/geom2d/normalizeAngle.m Mon Oct 03 21:52:47 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% 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 alpha = normalizeAngle(alpha, varargin) -%NORMALIZEANGLE Normalize an angle value within a 2*PI interval -% -% ALPHA2 = normalizeAngle(ALPHA); -% ALPHA2 is the same as ALPHA modulo 2*PI and is positive. -% -% ALPHA2 = normalizeAngle(ALPHA, CENTER); -% Specifies the center of the angle interval. -% If CENTER==0, the interval is [-pi ; +pi] -% If CENTER==PI, the interval is [0 ; 2*pi] (default). -% -% Example: -% % normalization between 0 and 2*pi (default) -% normalizeAngle(5*pi) -% ans = -% 3.1416 -% -% % normalization between -pi and +pi -% normalizeAngle(7*pi/2, 0) -% ans = -% -1.5708 -% -% See also -% vectorAngle, lineAngle -% -% References -% Follows the same convention as apache commons library, see: -% http://commons.apache.org/math/api-2.2/org/apache/commons/math/util/MathUtils.html -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% Created: 2008-03-10, using Matlab 7.4.0.287 (R2007a) -% Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. - -% HISTORY -% 2010-03-31 rename as normalizeAngle, and add psb to specify interval -% center - -center = pi; -if ~isempty(varargin) - center = varargin{1}; -end - -alpha = mod(alpha-center+pi, 2*pi) + center-pi;