changeset 11607:5f92eaa842cb octave-forge

geometry: adding missing functions
author jpicarbajal
date Sun, 07 Apr 2013 13:31:47 +0000
parents e6d0a45f9c65
children 260006aaf78d
files main/geometry/devel/polygons2d/polygonPoint.m main/geometry/devel/polygons2d/polygonSubcurve.m main/geometry/inst/polygons2d/polygonLoops.m main/geometry/inst/polygons2d/polygonPoint.m main/geometry/inst/polygons2d/polygonSubcurve.m
diffstat 5 files changed, 178 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- a/main/geometry/devel/polygons2d/polygonPoint.m	Sun Apr 07 13:11:47 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-## Copyright (C) 2003-2011 David Legland <david.legland@grignon.inra.fr>
-## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
-## All rights reserved.
-## 
-## 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 AUTHOR 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 the copyright holders.
-
-function point = polygonPoint(poly, pos)
-#POLYGONPOINT Extract a point from a polygon
-#
-#   POINT = polygonPoint(POLYGON, POS)
-#   
-#
-#   Example
-#   polygonPoint
-#
-#   See also
-#   polygons2d, polylinePoint
-#
-# ------
-# Author: David Legland
-# e-mail: david.legland@grignon.inra.fr
-# Created: 2009-04-30,    using Matlab 7.7.0.471 (R2008b)
-# Copyright 2009 INRA - Cepia Software Platform.
-
-# eventually copy first point at the end to ensure closed polygon
-if sum(poly(end, :)==poly(1,:))~=2
-    poly = [poly; poly(1,:)];
-end
-
-# number of points to compute
-Np = length(pos(:));
-
-# number of vertices in polygon
-Nv = size(poly, 1)-1;
-
-# allocate memory results
-point = zeros(Np, 2);
-
-# iterate on points
-for i=1:Np
-    # compute index of edge (between 0 and Nv)
-    ind = floor(pos(i));
-    
-    # special case of last point of polyline
-    if ind==Nv
-        point(i,:) = poly(end,:);
-        continue;
-    end
-    
-    # format index to ensure being on polygon
-    ind = min(max(ind, 0), Nv-1);
-    
-    # position on current edge
-    t = min(max(pos(i)-ind, 0), 1);
-    
-    # parameters of current edge
-    x0 = poly(ind+1, 1);
-    y0 = poly(ind+1, 2);
-    dx = poly(ind+2,1)-x0;
-    dy = poly(ind+2,2)-y0;
-    
-    # compute position of current point
-    point(i, :) = [x0+t*dx, y0+t*dy];
-end
--- a/main/geometry/devel/polygons2d/polygonSubcurve.m	Sun Apr 07 13:11:47 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-## Copyright (C) 2003-2011 David Legland <david.legland@grignon.inra.fr>
-## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
-## All rights reserved.
-## 
-## 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 AUTHOR 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 the copyright holders.
-
-function res = polygonSubcurve(poly, t0, t1)
-#POLYGONSUBCURVE Extract a portion of a polygon
-#
-#   POLY2 = polygonSubcurve(POLYGON, POS0, POS1)
-#   Create a new polyline, by keeping vertices located between positions
-#   POS0 and POS1, and adding points corresponding to positions POS0 and
-#   POS1 if they are not already vertices.
-#
-#   Example
-#   Nv = 100;
-#   poly = circleAsPolygon([10 20 30], Nv);
-#   poly2 = polygonSubcurve(poly, 15, 65);
-#   drawCurve(poly2);
-#
-#   See also
-#   polygons2d, polylineSubcurve
-#
-# ------
-# Author: David Legland
-# e-mail: david.legland@grignon.inra.fr
-# Created: 2009-04-30,    using Matlab 7.7.0.471 (R2008b)
-# Copyright 2009 INRA - Cepia Software Platform.
-
-# number of vertices
-Nv = size(poly, 1);
-
-if t0<t1
-    # format positions
-    t0 = max(t0, 0);
-    t1 = min(t1, Nv);
-end
-
-# indices of extreme vertices inside subcurve
-ind0 = ceil(t0)+1;
-ind1 = floor(t1)+1;
-
-# get the portion of polyline between 2 extremities
-if t0<t1
-    if ind1<=Nv
-        res = poly(ind0:ind1, :);
-    else
-        res = poly(1, :);
-    end
-else 
-    res = poly([ind0:end 1:ind1], :);
-end
-
-# add first point if it is not already a vertex
-if t0~=ind0-1
-    res = [polygonPoint(poly, t0); res];
-end
-
-# add last point if it is not already a vertex
-if t1~=ind1-1
-    res = [res; polygonPoint(poly, t1)];
-end
-    
--- a/main/geometry/inst/polygons2d/polygonLoops.m	Sun Apr 07 13:11:47 2013 +0000
+++ b/main/geometry/inst/polygons2d/polygonLoops.m	Sun Apr 07 13:31:47 2013 +0000
@@ -2,16 +2,16 @@
 ## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas)
 ## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
 ## All rights reserved.
-## 
+##
 ## 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
@@ -73,15 +73,15 @@
   while true
       # index of next intersection point
       ind = find(positions(:,1)>pos, 1, 'first');
-      
+
       # if not found, break
       if isempty(ind)
           break;
       end
-      
+
       # add portion of curve
-      loop = [loop;polygonSubcurve(poly, pos, positions(ind, 1))]; ##ok<AGROW>
-      
+      loop = [loop; polygonSubcurve(poly, pos, positions(ind, 1))]; ##ok<AGROW>
+
       # look for next intersection point
       pos = positions(ind, 2);
       positions(ind, :) = [];
@@ -108,7 +108,7 @@
       loop    = [];
       pos0    = positions(1, 2);
       pos     = positions(1, 2);
-      
+
       while true
           # index of next intersection point
           ind = find(positions(:,1)>pos, 1, 'first');
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/geometry/inst/polygons2d/polygonPoint.m	Sun Apr 07 13:31:47 2013 +0000
@@ -0,0 +1,77 @@
+## Copyright (C) 2003-2011 David Legland <david.legland@grignon.inra.fr>
+## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
+## All rights reserved.
+##
+## 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 AUTHOR 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 the copyright holders.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{point} =} polygonPoint (@var{poly}, @var{pos})
+## Extract a point from a polygon
+## @seealso{polygons2d, polylinePoint}
+## @end deftypefn
+
+function point = polygonPoint(poly, pos)
+
+  # eventually copy first point at the end to ensure closed polygon
+  if sum(poly(end, :)==poly(1,:))~=2
+      poly = [poly; poly(1,:)];
+  end
+
+  # number of points to compute
+  Np = length(pos(:));
+
+  # number of vertices in polygon
+  Nv = size(poly, 1)-1;
+
+  # allocate memory results
+  point = zeros(Np, 2);
+
+  # iterate on points
+  for i=1:Np
+      # compute index of edge (between 0 and Nv)
+      ind = floor(pos(i));
+      
+      # special case of last point of polyline
+      if ind==Nv
+          point(i,:) = poly(end,:);
+          continue;
+      end
+      
+      # format index to ensure being on polygon
+      ind = min(max(ind, 0), Nv-1);
+      
+      # position on current edge
+      t = min(max(pos(i)-ind, 0), 1);
+      
+      # parameters of current edge
+      x0 = poly(ind+1, 1);
+      y0 = poly(ind+1, 2);
+      dx = poly(ind+2,1)-x0;
+      dy = poly(ind+2,2)-y0;
+      
+      # compute position of current point
+      point(i, :) = [x0+t*dx, y0+t*dy];
+  end
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/geometry/inst/polygons2d/polygonSubcurve.m	Sun Apr 07 13:31:47 2013 +0000
@@ -0,0 +1,93 @@
+## Copyright (C) 2003-2011 David Legland <david.legland@grignon.inra.fr>
+## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
+## All rights reserved.
+##
+## 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 AUTHOR 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 the copyright holders.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{poly2} =} polygonSubcurve (@var{polygon}, @var{pos0},@var{pos1})
+## Extract a portion of a polygon
+##
+##   Create a new polyline, by keeping vertices located between positions
+##   @var{pos0} and @var{pos1}, and adding points corresponding to positions @var{pos0} and
+##   @var{pos1} if they are not already vertices.
+##
+##   Example:
+## @example
+## Nv    = 100;
+## poly  = circleAsPolygon ([10 20 30], Nv);
+## poly2 = polygonSubcurve (poly, 15, 65);
+## drawPolyline (poly2);
+## @end example
+##
+## @seealso{polygons2d, polylineSubcurve}
+## @end deftypefn
+
+function res = polygonSubcurve(poly, t0, t1)
+  # number of vertices
+  Nv = size(poly, 1);
+
+  if t0<t1
+      # format positions
+      t0 = max(t0, 0);
+      t1 = min(t1, Nv);
+  end
+
+  # indices of extreme vertices inside subcurve
+  ind0 = ceil(t0)+1;
+  ind1 = floor(t1)+1;
+
+  # get the portion of polyline between 2 extremities
+  if t0<t1
+      if ind1<=Nv
+          res = poly(ind0:ind1, :);
+      else
+          res = poly(1, :);
+      end
+  else
+      res = poly([ind0:end 1:ind1], :);
+  end
+
+  # add first point if it is not already a vertex
+  if t0~=ind0-1
+      res = [polygonPoint(poly, t0); res];
+  end
+
+  # add last point if it is not already a vertex
+  if t1~=ind1-1
+      res = [res; polygonPoint(poly, t1)];
+  end
+endfunction
+
+%!demo
+%! Nv    = 100;
+%! poly  = circleAsPolygon ([10 20 30], Nv);
+%! poly2 = polygonSubcurve (poly, 15, 65);
+%!
+%! drawPolygon (poly,'k-o',"MarkerSize",3);
+%! hold on
+%! drawPolyline (poly2,'r.',"linewidth",2);
+%! hold off
+%! axis square