Hi there, I'd like to register as an octave-forge developer. My sourceforge username is s5s. As a first contribution I've written a function which produces a simple closed path given a set of 2D coordinates (a path connecting all points). Below is a patch of the new file.
Simeon Index: main/geometry/inst/polygons2d/closed_path.m =================================================================== --- main/geometry/inst/polygons2d/closed_path.m (revision 0) +++ main/geometry/inst/polygons2d/closed_path.m (revision 0) @@ -0,0 +1,118 @@ +%% Copyright (C) 2012 Simeon Simeonov <simeon.simeono...@gmail.com> +%% 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 program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% (at your option) any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. + +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. +%% +%% 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{y} =} polygon (@var{x}) +%% Returns a simple closed path that passes through all the points in x. +%% x is a vector containing 2D coordinates of the points. +%% +%% @end deftypefn + +%% Author: Simeon Simeonov <simeon.simeono...@gmail.com> + +function y = closed_path(x) + +if(size(x,1) > 1 && size(x,1) < size(x,2)) + x = x'; +end + +N = size(x,1); % Number of points +idx = zeros(N, 1); % ind contains the indices of the sorted coordinates + +a = find(x(:,2)==min(x(:,2))); + +if(size(a,1) > 1) + [~, i] = sort(x(a,1)); + a = a(i(1)); +end + +x_1 = x(x(:,2)==x(a,2),:); % find all x with the same y coordinate + +if(x(a,1) == min(x(:,1))) + x_2 = x(x(:,1)==x(a,1),:); % find all x with the same x coordinate +else + x_2 = x(a,:); +end + +if(size(x_1,1) > 1 || size(x_2,1) > 1) + if(size(x_1,1) > 1) + x_1 = sort(x_1); % Sort by x coordinate + y(1,:) = x(a,:); % original starting point + end + + if (size(x_2,1) > 1) + x_2 = sort(x_2, 'descend'); + end + + x_not = [x_1; x_2]; + i = ismember(x,x_not,'rows'); + x(i, :) = []; + x = [x_1(size(x_1,1),:); x]; + x_1(size(x_1, 1),:) = []; + N = size(x,1); + a = 1; +else + x_1 = []; + x_2 = x(a,:); +end +d = x - repmat(x(a,:), N, 1); +th = d(:,2)./(d(:,1) + d(:,2)); + +[~, idx0] = ismember(sort(th(th==0)), th); +[~, idx1] = ismember(sort(th(th>0)), th); +[~, idx2] = ismember(sort(th(th<0)), th); + +idx = [a; idx0; idx1; idx2]; +% I contains the indices of idx in a sorted order. [v i] = sort(idx) then +% i==I. +[~,I,J]= unique(idx); +if(size(I,1) ~= size(J,1)) + R = histc(J, 1:size(I,1)); % R(1) will always be 1? + idx_sorted = idx(I); + r = find(R>1); + for ri = r' + idx_repeated = idx_sorted(ri); + idx(idx==idx_repeated) = find(th==th(idx_sorted(ri))); + end +end + +y = [x_1; x(idx,:); x_2;]; + +endfunction ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev