From: <jpi...@us...> - 2011-10-13 17:13:47
|
Revision: 8740 http://octave.svn.sourceforge.net/octave/?rev=8740&view=rev Author: jpicarbajal Date: 2011-10-13 17:13:37 +0000 (Thu, 13 Oct 2011) Log Message: ----------- geometry. Updating version and date Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/doc/NEWS Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-10-13 17:11:20 UTC (rev 8739) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-10-13 17:13:37 UTC (rev 8740) @@ -1,6 +1,6 @@ Name: Geometry Version: 1.1.3 -Date: 2011-10-10 +Date: 2011-10-13 Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Title: Computational Geometry Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:11:20 UTC (rev 8739) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:13:37 UTC (rev 8740) @@ -70,7 +70,7 @@ vectors2d.m =============================================================================== -geometry-1.1.3 Release Date: 2011-10-10 Release Manager: Juan Pablo Carbajal +geometry-1.1.3 Release Date: 2011-10-13 Release Manager: Juan Pablo Carbajal =============================================================================== * Continue to add geom2d from matGeom (transforms and points2d) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-13 17:26:18
|
Revision: 8742 http://octave.svn.sourceforge.net/octave/?rev=8742&view=rev Author: jpicarbajal Date: 2011-10-13 17:26:09 +0000 (Thu, 13 Oct 2011) Log Message: ----------- geometry. 1.1.3 missing function Modified Paths: -------------- trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/intersectLineEdge.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineEdge.m Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-10-13 17:18:06 UTC (rev 8741) +++ trunk/octave-forge/main/geometry/INDEX 2011-10-13 17:26:09 UTC (rev 8742) @@ -32,6 +32,7 @@ edgeAngle fitAffineTransform2d intersectBoxes + intersectLineEdge intersectLines isCounterClockwise isParallel Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:18:06 UTC (rev 8741) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:26:09 UTC (rev 8742) @@ -94,5 +94,5 @@ minDistancePoints.m pointOnLine.m points2d.m - + intersectLineEdge.m =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/intersectLineEdge.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/intersectLineEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/intersectLineEdge.m 2011-10-13 17:26:09 UTC (rev 8742) @@ -0,0 +1,106 @@ +%% 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{point} = } intersecLineEdge (@var{line}, @var{edge}) +%% Return intersection between a line and an edge. +%% +%% Returns the intersection point of lines @var{line} and edge @var{edge}. +%% @var{line} is a 1x4 array containing parametric representation of the line +%% (in the form [x0 y0 dx dy], see @code{createLine} for details). +%% @var{edge} is a 1x4 array containing coordinates of first and second point +%% (in the form [x1 y1 x2 y2], see @code{createEdge} for details). +%% +%% In case of colinear line and edge, returns [Inf Inf]. +%% If line does not intersect edge, returns [NaN NaN]. +%% +%% If each input is [N*4] array, the result is a [N*2] array containing +%% intersections for each couple of edge and line. +%% If one of the input has N rows and the other 1 row, the result is a +%% [N*2] array. +%% +%% @seealso{lines2d, edges2d, intersectEdges, intersectLine} +%% @end deftypefn + +function point = intersectLineEdge(lin, edge) + x0 = lin(:,1); + y0 = lin(:,2); + dx1 = lin(:,3); + dy1 = lin(:,4); + x1 = edge(:,1); + y1 = edge(:,2); + x2 = edge(:,3); + y2 = edge(:,4); + dx2 = x2-x1; + dy2 = y2-y1; + + N1 = length(x0); + N2 = length(x1); + + % indices of parallel lines + par = abs(dx1.*dy2-dx2.*dy1)<1e-14; + + % indices of colinear lines + col = abs((x1-x0).*dy1-(y1-y0).*dx1)<1e-14 & par ; + + xi(col) = Inf; + yi(col) = Inf; + xi(par & ~col) = NaN; + yi(par & ~col) = NaN; + + i = ~par; + + % compute intersection points + if N1==N2 + xi(i) = ((y1(i)-y0(i)).*dx1(i).*dx2(i) + x0(i).*dy1(i).*dx2(i) - x1(i).*dy2(i).*dx1(i)) ./ ... + (dx2(i).*dy1(i)-dx1(i).*dy2(i)) ; + yi(i) = ((x1(i)-x0(i)).*dy1(i).*dy2(i) + y0(i).*dx1(i).*dy2(i) - y1(i).*dx2(i).*dy1(i)) ./ ... + (dx1(i).*dy2(i)-dx2(i).*dy1(i)) ; + elseif N1==1 + xi(i) = ((y1(i)-y0).*dx1.*dx2(i) + x0.*dy1.*dx2(i) - x1(i).*dy2(i).*dx1) ./ ... + (dx2(i).*dy1-dx1.*dy2(i)) ; + yi(i) = ((x1(i)-x0).*dy1.*dy2(i) + y0.*dx1.*dy2(i) - y1(i).*dx2(i).*dy1) ./ ... + (dx1.*dy2(i)-dx2(i).*dy1) ; + elseif N2==1 + xi(i) = ((y1-y0(i)).*dx1(i).*dx2 + x0(i).*dy1(i).*dx2 - x1(i).*dy2.*dx1(i)) ./ ... + (dx2.*dy1(i)-dx1(i).*dy2) ; + yi(i) = ((x1-x0(i)).*dy1(i).*dy2 + y0(i).*dx1(i).*dy2 - y1(i).*dx2.*dy1(i)) ./ ... + (dx1(i).*dy2-dx2.*dy1(i)) ; + end + + point = [xi' yi']; + out = find(~isPointOnEdge(point, edge)); + point(out, :) = repmat([NaN NaN], [length(out) 1]); + +endfunction + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineEdge.m 2011-10-13 17:18:06 UTC (rev 8741) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineEdge.m 2011-10-13 17:26:09 UTC (rev 8742) @@ -1,113 +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 point = intersectLineEdge(line, edge) -%INTERSECTLINEEDGE Return intersection between a line and an edge -% -% P = intersectLineEdge(LINE, EDGE); -% returns the intersection point of lines LINE and edge EDGE. -% LINE is a 1x4 array containing parametric representation of the line -% (in the form [x0 y0 dx dy], see 'createLine' for details). -% EDGE is a 1x4 array containing coordinates of first and second point -% (in the form [x1 y1 x2 y2], see 'createEdge' for details). -% -% In case of colinear line and edge, returns [Inf Inf]. -% If line does not intersect edge, returns [NaN NaN]. -% -% If each input is [N*4] array, the result is a [N*2] array containing -% intersections for each couple of edge and line. -% If one of the input has N rows and the other 1 row, the result is a -% [N*2] array. -% -% See also: -% lines2d, edges2d, intersectEdges, intersectLines -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 19/02/2004: add support for multiple lines. -% 08/03/2007: update doc - -x0 = line(:,1); -y0 = line(:,2); -dx1 = line(:,3); -dy1 = line(:,4); -x1 = edge(:,1); -y1 = edge(:,2); -x2 = edge(:,3); -y2 = edge(:,4); -dx2 = x2-x1; -dy2 = y2-y1; - -N1 = length(x0); -N2 = length(x1); - -% indices of parallel lines -par = abs(dx1.*dy2-dx2.*dy1)<1e-14; - -% indices of colinear lines -col = abs((x1-x0).*dy1-(y1-y0).*dx1)<1e-14 & par ; - -xi(col) = Inf; -yi(col) = Inf; -xi(par & ~col) = NaN; -yi(par & ~col) = NaN; - -i = ~par; - -% compute intersection points -if N1==N2 - xi(i) = ((y1(i)-y0(i)).*dx1(i).*dx2(i) + x0(i).*dy1(i).*dx2(i) - x1(i).*dy2(i).*dx1(i)) ./ ... - (dx2(i).*dy1(i)-dx1(i).*dy2(i)) ; - yi(i) = ((x1(i)-x0(i)).*dy1(i).*dy2(i) + y0(i).*dx1(i).*dy2(i) - y1(i).*dx2(i).*dy1(i)) ./ ... - (dx1(i).*dy2(i)-dx2(i).*dy1(i)) ; -elseif N1==1 - xi(i) = ((y1(i)-y0).*dx1.*dx2(i) + x0.*dy1.*dx2(i) - x1(i).*dy2(i).*dx1) ./ ... - (dx2(i).*dy1-dx1.*dy2(i)) ; - yi(i) = ((x1(i)-x0).*dy1.*dy2(i) + y0.*dx1.*dy2(i) - y1(i).*dx2(i).*dy1) ./ ... - (dx1.*dy2(i)-dx2(i).*dy1) ; -elseif N2==1 - xi(i) = ((y1-y0(i)).*dx1(i).*dx2 + x0(i).*dy1(i).*dx2 - x1(i).*dy2.*dx1(i)) ./ ... - (dx2.*dy1(i)-dx1(i).*dy2) ; - yi(i) = ((x1-x0(i)).*dy1(i).*dy2 + y0(i).*dx1(i).*dy2 - y1(i).*dx2.*dy1(i)) ./ ... - (dx1(i).*dy2-dx2.*dy1(i)) ; -end - -point = [xi' yi']; -out = find(~isPointOnEdge(point, edge)); -point(out, :) = repmat([NaN NaN], [length(out) 1]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-13 18:17:49
|
Revision: 8743 http://octave.svn.sourceforge.net/octave/?rev=8743&view=rev Author: jpicarbajal Date: 2011-10-13 18:17:43 +0000 (Thu, 13 Oct 2011) Log Message: ----------- geometry. Missing functions, fixing demo Modified Paths: -------------- trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/doc/NEWS trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/INDEX 2011-10-13 18:17:43 UTC (rev 8743) @@ -37,6 +37,7 @@ isCounterClockwise isParallel isPerpendicular + isPointOnEdge isPointOnRay lineAngle linePosition Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-13 18:17:43 UTC (rev 8743) @@ -95,4 +95,5 @@ pointOnLine.m points2d.m intersectLineEdge.m + isPointOnEdge.m =============================================================================== Modified: trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/geom2d/inst/clipLine.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -130,7 +130,7 @@ %!demo %! lin = [30 40 10 0]; %! bb = [0 100 0 100]; -%! res = clipLine(line, bb) +%! res = clipLine(lin, bb) %! %! drawBox(bb,'color','k'); %! line(lin([1 3]),lin([2 4]),'color','b'); Copied: trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isPointOnEdge.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -0,0 +1,294 @@ +%% 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{b} = } isPointOnEdge (@var{point}, @var{edge}) +%% @deftypefnx {Function File} {@var{b} = } isPointOnEdge (@var{point}, @var{edge}, @var{tol}) +%% @deftypefnx {Function File} {@var{b} = } isPointOnEdge (@var{point}, @var{edgearray}) +%% @deftypefnx {Function File} {@var{b} = } isPointOnEdge (@var{pointarray}, @var{edgearray}) +%% Test if a point belongs to an edge. +% +% with @var{point} being [xp yp], and @var{edge} being [x1 y1 x2 y2], returns TRUE if +% the point is located on the edge, and FALSE otherwise. +% +% Specify an optilonal tolerance value @var{tol}. The tolerance is given as a +% fraction of the norm of the edge direction vector. Default is 1e-14. +% +% When one of the inputs has several rows, return the result of the test +% for each element of the array tested against the single parameter. +% +% When both @var{pointarray} and @var{edgearray} have the same number of rows, +% returns a column vector with the same number of rows. +% When the number of rows are different and both greater than 1, returns +% a Np-by-Ne matrix of booleans, containing the result for each couple of +% point and edge. +% +% @seealso{edges2d, points2d, isPointOnLine} +%% @end deftypefn + +function b = isPointOnEdge(point, edge, varargin) + + % extract computation tolerance + tol = 1e-14; + if ~isempty(varargin) + tol = varargin{1}; + end + + % number of edges and of points + Np = size(point, 1); + Ne = size(edge, 1); + + % adapt size of inputs if needed, and extract elements for computation + if Np == Ne + % When the number of points and edges is the same, the one-to-one test + % will be computed, so there is no need to repeat matrices + dx = edge(:,3) - edge(:,1); + dy = edge(:,4) - edge(:,2); + lx = point(:,1) - edge(:,1); + ly = point(:,2) - edge(:,2); + + elseif Np == 1 + % one point, several edges + dx = edge(:, 3) - edge(:, 1); + dy = edge(:, 4) - edge(:, 2); + lx = point(ones(Ne, 1), 1) - edge(:, 1); + ly = point(ones(Ne, 1), 2) - edge(:, 2); + + elseif Ne == 1 + % several points, one edge + dx = (edge(3) - edge(1)) * ones(Np, 1); + dy = (edge(4) - edge(2)) * ones(Np, 1); + lx = point(:, 1) - edge(1); + ly = point(:, 2) - edge(2); + + else + % Np points and Ne edges: + % Create an array for each parameter, so that the result will be a + % Np-by-Ne matrix of booleans (requires more memory, and uses repmat) + + x0 = repmat(edge(:, 1)', Np, 1); + y0 = repmat(edge(:, 2)', Np, 1); + dx = repmat(edge(:,3)', Np, 1) - x0; + dy = repmat(edge(:,4)', Np, 1) - y0; + + lx = repmat(point(:, 1), 1, Ne) - x0; + ly = repmat(point(:, 2), 1, Ne) - y0; + end + + % test if point is located on supporting line + b1 = (abs(lx.*dy - ly.*dx) ./ hypot(dx, dy)) < tol; + + % compute position of point with respect to edge bounds + % use different tests depending on line angle + ind = abs(dx) > abs(dy); + t = zeros(size(dx)); + t(ind) = lx( ind) ./ dx( ind); + t(~ind) = ly(~ind) ./ dy(~ind); + + % check if point is located between edge bounds + b = t >- tol & t-1 < tol & b1; + +endfunction + +%!shared points, vertices, edges + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test one point and one edge +%! isPointOnEdge(points(1,:), edges(1,:)) +%! isPointOnEdge(points(3,:), edges(1,:)) + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test one point and several edges +%! isPointOnEdge(points(1,:), edges)' + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test several points and one edge +%! isPointOnEdge(points, edges(1,:))' + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test N points and N edges +%! isPointOnEdge(points, edges(1:3,:))' + +%!demo +%! % create a point array +%! points = [10 10;15 10; 30 10]; +%! % create an edge array +%! vertices = [10 10;20 10;20 20;10 20]; +%! edges = [vertices vertices([2:end 1], :)]; +%! +%! % Test NP points and NE edges +%! isPointOnEdge(points, edges) + +%!test +%! p1 = [10 20]; +%! p2 = [80 20]; +%! edge = [p1 p2]; +%! p0 = [10 20]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [80 20]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [50 20]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 20]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [80.01 20]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [50 21]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [79 19]; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! p1 = [20 10]; +%! p2 = [20 80]; +%! edge = [p1 p2]; +%! p0 = [20 10]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [20 80]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [20 50]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [20 9.99]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [20 80.01]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [21 50]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [19 79]; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! p1 = [10 20]; +%! p2 = [60 70]; +%! edge = [p1 p2]; +%! assert (isPointOnEdge(p1, edge)); +%! assert (isPointOnEdge(p2, edge)); +%! p0 = [11 21]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [59 69]; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 19.99]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [60.01 70.01]; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [30 50.01]; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! edge = [10 20 80 20; 20 10 20 80; 20 10 60 70]; +%! p0 = [20 20]; +%! assert ([true ; true ; false], isPointOnEdge(p0, edge)); + +%!test +%! k = 1e15; +%! p1 = [10 20]*k; +%! p2 = [60 70]*k; +%! edge = [p1 p2]; +%! assert (isPointOnEdge(p1, edge)); +%! assert (isPointOnEdge(p2, edge)); +%! p0 = [11 21]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [59 69]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 19.99]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [60.01 70.01]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [30 50.01]*k; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! k = 1e-10; +%! p1 = [10 20]*k; +%! p2 = [60 70]*k; +%! edge = [p1 p2]; +%! assert (isPointOnEdge(p1, edge)); +%! assert (isPointOnEdge(p2, edge)); +%! p0 = [11 21]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [59 69]*k; +%! assert (isPointOnEdge(p0, edge)); +%! p0 = [9.99 19.99]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [60.01 70.01]*k; +%! assert (!isPointOnEdge(p0, edge)); +%! p0 = [30 50.01]*k; +%! assert (!isPointOnEdge(p0, edge)); + +%!test +%! p1 = [10 20]; +%! p2 = [80 20]; +%! edge = [p1 p2]; +%! p0 = [10 20; 80 20; 50 20;50 21]; +%! exp = [true;true;true;false]; +%! assert (exp, isPointOnEdge(p0, edge)); + +%!test +%! p1 = [10 20]; +%! p2 = [80 20]; +%! edge = [p1 p2]; +%! p0 = [40 20]; +%! exp = [true;true;true;true]; +%! assert (exp, isPointOnEdge(p0, [edge;edge;edge;edge])); + +%!test +%! edge1 = [10 20 80 20]; +%! edge2 = [30 10 30 80]; +%! edges = [edge1; edge2]; +%! p0 = [40 20;30 90]; +%! exp = [true;false]; +%! assert (exp, isPointOnEdge(p0, edges)); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPointOnEdge.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -1,192 +0,0 @@ -function test_suite = testIsPointOnEdge(varargin) %#ok<STOUT> -%TESTISPOINTONEDGE One-line description here, please. -% -% output = testIsPointOnEdge(input) -% -% Example -% testIsPointOnEdge -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - -initTestSuite; - -function testHoriz %#ok<*DEFNU> - -p1 = [10 20]; -p2 = [80 20]; -edge = [p1 p2]; - -p0 = [10 20]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [80 20]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [50 20]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 20]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [80.01 20]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [50 21]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [79 19]; -assertFalse(isPointOnEdge(p0, edge)); - - -function testVertical %#ok<*DEFNU> - -p1 = [20 10]; -p2 = [20 80]; -edge = [p1 p2]; - -p0 = [20 10]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [20 80]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [20 50]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [20 9.99]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [20 80.01]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [21 50]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [19 79]; -assertFalse(isPointOnEdge(p0, edge)); - -function testDiagonal - -p1 = [10 20]; -p2 = [60 70]; -edge = [p1 p2]; - -assertTrue(isPointOnEdge(p1, edge)); -assertTrue(isPointOnEdge(p2, edge)); - -p0 = [11 21]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [59 69]; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 19.99]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [60.01 70.01]; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [30 50.01]; -assertFalse(isPointOnEdge(p0, edge)); - - -function testScalarArray - -edge = [10 20 80 20; 20 10 20 80; 20 10 60 70]; -p0 = [20 20]; -assertEqual([true ; true ; false], isPointOnEdge(p0, edge)); - -function testLargeEdge - -k = 1e15; - -p1 = [10 20]*k; -p2 = [60 70]*k; -edge = [p1 p2]; - -assertTrue(isPointOnEdge(p1, edge)); -assertTrue(isPointOnEdge(p2, edge)); - -p0 = [11 21]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [59 69]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 19.99]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [60.01 70.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [30 50.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - - -function testSmallEdge - -k = 1e-10; - -p1 = [10 20]*k; -p2 = [60 70]*k; -edge = [p1 p2]; - -assertTrue(isPointOnEdge(p1, edge)); -assertTrue(isPointOnEdge(p2, edge)); - -p0 = [11 21]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [59 69]*k; -assertTrue(isPointOnEdge(p0, edge)); - -p0 = [9.99 19.99]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [60.01 70.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - -p0 = [30 50.01]*k; -assertFalse(isPointOnEdge(p0, edge)); - - -function testPointArray - -p1 = [10 20]; -p2 = [80 20]; -edge = [p1 p2]; - -p0 = [10 20; 80 20; 50 20;50 21]; -exp = [true;true;true;false]; -assertEqual(exp, isPointOnEdge(p0, edge)); - - -function testEdgeArray - -p1 = [10 20]; -p2 = [80 20]; -edge = [p1 p2]; - -p0 = [40 20]; -exp = [true;true;true;true]; -assertEqual(exp, isPointOnEdge(p0, [edge;edge;edge;edge])); - - -function testTwoArrays - -edge1 = [10 20 80 20]; -edge2 = [30 10 30 80]; -edges = [edge1; edge2]; - -p0 = [40 20;30 90]; - -exp = [true;false]; -assertEqual(exp, isPointOnEdge(p0, edges)); - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m 2011-10-13 17:26:09 UTC (rev 8742) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnEdge.m 2011-10-13 18:17:43 UTC (rev 8743) @@ -1,181 +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 b = isPointOnEdge(point, edge, varargin) -%ISPOINTONEDGE Test if a point belongs to an edge -% -% Usage -% B = isPointOnEdge(POINT, EDGE) -% B = isPointOnEdge(POINT, EDGE, TOL) -% -% Description -% B = isPointOnEdge(POINT, EDGE) -% with POINT being [xp yp], and EDGE being [x1 y1 x2 y2], returns TRUE if -% the point is located on the edge, and FALSE otherwise. -% -% B = isPointOnEdge(POINT, EDGE, TOL) -% Specify an optilonal tolerance value TOL. The tolerance is given as a -% fraction of the norm of the edge direction vector. Default is 1e-14. -% -% B = isPointOnEdge(POINTARRAY, EDGE) -% B = isPointOnEdge(POINT, EDGEARRAY) -% When one of the inputs has several rows, return the result of the test -% for each element of the array tested against the single parameter. -% -% B = isPointOnEdge(POINTARRAY, EDGEARRAY) -% When both POINTARRAY and EDGEARRAY have the same number of rows, -% returns a column vector with the same number of rows. -% When the number of rows are different and both greater than 1, returns -% a Np-by-Ne matrix of booleans, containing the result for each couple of -% point and edge. -% -% Examples -% % create a point array -% points = [10 10;15 10; 30 10]; -% % create an edge array -% vertices = [10 10;20 10;20 20;10 20]; -% edges = [vertices vertices([2:end 1], :)]; -% -% % Test one point and one edge -% isPointOnEdge(points(1,:), edges(1,:)) -% ans = -% 1 -% isPointOnEdge(points(3,:), edges(1,:)) -% ans = -% 0 -% -% % Test one point and several edges -% isPointOnEdge(points(1,:), edges)' -% ans = -% 1 0 0 1 -% -% % Test several points and one edge -% isPointOnEdge(points, edges(1,:))' -% ans = -% 1 1 0 -% -% % Test N points and N edges -% isPointOnEdge(points, edges(1:3,:))' -% ans = -% 1 0 0 -% -% % Test NP points and NE edges -% isPointOnEdge(points, edges) -% ans = -% 1 0 0 1 -% 1 0 0 0 -% 0 0 0 0 -% -% -% See also -% edges2d, points2d, isPointOnLine -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 11/03/2004 change input format: edge is [x1 y1 x2 y2]. -% 17/01/2005 if test N edges with N points, return N boolean. -% 21/01/2005 normalize test for colinearity, so enhance precision -% 22/05/2009 rename to isPointOnEdge, add psb to specify tolerance -% 26/01/2010 fix bug in precision computation -% 04/10/2010 fix a bug, and clean up code -% 28/10/2010 fix bug to have N results when input is N points and N -% edges, add support for arrays with different numbers of rows, and -% update doc. -% 2011-06-15 rewrites by using less memory, and avoiding repmat when psb - - -% extract computation tolerance -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -% number of edges and of points -Np = size(point, 1); -Ne = size(edge, 1); - -% adapt size of inputs if needed, and extract elements for computation -if Np == Ne - % When the number of points and edges is the same, the one-to-one test - % will be computed, so there is no need to repeat matrices - dx = edge(:,3) - edge(:,1); - dy = edge(:,4) - edge(:,2); - lx = point(:,1) - edge(:,1); - ly = point(:,2) - edge(:,2); - -elseif Np == 1 - % one point, several edges - dx = edge(:, 3) - edge(:, 1); - dy = edge(:, 4) - edge(:, 2); - lx = point(ones(Ne, 1), 1) - edge(:, 1); - ly = point(ones(Ne, 1), 2) - edge(:, 2); - -elseif Ne == 1 - % several points, one edge - dx = (edge(3) - edge(1)) * ones(Np, 1); - dy = (edge(4) - edge(2)) * ones(Np, 1); - lx = point(:, 1) - edge(1); - ly = point(:, 2) - edge(2); - -else - % Np points and Ne edges: - % Create an array for each parameter, so that the result will be a - % Np-by-Ne matrix of booleans (requires more memory, and uses repmat) - - x0 = repmat(edge(:, 1)', Np, 1); - y0 = repmat(edge(:, 2)', Np, 1); - dx = repmat(edge(:,3)', Np, 1) - x0; - dy = repmat(edge(:,4)', Np, 1) - y0; - - lx = repmat(point(:, 1), 1, Ne) - x0; - ly = repmat(point(:, 2), 1, Ne) - y0; -end - -% test if point is located on supporting line -b1 = (abs(lx.*dy - ly.*dx) ./ hypot(dx, dy)) < tol; - -% compute position of point with respect to edge bounds -% use different tests depending on line angle -ind = abs(dx) > abs(dy); -t = zeros(size(dx)); -t(ind) = lx( ind) ./ dx( ind); -t(~ind) = ly(~ind) ./ dy(~ind); - -% check if point is located between edge bounds -b = t >- tol & t-1 < tol & b1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-16 20:55:57
|
Revision: 8757 http://octave.svn.sourceforge.net/octave/?rev=8757&view=rev Author: jpicarbajal Date: 2011-10-16 20:55:49 +0000 (Sun, 16 Oct 2011) Log Message: ----------- geometry. Adding rest of create* functions 2 to go Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m trunk/octave-forge/main/geometry/geom2d/inst/private/ trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m Copied: trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,123 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{circle} = } createCircle (@var{p1}, @var{p2}, @var{p3}) +%% @deftypefnx {Function File} {@var{circle} = } createCircle (@var{p1}, @var{p2}) +%% Create a circle from 2 or 3 points. +%% +%% Creates the circle passing through the 3 given points. +%% C is a 1x3 array of the form: [XC YX R]. +%% +%% When two points are given, creates the circle whith center @var{p1} and passing +%% throuh the point @var{p2}. +%% +%% Works also when input are point arrays the same size, in this case the +%% result has as many lines as the point arrays. +%% +%% Example +%% +%% @example +%% % Draw a circle passing through 3 points. +%% p1 = [10 15]; +%% p2 = [15 20]; +%% p3 = [10 25]; +%% circle = createCircle(p1, p2, p3); +%% figure; hold on; axis equal; axis([0 50 0 50]); +%% drawPoint([p1 ; p2; p3]); +%% drawCircle(circle); +%% @end example +%% +%% @seealso{circles2d, createDirectedCircle} +%% @end deftypefn + +function circle = createCircle(varargin) + + if nargin == 2 + % inputs are the center and a point on the circle + p1 = varargin{1}; + p2 = varargin{2}; + x0 = p1(:,1); + y0 = p1(:,2); + r = hypot((p2(:,1)-x0), (p2(:,2)-y0)); + + elseif nargin == 3 + % inputs are three points on the circle + p1 = varargin{1}; + p2 = varargin{2}; + p3 = varargin{3}; + + % compute circle center + line1 = medianLine(p1, p2); + line2 = medianLine(p1, p3); + point = intersectLines(line1, line2); + x0 = point(:, 1); + y0 = point(:, 2); + + % circle radius + r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); + end + + % create array for returning result + circle = [x0 y0 r]; + +endfunction + +%!test +%! p1 = [10 15]; +%! p2 = [15 20]; +%! p3 = [10 25]; +%! exp = [10 20 5]; +%! circle = createCircle(p1, p2, p3); +%! assertEqual(exp, circle); +%! circle = createCircle(p3, p1, p2); +%! assertEqual(exp, circle); +%! circle = createCircle(p2, p3, p1); +%! assertEqual(exp, circle); + +%!test +%! p1 = [10 15]; +%! p2 = [15 20]; +%! p3 = [10 25]; +%! exp = [10 20 5]; +%! p1 = [p1; p1+10; p1+20; p1-5]; +%! p2 = [p2; p2+10; p2+20; p2-5]; +%! p3 = [p3; p3+10; p3+20; p3-5]; +%! exp = repmat(exp, 4, 1) + [0 0 0;10 10 0;20 20 0;-5 -5 0]; +%! circle = createCircle(p1, p2, p3); +%! assertEqual(exp, circle); +%! circle = createCircle(p3, p1, p2); +%! assertEqual(exp, circle); +%! circle = createCircle(p2, p3, p1); +%! assertEqual(exp, circle); + Copied: trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createDirectedCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,92 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{circle} = } createDirectedCircle (@var{p1}, @var{p2}, @var{p3}) +%% @deftypefnx {Function File} {@var{circle} = } createDirectedCircle (@var{p1}, @var{p2}) +%% Create a circle from 2 or 3 points. +%% +%% Creates the circle passing through the 3 given points. +%% C is a 1x4 array of the form: [XC YX R INV]. +%% +%% When two points are given, creates the circle whith center @var{p1} and passing +%% throuh the point @var{p2}. +%% +%% Works also when input are point arrays the same size, in this case the +%% result has as many lines as the point arrays. +%% +%% Example +%% +%% +%% @seealso{circles2d, createCircle} +%% @end deftypefn + +function circle = createDirectedCircle(varargin) + + if nargin == 2 + % inputs are the center and a point on the circle + p1 = varargin{1}; + p2 = varargin{2}; + x0 = (p1(:,1) + p2(:,1))/2; + y0 = (p1(:,2) + p2(:,2))/2; + r = hypot((p2(:,1)-p1(:,1)), (p2(:,2)-p1(:,2)))/2; + + % circle is direct by default + d = 0; + + elseif nargin == 3 + % inputs are three points on the circle + p1 = varargin{1}; + p2 = varargin{2}; + p3 = varargin{3}; + + % compute circle center + line1 = medianLine(p1, p2); + line2 = medianLine(p1, p3); + center = intersectLines(line1, line2); + x0 = center(:, 1); + y0 = center(:, 2); + + % circle radius + r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); + + % compute circle orientation + angle = angle3Points(p1, center, p2) + angle3Points(p2, center, p3); + d = angle>2*pi; + end + + + circle = [x0 y0 r d]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createEdge.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,121 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{edge} = } createEdge (@var{p1}, @var{p2}) +%% @deftypefnx {Function File} {@var{edge} = } createEdge (@var{x0}, @var{y0}, @var{dx}, @var{dy}) +%% @deftypefnx {Function File} {@var{edge} = } createEdge (@var{param}) +%% @deftypefnx {Function File} {@var{edge} = } createEdge (@var{line}, @var{d}) +%% Create an edge between two points, or from a line. +%% +%% The internal format for edge representation is given by coordinates of +%% two points : [x1 y1 x2 y2]. +%% This function can serve as a line to edge converter. +%% +%% +%% Returns the edge between the two given points @var{p1} and @var{p2}. +%% +%% Returns the edge going through point (@var{x0}, @var{y0}) and with direction +%% vector (@var{dx},@var{dy}). +%% +%% When @var{param} is an array of 4 values, creates the edge going through the +%% point (param(1) param(2)), and with direction vector given by +%% (param(3) param(4)). +%% +%% When @var{line} is given, creates the edge contained in @var{line}, with same +%% direction and start point, but with length given by @var{d}. +%% +%% +%% Note: in all cases, parameters can be vertical arrays of the same +%% dimension. The result is then an array of edges, of dimensions [N*4]. +%% +%% @seealso{edges2d, lines2d, drawEdge, clipEdge} +%% @end deftypefn + +function edge = createEdge(varargin) + + if length(varargin)==1 + % Only one input parameter. It can be : + % - line angle + % - array of four parameters + % TODO : add control for arrays of lines. + var = varargin{1}; + + if size(var, 2)==4 + % 4 parameters of the line in a single array. + %edge = var; + edge = zeros(size(var)); + edge(:, 1:2) = var(:,1:2); + edge(:, 3:4) = edge(:, 1:2)+var(:,3:4); + elseif size(var, 2)==1 + % 1 parameter : angle of the line, going through origin. + edge = [zeros(size(var,1)) zeros(size(var,1)) cos(var) sin(var)]; + else + error('wrong number of dimension for arg1 : can be 1 or 4'); + end + + elseif length(varargin)==2 + % 2 input parameters. They can be : + % - 2 points, then 2 arrays of 1*2 double, + % - a line, and a distance. + v1 = varargin{1}; + v2 = varargin{2}; + if size(v1, 2)==2 + % first input parameter is first point, and second input is the + % second point. + %edge = [v1(:,1), v1(:,2), v2(:,1), v2(:,2)]; + edge = [v1 v2]; + else + % first input parameter is a line, and second one a distance. + angle = atan2(v1(:,4), v1(:,3)); + edge = [v1(:,1), v1(:,2), v1(:,1)+v2.*cos(angle), v1(:,2)+v2.*sin(angle)]; + end + + elseif length(varargin)==3 + % 3 input parameters : + % first one is a point belonging to the line, + % second and third ones are direction vector of the line (dx and dy). + p = varargin{1}; + edge = [p(:,1) p(:,2) p(:,1)+varargin{2} p(:,2)+varargin{3}]; + + elseif length(varargin)==4 + % 4 input parameters : + % they are x0, y0 (point belonging to line) and dx, dy (direction + % vector of the line). + % All parameters should have the same size. + edge = [varargin{1} varargin{2} varargin{1}+varargin{3} varargin{2}+varargin{4}]; + else + error('Wrong number of arguments in ''createLine'' '); + end + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/medianLine.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,137 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{line} = } medianLine (@var{p1}, @var{p2}) +%% @deftypefnx {Function File} {@var{line} = } medianLine (@var{pts}) +%% @deftypefnx {Function File} {@var{line} = } medianLine (@var{edge}) +%% Create a median line between two points. +%% +%% Create the median line of points @var{p1} and @var{p2}, that is the line containing +%% all points located at equal distance of @var{p1} and @var{p2}. +%% +%% Creates the median line of 2 points, given as a 2*2 array @var{pts}. Array has +%% the form: +%% [ [ x1 y1 ] ; [ x2 y2 ] ] +%% +%% Creates the median of the @var{edge}. @var{edge} is a 1*4 array, containing [X1 Y1] +%% coordinates of first point, and [X2 Y2], the coordinates of the second +%% point. +%% +%% Example +%% +%% @example +%% % Draw the median line of two points +%% P1 = [10 20]; +%% P2 = [30 50]; +%% med = medianLine(P1, P2); +%% figure; axis square; axis([0 100 0 100]); +%% drawEdge([P1 P2], 'linewidth', 2, 'color', 'k'); +%% drawLine(med) +%% +%% % Draw the median line of an edge +%% P1 = [50 60]; +%% P2 = [80 30]; +%% edge = createEdge(P1, P2); +%% figure; axis square; axis([0 100 0 100]); +%% drawEdge(edge, 'linewidth', 2) +%% med = medianLine(edge); +%% drawLine(med) +%% @end example +%% +%% @seealso{lines2d, createLine, orthogonalLine} +%% @end deftypefn + +function lin = medianLine(varargin) + + nargs = length(varargin); + x0 = 0; + y0 = 0; + dx = 0; + dy = 0; + + if nargs == 1 + tab = varargin{1}; + if size(tab, 2)==2 + % input is an array of two points + x0 = tab(1,1); + y0 = tab(1,2); + dx = tab(2,1)-x0; + dy = tab(2,2)-y0; + else + % input is an edge + x0 = tab(:, 1); + y0 = tab(:, 2); + dx = tab(:, 3) - tab(:, 1); + dy = tab(:, 4) - tab(:, 2); + end + + elseif nargs==2 + % input is given as two points, or two point arrays + p1 = varargin{1}; + p2 = varargin{2}; + x0 = p1(:, 1); + y0 = p1(:, 2); + dx = bsxfun(@minus, p2(:, 1), x0); + dy = bsxfun(@minus, p2(:, 2), y0); + + else + error('Too many input arguments'); + end + + % compute median using middle point of the edge, and the direction vector + % rotated by 90 degrees counter-clockwise + lin = [bsxfun(@plus, x0, dx/2), bsxfun(@plus, y0, dy/2), -dy, dx]; + +endfunction + +%!test +%! p1 = [0 0]; +%! p2 = [10 0]; +%! exp = [5 0 0 10]; +%! lin = medianLine(p1, p2); +%! assertElementsAlmostEqual(exp, lin); + +%!test +%! p1 = [0 0]; +%! p2 = [10 0]; +%! exp = [5 0 0 10]; +%! lin = medianLine([p1 p2]); +%! assertElementsAlmostEqual(exp, lin); + +%!test +%! p1 = [0 0; 10 10]; +%! p2 = [10 0;10 20]; +%! exp = [5 0 0 10; 10 15 -10 0]; +%! lin = medianLine(p1, p2); +%! assertElementsAlmostEqual(exp, lin); Added: trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/private/assertAlmostEqual.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,26 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {} assertAlmostEqual () +%% Wrapper. Not documented. +%% +%% @end deftypefn + +function assertAlmostEqual(a,b) + + assert(b,a,1e-6); + +endfunction Added: trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/private/assertEqual.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -0,0 +1,26 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {} assertEqual () +%% Wrapper. Not documented. +%% +%% @end deftypefn + +function assertEqual(a,b) + + assert(b,a); + +endfunction Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testCreateCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,56 +0,0 @@ -function test_suite = testCreateCircle(varargin) %#ok<STOUT> -% One-line description here, please. -% output = testMidPoint(input) -% -% Example -% testMidPoint -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -initTestSuite; - -function test_threePoints %#ok<*DEFNU> - -p1 = [10 15]; -p2 = [15 20]; -p3 = [10 25]; -exp = [10 20 5]; - -circle = createCircle(p1, p2, p3); -assertEqual(exp, circle); - -circle = createCircle(p3, p1, p2); -assertEqual(exp, circle); - -circle = createCircle(p2, p3, p1); -assertEqual(exp, circle); - - -function test_threeArrays %#ok<*DEFNU> - -p1 = [10 15]; -p2 = [15 20]; -p3 = [10 25]; -exp = [10 20 5]; - -p1 = [p1; p1+10; p1+20; p1-5]; -p2 = [p2; p2+10; p2+20; p2-5]; -p3 = [p3; p3+10; p3+20; p3-5]; - -exp = repmat(exp, 4, 1) + [0 0 0;10 10 0;20 20 0;-5 -5 0]; - -circle = createCircle(p1, p2, p3); -assertEqual(exp, circle); - -circle = createCircle(p3, p1, p2); -assertEqual(exp, circle); - -circle = createCircle(p2, p3, p1); -assertEqual(exp, circle); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testMedianLine.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,47 +0,0 @@ -function test_suite = testMedianLine(varargin) %#ok<STOUT> -%TESTMEDIANLINE One-line description here, please. -% output = testMedianLine(input) -% -% Example -% testMedianLine -% -% See also -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-04-22, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. -% Licensed under the terms of the LGPL, see the file "license.txt" - -initTestSuite; - -function testTwoPoints %#ok<*DEFNU> -% test with 2 points - -p1 = [0 0]; -p2 = [10 0]; -exp = [5 0 0 10]; -line = medianLine(p1, p2); -assertElementsAlmostEqual(exp, line); - -function testEdge -% test with an edge as input - -p1 = [0 0]; -p2 = [10 0]; -exp = [5 0 0 10]; -line = medianLine([p1 p2]); -assertElementsAlmostEqual(exp, line); - -function testTwoPointArrays %#ok<*DEFNU> -% test with 2 points - -p1 = [0 0; 10 10]; -p2 = [10 0;10 20]; - -exp = [5 0 0 10; 10 15 -10 0]; - -line = medianLine(p1, p2); -assertElementsAlmostEqual(exp, line); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,94 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function circle = createCircle(varargin) -%CREATECIRCLE Create a circle from 2 or 3 points -% -% C = createCircle(P1, P2, P3); -% Creates the circle passing through the 3 given points. -% C is a 1*3 array of the form: [XC YX R]. -% -% C = createCircle(P1, P2); -% Creates the circle whith center P1 and passing throuh the point P2. -% -% Works also when input are point arrays the same size, in this case the -% result has as many lines as the point arrays. -% -% Example -% % Draw a circle passing through 3 points. -% p1 = [10 15]; -% p2 = [15 20]; -% p3 = [10 25]; -% circle = createCircle(p1, p2, p3); -% figure; hold on; axis equal; axis([0 50 0 50]); -% drawPoint([p1 ; p2; p3]); -% drawCircle(circle); -% -% See also: -% circles2d, createDirectedCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - - -if nargin == 2 - % inputs are the center and a point on the circle - p1 = varargin{1}; - p2 = varargin{2}; - x0 = p1(:,1); - y0 = p1(:,2); - r = hypot((p2(:,1)-x0), (p2(:,2)-y0)); - -elseif nargin == 3 - % inputs are three points on the circle - p1 = varargin{1}; - p2 = varargin{2}; - p3 = varargin{3}; - - % compute circle center - line1 = medianLine(p1, p2); - line2 = medianLine(p1, p3); - point = intersectLines(line1, line2); - x0 = point(:, 1); - y0 = point(:, 2); - - % circle radius - r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); -end - -% create array for returning result -circle = [x0 y0 r]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createDirectedCircle.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,92 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function circle = createDirectedCircle(varargin) -%CREATEDIRECTEDCIRCLE Create a directed circle -% -% C = createDirectedCircle(P1, P2, P3); -% Creates a circle going through the given points. -% C is a 1*4 array of the form: [XC YC R INV]. -% The last parameter is set to 1 if the points are located in clockwise -% order on the circle. -% -% C = createDirectedCircle(P1, P2); -% Creates the circle whith center P1 and passing throuh the point P2. -% -% Works also when input are point arrays the same size, in this case the -% result has as many lines as the point arrays. -% -% See also: -% circles2d, createCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 12/01/2005. -% - -if nargin == 2 - % inputs are the center and a point on the circle - p1 = varargin{1}; - p2 = varargin{2}; - x0 = (p1(:,1) + p2(:,1))/2; - y0 = (p1(:,2) + p2(:,2))/2; - r = hypot((p2(:,1)-p1(:,1)), (p2(:,2)-p1(:,2)))/2; - - % circle is direct by default - d = 0; - -elseif nargin == 3 - % inputs are three points on the circle - p1 = varargin{1}; - p2 = varargin{2}; - p3 = varargin{3}; - - % compute circle center - line1 = medianLine(p1, p2); - line2 = medianLine(p1, p3); - center = intersectLines(line1, line2); - x0 = center(:, 1); - y0 = center(:, 2); - - % circle radius - r = hypot((p1(:,1)-x0), (p1(:,2)-y0)); - - % compute circle orientation - angle = angle3Points(p1, center, p2) + angle3Points(p2, center, p3); - d = angle>2*pi; -end - - -circle = [x0 y0 r d]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createEdge.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,130 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function edge = createEdge(varargin) -%CREATEEDGE Create an edge between two points, or from a line -% -% The internal format for edge representation is given by coordinates of -% two points : [x1 y1 x2 y2]. -% This function can serve as a line to edge converter. -% -% -% E = createEdge(P1, P2); -% Returns the edge between the two given points P1 and P2. -% -% E = createEdge(x0, y0, dx, dy); -% Returns the edge going through point (x0, y0) and with direction -% vector (dx,dy). -% -% E = createEdge(param); -% where param is an array of 4 values, creates the edge going through the -% point (param(1) param(2)), and with direction vector given by -% (param(3) param(4)). -% -% E = createEdge(LINE, D); -% create the edge contained in LINE, with same direction and start point, -% but with length given by D. -% -% -% Note: in all cases, parameters can be vertical arrays of the same -% dimension. The result is then an array of edges, of dimensions [N*4]. -% -% -% See also: -% edges2d, lines2d, drawEdge, clipEdge -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY : -% 18/02/2004 : add more possibilities to create edges, not only from 2 -% points. Also add support for arrays. -% 31/03/2004 : convert to [P1 P2] format - -if length(varargin)==1 - % Only one input parameter. It can be : - % - line angle - % - array of four parameters - % TODO : add control for arrays of lines. - var = varargin{1}; - - if size(var, 2)==4 - % 4 parameters of the line in a single array. - %edge = var; - edge = zeros(size(var)); - edge(:, 1:2) = var(:,1:2); - edge(:, 3:4) = edge(:, 1:2)+var(:,3:4); - elseif size(var, 2)==1 - % 1 parameter : angle of the line, going through origin. - edge = [zeros(size(var,1)) zeros(size(var,1)) cos(var) sin(var)]; - else - error('wrong number of dimension for arg1 : can be 1 or 4'); - end - -elseif length(varargin)==2 - % 2 input parameters. They can be : - % - 2 points, then 2 arrays of 1*2 double, - % - a line, and a distance. - v1 = varargin{1}; - v2 = varargin{2}; - if size(v1, 2)==2 - % first input parameter is first point, and second input is the - % second point. - %edge = [v1(:,1), v1(:,2), v2(:,1), v2(:,2)]; - edge = [v1 v2]; - else - % first input parameter is a line, and second one a distance. - angle = atan2(v1(:,4), v1(:,3)); - edge = [v1(:,1), v1(:,2), v1(:,1)+v2.*cos(angle), v1(:,2)+v2.*sin(angle)]; - end - -elseif length(varargin)==3 - % 3 input parameters : - % first one is a point belonging to the line, - % second and third ones are direction vector of the line (dx and dy). - p = varargin{1}; - edge = [p(:,1) p(:,2) p(:,1)+varargin{2} p(:,2)+varargin{3}]; - -elseif length(varargin)==4 - % 4 input parameters : - % they are x0, y0 (point belonging to line) and dx, dy (direction - % vector of the line). - % All parameters should have the same size. - edge = [varargin{1} varargin{2} varargin{1}+varargin{3} varargin{2}+varargin{4}]; -else - error('Wrong number of arguments in ''createLine'' '); -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m 2011-10-16 19:59:02 UTC (rev 8756) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/medianLine.m 2011-10-16 20:55:49 UTC (rev 8757) @@ -1,120 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function line = medianLine(varargin) -%MEDIANLINE Create a median line between two points -% -% L = medianLine(P1, P2); -% Create the median line of points P1 and P2, that is the line containing -% all points located at equal distance of P1 and P2. -% -% L = medianLine(PTS); -% Creates the median line of 2 points, given as a 2*2 array. Array has -% the form: -% [ [ x1 y1 ] ; [ x2 y2 ] ] -% -% L = medianLine(EDGE); -% Creates the median of the edge. Edge is a 1*4 array, containing [X1 Y1] -% coordinates of first point, and [X2 Y2], the coordinates of the second -% point. -% -% Example -% % Draw the median line of two points -% P1 = [10 20]; -% P2 = [30 50]; -% med = medianLine(P1, P2); -% figure; axis square; axis([0 100 0 100]); -% drawEdge([P1 P2], 'linewidth', 2, 'color', 'k'); -% drawLine(med) -% -% % Draw the median line of an edge -% P1 = [50 60]; -% P2 = [80 30]; -% edge = createEdge(P1, P2); -% figure; axis square; axis([0 100 0 100]); -% drawEdge(edge, 'linewidth', 2) -% med = medianLine(edge); -% drawLine(med) -% -% -% See also: -% lines2d, createLine, orthogonalLine -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% history -% 2010-08-06 vectorize and change behaviour for N-by-4 inputs - -nargs = length(varargin); -x0 = 0; -y0 = 0; -dx = 0; -dy = 0; - -if nargs == 1 - tab = varargin{1}; - if size(tab, 2)==2 - % input is an array of two points - x0 = tab(1,1); - y0 = tab(1,2); - dx = tab(2,1)-x0; - dy = tab(2,2)-y0; - else - % input is an edge - x0 = tab(:, 1); - y0 = tab(:, 2); - dx = tab(:, 3) - tab(:, 1); - dy = tab(:, 4) - tab(:, 2); - end - -elseif nargs==2 - % input is given as two points, or two point arrays - p1 = varargin{1}; - p2 = varargin{2}; - x0 = p1(:, 1); - y0 = p1(:, 2); - dx = bsxfun(@minus, p2(:, 1), x0); - dy = bsxfun(@minus, p2(:, 2), y0); - -else - error('Too many input arguments'); -end - -% compute median using middle point of the edge, and the direction vector -% rotated by 90 degrees counter-clockwise -line = [bsxfun(@plus, x0, dx/2), bsxfun(@plus, y0, dy/2), -dy, dx]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-18 15:24:56
|
Revision: 8780 http://octave.svn.sourceforge.net/octave/?rev=8780&view=rev Author: jpicarbajal Date: 2011-10-18 15:24:44 +0000 (Tue, 18 Oct 2011) Log Message: ----------- geometry. Adding final functions from geom2d. Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lineFit.m Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/Contents.m trunk/octave-forge/main/geometry/geom2d/inst/bisector.m trunk/octave-forge/main/geometry/geom2d/inst/cartesianLine.m trunk/octave-forge/main/geometry/geom2d/inst/drawArrow.m trunk/octave-forge/main/geometry/geom2d/inst/edges2d.m trunk/octave-forge/main/geometry/geom2d/inst/lines2d.m trunk/octave-forge/main/geometry/geom2d/inst/orthogonalLine.m trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m trunk/octave-forge/main/geometry/geom2d/inst/projPointOnLine.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testBisector.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/Contents.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/bisector.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/cartesianLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawArrow.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edges2d.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lines2d.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/orthogonalLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/parallelLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/projPointOnLine.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-18 12:34:40 UTC (rev 8779) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-18 15:24:44 UTC (rev 8780) @@ -96,4 +96,16 @@ points2d.m intersectLineEdge.m isPointOnEdge.m + =============================================================================== +geometry-1.2 Release Date: 2011-10-13 Release Manager: Juan Pablo Carbajal +=============================================================================== + +* Continue all geom2d added + createCircle.m + createDirectedCircle.m + createEdge.m + medianLine.m + +=============================================================================== + Copied: trunk/octave-forge/main/geometry/geom2d/inst/Contents.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/Contents.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/Contents.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/Contents.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,230 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} Contents () +%% GEOM2D Geometry 2D Toolbox +%% Version 1.0 21-Mar-2011 . +%% +%% Library to handle and visualize geometric primitives such as points, +%% lines, circles and ellipses, polygons... +%% +%% The goal is to provide a low-level library for manipulating geometrical +%% primitives, making easier the development of more complex geometric +%% algorithms. +%% +%% Most functions works for planar shapes, but some ones have been +%% extended to 3D or to any dimension. +%% +%% Points +%% points2d - Description of functions operating on points +%% clipPoints - Clip a set of points by a box +%% centroid - Compute centroid (center of mass) of a set of points +%% midPoint - Middle point of two points or of an edge +%% isCounterClockwise - Compute relative orientation of 3 points +%% polarPoint - Create a point from polar coordinates (rho + theta) +%% angle2Points - Compute horizontal angle between 2 points +%% angle3Points - Compute oriented angle made by 3 points +%% angleSort - Sort points in the plane according to their angle to origin +%% distancePoints - Compute distance between two points +%% minDistancePoints - Minimal distance between several points +%% transformPoint - Transform a point with an affine transform +%% drawPoint - Draw the point on the axis. +%% +%% Vectors +%% vectors2d - Description of functions operating on plane vectors +%% createVector - Create a vector from two points +%% vectorNorm - Compute norm of a vector, or of a set of vectors +%% vectorAngle - Angle of a vector, or between 2 vectors +%% normalizeVector - Normalize a vector to have norm equal to 1 +%% isPerpendicular - Check orthogonality of two vectors +%% isParallel - Check parallelism of two vectors +%% transformVector - Transform a vector with an affine transform +%% rotateVector - Rotate a vector by a given angle +%% +%% Straight lines +%% lines2d - Description of functions operating on planar lines +%% createLine - Create a straight line from 2 points, or from other inputs +%% medianLine - Create a median line between two points +%% cartesianLine - Create a straight line from cartesian equation coefficients +%% orthogonalLine - Create a line orthogonal to another one. +%% parallelLine - Create a line parallel to another one. +%% intersectLines - Return all intersection points of N lines in 2D +%% lineAngle - Computes angle between two straight lines +%% linePosition - Position of a point on a line +%% lineFit - Fit a straight line to a set of points +%% clipLine - Clip a line with a box +%% reverseLine - Return same line but with opposite orientation +%% transformLine - Transform a line with an affine transform +%% drawLine - Draw the line on the current axis +%% +%% Edges (line segments between 2 points) +%% edges2d - Description of functions operating on planar edges +%% createEdge - Create an edge between two points, or from a line +%% edgeToLine - Convert an edge to a straight line +%% edgeAngle - Return angle of edge +%% edgeLength - Return length of an edge +%% midPoint - Middle point of two points or of an edge +%% edgePosition - Return position of a point on an edge +%% clipEdge - Clip an edge with a rectangular box +%% reverseEdge - Intervert the source and target vertices of edge +%% intersectEdges - Return all intersections between two set of edges +%% intersectLineEdge - Return intersection between a line and an edge +%% transformEdge - Transform an edge with an affine transform +%% drawEdge - Draw an edge given by 2 points +%% drawCenteredEdge - Draw an edge centered on a point +%% +%% Rays +%% rays2d - Description of functions operating on planar rays +%% createRay - Create a ray (half-line), from various inputs +%% bisector - Return the bisector of two lines, or 3 points +%% clipRay - Clip a ray with a box +%% drawRay - Draw a ray on the current axis +%% +%% Relations between points and lines +%% distancePointEdge - Minimum distance between a point and an edge +%% distancePointLine - Minimum distance between a point and a line +%% projPointOnLine - Project of a point orthogonally onto a line +%% pointOnLine - Create a point on a line at a given position on the line +%% isPointOnLine - Test if a point belongs to a line +%% isPointOnEdge - Test if a point belongs to an edge +%% isPointOnRay - Test if a point belongs to a ray +%% isLeftOriented - Test if a point is on the left side of a line +%% +%% Circles +%% circles2d - Description of functions operating on circles +%% createCircle - Create a circle from 2 or 3 points +%% createDirectedCircle - Create a directed circle +%% intersectCircles - Intersection points of two circles +%% intersectLineCircle - Intersection point(s) of a line and a circle +%% circleAsPolygon - Convert a circle into a series of points +%% circleArcAsCurve - Convert a circle arc into a series of points +%% isPointInCircle - Test if a point is located inside a given circle +%% isPointOnCircle - Test if a point is located on a given circle. +%% enclosingCircle - Find the minimum circle enclosing a set of points. +%% radicalAxis - Compute the radical axis (or radical line) of 2 circles +%% drawCircle - Draw a circle on the current axis +%% drawCircleArc - Draw a circle arc on the current axis +%% +%% Ellipses +%% ellipses2d - Description of functions operating on ellipses +%% inertiaEllipse - Inertia ellipse of a set of points +%% isPointInEllipse - Check if a point is located inside a given ellipse +%% ellipseAsPolygon - Convert an ellipse into a series of points +%% drawEllipse - Draw an ellipse on the current axis +%% drawEllipseArc - Draw an ellipse arc on the current axis +%% +%% Geometric transforms +%% transforms2d - Description of functions operating on transforms +%% createTranslation - Create the 3*3 matrix of a translation +%% createRotation - Create the 3*3 matrix of a rotation +%% createScaling - Create the 3*3 matrix of a scaling in 2 dimensions +%% createHomothecy - Create the the 3x3 matrix of an homothetic transform +%% createBasisTransform - Compute matrix for transforming a basis into another basis +%% createLineReflection - Create the the 3x3 matrix of a line reflection +%% fitAffineTransform2d - Fit an affine transform using two point sets +%% +%% Angles +%% angles2d - Description of functions for manipulating angles +%% normalizeAngle - Normalize an angle value within a 2*PI interval +%% angleAbsDiff - Absolute difference between two angles +%% angleDiff - Difference between two angles +%% deg2rad - Convert angle from degrees to radians +%% rad2deg - Convert angle from radians to degrees +%% +%% Boxes +%% boxes2d - Description of functions operating on bounding boxes +%% intersectBoxes - Intersection of two bounding boxes +%% mergeBoxes - Merge two boxes, by computing their greatest extent +%% randomPointInBox - Generate random point within a box +%% drawBox - Draw a box defined by coordinate extents +%% +%% Various drawing functions +%% drawBezierCurve - Draw a cubic bezier curve defined by 4 control points +%% drawParabola - Draw a parabola on the current axis +%% drawOrientedBox - Draw centered oriented rectangle +%% drawRect - Draw rectangle on the current axis +%% drawArrow - Draw an arrow on the current axis +%% drawLabels - Draw labels at specified positions +%% drawShape - Draw various types of shapes (circles, polygons...) +%% +%% Other shapes +%% squareGrid - Generate equally spaces points in plane. +%% hexagonalGrid - Generate hexagonal grid of points in the plane. +%% triangleGrid - Generate triangular grid of points in the plane. +%% crackPattern - Create a (bounded) crack pattern tessellation +%% crackPattern2 - Create a (bounded) crack pattern tessellation +%% +%% +%% Credits: +%% * function 'enclosingCircle' rewritten from a file from Yazan Ahed +%% (ya...@gm...), available on Matlab File Exchange +%% +%% ----- +%% Author: David Legland +%% e-mail: dav...@gr... +%% Created: 2005-11-07 +%% Copyright INRA - Cepia Software Platform. +%% Homepage: http://matgeom.sourceforge.net/ +%% http://www.pfl-cepia.inra.fr/index.php?page=geom2d +%% @end deftypefn + + help('Contents'); + + + %% Deprecated functions + + % createMedian - create a median line + % minDistance - compute minimum distance between a point and a set of points + % homothecy - create a homothecy as an affine transform + % rotation - return 3*3 matrix of a rotation + % translation - return 3*3 matrix of a translation + % scaling - return 3*3 matrix of a scaling in 2 dimensions + % lineSymmetry - create line symmetry as 2D affine transform + % vecnorm - compute norm of vector or of set of vectors + % normalize - normalize a vector + % onCircle - test if a point is located on a given circle. + % inCircle - test if a point is located inside a given circle. + % onEdge - test if a point belongs to an edge + % onLine - test if a point belongs to a line + % onRay - test if a point belongs to a ray + % invertLine - return same line but with opposite orientation + % clipLineRect - clip a line with a polygon + % formatAngle - Ensure an angle value is comprised between 0 and 2*PI + + + %% Others... + % drawRect2 - Draw centered rectangle on the current axis + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/bisector.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/bisector.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/bisector.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/bisector.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,117 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{ray} = } bisector (@var{line1}, @var{line2}) +%% @deftypefnx {Function File} {@var{ray} = } bisector (@var{p1}, @var{p2}, @var{p3}) +%% Return the bisector of two lines, or 3 points. +%% +%% Creates the bisector of the two lines, given as [x0 y0 dx dy]. +%% +%% create the bisector of lines (@var{p2} @var{p1}) and (@var{p2} @var{p3}). +%% +%% The result has the form [x0 y0 dx dy], with [x0 y0] being the origin +%% point ans [dx dy] being the direction vector, normalized to have unit +%% norm. +%% +%% @seealso{lines2d, rays2d} +%% @end deftypefn + +function ray = bisector(varargin) + + if length(varargin)==2 + % two lines + line1 = varargin{1}; + line2 = varargin{2}; + + point = intersectLines(line1, line2); + + elseif length(varargin)==3 + % three points + p1 = varargin{1}; + p2 = varargin{2}; + p3 = varargin{3}; + + line1 = createLine(p2, p1); + line2 = createLine(p2, p3); + point = p2; + + elseif length(varargin)==1 + % three points, given in one array + var = varargin{1}; + p1 = var(1, :); + p2 = var(2, :); + p3 = var(3, :); + + line1 = createLine(p2, p1); + line2 = createLine(p2, p3); + point = p2; + end + + % compute line angles + a1 = lineAngle(line1); + a2 = lineAngle(line2); + + % compute bisector angle (angle of first line + half angle between lines) + angle = mod(a1 + mod(a2-a1+2*pi, 2*pi)/2, pi*2); + + % create the resulting ray + ray = [point cos(angle) sin(angle)]; + +endfunction + +%!test +%! p0 = [0 0]; +%! p1 = [10 0]; +%! p2 = [0 10]; +%! line1 = createLine(p0, p1); +%! line2 = createLine(p0, p2); +%! ray = bisector(line1, line2); +%! assertElementsAlmostEqual([0 0], ray(1,1:2)); +%! assertAlmostEqual(pi/4, lineAngle(ray)); + +%!test +%! p0 = [0 0]; +%! p1 = [10 0]; +%! p2 = [0 10]; +%! ray = bisector(p1, p0, p2); +%! assertElementsAlmostEqual([0 0], ray(1,1:2)); +%! assertAlmostEqual(pi/4, lineAngle(ray)); + +%!test +%! p0 = [0 0]; +%! p1 = [10 0]; +%! p2 = [0 10]; +%! ray = bisector([p1; p0; p2]); +%! assertElementsAlmostEqual([0 0], ray(1,1:2)); +%! assertAlmostEqual(pi/4, lineAngle(ray)); Copied: trunk/octave-forge/main/geometry/geom2d/inst/cartesianLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/cartesianLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/cartesianLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/cartesianLine.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,69 @@ +%% 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{line} = } cartesianLine (@var{A}, @var{B},@var{C}) +%% Create a straight line from cartesian equation coefficients. +%% +%% Create a line verifying the Cartesian equation: +%% @var{A}*x + @var{B}*x + @var{C} = 0; +%% +%% @seealso{lines2d, createLine} +%% @end deftypefn + +function line = cartesianLine(varargin) + + if length(varargin)==1 + var = varargin{1}; + a = var(:,1); + b = var(:,2); + c = var(:,3); + elseif length(varargin)==3 + a = varargin{1}; + b = varargin{2}; + c = varargin{3}; + end + + % normalisation factor + d = a.*a + b.*b; + + x0 = -a.*c./d; + y0 = -b.*c./d; + theta = atan2(-a, b); + dx = cos(theta); + dy = sin(theta); + + line = [x0 y0 dx dy]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawArrow.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawArrow.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawArrow.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawArrow.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,142 @@ +%% 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{h} = } drawArrow (@var{x1}, @var{y1}, @var{x2}, @var{y2}) +%% @deftypefnx {Function File} {@var{h} = } drawArrow ([@var{ @var{x1}} @var{ @var{y1}} @var{x2} @var{y2}]) +%% @deftypefnx {Function File} {@var{h} = } drawArrow (@dots{}, @var{L}, @var{W}) +%% @deftypefnx {Function File} {@var{h} = } drawArrow (@dots{}, @var{L}, @var{W},@var{TYPE}) +%% Draw an arrow on the current axis. +%% +%% draw an arrow between the points (@var{x1} @var{y1}) and (@var{x2} @var{y2}). +%% The points can be given as a single array. @var{L}, @var{W} specify length +%% and width of the arrow. +%% +%% Also specify arrow type. @var{TYPE} can be one of the following : +%% 0: draw only two strokes +%% 1: fill a triangle +%% .5: draw a half arrow (try it to see ...) +%% +%% Arguments can be single values or array of size [N*1]. In this case, +%% the function draws multiple arrows. +%% +%% @end deftypefn + +function varargout = drawArrow(varargin) + + if isempty(varargin) + error('should specify at least one argument'); + end + + % parse arrow coordinate + var = varargin{1}; + if size(var, 2)==4 + @var{x1} = var(:,1); + @var{y1} = var(:,2); + x2 = var(:,3); + y2 = var(:,4); + varargin = varargin(2:end); + elseif length(varargin)>3 + @var{x1} = varargin{1}; + @var{y1} = varargin{2}; + x2 = varargin{3}; + y2 = varargin{4}; + varargin = varargin(5:end); + else + error('wrong number of arguments, please read the doc'); + end + + l = 10*size(size( @var{x1})); + w = 5*ones(size( @var{x1})); + h = zeros(size( @var{x1})); + + % exctract length of arrow + if ~isempty(varargin) + l = varargin{1}; + if length( @var{x1})>length(l) + l = l(1)*ones(size( @var{x1})); + end + end + + % extract width of arrow + if length(varargin)>1 + w = varargin{2}; + if length( @var{x1})>length(w) + w = w(1)*ones(size( @var{x1})); + end + end + + % extract 'ratio' of arrow + if length(varargin)>2 + h = varargin{3}; + if length( @var{x1})>length(h) + h = h(1)*ones(size( @var{x1})); + end + end + + hold on; + axis equal; + + % angle of the edge + theta = atan2(y2- @var{y1}, x2- @var{x1}); + + % point on the 'left' + xa1 = x2 - l.*cos(theta) - w.*sin(theta)/2; + ya1 = y2 - l.*sin(theta) + w.*cos(theta)/2; + % point on the 'right' + xa2 = x2 - l.*cos(theta) + w.*sin(theta)/2; + ya2 = y2 - l.*sin(theta) - w.*cos(theta)/2; + % point on the middle of the arrow + xa3 = x2 - l.*cos(theta).*h; + ya3 = y2 - l.*sin(theta).*h; + + % draw main edge + line([ @var{x1}'; x2'], [ @var{y1}'; y2'], 'color', [0 0 1]); + + % draw only 2 wings + ind = find(h==0); + line([xa1(ind)'; x2(ind)'], [ya1(ind)'; y2(ind)'], 'color', [0 0 1]); + line([xa2(ind)'; x2(ind)'], [ya2(ind)'; y2(ind)'], 'color', [0 0 1]); + + % draw a full arrow + ind = find(h~=0); + patch([x2(ind) xa1(ind) xa3(ind) xa2(ind) x2(ind)]', ... + [y2(ind) ya1(ind) ya3(ind) ya2(ind) y2(ind)]', [0 0 1]); + + + if nargout>0 + varargout{1}=h; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/edges2d.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edges2d.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/edges2d.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/edges2d.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,56 @@ +%% Copyright (c) 2011, INRA +%% 2008-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} edges2d () +%% Description of functions operating on planar edges +% +% An edge is represented by the corodinate of its end points: +% EDGE = [X1 Y1 X2 Y2]; +% +% A set of edges is represented by a N*4 array, each row representing an +% edge. +% +% +% @seealso{lines2d, rays2d, points2d +% createEdge, edgeAngle, edgeLength, edgeToLine, midPoint +% intersectEdges, intersectLineEdge, isPointOnEdge +% clipEdge, transformEdge +% drawEdge, drawCenteredEdge} +%% @end deftypefn +function edges2d(varargin) + + help('edges2d'); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/lines2d.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/lines2d.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/lines2d.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/lines2d.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,66 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} lines2d () +%% Description of functions operating on planar lines. +% +% The term 'line' refers to a planar straight line, which is an unbounded +% curve. Line segments defined between 2 points, which are bounded, are +% called 'edge', and are presented in file 'edges2d'. +% +% A straight line is defined by a point (its origin), and a vector (its +% direction). The different parameters are bundled into a row vector: +% LINE = [x0 y0 dx dy]; +% +% A line contains all points (x,y) such that: +% x = x0 + t*dx +% y = y0 + t*dy; +% for all t between -infinity and +infinity. +% +% @seealso{points2d, vectors2d, edges2d, rays2d +% createLine, cartesianLine, medianLine, edgeToLine +% orthogonalLine, parallelLine, bisector, radicalAxis +% lineAngle, linePosition, projPointOnLine +% isPointOnLine, distancePointLine, isLeftOriented +% intersectLines, intersectLineEdge, clipLine +% invertLine, transformLine, drawLine +% lineFit} +%% @end deftypefn + +function lines2d(varargin) + + help('lines2d'); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/orthogonalLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/orthogonalLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/orthogonalLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/orthogonalLine.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,64 @@ +%% 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{perp} = } orthogonalLine (@var{line}, @var{point}) +%% Create a line orthogonal to another one. +% +% Returns the line orthogonal to the line @var{line} and going through the +% point given by @var{point}. Directed angle from @var{line} to @var{perp} is pi/2. +% @var{line} is given as [x0 y0 dx dy] and @var{point} is [xp yp]. +% +% @seealso{lines2d, parallelLine} +%% @end deftypefn + +function res = orthogonalLine(line, point) + + N = max(size(point, 1), size(line, 1)); + + if size(point, 1)>1 + res = point; + else + res = ones(N, 1)*point; + end + + if size(line, 1)>1 + res(:,3) = -line(:,4); + res(:,4) = line(:,3); + else + res(:,3) = -ones(N,1)*line(4); + res(:,4) = ones(N,1)*line(3); + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/parallelLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,64 @@ +%% 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{res} = } parallelLine (@var{line}, @var{point}) +%% @deftypefnx {Function File} {@var{res} = } parallelLine (@var{line}, @var{dist}) +%% Create a line parallel to another one. +%% +%% Returns the line with same direction vector than @var{line} and going through +%% the point given by @var{point}. +%% @var{line} is given as [x0 y0 dx dy] and @var{point} is [xp yp]. +%% +%% Uses relative distance to specify position. The new line will be +%% located at distance @var{dist}, counted positive in the right side of @var{line} +%% and negative in the left side. +%% +%% @seealso{lines2d, orthogonalLine, distancePointLine} +%% @end deftypefn + +function res = parallelLine(line, point) + + if size(point, 1)==1 + % use a distance. Compute position of point located at distance DIST on + % the line orthogonal to the first one. + point = pointOnLine([line(:,1) line(:,2) line(:,4) -line(:,3)], point); + end + + % normal case: compute line through a point with given direction + res = zeros(1, 4); + res(1:2) = point; + res(3:4) = line(3:4); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/projPointOnLine.m (from rev 8731, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/projPointOnLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/projPointOnLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/projPointOnLine.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -0,0 +1,69 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{point} = } projPointOnLine (@var{pt1}, @var{line}) +%% Project of a point orthogonally onto a line +%% +%% Computes the (orthogonal) projection of point @var{pt1} onto the line @var{line}. +%% +%% Function works also for multiple points and lines. In this case, it +%% returns multiple points. +%% Point @var{pt1} is a [N*2] array, and @var{line} is a [N*4] array (see createLine +%% for details). Result @var{point} is a [N*2] array, containing coordinates of +%% orthogonal projections of @var{pt1} onto lines @var{line}. +%% +%% @seealso{lines2d, points2d, isPointOnLine, linePosition} +%% @end deftypefn + +function point = projPointOnLine(point, line) + + % ensure input arguments have same size + if size(line, 1)==1 && size(point, 1)>1 + line = repmat(line, [size(point, 1) 1]); + end + if size(point, 1)==1 && size(line, 1)>1 + point = repmat(point, [size(line, 1) 1]); + end + + % slope of line + dx = line(:, 3); + dy = line(:, 4); + + % first find relative position of projection on the line, + tp = ((point(:, 2) - line(:, 2)).*dy + (point(:, 1) - line(:, 1)).*dx) ./ (dx.*dx+dy.*dy); + + % convert position on line to cartesian coordinate + point = line(:,1:2) + [tp tp].*[dx dy]; + +endfunction Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testBisector.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testBisector.m 2011-10-18 12:34:40 UTC (rev 8779) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testBisector.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -1,49 +0,0 @@ -function test_suite = testBisector(varargin) -% One-line description here, please. -% output = testBisector(input) -% -% Example -% testBisector -% -% 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 testTwoLines - -p0 = [0 0]; -p1 = [10 0]; -p2 = [0 10]; -line1 = createLine(p0, p1); -line2 = createLine(p0, p2); - -ray = bisector(line1, line2); -assertElementsAlmostEqual([0 0], ray(1,1:2)); -assertAlmostEqual(pi/4, lineAngle(ray)); - -function testThreePoints - -p0 = [0 0]; -p1 = [10 0]; -p2 = [0 10]; - -ray = bisector(p1, p0, p2); -assertElementsAlmostEqual([0 0], ray(1,1:2)); -assertAlmostEqual(pi/4, lineAngle(ray)); - -function testThreeBundldedPoints - -p0 = [0 0]; -p1 = [10 0]; -p2 = [0 10]; - -ray = bisector([p1; p0; p2]); -assertElementsAlmostEqual([0 0], ray(1,1:2)); -assertAlmostEqual(pi/4, lineAngle(ray)); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/Contents.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/Contents.m 2011-10-18 12:34:40 UTC (rev 8779) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/Contents.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -1,227 +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. - - -% GEOM2D Geometry 2D Toolbox -% Version 1.0 21-Mar-2011 . -% -% Library to handle and visualize geometric primitives such as points, -% lines, circles and ellipses, polygons... -% -% The goal is to provide a low-level library for manipulating geometrical -% primitives, making easier the development of more complex geometric -% algorithms. -% -% Most functions works for planar shapes, but some ones have been -% extended to 3D or to any dimension. -% -% Points -% points2d - Description of functions operating on points -% clipPoints - Clip a set of points by a box -% centroid - Compute centroid (center of mass) of a set of points -% midPoint - Middle point of two points or of an edge -% isCounterClockwise - Compute relative orientation of 3 points -% polarPoint - Create a point from polar coordinates (rho + theta) -% angle2Points - Compute horizontal angle between 2 points -% angle3Points - Compute oriented angle made by 3 points -% angleSort - Sort points in the plane according to their angle to origin -% distancePoints - Compute distance between two points -% minDistancePoints - Minimal distance between several points -% transformPoint - Transform a point with an affine transform -% drawPoint - Draw the point on the axis. -% -% Vectors -% vectors2d - Description of functions operating on plane vectors -% createVector - Create a vector from two points -% vectorNorm - Compute norm of a vector, or of a set of vectors -% vectorAngle - Angle of a vector, or between 2 vectors -% normalizeVector - Normalize a vector to have norm equal to 1 -% isPerpendicular - Check orthogonality of two vectors -% isParallel - Check parallelism of two vectors -% transformVector - Transform a vector with an affine transform -% rotateVector - Rotate a vector by a given angle -% -% Straight lines -% lines2d - Description of functions operating on planar lines -% createLine - Create a straight line from 2 points, or from other inputs -% medianLine - Create a median line between two points -% cartesianLine - Create a straight line from cartesian equation coefficients -% orthogonalLine - Create a line orthogonal to another one. -% parallelLine - Create a line parallel to another one. -% intersectLines - Return all intersection points of N lines in 2D -% lineAngle - Computes angle between two straight lines -% linePosition - Position of a point on a line -% lineFit - Fit a straight line to a set of points -% clipLine - Clip a line with a box -% reverseLine - Return same line but with opposite orientation -% transformLine - Transform a line with an affine transform -% drawLine - Draw the line on the current axis -% -% Edges (line segments between 2 points) -% edges2d - Description of functions operating on planar edges -% createEdge - Create an edge between two points, or from a line -% edgeToLine - Convert an edge to a straight line -% edgeAngle - Return angle of edge -% edgeLength - Return length of an edge -% midPoint - Middle point of two points or of an edge -% edgePosition - Return position of a point on an edge -% clipEdge - Clip an edge with a rectangular box -% reverseEdge - Intervert the source and target vertices of edge -% intersectEdges - Return all intersections between two set of edges -% intersectLineEdge - Return intersection between a line and an edge -% transformEdge - Transform an edge with an affine transform -% drawEdge - Draw an edge given by 2 points -% drawCenteredEdge - Draw an edge centered on a point -% -% Rays -% rays2d - Description of functions operating on planar rays -% createRay - Create a ray (half-line), from various inputs -% bisector - Return the bisector of two lines, or 3 points -% clipRay - Clip a ray with a box -% drawRay - Draw a ray on the current axis -% -% Relations between points and lines -% distancePointEdge - Minimum distance between a point and an edge -% distancePointLine - Minimum distance between a point and a line -% projPointOnLine - Project of a point orthogonally onto a line -% pointOnLine - Create a point on a line at a given position on the line -% isPointOnLine - Test if a point belongs to a line -% isPointOnEdge - Test if a point belongs to an edge -% isPointOnRay - Test if a point belongs to a ray -% isLeftOriented - Test if a point is on the left side of a line -% -% Circles -% circles2d - Description of functions operating on circles -% createCircle - Create a circle from 2 or 3 points -% createDirectedCircle - Create a directed circle -% intersectCircles - Intersection points of two circles -% intersectLineCircle - Intersection point(s) of a line and a circle -% circleAsPolygon - Convert a circle into a series of points -% circleArcAsCurve - Convert a circle arc into a series of points -% isPointInCircle - Test if a point is located inside a given circle -% isPointOnCircle - Test if a point is located on a given circle. -% enclosingCircle - Find the minimum circle enclosing a set of points. -% radicalAxis - Compute the radical axis (or radical line) of 2 circles -% drawCircle - Draw a circle on the current axis -% drawCircleArc - Draw a circle arc on the current axis -% -% Ellipses -% ellipses2d - Description of functions operating on ellipses -% inertiaEllipse - Inertia ellipse of a set of points -% isPointInEllipse - Check if a point is located inside a given ellipse -% ellipseAsPolygon - Convert an ellipse into a series of points -% drawEllipse - Draw an ellipse on the current axis -% drawEllipseArc - Draw an ellipse arc on the current axis -% -% Geometric transforms -% transforms2d - Description of functions operating on transforms -% createTranslation - Create the 3*3 matrix of a translation -% createRotation - Create the 3*3 matrix of a rotation -% createScaling - Create the 3*3 matrix of a scaling in 2 dimensions -% createHomothecy - Create the the 3x3 matrix of an homothetic transform -% createBasisTransform - Compute matrix for transforming a basis into another basis -% createLineReflection - Create the the 3x3 matrix of a line reflection -% fitAffineTransform2d - Fit an affine transform using two point sets -% -% Angles -% angles2d - Description of functions for manipulating angles -% normalizeAngle - Normalize an angle value within a 2*PI interval -% angleAbsDiff - Absolute difference between two angles -% angleDiff - Difference between two angles -% deg2rad - Convert angle from degrees to radians -% rad2deg - Convert angle from radians to degrees -% -% Boxes -% boxes2d - Description of functions operating on bounding boxes -% intersectBoxes - Intersection of two bounding boxes -% mergeBoxes - Merge two boxes, by computing their greatest extent -% randomPointInBox - Generate random point within a box -% drawBox - Draw a box defined by coordinate extents -% -% Various drawing functions -% drawBezierCurve - Draw a cubic bezier curve defined by 4 control points -% drawParabola - Draw a parabola on the current axis -% drawOrientedBox - Draw centered oriented rectangle -% drawRect - Draw rectangle on the current axis -% drawArrow - Draw an arrow on the current axis -% drawLabels - Draw labels at specified positions -% drawShape - Draw various types of shapes (circles, polygons...) -% -% Other shapes -% squareGrid - Generate equally spaces points in plane. -% hexagonalGrid - Generate hexagonal grid of points in the plane. -% triangleGrid - Generate triangular grid of points in the plane. -% crackPattern - Create a (bounded) crack pattern tessellation -% crackPattern2 - Create a (bounded) crack pattern tessellation -% -% -% Credits: -% * function 'enclosingCircle' rewritten from a file from Yazan Ahed -% (ya...@gm...), available on Matlab File Exchange -% -% ----- -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2005-11-07 -% Copyright INRA - Cepia Software Platform. -% Homepage: http://matgeom.sourceforge.net/ -% http://www.pfl-cepia.inra.fr/index.php?page=geom2d - -help('Contents'); - - -%% Deprecated functions - -% createMedian - create a median line -% minDistance - compute minimum distance between a point and a set of points -% homothecy - create a homothecy as an affine transform -% rotation - return 3*3 matrix of a rotation -% translation - return 3*3 matrix of a translation -% scaling - return 3*3 matrix of a scaling in 2 dimensions -% lineSymmetry - create line symmetry as 2D affine transform -% vecnorm - compute norm of vector or of set of vectors -% normalize - normalize a vector -% onCircle - test if a point is located on a given circle. -% inCircle - test if a point is located inside a given circle. -% onEdge - test if a point belongs to an edge -% onLine - test if a point belongs to a line -% onRay - test if a point belongs to a ray -% invertLine - return same line but with opposite orientation -% clipLineRect - clip a line with a polygon -% formatAngle - Ensure an angle value is comprised between 0 and 2*PI - - -%% Others... -% drawRect2 - Draw centered rectangle on the current axis - - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/bisector.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/bisector.m 2011-10-18 12:34:40 UTC (rev 8779) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/bisector.m 2011-10-18 15:24:44 UTC (rev 8780) @@ -1,98 +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 ray = bisector(varargin) -%BISECTOR Return the bisector of two lines, or 3 points -% -% RAY = bisector(LINE1, LINE2); -% create the bisector of the two lines, given as [x0 y0 dx dy]. -% -% RAY = bisector(P1, P2, P3); -% create the bisector of lines (P2 P1) and (P2 P3). -% -% The result has the form [x0 y0 dx dy], with [x0 y0] being the origin -% point ans [dx dy] being the direction vector, ... [truncated message content] |
From: <jpi...@us...> - 2011-10-18 15:32:45
|
Revision: 8781 http://octave.svn.sourceforge.net/octave/?rev=8781&view=rev Author: jpicarbajal Date: 2011-10-18 15:32:38 +0000 (Tue, 18 Oct 2011) Log Message: ----------- geometry. Cleaning up Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsParallel.m trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPerpendicular.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-18 15:24:44 UTC (rev 8780) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-18 15:32:38 UTC (rev 8781) @@ -98,14 +98,23 @@ isPointOnEdge.m =============================================================================== -geometry-1.2 Release Date: 2011-10-13 Release Manager: Juan Pablo Carbajal +geometry-1.2 Release Date: 2011-10-xx Release Manager: Juan Pablo Carbajal =============================================================================== -* Continue all geom2d added +* All geom2d added createCircle.m createDirectedCircle.m createEdge.m medianLine.m + Contents.m + bisector.m + cartesianLine.m + drawArrow.m + edges2d.m + lines2d.m + orthogonalLine.m + parallelLine.m + projPointOnLine.m =============================================================================== Modified: trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m 2011-10-18 15:24:44 UTC (rev 8780) +++ trunk/octave-forge/main/geometry/geom2d/inst/parallelLine.m 2011-10-18 15:32:38 UTC (rev 8781) @@ -61,4 +61,3 @@ res(3:4) = line(3:4); endfunction - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsParallel.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsParallel.m 2011-10-18 15:24:44 UTC (rev 8780) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsParallel.m 2011-10-18 15:32:38 UTC (rev 8781) @@ -1,52 +0,0 @@ -function test_suite = testIsParallel(varargin) -%TESTISPARALLEL One-line description here, please. -% output = testIsParallel(input) -% -% Example -% testIsParallel -% -% 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 testParallel %#ok<*DEFNU> - -v1 = [1 2]; -v2 = [2 4]; -b = isParallel(v1, v2); -assertTrue(b); - - -function testNotParallel - -v1 = [1 2]; -v2 = [2 5]; -b = isParallel(v1, v2); -assertFalse(b); - - -function testArraySingle - -v1 = [1 0;1 1;1 2]; -v2 = [2 4]; -th = [false; false; true]; -res = isParallel(v1, v2); -assertEqual(res, th); - - -function testSingleArray - -v1 = [2 4]; -v2 = [1 0;1 1;1 2]; -th = [false; false; true]; -res = isParallel(v1, v2); -assertEqual(res, th); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPerpendicular.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPerpendicular.m 2011-10-18 15:24:44 UTC (rev 8780) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testIsPerpendicular.m 2011-10-18 15:32:38 UTC (rev 8781) @@ -1,60 +0,0 @@ -function test_suite = testIsPerpendicular(varargin) %#ok<STOUT> -%testIsPerpendicular One-line description here, please. -% output = testIsPerpendicular(input) -% -% Example -% testIsPerpendicular -% -% 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 testPerpendicular %#ok<*DEFNU> - -v1 = [1 2]; -v2 = [-4 2]; -b = isPerpendicular(v1, v2); -assertTrue(b); - - -function testNotPerpendicular - -v1 = [1 2]; -v2 = [-4 1]; -b = isPerpendicular(v1, v2); -assertFalse(b); - -function testArrayAndSingle - -v1 = [1 0; 1 1; 1 2]; -v2 = [-4 2]; -th = [false; false; true]; - -res = isPerpendicular(v1, v2); -assertEqual(res, th); - -res = isPerpendicular(v2, v1); -assertEqual(res, th); - - -function testArrayArray - -v1 = [1 0; 1 1; 1 2]; -v2 = [0 1; 1 2; 1 1]; - -th = [true; false; false]; - -res = isPerpendicular(v1, v2); -assertEqual(res, th); - -res = isPerpendicular(v1, v2); -assertEqual(res, th); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-18 15:39:55
|
Revision: 8782 http://octave.svn.sourceforge.net/octave/?rev=8782&view=rev Author: jpicarbajal Date: 2011-10-18 15:39:48 +0000 (Tue, 18 Oct 2011) Log Message: ----------- geometry. Cleaning up Modified Paths: -------------- trunk/octave-forge/main/geometry/geom2d/inst/drawLine.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDrawLine.m Modified: trunk/octave-forge/main/geometry/geom2d/inst/drawLine.m =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawLine.m 2011-10-18 15:32:38 UTC (rev 8781) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawLine.m 2011-10-18 15:39:48 UTC (rev 8782) @@ -85,3 +85,110 @@ %! drawLine([30 40 10 20]); %! drawLine([30 40 20 -10], 'color', 'm', 'linewidth', 2); +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [30 40 10 0]; +%%! edge = [0 40 100 40]; +%%! hl = drawLine(line); +%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [30 40 -10 0]; +%%! edge = [100 40 0 40]; +%%! hl = drawLine(line); +%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [30 140 10 0]; +%%! hl = drawLine(line); +%%! assertEqual(-1, hl); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [30 40 0 10]; +%%! edge = [30 0 30 100]; +%%! hl = drawLine(line); +%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [30 40 0 -10]; +%%! edge = [30 100 30 0]; +%%! hl = drawLine(line); +%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [140 30 0 10]; +%%! hl = drawLine(line); +%%! assertEqual(-1, hl); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [80 30 10 10]; +%%! edge = [50 0 100 50]; +%%! hl = drawLine(line); +%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [20 70 10 10]; +%%! edge = [0 50 50 100]; +%%! hl = drawLine(line); +%%! assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); +%%! assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [140 -30 10 10]; +%%! hl = drawLine(line); +%%! assertEqual(-1, hl); +%%! line = [-40 130 10 10]; +%%! hl = drawLine(line); +%%! assertEqual(-1, hl); + +%%!test +%%! box = [0 100 0 100]; +%%! hf = figure(); +%%! axis(box); +%%! line = [... +%%! 80 30 10 10; ... +%%! 20 70 10 10; ... +%%! 140 -30 10 10; ... +%%! -40 130 10 10]; +%%! edge = [... +%%! 50 0 100 50; ... +%%! 0 50 50 100]; +%%! hl = drawLine(line); +%%! assertEqual(4, length(hl)); +%%! assertElementsAlmostEqual(edge(1, [1 3]), get(hl(1), 'xdata')); +%%! assertElementsAlmostEqual(edge(1, [2 4]), get(hl(1), 'ydata')); +%%! assertElementsAlmostEqual(edge(2, [1 3]), get(hl(2), 'xdata')); +%%! assertElementsAlmostEqual(edge(2, [2 4]), get(hl(2), 'ydata')); +%%! assertEqual(-1, hl(3)); +%%! assertEqual(-1, hl(4)); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDrawLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDrawLine.m 2011-10-18 15:32:38 UTC (rev 8781) +++ trunk/octave-forge/main/geometry/matGeom_raw/Tests/geom2d/testDrawLine.m 2011-10-18 15:39:48 UTC (rev 8782) @@ -1,139 +0,0 @@ -function test_suite = testClipLine(varargin) -% Tests the function 'clipLine' -% output = testClipLine(input) -% -% Example -% testClipLine -% -% 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 testHoriz -% test clipping of horizontal lines - -box = [0 100 0 100]; - -hf = figure; clf; -axis(box); - -% inside, to the right -line = [30 40 10 0]; -edge = [0 40 100 40]; - -hl = drawLine(line); -assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); - -% inside, to the left -line = [30 40 -10 0]; -edge = [100 40 0 40]; -hl = drawLine(line); -assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); - -% outside -line = [30 140 10 0]; -hl = drawLine(line); -assertEqual(-1, hl); - -close(hf); - - -function testVert -% test clipping of vertical lines - -box = [0 100 0 100]; - -hf = figure; clf; -axis(box); - -% inside, upward -line = [30 40 0 10]; -edge = [30 0 30 100]; -hl = drawLine(line); -assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); - -% inside, downward -line = [30 40 0 -10]; -edge = [30 100 30 0]; -hl = drawLine(line); -assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); - -% outside -line = [140 30 0 10]; -hl = drawLine(line); -assertEqual(-1, hl); - -close(hf); - - -function testDiagUp -% test clipping of upward diagonal lines - -box = [0 100 0 100]; - -hf = figure; clf; -axis(box); - -% inside, top right corner -line = [80 30 10 10]; -edge = [50 0 100 50]; -hl = drawLine(line); -assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); - -% inside, down right corner -line = [20 70 10 10]; -edge = [0 50 50 100]; -hl = drawLine(line); -assertElementsAlmostEqual(edge([1 3]), get(hl, 'xdata')); -assertElementsAlmostEqual(edge([2 4]), get(hl, 'ydata')); - -% outside -line = [140 -30 10 10]; -hl = drawLine(line); -assertEqual(-1, hl); - -line = [-40 130 10 10]; -hl = drawLine(line); -assertEqual(-1, hl); - -close(hf); - -function testMultiLines - -box = [0 100 0 100]; - -hf = figure; clf; -axis(box); - -% inside, top right corner -line = [... - 80 30 10 10; ... - 20 70 10 10; ... - 140 -30 10 10; ... - -40 130 10 10]; -edge = [... - 50 0 100 50; ... - 0 50 50 100]; -hl = drawLine(line); -assertEqual(4, length(hl)); -assertElementsAlmostEqual(edge(1, [1 3]), get(hl(1), 'xdata')); -assertElementsAlmostEqual(edge(1, [2 4]), get(hl(1), 'ydata')); -assertElementsAlmostEqual(edge(2, [1 3]), get(hl(2), 'xdata')); -assertElementsAlmostEqual(edge(2, [2 4]), get(hl(2), 'ydata')); -assertEqual(-1, hl(3)); -assertEqual(-1, hl(4)); - -close(hf); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 18:41:02
|
Revision: 8821 http://octave.svn.sourceforge.net/octave/?rev=8821&view=rev Author: jpicarbajal Date: 2011-10-21 18:40:53 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. Adding all draw functions Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/drawCenteredEdge.m trunk/octave-forge/main/geometry/geom2d/inst/drawCircle.m trunk/octave-forge/main/geometry/geom2d/inst/drawCircleArc.m trunk/octave-forge/main/geometry/geom2d/inst/drawEllipse.m trunk/octave-forge/main/geometry/geom2d/inst/drawEllipseArc.m trunk/octave-forge/main/geometry/geom2d/inst/drawLabels.m trunk/octave-forge/main/geometry/geom2d/inst/drawOrientedBox.m trunk/octave-forge/main/geometry/geom2d/inst/drawParabola.m trunk/octave-forge/main/geometry/geom2d/inst/drawRect.m trunk/octave-forge/main/geometry/geom2d/inst/drawShape.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircleArc.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawEllipse.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawEllipseArc.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawLabels.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawOrientedBox.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawParabola.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawRect.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawRect2.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawShape.m Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawCenteredEdge.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawCenteredEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawCenteredEdge.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,152 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{h} =} drawCenteredEdge (@var{center}, @var{L}, @var{theta}) +%% @deftypefnx {Function File} {@var{h} =} drawCenteredEdge (@var{edge}) +%% @deftypefnx {Function File} {@var{h} =} drawCenteredEdge (@dots{}, @var{name},@var{value}) +%% Draw an edge centered on a point. +%% +%% drawCenteredEdge(CENTER, L, THETA) +%% Draws an edge centered on point CENTER, with length L, and orientation +%% THETA (given in degrees). Input arguments can also be arrays, that must +%% all have the same number odf rows. +%% +%% drawCenteredEdge(EDGE) +%% Concatenates edge parameters into a single N-by-4 array, containing: +%% [XC YV L THETA]. +%% +%% drawCenteredEdge(..., NAME, VALUE) +%% Also specifies drawing options by using one or several parameter name - +%% value pairs (see doc of plot function for details). +%% +%% H = drawCenteredEdge(...) +%% Returns handle(s) to the created edges(s). +%% +%% @example +%% % Draw an ellipse with its two axes +%% figure(1); clf; +%% center = [50 40]; +%% r1 = 30; r2 = 10; +%% theta = 20; +%% elli = [center r1 r2 theta]; +%% drawEllipse(elli, 'linewidth', 2); +%% axis([0 100 0 100]); axis equal; +%% hold on; +%% edges = [center 2*r1 theta ; center 2*r2 theta+90]; +%% drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g'); +%% @end example +%% +%% @seealso{edges2d, drawEdge} +%% @end deftypefn + +function varargout = drawCenteredEdge(center, len, theta, varargin) + + %% process input variables + + if size(center, 2) == 4 + % manage edge in single parameter + + varargin = [{len, theta}, varargin]; + + len = center(:, 3); + theta = center(:, 4); + center = center(:, 1:2); + + N = size(center, 1); + + else + % parameters given in different arguments + + % size of data + NP = size(center, 1); + NL = size(len, 1); + ND = size(theta, 1); + N = max([NP NL ND]); + + % ensure all data have same size + if N > 1 + if NP == 1, center = repmat(center, [N 1]); end + if NL == 1, len = repmat(len, [N 1]); end + if ND == 1, theta = repmat(theta, [N 1]); end + end + + end + + % extract drawing options + options = varargin(:); + + + %% Draw edges + + % coordinates of center point + xc = center(:, 1); + yc = center(:, 2); + + % convert angle to radians + theta = theta * pi / 180; + + % computation shortcuts + cot = cos(theta); + sit = sin(theta); + + % compute starting and ending points + x1 = xc - len .* cot / 2; + x2 = xc + len .* cot / 2; + y1 = yc - len .* sit / 2; + y2 = yc + len .* sit / 2; + + + % draw the edges + h = zeros(N, 1); + for i = 1:N + h(i) = plot([x1(i) x2(i)], [y1(i) y2(i)]); + end + + % apply style to edges + if ~isempty(options) > 0 + for i = 1:N + set(h(i), options{:}); + end + end + + + %% Format output + + % process output arguments + if nargout > 0 + varargout = {h}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawCircle.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawCircle.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,132 @@ +%% 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{h} = } drawCircle (@var{x0}, @var{y0}, @var{r}) +%% @deftypefnx {Function File} {@var{h} = } drawCircle (@var{circle}) +%% @deftypefnx {Function File} {@var{h} = } drawCircle (@var{center}, @var{radius}) +%% @deftypefnx {Function File} {@var{h} = } drawCircle (@dots{}, @var{nstep}) +%% @deftypefnx {Function File} {@var{h} = } drawCircle (@dots{}, @var{name}, @var{value}) +%% Draw a circle on the current axis +%% +%% drawCircle(X0, Y0, R); +%% Draw the circle with center (X0,Y0) and the radius R. If X0, Y0 and R +%% are column vectors of the same length, draw each circle successively. +%% +%% drawCircle(CIRCLE); +%% Concatenate all parameters in a Nx3 array, where N is the number of +%% circles to draw. +%% +%% drawCircle(CENTER, RADIUS); +%% Specify CENTER as Nx2 array, and radius as a Nx1 array. +%% +%% drawCircle(..., NSTEP); +%% Specify the number of edges that will be used to draw the circle. +%% Default value is 72, creating an approximation of one point for each 5 +%% degrees. +%% +%% drawCircle(..., NAME, VALUE); +%% Specifies plotting options as pair of parameters name/value. See plot +%% documentation for details. +%% +%% +%% H = drawCircle(...); +%% return handles to each created curve. +%% +%% @seealso{circles2d, drawCircleArc, drawEllipse} +%% @end deftypefn + +function varargout = drawCircle(varargin) + + % process input parameters + var = varargin{1}; + if size(var, 2) == 1 + x0 = varargin{1}; + y0 = varargin{2}; + r = varargin{3}; + varargin(1:3) = []; + + elseif size(var, 2) == 2 + x0 = var(:,1); + y0 = var(:,2); + r = varargin{2}; + varargin(1:2) = []; + + elseif size(var, 2) == 3 + x0 = var(:,1); + y0 = var(:,2); + r = var(:,3); + varargin(1) = []; + else + error('bad format for input in drawCircle'); + end + + % ensure each parameter is column vector + x0 = x0(:); + y0 = y0(:); + r = r(:); + + % default number of discretization steps + N = 72; + + % check if discretization step is specified + if ~isempty(varargin) + var = varargin{1}; + if length(var)==1 && isnumeric(var) + N = round(var); + varargin(1) = []; + end + end + + % parametrization variable for circle (use N+1 as first point counts twice) + t = linspace(0, 2*pi, N+1); + cot = cos(t); + sit = sin(t); + + % empty array for graphic handles + h = zeros(size(x0)); + + % compute discretization of each circle + for i = 1:length(x0) + xt = x0(i) + r(i) * cot; + yt = y0(i) + r(i) * sit; + + h(i) = plot(xt, yt, varargin{:}); + end + + if nargout > 0 + varargout = {h}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawCircleArc.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircleArc.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawCircleArc.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawCircleArc.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,123 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{h} = } drawCircleArc (@var{xc}, @var{yc}, @var{r}, @var{start}, @var{end}) +%% @deftypefnx {Function File} {@var{h} = } drawCircleArc (@var{arc}) +%% @deftypefnx {Function File} {@var{h} = } drawCircleArc (@dots{}, @var{param}, @var{value}) +%% Draw a circle arc on the current axis +%% +%% drawCircleArc(XC, YC, R, START, EXTENT); +%% Draws circle with center (XC, YC), with radius R, starting from angle +%% START, and with angular extent given by EXTENT. START and EXTENT angles +%% are given in degrees. +%% +%% drawCircleArc(ARC); +%% Puts all parameters into one single array. +%% +%% drawCircleArc(..., PARAM, VALUE); +%% specifies plot properties by using one or several parameter name-value +%% pairs. +%% +%% H = drawCircleArc(...); +%% Returns a handle to the created line object. +%% +%% @example +%% % Draw a red thick circle arc +%% arc = [10 20 30 -120 240]; +%% figure; +%% axis([-50 100 -50 100]); +%% hold on +%% drawCircleArc(arc, 'LineWidth', 3, 'Color', 'r') +%% @end example +%% +%% @seealso{circles2d, drawCircle, drawEllipse} +%% @end deftypefn + +function varargout = drawCircleArc(varargin) + + if nargin == 0 + error('Need to specify circle arc'); + end + + circle = varargin{1}; + if size(circle, 2) == 5 + x0 = circle(:,1); + y0 = circle(:,2); + r = circle(:,3); + start = circle(:,4); + extent = circle(:,5); + varargin(1) = []; + + elseif length(varargin) >= 5 + x0 = varargin{1}; + y0 = varargin{2}; + r = varargin{3}; + start = varargin{4}; + extent = varargin{5}; + varargin(1:5) = []; + + else + error('drawCircleArc: please specify center, radius and angles of circle arc'); + end + + % convert angles in radians + t0 = deg2rad(start); + t1 = t0 + deg2rad(extent); + + % number of line segments + N = 60; + + % initialize handles vector + h = zeros(length(x0), 1); + + % draw each circle arc individually + for i = 1:length(x0) + % compute basis + t = linspace(t0(i), t1(i), N+1)'; + + % compute vertices coordinates + xt = x0(i) + r(i)*cos(t); + yt = y0(i) + r(i)*sin(t); + + % draw the circle arc + h(i) = plot(xt, yt, varargin{:}); + end + + if nargout > 0 + varargout = {h}; + end + + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawEllipse.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawEllipse.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawEllipse.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawEllipse.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,140 @@ +%% 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{h} = } drawEllipse (@var{elli}) +%% @deftypefnx {Function File} {@var{h} = } drawEllipse (@var{xc}, @var{yc}, @var{ra}, @var{rb}) +%% @deftypefnx {Function File} {@var{h} = } drawEllipse (@var{xc}, @var{yc}, @var{ra}, @var{rb}, @var{theta}) +%% @deftypefnx {Function File} {@var{h} = } drawEllipse (@dots{}, @var{param}, @var{value}) +%% Draw an ellipse on the current axis. +%% +%% drawEllipse(ELLI); +%% Draws the ellipse ELLI in the form [XC YC RA RB THETA], with center +%% (XC, YC), with main axis of half-length RA and RB, and orientation +%% THETA in degrees counted counter-clockwise. +%% Puts all parameters into one single array. +%% +%% drawEllipse(XC, YC, RA, RB); +%% drawEllipse(XC, YC, RA, RB, THETA); +%% Specifies ellipse parameters as separate arguments (old syntax). +%% +%% drawEllipse(..., NAME, VALUE); +%% Specifies drawing style of ellipse, see the help of plot function. +%% +%% H = drawEllipse(...); +%% Also returns handles to the created line objects. +%% +%% -> Parameters can also be arrays. In this case, all arrays are supposed +%% to have the same size. +%% +%% @example: +%% % Draw an ellipse centered in [50 50], with semi major axis length of +%% % 40, semi minor axis length of 20, and rotated by 30 degrees. +%% figure(1); clf; hold on; +%% drawEllipse([50 50 40 20 30]); +%% axis equal; +%% @end example +%% +%% @seealso{ellipses2d, drawCircle, drawEllipseArc, ellipseAsPolygon} +%% @end deftypefn + +function varargout = drawEllipse(varargin) + + % extract dawing style strings + styles = {}; + for i = 1:length(varargin) + if ischar(varargin{i}) + styles = varargin(i:end); + varargin(i:end) = []; + break; + end + end + + % extract ellipse parameters + if length(varargin)==1 + % ellipse is given in a single array + ellipse = varargin{1}; + x0 = ellipse(:, 1); + y0 = ellipse(:, 2); + a = ellipse(:, 3); + b = ellipse(:, 4); + if length(ellipse)>4 + theta = ellipse(:, 5); + else + theta = zeros(size(x0)); + end + + elseif length(varargin)>=4 + % ellipse parameters given as separate arrays + x0 = varargin{1}; + y0 = varargin{2}; + a = varargin{3}; + b = varargin{4}; + if length(varargin)>4 + theta = varargin{5}; + else + theta = zeros(size(x0)); + end + + else + error('drawEllipse: incorrect input arguments'); + end + + + %% Process drawing of a set of ellipses + + % angular positions of vertices + t = linspace(0, 2*pi, 145); + + % compute position of points to draw each ellipse + h = zeros(length(x0), 1); + for i = 1:length(x0) + % pre-compute rotation angles (given in degrees) + cot = cosd(theta(i)); + sit = sind(theta(i)); + + % compute position of points used to draw current ellipse + xt = x0(i) + a(i) * cos(t) * cot - b(i) * sin(t) * sit; + yt = y0(i) + a(i) * cos(t) * sit + b(i) * sin(t) * cot; + + % stores handle to graphic object + h(i) = plot(xt, yt, styles{:}); + end + + % return handles if required + if nargout > 0 + varargout = {h}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawEllipseArc.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawEllipseArc.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawEllipseArc.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawEllipseArc.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,161 @@ +%% 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{h} = } drawEllipseArc (@var{arc}) +%% Draw an ellipse arc on the current axis. +%% +%% drawEllipseArc(ARC) +%% draw ellipse arc specified by ARC. ARC has the format: +%% ARC = [XC YC A B THETA T1 T2] +%% or: +%% ARC = [XC YC A B T1 T2] (isothetic ellipse) +%% with center (XC, YC), main axis of half-length A, second axis of +%% half-length B, and ellipse arc running from t1 to t2 (both in degrees, +%% in Counter-Clockwise orientation). +%% +%% Parameters can also be arrays. In this case, all arrays are suposed to +%% have the same size... +%% +%% @example +%% % draw an ellipse arc: center = [10 20], radii = 50 and 30, theta = 45 +%% arc = [10 20 50 30 45 -90 270]; +%% figure; +%% axis([-50 100 -50 100]); axis equal; +%% hold on +%% drawEllipseArc(arc, 'color', 'r') +%% +%% % draw another ellipse arc, between angles -60 and 70 +%% arc = [10 20 50 30 45 -60 (60+70)]; +%% figure; +%% axis([-50 100 -50 100]); axis equal; +%% hold on +%% drawEllipseArc(arc, 'LineWidth', 2); +%% ray1 = createRay([10 20], deg2rad(-60+45)); +%% drawRay(ray1) +%% ray2 = createRay([10 20], deg2rad(70+45)); +%% drawRay(ray2) +%% @end example +%% +%% @seealso{ellipses2d, drawEllipse, drawCircleArc} +%% @end deftypefn + +function varargout = drawEllipseArc(varargin) + + %% Extract input arguments + + % extract dawing style strings + styles = {}; + for i = 1:length(varargin) + if ischar(varargin{i}) + styles = varargin(i:end); + varargin(i:end) = []; + break; + end + end + + if length(varargin)==1 + ellipse = varargin{1}; + x0 = ellipse(1); + y0 = ellipse(2); + a = ellipse(3); + b = ellipse(4); + if size(ellipse, 2)>6 + theta = ellipse(5); + start = ellipse(6); + extent = ellipse(7); + else + theta = zeros(size(x0)); + start = ellipse(5); + extent = ellipse(6); + end + + elseif length(varargin)>=6 + x0 = varargin{1}; + y0 = varargin{2}; + a = varargin{3}; + b = varargin{4}; + if length(varargin)>6 + theta = varargin{5}; + start = varargin{6}; + extent = varargin{7}; + else + theta = zeros(size(x0)); + start = varargin{5}; + extent = varargin{6}; + end + + else + error('drawellipse: please specify center x, center y and radii a and b'); + end + + + %% Drawing + + % allocate memory for handles + h = zeros(size(x0)); + + for i = 1:length(x0) + % start and end angles + t1 = deg2rad(start); + t2 = t1 + deg2rad(extent); + + % vertices of ellipse + t = linspace(t1, t2, 60); + + % convert angles to ellipse parametrisation + sup = cos(t) > 0; + t(sup) = atan(a(i) / b(i) * tan(t(sup))); + t(~sup) = atan2(a(i) / b(i) * tan(2*pi - t(~sup)), -1); + t = mod(t, 2*pi); + + % precompute cos and sin of theta (given in degrees) + cot = cosd(theta(i)); + sit = sind(theta(i)); + + % compute position of points + xt = x0(i) + a(i)*cos(t)*cot - b(i)*sin(t)*sit; + yt = y0(i) + a(i)*cos(t)*sit + b(i)*sin(t)*cot; + + h(i) = plot(xt, yt, styles{:}); + end + + + %% Process output arguments + + if nargout > 0 + varargout = {h}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawLabels.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawLabels.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawLabels.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawLabels.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,108 @@ +%% 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} drawLabels (@var{x}, @var{y}, @var{lbl}) +%% @deftypefnx {Function File} drawLabels (@var{pos}, @var{lbl}) +%% @deftypefnx {Function File} drawLabels (@dots{}, @var{numbers}, @var{format}) +%% Draw labels at specified positions. +%% +%% DRAWLABELS(X, Y, LBL) draw labels LBL at position X and Y. +%% LBL can be either a string array, or a number array. In this case, +%% string are created by using sprintf function, with '%.2f' mask. +%% +%% DRAWLABELS(POS, LBL) draw labels LBL at position specified by POS, +%% where POS is a N*2 int array. +%% +%% DRAWLABELS(..., NUMBERS, FORMAT) create labels using sprintf function, +%% with the mask given by FORMAT (e. g. '%03d' or '5.3f'), and the +%% corresponding values. +%% @end deftypefn + +function varargout = drawLabels(varargin) + + % check if enough inputs are given + if isempty(varargin) + error('wrong number of arguments in drawLabels'); + end + + % process input parameters + var = varargin{1}; + if size(var, 2)==1 + if length(varargin)<3 + error('wrong number of arguments in drawLabels'); + end + px = var; + py = varargin{2}; + lbl = varargin{3}; + varargin(1:3) = []; + else + if length(varargin)<2 + error('wrong number of arguments in drawLabels'); + end + px = var(:,1); + py = var(:,2); + lbl = varargin{2}; + varargin(1:2) = []; + end + + format = '%.2f'; + if ~isempty(varargin) + format = varargin{1}; + end + if size(format, 1)==1 && size(px, 1)>1 + format = repmat(format, size(px, 1), 1); + end + + labels = cell(length(px), 1); + if isnumeric(lbl) + for i=1:length(px) + labels{i} = sprintf(format(i,:), lbl(i)); + end + elseif ischar(lbl) + for i=1:length(px) + labels{i} = lbl(i,:); + end + elseif iscell(lbl) + labels = lbl; + end + labels = char(labels); + + h = text(px, py, labels); + + if nargout>0 + varargout{1}=h; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawOrientedBox.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawOrientedBox.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawOrientedBox.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawOrientedBox.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,113 @@ +%% 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{hb} = } drawOrientedBox (@var{box}) +%% @deftypefnx {Function File} {@var{hb} = } drawOrientedBox (@dots{}, @var{param}, @var{value}) +%% Draw centered oriented rectangle. +%% +%% Syntax +%% drawOrientedBox(BOX) +%% drawOrientedBox(BOX, 'PropertyName', propertyvalue, ...) +%% +%% Description +%% drawOrientedBox(OBOX) +%% Draws an oriented rectangle (or bounding box) on the current axis. +%% OBOX is a 1-by-5 row vector containing box center, dimension (length +%% and width) and orientation (in degrees): +%% OBOX = [CX CY LENGTH WIDTH THETA]. +%% +%% When OBOX is a N-by-5 array, the N boxes are drawn. +%% +%% HB = drawOrientedBox(...) +%% Returns a handle to the created graphic object(s). Object style can be +%% modified using syntaw like: +%% set(HB, 'color', 'g', 'linewidth', 2); +%% +%% @seealso{drawPolygon, drawRect, drawBox} +%% @end deftypefn + +function varargout = drawOrientedBox(box, varargin) + + %% Parses input arguments + + if nargin > 4 && sum(cellfun(@isnumeric, varargin(1:4))) == 4 + cx = box; + cy = varargin{1}; + hl = varargin{2} / 2; + hw = varargin{3} / 2; + theta = varargin{4}; + varargin = varargin(5:end); + else + cx = box(:,1); + cy = box(:,2); + hl = box(:,3) / 2; + hw = box(:,4) / 2; + theta = box(:,5); + end + + + %% Draw each box + + % allocate memory for graphical handle + hr = zeros(length(cx), 1); + + % iterate on oriented boxes + for i = 1:length(cx) + % pre-compute angle data + cot = cosd(theta(i)); + sit = sind(theta(i)); + + % x and y shifts + lc = hl(i) * cot; + ls = hl(i) * sit; + wc = hw(i) * cot; + ws = hw(i) * sit; + + % coordinates of box vertices + vx = cx(i) + [-lc + ws; lc + ws ; lc - ws ; -lc - ws ; -lc + ws]; + vy = cy(i) + [-ls - wc; ls - wc ; ls + wc ; -ls + wc ; -ls - wc]; + + % draw polygons + hr(i) = line(vx, vy, varargin{:}); + end + + + %% Format output + + if nargout > 0 + varargout = {hr}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawParabola.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawParabola.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawParabola.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawParabola.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,141 @@ +%% Copyright (c) 2011, INRA +%% 2006-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{h} = } drawParabola (@var{parabola}) +%% @deftypefnx {Function File} {@var{h} = } drawParabola (@var{parabola}, @var{t}) +%% @deftypefnx {Function File} {@var{h} = } drawParabola (@dots{}, @var{param}, @var{value}) +%% Draw a parabola on the current axis. +%% +%% drawParabola(PARABOLA); +%% Draws a vertical parabola, defined by its vertex and its parameter. +%% Such a parabola admits a vertical axis of symetry. +%% +%% The algebraic equation of parabola is given by: +%% (Y - YV) = A * (X - VX)^2 +%% Where XV and YV are vertex coordinates and A is parabola parameter. +%% +%% A parametric equation of parabola is given by: +%% x(t) = t + VX; +%% y(t) = A * t^2 + VY; +%% +%% PARABOLA can also be defined by [XV YV A THETA], with theta being the +%% angle of rotation of the parabola (in degrees and Counter-Clockwise). +%% +%% drawParabola(PARABOLA, T); +%% Specifies which range of 't' are used for drawing parabola. If T is an +%% array with only two values, the first and the last values are used as +%% interval bounds, and several values are distributed within this +%% interval. +%% +%% drawParabola(..., NAME, VALUE); +%% Can specify one or several graphical options using parameter name-value +%% pairs. +%% +%% H = drawParabola(...); +%% Returns an handle to the created graphical object. +%% +%% +%% @example: +%% figure(1); clf; hold on; +%% drawParabola([50 50 .2 30]); +%% drawParabola([50 50 .2 30], [-1 1], 'color', 'r', 'linewidth', 2); +%% axis equal; +%% @end example +%% +%% @seealso{drawCircle, drawEllipse} +%% @end deftypefn + +function varargout = drawParabola(varargin) + + % Extract parabola + if nargin<1 + error('geom2d:IllegalArgument', ... + 'Please specify parabola representation'); + end + + % input parabola is given as a packed array + parabola = varargin{1}; + varargin(1) = []; + x0 = parabola(:,1); + y0 = parabola(:,2); + a = parabola(:,3); + + if size(parabola, 2)>3 + theta = parabola(:, 4); + else + theta = zeros(length(a), 1); + end + + % extract parametrisation bounds + bounds = [-100 100]; + if ~isempty(varargin) + var = varargin{1}; + if isnumeric(var) + bounds = var; + varargin(1) = []; + end + end + + % create parametrisation + if length(bounds)>2 + t = bounds; + else + t = linspace(bounds(1), bounds(end), 100); + end + + % create handle array (in the case of several parabola) + h = zeros(size(x0)); + + % draw each parabola + for i=1:length(x0) + % compute transformation + trans = ... + createTranslation(x0(i), y0(i)) * ... + createRotation(deg2rad(theta(i))) * ... + createScaling(1, a); + + % compute points on the parabola + [xt yt] = transformPoint(t(:), t(:).^2, trans); + + % draw it + h(i) = plot(xt, yt, varargin{:}); + end + + % process output arguments + if nargout>0 + varargout{1}=h; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawRect.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawRect.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawRect.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawRect.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,104 @@ +%% 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{r} = } drawRect (@var{x}, @var{y}, @var{w}, @var{h}) +%% @deftypefnx {Function File} {@var{r} = } drawRect (@var{x}, @var{y}, @var{w}, @var{h}, @var{theta}) +%% @deftypefnx {Function File} {@var{r} = } drawRect (@var{coord}) +%% Draw rectangle on the current axis. +%% +%% r = DRAWRECT(x, y, w, h) draw rectangle with width W and height H, at +%% position (X, Y). +%% the four corners of rectangle are then : +%% (X, Y), (X+W, Y), (X, Y+H), (X+W, Y+H). +%% +%% r = DRAWRECT(x, y, w, h, theta) also specifies orientation for +%% rectangle. Theta is given in degrees. +%% +%% r = DRAWRECT(coord) is the same as DRAWRECT(X,Y,W,H), but all +%% parameters are packed into one array, whose dimensions is 4*1 or 5*1. +%% +%% +%% @seealso{drawBox, drawOrientedBox} +%% @end deftypefn + +function varargout = drawRect(varargin) + + % default values + theta = 0; + + % get entered values + if length(varargin) > 3 + x = varargin{1}; + y = varargin{2}; + w = varargin{3}; + h = varargin{4}; + if length(varargin)> 4 + theta = varargin{5} * pi / 180; + end + + else + coord = varargin{1}; + x = coord(1); + y = coord(2); + w = coord(3); + h = coord(4); + if length(coord) > 4 + theta = coord(5) * pi / 180; + end + end + + r = zeros(size(x)); + for i = 1:length(x) + tx = zeros(5, 1); + ty = zeros(5, 1); + tx(1) = x(i); + ty(1) = y(i); + tx(2) = x(i) + w(i) * cos(theta(i)); + ty(2) = y(i) + w(i) * sin(theta(i)); + tx(3) = x(i) + w(i) * cos(theta(i)) - h(i) * sin(theta(i)); + ty(3) = y(i) + w(i) * sin(theta(i)) + h(i) * cos(theta(i)); + tx(4) = x(i) - h(i) * sin(theta(i)); + ty(4) = y(i) + h(i) * cos(theta(i)); + tx(5) = x(i); + ty(5) = y(i); + + r(i) = line(tx, ty); + end + + if nargout > 0 + varargout{1} = r; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/drawShape.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawShape.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/drawShape.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/drawShape.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -0,0 +1,109 @@ +%% 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} drawShape (@var{type}, @var{param}) +%% @deftypefnx {Function File} drawShape (@dots{}, @var{option}) +%% Draw various types of shapes (circles, polygons...). +%% +%% drawShape(TYPE, PARAM) +%% Draw the shape of type TYPE, specified by given parameter PARAM. TYPE +%% can be one of {'circle', 'ellipse', 'rect', 'polygon', 'curve'} +%% PARAM depend on the type. For example, if TYPE is 'circle', PARAM will +%% contain [x0 y0 R]. +%% +%% Examples : +%% drawShape('circle', [20 10 30]); +%% Draw circle centered on [20 10] with radius 10. +%% drawShape('rect', [20 20 40 10 pi/3]); +%% Draw rectangle centered on [20 20] with length 40 and width 10, and +%% oriented pi/3 wrt axis Ox. +%% +%% +%% drawShape(..., OPTION) +%% also specifies drawing options. OPTION can be 'draw' (default) or +%% 'fill'. +%% @end deftypefn +function varargout = drawShape(type, param, varargin) + + if ~iscell(type) + type = {type}; + end + if ~iscell(param) + tmp = cell(1, size(param, 1)); + for i=1:size(param, 1) + tmp{i} = param(i,:); + end + param = tmp; + end + + option = 'draw'; + if ~isempty(varargin) + var = varargin{1}; + if strcmpi(var, 'fill') + option = 'fill'; + end + end + + + % transform each shape into a polygon + shape = cell(1,length(type)); + for i=1:length(type) + if strcmpi(type{i}, 'circle') + shape{i} = circleAsPolygon(param{i}, 128); + elseif strcmpi(type{i}, 'rect') + shape{i} = rectAsPolygon(param{i}); + elseif strcmpi(type{i}, 'polygon') + shape{i} = param{i}; + end + end + + + hold on; + h = zeros(length(shape), 1); + if strcmp(option, 'draw') + for i=1:length(shape) + h(i) = drawPolygon(shape{i}); + end + else + for i=1:length(shape) + h(i) = fillPolygon(shape{i}); + end + end + + if nargout>0 + varargout{1}=h; + end + +endfunction + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m 2011-10-21 18:03:57 UTC (rev 8820) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -1,155 +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 = drawCenteredEdge(center, len, theta, varargin) -%DRAWCENTEREDEDGE Draw an edge centered on a point -% -% drawCenteredEdge(CENTER, L, THETA) -% Draws an edge centered on point CENTER, with length L, and orientation -% THETA (given in degrees). Input arguments can also be arrays, that must -% all have the same number odf rows. -% -% drawCenteredEdge(EDGE) -% Concatenates edge parameters into a single N-by-4 array, containing: -% [XC YV L THETA]. -% -% drawCenteredEdge(..., NAME, VALUE) -% Also specifies drawing options by using one or several parameter name - -% value pairs (see doc of plot function for details). -% -% H = drawCenteredEdge(...) -% Returns handle(s) to the created edges(s). -% -% Example -% % Draw an ellipse with its two axes -% figure(1); clf; -% center = [50 40]; -% r1 = 30; r2 = 10; -% theta = 20; -% elli = [center r1 r2 theta]; -% drawEllipse(elli, 'linewidth', 2); -% axis([0 100 0 100]); axis equal; -% hold on; -% edges = [center 2*r1 theta ; center 2*r2 theta+90]; -% drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g'); -% -% See also: -% edges2d, drawEdge -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 05/08/2005. -% - -% HISTORY -% 2007-06-15 update doc, clean up code -% 2011-05-18 use angle in degrees, cleanup code and doc - - -%% process input variables - -if size(center, 2) == 4 - % manage edge in single parameter - - varargin = [{len, theta}, varargin]; - - len = center(:, 3); - theta = center(:, 4); - center = center(:, 1:2); - - N = size(center, 1); - -else - % parameters given in different arguments - - % size of data - NP = size(center, 1); - NL = size(len, 1); - ND = size(theta, 1); - N = max([NP NL ND]); - - % ensure all data have same size - if N > 1 - if NP == 1, center = repmat(center, [N 1]); end - if NL == 1, len = repmat(len, [N 1]); end - if ND == 1, theta = repmat(theta, [N 1]); end - end - -end - -% extract drawing options -options = varargin(:); - - -%% Draw edges - -% coordinates of center point -xc = center(:, 1); -yc = center(:, 2); - -% convert angle to radians -theta = theta * pi / 180; - -% computation shortcuts -cot = cos(theta); -sit = sin(theta); - -% compute starting and ending points -x1 = xc - len .* cot / 2; -x2 = xc + len .* cot / 2; -y1 = yc - len .* sit / 2; -y2 = yc + len .* sit / 2; - - -% draw the edges -h = zeros(N, 1); -for i = 1:N - h(i) = plot([x1(i) x2(i)], [y1(i) y2(i)]); -end - -% apply style to edges -if ~isempty(options) > 0 - for i = 1:N - set(h(i), options{:}); - end -end - - -%% Format output - -% process output arguments -if nargout > 0 - varargout = {h}; -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircle.m 2011-10-21 18:03:57 UTC (rev 8820) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircle.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -1,136 +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 = drawCircle(varargin) -%DRAWCIRCLE Draw a circle on the current axis -% -% drawCircle(X0, Y0, R); -% Draw the circle with center (X0,Y0) and the radius R. If X0, Y0 and R -% are column vectors of the same length, draw each circle successively. -% -% drawCircle(CIRCLE); -% Concatenate all parameters in a Nx3 array, where N is the number of -% circles to draw. -% -% drawCircle(CENTER, RADIUS); -% Specify CENTER as Nx2 array, and radius as a Nx1 array. -% -% drawCircle(..., NSTEP); -% Specify the number of edges that will be used to draw the circle. -% Default value is 72, creating an approximation of one point for each 5 -% degrees. -% -% drawCircle(..., NAME, VALUE); -% Specifies plotting options as pair of parameters name/value. See plot -% documentation for details. -% -% -% H = drawCircle(...); -% return handles to each created curve. -% -% See also: -% circles2d, drawCircleArc, drawEllipse -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 02/11/2004: add possibility to draw multiple circles in one call -% 12/01/2005: allow more than 3 parameters -% 26/02/2007: add possibility to specify plot options, number of -% discretization steps, and circle as center+radius. - - -% process input parameters -var = varargin{1}; -if size(var, 2) == 1 - x0 = varargin{1}; - y0 = varargin{2}; - r = varargin{3}; - varargin(1:3) = []; - -elseif size(var, 2) == 2 - x0 = var(:,1); - y0 = var(:,2); - r = varargin{2}; - varargin(1:2) = []; - -elseif size(var, 2) == 3 - x0 = var(:,1); - y0 = var(:,2); - r = var(:,3); - varargin(1) = []; -else - error('bad format for input in drawCircle'); -end - -% ensure each parameter is column vector -x0 = x0(:); -y0 = y0(:); -r = r(:); - -% default number of discretization steps -N = 72; - -% check if discretization step is specified -if ~isempty(varargin) - var = varargin{1}; - if length(var)==1 && isnumeric(var) - N = round(var); - varargin(1) = []; - end -end - -% parametrization variable for circle (use N+1 as first point counts twice) -t = linspace(0, 2*pi, N+1); -cot = cos(t); -sit = sin(t); - -% empty array for graphic handles -h = zeros(size(x0)); - -% compute discretization of each circle -for i = 1:length(x0) - xt = x0(i) + r(i) * cot; - yt = y0(i) + r(i) * sit; - - h(i) = plot(xt, yt, varargin{:}); -end - -if nargout > 0 - varargout = {h}; -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircleArc.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircleArc.m 2011-10-21 18:03:57 UTC (rev 8820) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/drawCircleArc.m 2011-10-21 18:40:53 UTC (rev 8821) @@ -1,126 +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 th... [truncated message content] |
From: <jpi...@us...> - 2011-10-21 18:45:42
|
Revision: 8822 http://octave.svn.sourceforge.net/octave/?rev=8822&view=rev Author: jpicarbajal Date: 2011-10-21 18:45:35 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. All *2d functions Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/circles2d.m trunk/octave-forge/main/geometry/geom2d/inst/ellipses2d.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circles2d.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipses2d.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:40:53 UTC (rev 8821) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:45:35 UTC (rev 8822) @@ -115,6 +115,17 @@ orthogonalLine.m parallelLine.m projPointOnLine.m - + drawCenteredEdge.m + drawCircle.m + drawCircleArc.m + drawEllipse.m + drawEllipseArc.m + drawLabels.m + drawOrientedBox.m + drawParabola.m + drawRect.m + drawShape.m + circles2d.m + ellipses2d.m =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/circles2d.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circles2d.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/circles2d.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/circles2d.m 2011-10-21 18:45:35 UTC (rev 8822) @@ -0,0 +1,64 @@ +%% Copyright (c) 2011, INRA +%% 2008-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} circles2d () +%% Description of functions operating on circles +%% +%% Circles are represented by their center and their radius: +%% C = [xc yc r]; +%% One sometimes considers orientation of circle, by adding an extra +%% boolean value in 4-th position, with value TRUE for direct (i.e. +%% turning Counter-clockwise) circles. +%% +%% Circle arcs are represented by their center, their radius, the starting +%% angle and the angle extent, both in degrees: +%% CA = [xc yc r theta0 dtheta]; +%% +%% Ellipses are represented by their center, their 2 semi-axis length, and +%% their angle (in degrees) with Ox direction. +%% E = [xc yc A B theta]; +%% +%% @seealso{ellipses2d, createCircle, createDirectedCircle, enclosingCircle +%% isPointInCircle, isPointOnCircle +%% intersectLineCircle, intersectCircles, radicalAxis +%% circleAsPolygon, circleArcAsCurve +%% drawCircle, drawCircleArc} +%% @end deftypefn + +function circles2d(varargin) + + help('circles2d'); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/ellipses2d.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipses2d.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/ellipses2d.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/ellipses2d.m 2011-10-21 18:45:35 UTC (rev 8822) @@ -0,0 +1,50 @@ +%% Copyright (c) 2011, INRA +%% 2008-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} ellipses2d () +%% Description of functions operating on ellipses. +%% +%% Ellipses are represented by their center, the length of their 2 +%% semi-axes length, and their angle from the Ox direction (in degrees). +%% E = [XC YC A B THETA]; +%% +%% @seealso{circles2d, inertiaEllipse, isPointInEllipse, ellipseAsPolygon +%% drawEllipse, drawEllipseArc} +%% @end deftypefn + +function ellipses2d(varargin) + + help('ellipses2d'); + +endfunction Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circles2d.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circles2d.m 2011-10-21 18:40:53 UTC (rev 8821) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circles2d.m 2011-10-21 18:45:35 UTC (rev 8822) @@ -1,65 +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 circles2d(varargin) -%CIRCLES2D Description of functions operating on circles -% -% Circles are represented by their center and their radius: -% C = [xc yc r]; -% One sometimes considers orientation of circle, by adding an extra -% boolean value in 4-th position, with value TRUE for direct (i.e. -% turning Counter-clockwise) circles. -% -% Circle arcs are represented by their center, their radius, the starting -% angle and the angle extent, both in degrees: -% CA = [xc yc r theta0 dtheta]; -% -% Ellipses are represented by their center, their 2 semi-axis length, and -% their angle (in degrees) with Ox direction. -% E = [xc yc A B theta]; -% -% See also: -% ellipses2d, createCircle, createDirectedCircle, enclosingCircle -% isPointInCircle, isPointOnCircle -% intersectLineCircle, intersectCircles, radicalAxis -% circleAsPolygon, circleArcAsCurve -% drawCircle, drawCircleArc -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) -% Copyright 2010 INRA - Cepia Software Platform. - -help('circles2d'); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipses2d.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipses2d.m 2011-10-21 18:40:53 UTC (rev 8821) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipses2d.m 2011-10-21 18:45:35 UTC (rev 8822) @@ -1,52 +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 ellipses2d(varargin) -%ELLIPSES2D Description of functions operating on ellipses -% -% Ellipses are represented by their center, the length of their 2 -% semi-axes length, and their angle from the Ox direction (in degrees). -% E = [XC YC A B THETA]; -% -% See also: -% circles2d, inertiaEllipse, isPointInEllipse, ellipseAsPolygon -% drawEllipse, drawEllipseArc -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) -% Copyright 2010 INRA - Cepia Software Platform. - -help('ellipses2d'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 18:51:55
|
Revision: 8823 http://octave.svn.sourceforge.net/octave/?rev=8823&view=rev Author: jpicarbajal Date: 2011-10-21 18:51:49 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. All create* functions Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/createVector.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createMedian.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createVector.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:45:35 UTC (rev 8822) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:51:49 UTC (rev 8823) @@ -127,5 +127,6 @@ drawShape.m circles2d.m ellipses2d.m + =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/createVector.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createVector.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/createVector.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/createVector.m 2011-10-21 18:51:49 UTC (rev 8823) @@ -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} {@var{vect} = } createVector (@var{p1}, @var{p2}) +%% Create a vector from two points. +%% +%% V12 = createVector(P1, P2) +%% Creates the vector V12, defined as the difference between coordinates +%% of points P1 and P2. +%% P1 and P2 are row vectors with ND elements, ND being the space +%% dimension. +%% +%% If one of the inputs is a N-by-Nd array, the other input is +%% automatically repeated, and the result is N-by-Nd. +%% +%% If both inputs have the same size, the result also have the same size. +%% +%% @seealso{vectors2d, vectors3d, points2d} +%% @end deftypefn +function vect = createVector(p1, p2) + vect = bsxfun(@minus, p2, p1); +endfunction + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createMedian.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createMedian.m 2011-10-21 18:45:35 UTC (rev 8822) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createMedian.m 2011-10-21 18:51:49 UTC (rev 8823) @@ -1,92 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function line = createMedian(varargin) -%CREATEMEDIAN create a median line -% -% DEPRECATED: use medianLine instead -% -% l = CREATEMEDIAN(P1, P2) create the median line of points P1 and P2, -% that is the line containing all points located at equal distance of -% P1 and P2. -% -% l = CREATEMEDIAN(points) create the median line of 2 points, given as -% a 2*2 array. array has the form : -% [ [ x1 y1 ] ; [ x2 y2 ] ] -% -% l = CREATEMEDIAN(edge) create the median of the edge. Edge is a 1*4 -% array, containing [x0 y0] coordiantes of first point, and [dx dy], -% the vector from first point to second point. -% -% -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% deprecation warning -warning('geom2d:deprecated', ... - '''createMedian'' is deprecated, use ''medianLine'' instead'); - - -nargs = length(varargin); -x0=0; -y0=0; -dx=0; -dy=0; - -if nargs == 1 - tab = varargin{1}; - if size(tab, 2)==2 - % array of two points - x0 = tab(1,1); y0 = tab(1,2); - dx = tab(2,1)-x0; dy = tab(2,2)-y0; - else - % edge equation - x0 = tab(1); y0 = tab(2); - dx = tab(3); dy = tab(4); - end -elseif nargs==2 - % two points - p1 = varargin{1}; - p2 = varargin{2}; - x0 = p1(1); y0 = p1(2); - dx = p2(1)-x0; dy = p2(2)-y0; -end - - -line = [x0+dx/2, y0+dy/2, -dy, dx]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createVector.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createVector.m 2011-10-21 18:45:35 UTC (rev 8822) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/createVector.m 2011-10-21 18:51:49 UTC (rev 8823) @@ -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 vect = createVector(p1, p2) -%CREATEVECTOR Create a vector from two points -% -% V12 = createVector(P1, P2) -% Creates the vector V12, defined as the difference between coordinates -% of points P1 and P2. -% P1 and P2 are row vectors with ND elements, ND being the space -% dimension. -% -% If one of the inputs is a N-by-Nd array, the other input is -% automatically repeated, and the result is N-by-Nd. -% -% If both inputs have the same size, the result also have the same size. -% -% -% Example -% -% See also -% vectors2d, vectors3d, points2d -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2010-12-07, using Matlab 7.9.0.529 (R2009b) -% Copyright 2010 INRA - Cepia Software Platform. - -vect = bsxfun(@minus, p2, p1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 18:58:22
|
Revision: 8824 http://octave.svn.sourceforge.net/octave/?rev=8824&view=rev Author: jpicarbajal Date: 2011-10-21 18:58:15 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. 27 functions to go! Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/changelog.txt trunk/octave-forge/main/geometry/geom2d/inst/inertiaEllipse.m trunk/octave-forge/main/geometry/geom2d/inst/readme.txt Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/changelog.txt trunk/octave-forge/main/geometry/matGeom_raw/geom2d/inertiaEllipse.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/invertLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/readme.txt Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:51:49 UTC (rev 8823) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:58:15 UTC (rev 8824) @@ -127,6 +127,10 @@ drawShape.m circles2d.m ellipses2d.m + createVector.m + inertiaEllipse.m + changelog.txt + readme.txt =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/changelog.txt (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/changelog.txt) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/changelog.txt (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/changelog.txt 2011-10-21 18:58:15 UTC (rev 8824) @@ -0,0 +1,192 @@ +%% 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. + + +change log for geom2d + +geom2d, release 2011.??.?? +========================== + +New functions +- added angleDiff and angleAbsDiff + +various doc updates + + +geom2d, release 2011.06.30 +========================== + +New functions +- added function rotateVector +- added function randomPointInBox + +Changes +- Shape orientation is now represented using degrees +- function vectorAngle can now compute the angle between two vectors + +Bug fixes +- enhanced function distancePointEdge +- enhanced function isPointOnEdge +- enhanced function isParallel +- fixed bugs intersectLineCircle + + +geom2d, release 2011.03.21 +========================== + +New functions +- added functions intersectLineCircle and intersectCircles +- added functions inertiaEllipse, isPointInEllipse +- added function drawBezierCurve +- added functions intersectBoxes and mergeBoxes + +Changes +- re-organized the library in three sub-directories: geom2d, polygons2d, and + polynomialCurves2d +- cleanup of code and doc + +Bug fixes +- several bugs fixed in clipEdge, isPointOnEdge + + +geom2d, release 2010.08.06 +========================== + +New functions +- polygonToRow and rowToPolygon, to convert polygon to a row vector +- midPoint, to compute middle points of either 2 points or an edge +- added rad2deg and deg2rad, for angle conversions + +Changes +- createCircle and createdirectedCircle are now vectorized, and use different + convention for 2 input variables (center + point and circle) +- median line has been vectorized + +Bug fixes +- fix bugs in intersectEdges +- fix bugs in clipLine +- rewrite drawLine using clipLine + + +geom2d, release 2010.07.19 +========================== + +new functions + +- isCounterClockwise +- intersectRayPolygon +- clipRay +- reverseEdge +- drawBox +- fitAffineTransform2d + +Changes + +- updated inertiaEllipse +- fixed bugs in intersectEdges.m, isParallel.m and isPerpendicular.m +- vectorized intersectLinePolygon +- fixed precision bug in isPointOnEdge +- renamed formatAngle to normalizeAngle +- created help file 'angles2d' +- fixed bug in weighted centroid computation + +various bug fixes, and doc updates. + + + +geom2d, release 2009.07.22 +========================== + +new features + +- new functions for polygons: + polygonPoint, polygonSubcurve, polygonLoops, distancePointPolygon, + distancePolygons, expandPolygon, polygonSelfIntersections, + projPointOnPolygon, isPointInPolygon, reveresPolygon + +- new functions for polylines: + intersectPolylines, polylineSelfIntersections, distancePolylines, + isPointOnPolyline, reveresPolyline + +- projPointOnPolyline can also return the distance of the point to the polyline + +- function 'edgeToLine' converts an edge to its supporting line + + +Changes + +- Renamed functions + + subcurve -> polylineSubCurve + + curveCentroid -> polylineCentroid + + invertLine -> reverseLine + +- Compatibility considerations + + parallelLine: changed convention for signed distance + +various bug fixes, and doc updates. + + +geom2d, release 2009.06.15 +========================== + +* new features + +- radicalAxis from 2 circles: +- moment of a curve (polyline): curveMoment, curveCMoment, curveCSMoment +- new functions for polylines + distancePointPolyline, drawPolyline, polylineLength, polylinePoint, + polylineSubcurve, projPointOnPolyline + +* changes + +- changed some function names to avoid potential name conflicts, and to make + function names more explicit: + + rotation -> createRotation + + scaling -> createScaling + + translation -> createRotation + + homothecy -> createHomothecy + + lineSymmetry -> createLineReflection + + inCircle -> isPointInCircle + + onCircle -> isPointOnCircle + + onEdge -> isPointOnEdge + + onLine -> isPointOnLine + + onRay -> isPointOnRay + + normalize -> normalizeVector + + +* bug fixes + +- fixed bug in intersectEdges + +many updates in doc. + Copied: trunk/octave-forge/main/geometry/geom2d/inst/inertiaEllipse.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/inertiaEllipse.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/inertiaEllipse.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/inertiaEllipse.m 2011-10-21 18:58:15 UTC (rev 8824) @@ -0,0 +1,96 @@ +%% Copyright (c) 2011, INRA +%% 2008-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{ell} = } inertiaEllipse (@var{pts}) +%% Inertia ellipse of a set of points +%% +%% ELL = inertiaEllipse(PTS); +%% where PTS is a N*2 array containing coordinates of N points, computes +%% the inertia ellispe of the set of points. +%% +%% The result has the form: +%% ELL = [XC YC A B THETA], +%% with XC and YC being the center of mass of the point set, A and B are +%% the lengths of the inertia ellipse (see below), and THETA is the angle +%% of the main inertia axis with the horizontal (counted in degrees +%% between 0 and 180). +%% A and B are the standard deviations of the point coordinates when +%% ellipse is aligned with the inertia axes. +%% +%% @example +%% pts = randn(100, 2); +%% pts = transformPoint(pts, createScaling(5, 2)); +%% pts = transformPoint(pts, createRotation(pi/6)); +%% pts = transformPoint(pts, createTranslation(3, 4)); +%% ell = inertiaEllipse(pts); +%% figure(1); clf; hold on; +%% drawPoint(pts); +%% drawEllipse(ell, 'linewidth', 2, 'color', 'r'); +%% @end example +%% +%% @seealso{ellipses2d, drawEllipse} +%% @end deftypefn + +function ell = inertiaEllipse(points) + + % ellipse center + xc = mean(points(:,1)); + yc = mean(points(:,2)); + + % recenter points + x = points(:,1) - xc; + y = points(:,2) - yc; + + % number of points + n = size(points, 1); + + % inertia parameters + Ixx = sum(x.^2) / n; + Iyy = sum(y.^2) / n; + Ixy = sum(x.*y) / n; + + % compute ellipse semi-axis lengths + common = sqrt( (Ixx - Iyy)^2 + 4 * Ixy^2); + ra = sqrt(2) * sqrt(Ixx + Iyy + common); + rb = sqrt(2) * sqrt(Ixx + Iyy - common); + + % compute ellipse angle in degrees + theta = atan2(2 * Ixy, Ixx - Iyy) / 2; + theta = rad2deg(theta); + + % create the resulting inertia ellipse + ell = [xc yc ra rb theta]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/readme.txt (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/readme.txt) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/readme.txt (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/readme.txt 2011-10-21 18:58:15 UTC (rev 8824) @@ -0,0 +1,68 @@ +%% 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. + + +Description of the geom2d library. + +The aim of geom2d library is to handle and visualize geometric primitives such +as points, lines, circles and ellipses, polylines and polygons... It provides +low-level functions for manipulating geometrical primitives, making easier the +development of more complex geometric algorithms. + +Some features of the library are: + +- creation of various shapes (points, circles, lines, ellipses, polylines, + polygons...) through an intuitive syntax. + Ex: createCircle(p1, p2, p3) to create a circle through 3 points. + +- derivation of new shapes: intersection between 2 lines, between line and + circle, between polylines... or point on a curve from its parametrisation + +- functions for polylines and polygons: compute centroid and area, expand, + self-intersections, clipping with half-plane... + +- manipulation of planar transformation. Ex.: + ROT = createRotation(CENTER, THETA); + P2 = transformPoint(P1, ROT); + +- direct drawing of shapes with specialized functions. Clipping is performed + automatically for infinite shapes such as lines or rays. Ex: + drawCircle([50 50 25]); % draw circle with radius 25 and center [50 50] + drawLine([X0 Y0 DX DY]); % clip and draw straight line + +- measure distances (between points, a point and a line, a point and a group + of points), angle (of a line, between 3 points), or test geometry (point + on a line, on a circle). + +Additional help is provided in geom/Contents.m file, as well as summary files + like 'points2d.m' or 'lines2d.m'. Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/changelog.txt =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/changelog.txt 2011-10-21 18:51:49 UTC (rev 8823) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/changelog.txt 2011-10-21 18:58:15 UTC (rev 8824) @@ -1,192 +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. - - -change log for geom2d - -geom2d, release 2011.??.?? -========================== - -New functions -- added angleDiff and angleAbsDiff - -various doc updates - - -geom2d, release 2011.06.30 -========================== - -New functions -- added function rotateVector -- added function randomPointInBox - -Changes -- Shape orientation is now represented using degrees -- function vectorAngle can now compute the angle between two vectors - -Bug fixes -- enhanced function distancePointEdge -- enhanced function isPointOnEdge -- enhanced function isParallel -- fixed bugs intersectLineCircle - - -geom2d, release 2011.03.21 -========================== - -New functions -- added functions intersectLineCircle and intersectCircles -- added functions inertiaEllipse, isPointInEllipse -- added function drawBezierCurve -- added functions intersectBoxes and mergeBoxes - -Changes -- re-organized the library in three sub-directories: geom2d, polygons2d, and - polynomialCurves2d -- cleanup of code and doc - -Bug fixes -- several bugs fixed in clipEdge, isPointOnEdge - - -geom2d, release 2010.08.06 -========================== - -New functions -- polygonToRow and rowToPolygon, to convert polygon to a row vector -- midPoint, to compute middle points of either 2 points or an edge -- added rad2deg and deg2rad, for angle conversions - -Changes -- createCircle and createdirectedCircle are now vectorized, and use different - convention for 2 input variables (center + point and circle) -- median line has been vectorized - -Bug fixes -- fix bugs in intersectEdges -- fix bugs in clipLine -- rewrite drawLine using clipLine - - -geom2d, release 2010.07.19 -========================== - -new functions - -- isCounterClockwise -- intersectRayPolygon -- clipRay -- reverseEdge -- drawBox -- fitAffineTransform2d - -Changes - -- updated inertiaEllipse -- fixed bugs in intersectEdges.m, isParallel.m and isPerpendicular.m -- vectorized intersectLinePolygon -- fixed precision bug in isPointOnEdge -- renamed formatAngle to normalizeAngle -- created help file 'angles2d' -- fixed bug in weighted centroid computation - -various bug fixes, and doc updates. - - - -geom2d, release 2009.07.22 -========================== - -new features - -- new functions for polygons: - polygonPoint, polygonSubcurve, polygonLoops, distancePointPolygon, - distancePolygons, expandPolygon, polygonSelfIntersections, - projPointOnPolygon, isPointInPolygon, reveresPolygon - -- new functions for polylines: - intersectPolylines, polylineSelfIntersections, distancePolylines, - isPointOnPolyline, reveresPolyline - -- projPointOnPolyline can also return the distance of the point to the polyline - -- function 'edgeToLine' converts an edge to its supporting line - - -Changes - -- Renamed functions - + subcurve -> polylineSubCurve - + curveCentroid -> polylineCentroid - + invertLine -> reverseLine - -- Compatibility considerations - + parallelLine: changed convention for signed distance - -various bug fixes, and doc updates. - - -geom2d, release 2009.06.15 -========================== - -* new features - -- radicalAxis from 2 circles: -- moment of a curve (polyline): curveMoment, curveCMoment, curveCSMoment -- new functions for polylines - distancePointPolyline, drawPolyline, polylineLength, polylinePoint, - polylineSubcurve, projPointOnPolyline - -* changes - -- changed some function names to avoid potential name conflicts, and to make - function names more explicit: - + rotation -> createRotation - + scaling -> createScaling - + translation -> createRotation - + homothecy -> createHomothecy - + lineSymmetry -> createLineReflection - + inCircle -> isPointInCircle - + onCircle -> isPointOnCircle - + onEdge -> isPointOnEdge - + onLine -> isPointOnLine - + onRay -> isPointOnRay - + normalize -> normalizeVector - - -* bug fixes - -- fixed bug in intersectEdges - -many updates in doc. - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/inertiaEllipse.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/inertiaEllipse.m 2011-10-21 18:51:49 UTC (rev 8823) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/inertiaEllipse.m 2011-10-21 18:58:15 UTC (rev 8824) @@ -1,100 +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 ell = inertiaEllipse(points) -%INERTIAELLIPSE Inertia ellipse of a set of points -% -% ELL = inertiaEllipse(PTS); -% where PTS is a N*2 array containing coordinates of N points, computes -% the inertia ellispe of the set of points. -% -% The result has the form: -% ELL = [XC YC A B THETA], -% with XC and YC being the center of mass of the point set, A and B are -% the lengths of the inertia ellipse (see below), and THETA is the angle -% of the main inertia axis with the horizontal (counted in degrees -% between 0 and 180). -% A and B are the standard deviations of the point coordinates when -% ellipse is aligned with the inertia axes. -% -% Example -% pts = randn(100, 2); -% pts = transformPoint(pts, createScaling(5, 2)); -% pts = transformPoint(pts, createRotation(pi/6)); -% pts = transformPoint(pts, createTranslation(3, 4)); -% ell = inertiaEllipse(pts); -% figure(1); clf; hold on; -% drawPoint(pts); -% drawEllipse(ell, 'linewidth', 2, 'color', 'r'); -% -% See also -% ellipses2d, drawEllipse -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2008-02-21, using Matlab 7.4.0.287 (R2007a) -% Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. - -% HISTORY -% 2009-07-29 take into account ellipse orientation -% 2011-03-12 rewrite using inertia moments - -% ellipse center -xc = mean(points(:,1)); -yc = mean(points(:,2)); - -% recenter points -x = points(:,1) - xc; -y = points(:,2) - yc; - -% number of points -n = size(points, 1); - -% inertia parameters -Ixx = sum(x.^2) / n; -Iyy = sum(y.^2) / n; -Ixy = sum(x.*y) / n; - -% compute ellipse semi-axis lengths -common = sqrt( (Ixx - Iyy)^2 + 4 * Ixy^2); -ra = sqrt(2) * sqrt(Ixx + Iyy + common); -rb = sqrt(2) * sqrt(Ixx + Iyy - common); - -% compute ellipse angle in degrees -theta = atan2(2 * Ixy, Ixx - Iyy) / 2; -theta = rad2deg(theta); - -% create the resulting inertia ellipse -ell = [xc yc ra rb theta]; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/invertLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/invertLine.m 2011-10-21 18:51:49 UTC (rev 8823) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/invertLine.m 2011-10-21 18:58:15 UTC (rev 8824) @@ -1,71 +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 = invertLine(var) -%INVERTLINE return same line but with opposite orientation -% -% INVLINE = invertLine(LINE); -% Returns the opposite line of LINE. -% LINE has the format [x0 y0 dx dy], then INVLINE will have following -% parameters: [x0 y0 -dx -dy]. -% -% See also: -% lines2d, createLine -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 20/01/2004. -% - -% HISTORY -% 30/06/2009 deprecate and replace by 'reverseLine'. - -% deprecation warning -warning('geom2d:deprecated', ... - '''invertLine'' is deprecated, use ''reverseLine'' instead'); - -line = 0; - -if size(var, 1)==1 - % only one line in a single array - line = [var(1) var(2) -var(3) -var(4)]; -else - % several lines in a single array - n = size(var, 1); - line(1:n, 1) = var(1:n, 1); - line(1:n, 2) = var(1:n, 2); - line(1:n, 3) = -var(1:n, 3); - line(1:n, 4) = -var(1:n, 4); -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/readme.txt =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/readme.txt 2011-10-21 18:51:49 UTC (rev 8823) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/readme.txt 2011-10-21 18:58:15 UTC (rev 8824) @@ -1,68 +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. - - -Description of the geom2d library. - -The aim of geom2d library is to handle and visualize geometric primitives such -as points, lines, circles and ellipses, polylines and polygons... It provides -low-level functions for manipulating geometrical primitives, making easier the -development of more complex geometric algorithms. - -Some features of the library are: - -- creation of various shapes (points, circles, lines, ellipses, polylines, - polygons...) through an intuitive syntax. - Ex: createCircle(p1, p2, p3) to create a circle through 3 points. - -- derivation of new shapes: intersection between 2 lines, between line and - circle, between polylines... or point on a curve from its parametrisation - -- functions for polylines and polygons: compute centroid and area, expand, - self-intersections, clipping with half-plane... - -- manipulation of planar transformation. Ex.: - ROT = createRotation(CENTER, THETA); - P2 = transformPoint(P1, ROT); - -- direct drawing of shapes with specialized functions. Clipping is performed - automatically for infinite shapes such as lines or rays. Ex: - drawCircle([50 50 25]); % draw circle with radius 25 and center [50 50] - drawLine([X0 Y0 DX DY]); % clip and draw straight line - -- measure distances (between points, a point and a line, a point and a group - of points), angle (of a line, between 3 points), or test geometry (point - on a line, on a circle). - -Additional help is provided in geom/Contents.m file, as well as summary files - like 'points2d.m' or 'lines2d.m'. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 19:10:25
|
Revision: 8825 http://octave.svn.sourceforge.net/octave/?rev=8825&view=rev Author: jpicarbajal Date: 2011-10-21 19:10:17 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. All intersect* functions Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/hexagonalGrid.m trunk/octave-forge/main/geometry/geom2d/inst/intersectCircles.m trunk/octave-forge/main/geometry/geom2d/inst/intersectEdges.m trunk/octave-forge/main/geometry/geom2d/inst/intersectLineCircle.m trunk/octave-forge/main/geometry/geom2d/inst/squareGrid.m trunk/octave-forge/main/geometry/geom2d/inst/triangleGrid.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/hexagonalGrid.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectCircles.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectEdges.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/squareGrid.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/triangleGrid.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 19:10:17 UTC (rev 8825) @@ -131,6 +131,12 @@ inertiaEllipse.m changelog.txt readme.txt - + hexagonalGrid.m + squareGrid.m + triangleGrid.m + intersectCircles.m + intersectEdges.m + intersectLineCircle.m + =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/hexagonalGrid.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/hexagonalGrid.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/hexagonalGrid.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/hexagonalGrid.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -0,0 +1,122 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{pts} = } hexagonalGrid (@var{bounds}, @var{origin}, @var{size}) +%% Generate hexagonal grid of points in the plane. +%% +%% usage +%% PTS = hexagonalGrid(BOUNDS, ORIGIN, SIZE) +%% generate points, lying in the window defined by BOUNDS (=[xmin ymin +%% xmax ymax]), starting from origin with a constant step equal to size. +%% SIZE is constant and is equals to the length of the sides of each +%% hexagon. +%% +%% TODO: add possibility to use rotated grid +%% @end deftypefn + +function varargout = hexagonalGrid(bounds, origin, size, varargin) + + size = size(1); + dx = 3*size; + dy = size*sqrt(3); + + + + % consider two square grids with different centers + pts1 = squareGrid(bounds, origin + [0 0], [dx dy], varargin{:}); + pts2 = squareGrid(bounds, origin + [dx/3 0], [dx dy], varargin{:}); + pts3 = squareGrid(bounds, origin + [dx/2 dy/2], [dx dy], varargin{:}); + pts4 = squareGrid(bounds, origin + [-dx/6 dy/2], [dx dy], varargin{:}); + + % gather points + pts = [pts1;pts2;pts3;pts4]; + + + + + % eventually compute also edges, clipped by bounds + % TODO : manage generation of edges + if nargout>1 + edges = zeros([0 4]); + x0 = origin(1); + y0 = origin(2); + + % find all x coordinate + x1 = bounds(1) + mod(x0-bounds(1), dx); + x2 = bounds(3) - mod(bounds(3)-x0, dx); + lx = (x1:dx:x2)'; + + % horizontal edges : first find y's + y1 = bounds(2) + mod(y0-bounds(2), dy); + y2 = bounds(4) - mod(bounds(4)-y0, dy); + ly = (y1:dy:y2)'; + + % number of points in each coord, and total number of points + ny = length(ly); + nx = length(lx); + + if bounds(1)-x1+dx<size + disp('intersect bounding box'); + end + + if bounds(3)-x2<size + disp('intersect 2'); + edges = [edges;repmat(x2, [ny 1]) ly repmat(bounds(3), [ny 1]) ly]; + x2 = x2-dx; + lx = (x1:dx:x2)'; + nx = length(lx); + end + + for i=1:length(ly) + ind = (1:nx)'; + tmpEdges(ind, 1) = lx; + tmpEdges(ind, 2) = ly(i); + tmpEdges(ind, 3) = lx+size; + tmpEdges(ind, 4) = ly(i); + edges = [edges; tmpEdges]; + end + + end + + % process output arguments + if nargout>0 + varargout{1} = pts; + + if nargout>1 + varargout{2} = edges; + end + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/intersectCircles.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectCircles.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/intersectCircles.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/intersectCircles.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -0,0 +1,129 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{points} = } intersectCircles (@var{circle1}, @var{circle2}) +%% Intersection points of two circles. +%% +%% POINTS = intersectCircles(CIRCLE1, CIRCLE2) +%% Computes the intersetion point of the two circles CIRCLE1 and CIRCLE1. +%% Both circles are given with format: [XC YC R], with (XC,YC) being the +%% coordinates of the center and R being the radius. +%% POINTS is a 2-by-2 array, containing coordinate of an intersection +%% point on each row. +%% In the case of tangent circles, the intersection is returned twice. It +%% can be simplified by using the 'unique' function. +%% +%% Example +%% % intersection points of two distant circles +%% c1 = [0 0 10]; +%% c2 = [10 0 10]; +%% pts = intersectCircles(c1, c2) +%% pts = +%% 5 -8.6603 +%% 5 8.6603 +%% +%% % intersection points of two tangent circles +%% c1 = [0 0 10]; +%% c2 = [20 0 10]; +%% pts = intersectCircles(c1, c2) +%% pts = +%% 10 0 +%% 10 0 +%% pts2 = unique(pts, 'rows') +%% pts2 = +%% 10 0 +%% +%% References +%% http://local.wasp.uwa.edu.au/~pbourke/geometry/2circle/ +%% http://mathworld.wolfram.com/Circle-CircleIntersection.html +%% +%% @seealso{circles2d, intersectLineCircle, radicalAxis} +%% @end deftypefn + +function points = intersectCircles(circle1, circle2) + + % adapt sizes of inputs + n1 = size(circle1, 1); + n2 = size(circle2, 1); + if n1 ~= n2 + if n1 > 1 && n2 == 1 + circle2 = repmat(circle2, n1, 1); + elseif n2 > 1 && n1 == 1 + circle1 = repmat(circle1, n2, 1); + else + error('Both input should have same number of rows'); + end + end + + % extract center and radius of each circle + center1 = circle1(:, 1:2); + center2 = circle2(:, 1:2); + r1 = circle1(:,3); + r2 = circle2(:,3); + + % allocate memory for result + nPoints = length(r1); + points = NaN * ones(2*nPoints, 2); + + % distance between circle centers + d12 = distancePoints(center1, center2, 'diag'); + + % get indices of circle couples with intersections + inds = d12 >= abs(r1 - r2) & d12 <= (r1 + r2); + + if sum(inds) == 0 + return; + end + + % angle of line from center1 to center2 + angle = angle2Points(center1(inds,:), center2(inds,:)); + + % position of intermediate point, located at the intersection of the + % radical axis with the line joining circle centers + d1m = d12(inds) / 2 + (r1(inds).^2 - r2(inds).^2) ./ (2 * d12(inds)); + tmp = polarPoint(center1(inds, :), d1m, angle); + + % distance between intermediate point and each intersection point + h = sqrt(r1(inds).^2 - d1m.^2); + + % indices of valid intersections + inds2 = find(inds)*2; + inds1 = inds2 - 1; + + % create intersection points + points(inds1, :) = polarPoint(tmp, h, angle - pi/2); + points(inds2, :) = polarPoint(tmp, h, angle + pi/2); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/intersectEdges.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectEdges.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/intersectEdges.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/intersectEdges.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -0,0 +1,175 @@ +%% 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{point} = } intersectEdges (@var{edge1}, @var{edge2}) +%% Return all intersections between two set of edges +%% +%% P = intersectEdges(E1, E2); +%% returns the intersection point of lines L1 and L2. E1 and E2 are 1-by-4 +%% arrays, containing parametric representation of each edge (in the form +%% [x1 y1 x2 y2], see 'createEdge' for details). +%% +%% In case of colinear edges, returns [Inf Inf]. +%% In case of parallel but not colinear edges, returns [NaN NaN]. +%% +%% If each input is [N*4] array, the result is a [N*2] array containing +%% intersections of each couple of edges. +%% If one of the input has N rows and the other 1 row, the result is a +%% [N*2] array. +%% +%% @seealso{edges2d, intersectLines} +%% @end deftypefn + +function point = intersectEdges(edge1, edge2) + %% Initialisations + + % ensure input arrays are same size + N1 = size(edge1, 1); + N2 = size(edge2, 1); + + % ensure input have same size + if N1~=N2 + if N1==1 + edge1 = repmat(edge1, [N2 1]); + N1 = N2; + elseif N2==1 + edge2 = repmat(edge2, [N1 1]); + end + end + + % tolerance for precision + tol = 1e-14; + + % initialize result array + x0 = zeros(N1, 1); + y0 = zeros(N1, 1); + + + %% Detect parallel and colinear cases + + % indices of parallel edges + %par = abs(dx1.*dy2 - dx1.*dy2)<tol; + par = isParallel(edge1(:,3:4)-edge1(:,1:2), edge2(:,3:4)-edge2(:,1:2)); + + % indices of colinear edges + % equivalent to: |(x2-x1)*dy1 - (y2-y1)*dx1| < eps + col = abs( (edge2(:,1)-edge1(:,1)).*(edge1(:,4)-edge1(:,2)) - ... + (edge2(:,2)-edge1(:,2)).*(edge1(:,3)-edge1(:,1)) )<tol & par; + + % Parallel edges have no intersection -> return [NaN NaN] + x0(par & ~col) = NaN; + y0(par & ~col) = NaN; + + + %% Process colinear edges + + % colinear edges may have 0, 1 or infinite intersection + % Discrimnation based on position of edge2 vertices on edge1 + if sum(col)>0 + % array for storing results of colinear edges + resCol = Inf*ones(size(col)); + + % compute position of edge2 vertices wrt edge1 + t1 = edgePosition(edge2(col, 1:2), edge1(col, :)); + t2 = edgePosition(edge2(col, 3:4), edge1(col, :)); + + % control location of vertices: we want t1<t2 + if t1>t2 + tmp = t1; + t1 = t2; + t2 = tmp; + end + + % edge totally before first vertex or totally after last vertex + resCol(col(t2<-eps)) = NaN; + resCol(col(t1>1+eps)) = NaN; + + % set up result into point coordinate + x0(col) = resCol; + y0(col) = resCol; + + % touches on first point of first edge + touch = col(abs(t2)<1e-14); + x0(touch) = edge1(touch, 1); + y0(touch) = edge1(touch, 2); + + % touches on second point of first edge + touch = col(abs(t1-1)<1e-14); + x0(touch) = edge1(touch, 3); + y0(touch) = edge1(touch, 4); + end + + + %% Process non parallel cases + + % process intersecting edges whose interecting lines intersect + i = find(~par); + + % use a test to avoid process empty arrays + if sum(i)>0 + % extract base parameters of supporting lines for non-parallel edges + x1 = edge1(i,1); + y1 = edge1(i,2); + dx1 = edge1(i,3)-x1; + dy1 = edge1(i,4)-y1; + x2 = edge2(i,1); + y2 = edge2(i,2); + dx2 = edge2(i,3)-x2; + dy2 = edge2(i,4)-y2; + + % compute intersection points of supporting lines + delta = (dx2.*dy1-dx1.*dy2); + x0(i) = ((y2-y1).*dx1.*dx2 + x1.*dy1.*dx2 - x2.*dy2.*dx1) ./ delta; + y0(i) = ((x2-x1).*dy1.*dy2 + y1.*dx1.*dy2 - y2.*dx2.*dy1) ./ -delta; + + % compute position of intersection points on each edge + % t1 is position on edge1, t2 is position on edge2 + t1 = ((y0(i)-y1).*dy1 + (x0(i)-x1).*dx1) ./ (dx1.*dx1+dy1.*dy1); + t2 = ((y0(i)-y2).*dy2 + (x0(i)-x2).*dx2) ./ (dx2.*dx2+dy2.*dy2); + + % check position of points on edges. + % it should be comprised between 0 and 1 for both t1 and t2. + % if not, the edges do not intersect + out = t1<-tol | t1>1+tol | t2<-tol | t2>1+tol; + x0(i(out)) = NaN; + y0(i(out)) = NaN; + end + + + %% format output arguments + + point = [x0 y0]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/intersectLineCircle.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/intersectLineCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/intersectLineCircle.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -0,0 +1,106 @@ +%% 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{points} = } intersectLineCircle (@var{line}, @var{circle}) +%% Intersection point(s) of a line and a circle +%% +%% INTERS = intersectLineCircle(LINE, CIRCLE); +%% Returns a 2-by-2 array, containing on each row the coordinates of an +%% intersection point. If the line and circle do not intersect, the result +%% is filled with NaN. +%% +%% Example +%% % base point +%% center = [10 0]; +%% % create vertical line +%% l1 = [center 0 1]; +%% % circle +%% c1 = [center 5]; +%% pts = intersectLineCircle(l1, c1) +%% pts = +%% 10 -5 +%% 10 5 +%% % draw the result +%% figure; clf; hold on; +%% axis([0 20 -10 10]); +%% drawLine(l1); +%% drawCircle(c1); +%% drawPoint(pts, 'rx'); +%% axis equal; +%% +%% @seealso{lines2d, circles2d, intersectLines, intersectCircles} +%% @end deftypefn + +function points = intersectLineCircle(line, circle) + + % local precision + eps = 1e-14; + + % center parameters + center = circle(:, 1:2); + radius = circle(:, 3); + + % line parameters + dp = line(:, 1:2) - center; + vl = line(:, 3:4); + + % coefficient of second order equation + a = sum(line(:, 3:4).^2, 2); + b = 2*sum(dp .* vl, 2); + c = sum(dp.^2, 2) - radius.^2; + + % discriminant + delta = b .^ 2 - 4 * a .* c; + + if delta > eps + % find two roots of second order equation + u1 = (-b - sqrt(delta)) / 2 ./ a; + u2 = (-b + sqrt(delta)) / 2 ./ a; + + % convert into 2D coordinate + points = [line(1:2) + u1 * line(3:4) ; line(1:2) + u2 * line(3:4)]; + + elseif abs(delta) < eps + % find unique root, and convert to 2D coord. + u = -b / 2 ./ a; + points = line(1:2) + u*line(3:4); + + else + % fill with NaN + points = NaN * ones(2, 2); + return; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/squareGrid.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/squareGrid.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/squareGrid.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/squareGrid.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -0,0 +1,82 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{pts} = } squaregrid (@var{bounds}, @var{origin}, @var{size}) +%% Generate equally spaces points in plane. +%% +%% usage +%% PTS = squareGrid(BOUNDS, ORIGIN, SIZE) +%% generate points, lying in the window defined by BOUNDS (=[xmin ymin +%% xmax ymax]), starting from origin with a constant step equal to size. +%% +%% Example +%% PTS = squareGrid([0 0 10 10], [3 3], [4 2]) +%% will return points : +%% [3 1;7 1;3 3;7 3;3 5;7 5;3 7;7 7;3 9;7 9]; +%% +%% TODO: add possibility to use rotated grid +%% +%% @end deftypefn + +function varargout = squareGrid(bounds, origin, size) + + % find all x coordinate + x1 = bounds(1) + mod(origin(1)-bounds(1), size(1)); + x2 = bounds(3) - mod(bounds(3)-origin(1), size(1)); + lx = (x1:size(1):x2)'; + + % find all y coordinate + y1 = bounds(2) + mod(origin(2)-bounds(2), size(2)); + y2 = bounds(4) - mod(bounds(4)-origin(2), size(2)); + ly = (y1:size(2):y2)'; + + % number of points in each coord, and total number of points + ny = length(ly); + nx = length(lx); + np = nx*ny; + + % create points + pts = zeros(np, 2); + for i=1:ny + pts( (1:nx)'+(i-1)*nx, 1) = lx; + pts( (1:nx)'+(i-1)*nx, 2) = ly(i); + end + + % process output + if nargout>0 + varargout{1} = pts; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/triangleGrid.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/triangleGrid.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/triangleGrid.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/triangleGrid.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -0,0 +1,69 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{pts} = } triangleGrid (@var{bounds}, @var{origin}, @var{size}) +%% Generate triangular grid of points in the plane. +%% +%% usage +%% PTS = triangleGrid(BOUNDS, ORIGIN, SIZE) +%% generate points, lying in the window defined by BOUNDS, given in form +%% [xmin ymin xmax ymax], starting from origin with a constant step equal +%% to size. +%% SIZE is constant and is equals to the length of the sides of each +%% triangles. +%% +%% TODO: add possibility to use rotated grid +%% +%% @end deftypefn + +function varargout = triangleGrid(bounds, origin, size, varargin) + + dx = size(1); + dy = size(1)*sqrt(3); + + % consider two square grids with different centers + pts1 = squareGrid(bounds, origin, [dx dy], varargin{:}); + pts2 = squareGrid(bounds, origin + [dx dy]/2, [dx dy], varargin{:}); + + % gather points + pts = [pts1;pts2]; + + + % process output + if nargout>0 + varargout{1} = pts; + end + +endfunction + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/hexagonalGrid.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/hexagonalGrid.m 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/hexagonalGrid.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -1,122 +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 = hexagonalGrid(bounds, origin, size, varargin) -%HEXAGONALGRID Generate hexagonal grid of points in the plane. -% -% usage -% PTS = hexagonalGrid(BOUNDS, ORIGIN, SIZE) -% generate points, lying in the window defined by BOUNDS (=[xmin ymin -% xmax ymax]), starting from origin with a constant step equal to size. -% SIZE is constant and is equals to the length of the sides of each -% hexagon. -% -% TODO: add possibility to use rotated grid -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 06/08/2005. -% -size = size(1); -dx = 3*size; -dy = size*sqrt(3); - - - -% consider two square grids with different centers -pts1 = squareGrid(bounds, origin + [0 0], [dx dy], varargin{:}); -pts2 = squareGrid(bounds, origin + [dx/3 0], [dx dy], varargin{:}); -pts3 = squareGrid(bounds, origin + [dx/2 dy/2], [dx dy], varargin{:}); -pts4 = squareGrid(bounds, origin + [-dx/6 dy/2], [dx dy], varargin{:}); - -% gather points -pts = [pts1;pts2;pts3;pts4]; - - - - -% eventually compute also edges, clipped by bounds -% TODO : manage generation of edges -if nargout>1 - edges = zeros([0 4]); - x0 = origin(1); - y0 = origin(2); - - % find all x coordinate - x1 = bounds(1) + mod(x0-bounds(1), dx); - x2 = bounds(3) - mod(bounds(3)-x0, dx); - lx = (x1:dx:x2)'; - - % horizontal edges : first find y's - y1 = bounds(2) + mod(y0-bounds(2), dy); - y2 = bounds(4) - mod(bounds(4)-y0, dy); - ly = (y1:dy:y2)'; - - % number of points in each coord, and total number of points - ny = length(ly); - nx = length(lx); - - if bounds(1)-x1+dx<size - disp('intersect bounding box'); - end - - if bounds(3)-x2<size - disp('intersect 2'); - edges = [edges;repmat(x2, [ny 1]) ly repmat(bounds(3), [ny 1]) ly]; - x2 = x2-dx; - lx = (x1:dx:x2)'; - nx = length(lx); - end - - for i=1:length(ly) - ind = (1:nx)'; - tmpEdges(ind, 1) = lx; - tmpEdges(ind, 2) = ly(i); - tmpEdges(ind, 3) = lx+size; - tmpEdges(ind, 4) = ly(i); - edges = [edges; tmpEdges]; - end - -end - -% process output arguments -if nargout>0 - varargout{1} = pts; - - if nargout>1 - varargout{2} = edges; - end -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectCircles.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectCircles.m 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectCircles.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -1,135 +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 points = intersectCircles(circle1, circle2) -%INTERSECTCIRCLES Intersection points of two circles -% -% POINTS = intersectCircles(CIRCLE1, CIRCLE2) -% Computes the intersetion point of the two circles CIRCLE1 and CIRCLE1. -% Both circles are given with format: [XC YC R], with (XC,YC) being the -% coordinates of the center and R being the radius. -% POINTS is a 2-by-2 array, containing coordinate of an intersection -% point on each row. -% In the case of tangent circles, the intersection is returned twice. It -% can be simplified by using the 'unique' function. -% -% Example -% % intersection points of two distant circles -% c1 = [0 0 10]; -% c2 = [10 0 10]; -% pts = intersectCircles(c1, c2) -% pts = -% 5 -8.6603 -% 5 8.6603 -% -% % intersection points of two tangent circles -% c1 = [0 0 10]; -% c2 = [20 0 10]; -% pts = intersectCircles(c1, c2) -% pts = -% 10 0 -% 10 0 -% pts2 = unique(pts, 'rows') -% pts2 = -% 10 0 -% -% References -% http://local.wasp.uwa.edu.au/~pbourke/geometry/2circle/ -% http://mathworld.wolfram.com/Circle-CircleIntersection.html -% -% See also -% circles2d, intersectLineCircle, radicalAxis -% -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2011-01-20, using Matlab 7.9.0.529 (R2009b) -% Copyright 2011 INRA - Cepia Software Platform. - -% HISTORY -% 2011-06-06 add support for multiple inputs - - -% adapt sizes of inputs -n1 = size(circle1, 1); -n2 = size(circle2, 1); -if n1 ~= n2 - if n1 > 1 && n2 == 1 - circle2 = repmat(circle2, n1, 1); - elseif n2 > 1 && n1 == 1 - circle1 = repmat(circle1, n2, 1); - else - error('Both input should have same number of rows'); - end -end - -% extract center and radius of each circle -center1 = circle1(:, 1:2); -center2 = circle2(:, 1:2); -r1 = circle1(:,3); -r2 = circle2(:,3); - -% allocate memory for result -nPoints = length(r1); -points = NaN * ones(2*nPoints, 2); - -% distance between circle centers -d12 = distancePoints(center1, center2, 'diag'); - -% get indices of circle couples with intersections -inds = d12 >= abs(r1 - r2) & d12 <= (r1 + r2); - -if sum(inds) == 0 - return; -end - -% angle of line from center1 to center2 -angle = angle2Points(center1(inds,:), center2(inds,:)); - -% position of intermediate point, located at the intersection of the -% radical axis with the line joining circle centers -d1m = d12(inds) / 2 + (r1(inds).^2 - r2(inds).^2) ./ (2 * d12(inds)); -tmp = polarPoint(center1(inds, :), d1m, angle); - -% distance between intermediate point and each intersection point -h = sqrt(r1(inds).^2 - d1m.^2); - -% indices of valid intersections -inds2 = find(inds)*2; -inds1 = inds2 - 1; - -% create intersection points -points(inds1, :) = polarPoint(tmp, h, angle - pi/2); -points(inds2, :) = polarPoint(tmp, h, angle + pi/2); Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectEdges.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectEdges.m 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectEdges.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -1,185 +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 point = intersectEdges(edge1, edge2) -%INTERSECTEDGES Return all intersections between two set of edges -% -% P = intersectEdges(E1, E2); -% returns the intersection point of lines L1 and L2. E1 and E2 are 1-by-4 -% arrays, containing parametric representation of each edge (in the form -% [x1 y1 x2 y2], see 'createEdge' for details). -% -% In case of colinear edges, returns [Inf Inf]. -% In case of parallel but not colinear edges, returns [NaN NaN]. -% -% If each input is [N*4] array, the result is a [N*2] array containing -% intersections of each couple of edges. -% If one of the input has N rows and the other 1 row, the result is a -% [N*2] array. -% -% See also: -% edges2d, intersectLines -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 19/02/2004 add support for multiple edges. -% 15/08/2005 rewrite a lot, and create unit tests -% 08/03/2007 update doc -% 21/09/2009 fix bug for edge arrays (thanks to Miquel Cubells) -% 03/08/2010 fix another bug for edge arrays (thanks to Reto Zingg) - -%% Initialisations - -% ensure input arrays are same size -N1 = size(edge1, 1); -N2 = size(edge2, 1); - -% ensure input have same size -if N1~=N2 - if N1==1 - edge1 = repmat(edge1, [N2 1]); - N1 = N2; - elseif N2==1 - edge2 = repmat(edge2, [N1 1]); - end -end - -% tolerance for precision -tol = 1e-14; - -% initialize result array -x0 = zeros(N1, 1); -y0 = zeros(N1, 1); - - -%% Detect parallel and colinear cases - -% indices of parallel edges -%par = abs(dx1.*dy2 - dx1.*dy2)<tol; -par = isParallel(edge1(:,3:4)-edge1(:,1:2), edge2(:,3:4)-edge2(:,1:2)); - -% indices of colinear edges -% equivalent to: |(x2-x1)*dy1 - (y2-y1)*dx1| < eps -col = abs( (edge2(:,1)-edge1(:,1)).*(edge1(:,4)-edge1(:,2)) - ... - (edge2(:,2)-edge1(:,2)).*(edge1(:,3)-edge1(:,1)) )<tol & par; - -% Parallel edges have no intersection -> return [NaN NaN] -x0(par & ~col) = NaN; -y0(par & ~col) = NaN; - - -%% Process colinear edges - -% colinear edges may have 0, 1 or infinite intersection -% Discrimnation based on position of edge2 vertices on edge1 -if sum(col)>0 - % array for storing results of colinear edges - resCol = Inf*ones(size(col)); - - % compute position of edge2 vertices wrt edge1 - t1 = edgePosition(edge2(col, 1:2), edge1(col, :)); - t2 = edgePosition(edge2(col, 3:4), edge1(col, :)); - - % control location of vertices: we want t1<t2 - if t1>t2 - tmp = t1; - t1 = t2; - t2 = tmp; - end - - % edge totally before first vertex or totally after last vertex - resCol(col(t2<-eps)) = NaN; - resCol(col(t1>1+eps)) = NaN; - - % set up result into point coordinate - x0(col) = resCol; - y0(col) = resCol; - - % touches on first point of first edge - touch = col(abs(t2)<1e-14); - x0(touch) = edge1(touch, 1); - y0(touch) = edge1(touch, 2); - - % touches on second point of first edge - touch = col(abs(t1-1)<1e-14); - x0(touch) = edge1(touch, 3); - y0(touch) = edge1(touch, 4); -end - - -%% Process non parallel cases - -% process intersecting edges whose interecting lines intersect -i = find(~par); - -% use a test to avoid process empty arrays -if sum(i)>0 - % extract base parameters of supporting lines for non-parallel edges - x1 = edge1(i,1); - y1 = edge1(i,2); - dx1 = edge1(i,3)-x1; - dy1 = edge1(i,4)-y1; - x2 = edge2(i,1); - y2 = edge2(i,2); - dx2 = edge2(i,3)-x2; - dy2 = edge2(i,4)-y2; - - % compute intersection points of supporting lines - delta = (dx2.*dy1-dx1.*dy2); - x0(i) = ((y2-y1).*dx1.*dx2 + x1.*dy1.*dx2 - x2.*dy2.*dx1) ./ delta; - y0(i) = ((x2-x1).*dy1.*dy2 + y1.*dx1.*dy2 - y2.*dx2.*dy1) ./ -delta; - - % compute position of intersection points on each edge - % t1 is position on edge1, t2 is position on edge2 - t1 = ((y0(i)-y1).*dy1 + (x0(i)-x1).*dx1) ./ (dx1.*dx1+dy1.*dy1); - t2 = ((y0(i)-y2).*dy2 + (x0(i)-x2).*dx2) ./ (dx2.*dx2+dy2.*dy2); - - % check position of points on edges. - % it should be comprised between 0 and 1 for both t1 and t2. - % if not, the edges do not intersect - out = t1<-tol | t1>1+tol | t2<-tol | t2>1+tol; - x0(i(out)) = NaN; - y0(i(out)) = NaN; -end - - -%% format output arguments - -point = [x0 y0]; - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineCircle.m 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/intersectLineCircle.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -1,116 +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 points = intersectLineCircle(line, circle) -%INTERSECTLINECIRCLE Intersection point(s) of a line and a circle -% -% INTERS = intersectLineCircle(LINE, CIRCLE); -% Returns a 2-by-2 array, containing on each row the coordinates of an -% intersection point. If the line and circle do not intersect, the result -% is filled with NaN. -% -% Example -% % base point -% center = [10 0]; -% % create vertical line -% l1 = [center 0 1]; -% % circle -% c1 = [center 5]; -% pts = intersectLineCircle(l1, c1) -% pts = -% 10 -5 -% 10 5 -% % draw the result -% figure; clf; hold on; -% axis([0 20 -10 10]); -% drawLine(l1); -% drawCircle(c1); -% drawPoint(pts, 'rx'); -% axis equal; -% -% See also -% lines2d, circles2d, intersectLines, intersectCircles -% -% References -% http://local.wasp.uwa.edu.au/~pbourke/geometry/sphereline/ -% http://mathworld.wolfram.com/Circle-LineIntersection.html -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2011-01-14, using Matlab 7.9.0.529 (R2009b) -% Copyright 2011 INRA - Cepia Software Platform. - -% HISTORY -% 2011-06-06 fix bug in delta test - - -% local precision -eps = 1e-14; - -% center parameters -center = circle(:, 1:2); -radius = circle(:, 3); - -% line parameters -dp = line(:, 1:2) - center; -vl = line(:, 3:4); - -% coefficient of second order equation -a = sum(line(:, 3:4).^2, 2); -b = 2*sum(dp .* vl, 2); -c = sum(dp.^2, 2) - radius.^2; - -% discriminant -delta = b .^ 2 - 4 * a .* c; - -if delta > eps - % find two roots of second order equation - u1 = (-b - sqrt(delta)) / 2 ./ a; - u2 = (-b + sqrt(delta)) / 2 ./ a; - - % convert into 2D coordinate - points = [line(1:2) + u1 * line(3:4) ; line(1:2) + u2 * line(3:4)]; - -elseif abs(delta) < eps - % find unique root, and convert to 2D coord. - u = -b / 2 ./ a; - points = line(1:2) + u*line(3:4); - -else - % fill with NaN - points = NaN * ones(2, 2); - return; -end - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/squareGrid.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/squareGrid.m 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/squareGrid.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -1,84 +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 = squareGrid(bounds, origin, size) -%SQUAREGRID Generate equally spaces points in plane. -% -% usage -% PTS = squareGrid(BOUNDS, ORIGIN, SIZE) -% generate points, lying in the window defined by BOUNDS (=[xmin ymin -% xmax ymax]), starting from origin with a constant step equal to size. -% -% Example -% PTS = squareGrid([0 0 10 10], [3 3], [4 2]) -% will return points : -% [3 1;7 1;3 3;7 3;3 5;7 5;3 7;7 7;3 9;7 9]; -% -% -% -% TODO: add possibility to use rotated grid -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 06/08/2005. -% - -% find all x coordinate -x1 = bounds(1) + mod(origin(1)-bounds(1), size(1)); -x2 = bounds(3) - mod(bounds(3)-origin(1), size(1)); -lx = (x1:size(1):x2)'; - -% find all y coordinate -y1 = bounds(2) + mod(origin(2)-bounds(2), size(2)); -y2 = bounds(4) - mod(bounds(4)-origin(2), size(2)); -ly = (y1:size(2):y2)'; - -% number of points in each coord, and total number of points -ny = length(ly); -nx = length(lx); -np = nx*ny; - -% create points -pts = zeros(np, 2); -for i=1:ny - pts( (1:nx)'+(i-1)*nx, 1) = lx; - pts( (1:nx)'+(i-1)*nx, 2) = ly(i); -end - -% process output -if nargout>0 - varargout{1} = pts; -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/triangleGrid.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/triangleGrid.m 2011-10-21 18:58:15 UTC (rev 8824) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/triangleGrid.m 2011-10-21 19:10:17 UTC (rev 8825) @@ -1,69 +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 = triangleGrid(bounds, origin, size, varargin) -%TRIANGLEGRID Generate triangular grid of points in the plane. -% -% usage -% PTS = triangleGrid(BOUNDS, ORIGIN, SIZE) -% generate points, lying in the window defined by BOUNDS, given in form -% [xmin ymin xmax ymax], starting from origin with a constant step equal -% to size. -% SIZE is constant and is equals to the length of the sides of each -% triangles. -% -% TODO: add possibility to use rotated grid -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 06/08/2005. -% - -dx = size(1); -dy = size(1)*sqrt(3); - -% consider two square grids with different centers -pts1 = squareGrid(bounds, origin, [dx dy], varargin{:}); -pts2 = squareGrid(bounds, origin + [dx dy]/2, [dx dy], varargin{:}); - -% gather points -pts = [pts1;pts2]; - - -% process output -if nargout>0 - varargout{1} = pts; -end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 19:17:33
|
Revision: 8826 http://octave.svn.sourceforge.net/octave/?rev=8826&view=rev Author: jpicarbajal Date: 2011-10-21 19:17:25 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. All is* functions Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/isLeftOriented.m trunk/octave-forge/main/geometry/geom2d/inst/isPointInCircle.m trunk/octave-forge/main/geometry/geom2d/inst/isPointInEllipse.m trunk/octave-forge/main/geometry/geom2d/inst/isPointOnCircle.m trunk/octave-forge/main/geometry/geom2d/inst/isPointOnLine.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isLeftOriented.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInEllipse.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnLine.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 19:10:17 UTC (rev 8825) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 19:17:25 UTC (rev 8826) @@ -137,6 +137,11 @@ intersectCircles.m intersectEdges.m intersectLineCircle.m + isLeftOriented.m + isPointInCircle.m + isPointInEllipse.m + isPointOnCircle.m + isPointOnLine.m =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/isLeftOriented.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isLeftOriented.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isLeftOriented.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isLeftOriented.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -0,0 +1,59 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{b} = } isLeftOriented (@var{point}, @var{line}) +%% Test if a point is on the left side of a line +%% +%% B = isLeftOriented(POINT, LINE); +%% Returns TRUE if the point lies on the left side of the line with +%% respect to the line direction. +%% +%% @seealso{lines2d, points2d, isCounterClockwise, isPointOnLine, distancePointLine} +%% @end deftypefn + +function b = isLeftOriented(point, line) + Nl = size(line, 1); + Np = size(point, 1); + + x0 = repmat(line(:,1)', Np, 1); + y0 = repmat(line(:,2)', Np, 1); + dx = repmat(line(:,3)', Np, 1); + dy = repmat(line(:,4)', Np, 1); + xp = repmat(point(:,1), 1, Nl); + yp = repmat(point(:,2), 1, Nl); + + + b = (xp-x0).*dy-(yp-y0).*dx < 0; + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/isPointInCircle.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isPointInCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isPointInCircle.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -0,0 +1,67 @@ +%% 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{b} = } isPointInCircle (@var{point}, @var{circle}) +%% Test if a point is located inside a given circle +%% +%% B = isPointInCircle(POINT, CIRCLE) +%% Returns true if point is located inside the circle, i.e. if distance to +%% circle center is lower than the circle radius. +%% +%% B = isPointInCircle(POINT, CIRCLE, TOL) +%% Specifies the tolerance value +%% +%% Example: +%% isPointInCircle([1 0], [0 0 1]) +%% isPointInCircle([0 0], [0 0 1]) +%% returns true, whereas +%% isPointInCircle([1 1], [0 0 1]) +%% return false +%% +%% @seealso{circles2d, isPointOnCircle} +%% @end deftypefn + +function b = isPointInCircle(point, circle, varargin) + + % extract computation tolerance + tol = 1e-14; + if ~isempty(varargin) + tol = varargin{1}; + end + + d = sqrt(sum(power(point - circle(:,1:2), 2), 2)); + b = d-circle(:,3)<=tol; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/isPointInEllipse.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInEllipse.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isPointInEllipse.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isPointInEllipse.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -0,0 +1,81 @@ +%% 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{b} = } isPointInellipse (@var{point}, @var{ellipse}) +%% Check if a point is located inside a given ellipse +%% +%% B = isPointInEllipse(POINT, ELLIPSE) +%% Returns true if point is located inside the given ellipse. +%% +%% B = isPointInEllipse(POINT, ELLIPSE, TOL) +%% Specifies the tolerance value +%% +%% Example: +%% isPointInEllipse([1 0], [0 0 2 1 0]) +%% ans = +%% 1 +%% isPointInEllipse([0 0], [0 0 2 1 0]) +%% ans = +%% 1 +%% isPointInEllipse([1 1], [0 0 2 1 0]) +%% ans = +%% 0 +%% isPointInEllipse([1 1], [0 0 2 1 30]) +%% ans = +%% 1 +%% +%% @seealso{ellipses2d, isPointInCircle} +%% @end deftypefn + +function b = isPointInEllipse(point, ellipse, varargin) + + % extract computation tolerance + tol = 1e-14; + if ~isempty(varargin) + tol = varargin{1}; + end + + % compute ellipse to unit circle transform + rot = createRotation(-deg2rad(ellipse(5))); + sca = createScaling(1./ellipse(3:4)); + trans = sca * rot; + + % transform points to unit circle basis + pTrans = bsxfun(@minus, point, ellipse(:,1:2)); + pTrans = transformPoint(pTrans, trans); + + % test if distance to origin smaller than 1 + b = sqrt(sum(power(pTrans, 2), 2)) - 1 <= tol; + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/isPointOnCircle.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isPointOnCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isPointOnCircle.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -0,0 +1,65 @@ +%% 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{b} = } isPointOnCircle (@var{point}, @var{circle}) +%% Test if a point is located on a given circle. +%% +%% B = isPointOnCircle(POINT, CIRCLE) +%% return true if point is located on the circle, i.e. if the distance to +%% the circle center equals the radius up to an epsilon value. +%% +%% B = isPointOnCircle(POINT, CIRCLE, TOL) +%% Specifies the tolerance value. +%% +%% Example: +%% isPointOnCircle([1 0], [0 0 1]) +%% returns true, whereas +%% isPointOnCircle([1 1], [0 0 1]) +%% return false +%% +%% @seealso{circles2d, isPointInCircle} +%% @end deftypefn + +function b = isPointOnCircle(point, circle, varargin) + + tol = 1e-14; + if ~isempty(varargin) + tol = varargin{1}; + end + + d = sqrt(sum(power(point - circle(:,1:2), 2), 2)); + b = abs(d-circle(:,3))<tol; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/isPointOnLine.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/isPointOnLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/isPointOnLine.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -0,0 +1,72 @@ +%% 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{b} = } isPointOnLine (@var{point}, @var{line}) +%% Test if a point belongs to a line +%% +%% B = isPointOnLine(POINT, LINE) +%% with POINT being [xp yp], and LINE being [x0 y0 dx dy]. +%% Returns 1 if point lies on the line, 0 otherwise. +%% +%% If POINT is an N*2 array of points, B is a N*1 array of booleans. +%% +%% If LINE is a N*4 array of line, B is a 1*N array of booleans. +%% +%% @seealso {lines2d, points2d, isPointOnEdge, isPointOnRay, angle3Points} +%% @end deftypefn + +function b = isPointOnLine(point, line, varargin) + + % extract computation tolerance + tol = 1e-14; + if ~isempty(varargin) + tol = varargin{1}; + end + + % number of lines and of points + Nl = size(line, 1); + Np = size(point, 1); + + % adapt the size of inputs + x0 = repmat(line(:,1)', Np, 1); + y0 = repmat(line(:,2)', Np, 1); + dx = repmat(line(:,3)', Np, 1); + dy = repmat(line(:,4)', Np, 1); + xp = repmat(point(:,1), 1, Nl); + yp = repmat(point(:,2), 1, Nl); + + % test if lines are colinear + b = abs((xp-x0).*dy-(yp-y0).*dx)./hypot(dx, dy) < tol; + +endfunction Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isLeftOriented.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isLeftOriented.m 2011-10-21 19:10:17 UTC (rev 8825) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isLeftOriented.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -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 b = isLeftOriented(point, line) -%ISLEFTORIENTED Test if a point is on the left side of a line -% -% B = isLeftOriented(POINT, LINE); -% Returns TRUE if the point lies on the left side of the line with -% respect to the line direction. -% -% See also: -% lines2d, points2d, isCounterClockwise, isPointOnLine, distancePointLine -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/07/2005. -% - -Nl = size(line, 1); -Np = size(point, 1); - -x0 = repmat(line(:,1)', Np, 1); -y0 = repmat(line(:,2)', Np, 1); -dx = repmat(line(:,3)', Np, 1); -dy = repmat(line(:,4)', Np, 1); -xp = repmat(point(:,1), 1, Nl); -yp = repmat(point(:,2), 1, Nl); - - -b = (xp-x0).*dy-(yp-y0).*dx < 0; Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInCircle.m 2011-10-21 19:10:17 UTC (rev 8825) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInCircle.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -1,72 +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 b = isPointInCircle(point, circle, varargin) -%ISPOINTINCIRCLE Test if a point is located inside a given circle -% -% B = isPointInCircle(POINT, CIRCLE) -% Returns true if point is located inside the circle, i.e. if distance to -% circle center is lower than the circle radius. -% -% B = isPointInCircle(POINT, CIRCLE, TOL) -% Specifies the tolerance value -% -% Example: -% isPointInCircle([1 0], [0 0 1]) -% isPointInCircle([0 0], [0 0 1]) -% returns true, whereas -% isPointInCircle([1 1], [0 0 1]) -% return false -% -% See also: -% circles2d, isPointOnCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 07/04/2004. -% - -% HISTORY -% 22/05/2009 rename to isPointInCircle, add psb to specify tolerance - -% extract computation tolerance -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -d = sqrt(sum(power(point - circle(:,1:2), 2), 2)); -b = d-circle(:,3)<=tol; - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInEllipse.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInEllipse.m 2011-10-21 19:10:17 UTC (rev 8825) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointInEllipse.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -1,86 +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 b = isPointInEllipse(point, ellipse, varargin) -%ISPOINTINELLIPSE Check if a point is located inside a given ellipse -% -% B = isPointInEllipse(POINT, ELLIPSE) -% Returns true if point is located inside the given ellipse. -% -% B = isPointInEllipse(POINT, ELLIPSE, TOL) -% Specifies the tolerance value -% -% Example: -% isPointInEllipse([1 0], [0 0 2 1 0]) -% ans = -% 1 -% isPointInEllipse([0 0], [0 0 2 1 0]) -% ans = -% 1 -% isPointInEllipse([1 1], [0 0 2 1 0]) -% ans = -% 0 -% isPointInEllipse([1 1], [0 0 2 1 30]) -% ans = -% 1 -% -% See also: -% ellipses2d, isPointInCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 11/03/2011 -% - -% HISTORY - -% extract computation tolerance -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -% compute ellipse to unit circle transform -rot = createRotation(-deg2rad(ellipse(5))); -sca = createScaling(1./ellipse(3:4)); -trans = sca * rot; - -% transform points to unit circle basis -pTrans = bsxfun(@minus, point, ellipse(:,1:2)); -pTrans = transformPoint(pTrans, trans); - -% test if distance to origin smaller than 1 -b = sqrt(sum(power(pTrans, 2), 2)) - 1 <= tol; - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnCircle.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnCircle.m 2011-10-21 19:10:17 UTC (rev 8825) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnCircle.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -1,70 +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 b = isPointOnCircle(point, circle, varargin) -%ISPOINTONCIRCLE Test if a point is located on a given circle. -% -% B = isPointOnCircle(POINT, CIRCLE) -% return true if point is located on the circle, i.e. if the distance to -% the circle center equals the radius up to an epsilon value. -% -% B = isPointOnCircle(POINT, CIRCLE, TOL) -% Specifies the tolerance value. -% -% Example: -% isPointOnCircle([1 0], [0 0 1]) -% returns true, whereas -% isPointOnCircle([1 1], [0 0 1]) -% return false -% -% See also: -% circles2d, isPointInCircle -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 07/04/2004. -% - -% HISTORY -% 22/05/2009 rename to isPointOnCircle, add psb to specify tolerance - -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -d = sqrt(sum(power(point - circle(:,1:2), 2), 2)); -b = abs(d-circle(:,3))<tol; - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnLine.m 2011-10-21 19:10:17 UTC (rev 8825) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/isPointOnLine.m 2011-10-21 19:17:25 UTC (rev 8826) @@ -1,94 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function b = isPointOnLine(point, line, varargin) -%ISPOINTONLINE Test if a point belongs to a line -% -% B = isPointOnLine(POINT, LINE) -% with POINT being [xp yp], and LINE being [x0 y0 dx dy]. -% Returns 1 if point lies on the line, 0 otherwise. -% -% If POINT is an N*2 array of points, B is a N*1 array of booleans. -% -% If LINE is a N*4 array of line, B is a 1*N array of booleans. -% -% See also: -% lines2d, points2d, isPointOnEdge, isPointOnRay, angle3Points -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 31/10/2003. -% - -% HISTORY -% 11/03/2004 support for multiple inputs -% 08/12/2004 complete implementation, add doc -% 22/05/2009 rename to isPointOnLine, add psb to specify tolerance - -% extract computation tolerance -tol = 1e-14; -if ~isempty(varargin) - tol = varargin{1}; -end - -% number of lines and of points -Nl = size(line, 1); -Np = size(point, 1); - -% adapt the size of inputs -x0 = repmat(line(:,1)', Np, 1); -y0 = repmat(line(:,2)', Np, 1); -dx = repmat(line(:,3)', Np, 1); -dy = repmat(line(:,4)', Np, 1); -xp = repmat(point(:,1), 1, Nl); -yp = repmat(point(:,2), 1, Nl); - -% test if lines are colinear -b = abs((xp-x0).*dy-(yp-y0).*dx)./hypot(dx, dy) < tol; - - - - - - - - - - - - - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 19:22:19
|
Revision: 8827 http://octave.svn.sourceforge.net/octave/?rev=8827&view=rev Author: jpicarbajal Date: 2011-10-21 19:22:12 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. all edge* functions Modified Paths: -------------- trunk/octave-forge/main/geometry/doc/NEWS Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/edgeLength.m trunk/octave-forge/main/geometry/geom2d/inst/edgePosition.m trunk/octave-forge/main/geometry/geom2d/inst/edgeToLine.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeLength.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgePosition.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeToLine.m Modified: trunk/octave-forge/main/geometry/doc/NEWS =================================================================== --- trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 19:17:25 UTC (rev 8826) +++ trunk/octave-forge/main/geometry/doc/NEWS 2011-10-21 19:22:12 UTC (rev 8827) @@ -142,6 +142,9 @@ isPointInEllipse.m isPointOnCircle.m isPointOnLine.m + edgeLength.m + edgePosition.m + edgeToLine.m =============================================================================== Copied: trunk/octave-forge/main/geometry/geom2d/inst/edgeLength.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeLength.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/edgeLength.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/edgeLength.m 2011-10-21 19:22:12 UTC (rev 8827) @@ -0,0 +1,60 @@ +%% 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{len} = } edgeLength (@var{edge}) +%% Return length of an edge +%% +%% L = edgeLength(EDGE); +%% Returns the length of an edge, with parametric representation: +%% [x1 y1 x2 y2]. +%% +%% The function also works for several edges, in this case input is a +%% [N*4] array, containing parametric representation of each edge, and +%% output is a [N*1] array containing length of each edge. +%% +%% @seealso{edges2d, edgeAngle} +%% @end deftypefn + +function len = edgeLength(varargin) + + % TODO : specify norm (euclidian, taxi, ...). + + nargs = length(varargin); + if nargs == 1 + edge = varargin{1}; + len = sqrt(power(edge(:,3)-edge(:,1), 2) + power(edge(:,4)-edge(:,2), 2)); + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/edgePosition.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgePosition.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/edgePosition.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/edgePosition.m 2011-10-21 19:22:12 UTC (rev 8827) @@ -0,0 +1,91 @@ +%% 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{d} = } edgePosition (@var{point}, @var{edge}) +%% Return position of a point on an edge +%% +%% POS = edgePosition(POINT, EDGE); +%% Computes position of point POINT on the edge EDGE, relative to the +%% position of edge vertices. +%% EDGE has the form [x1 y1 x2 y2], +%% POINT has the form [x y], and is assumed to belong to edge. +%% The position POS has meaning: +%% POS<0: POINT is located before the first vertex +%% POS=0: POINT is located on the first vertex +%% 0<POS<1: POINT is located between the 2 vertices (on the edge) +%% POS=1: POINT is located on the second vertex +%% POS<0: POINT is located after the second vertex +%% +%% POS = edgePosition(POINT, EDGES); +%% If EDGES is an array of NL edges, return NL positions, corresponding to +%% each edge. +%% +%% POS = edgePosition(POINTS, EDGE); +%% If POINTS is an array of NP points, return NP positions, corresponding +%% to each point. +%% +%% POS = edgePosition(POINTS, EDGES); +%% If POINTS is an array of NP points and edgeS is an array of NL edges, +%% return an array of [NP NL] position, corresponding to each couple +%% point-edge. +%% +%% @seealso{edges2d, createEdge, onEdge} +%% @end deftypefn + +function d = edgePosition(point, edge) + + % number of points and of edges + Nl = size(edge, 1); + Np = size(point, 1); + + if Np==Nl + dxl = edge(:, 3)-edge(:,1); + dyl = edge(:, 4)-edge(:,2); + dxp = point(:, 1) - edge(:, 1); + dyp = point(:, 2) - edge(:, 2); + + d = (dxp.*dxl + dyp.*dyl)./(dxl.*dxl+dyl.*dyl); + + else + % expand one of the array to have the same size + dxl = repmat((edge(:,3)-edge(:,1))', Np, 1); + dyl = repmat((edge(:,4)-edge(:,2))', Np, 1); + dxp = repmat(point(:,1), 1, Nl) - repmat(edge(:,1)', Np, 1); + dyp = repmat(point(:,2), 1, Nl) - repmat(edge(:,2)', Np, 1); + + d = (dxp.*dxl + dyp.*dyl)./(dxl.*dxl+dyl.*dyl); + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/edgeToLine.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeToLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/edgeToLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/edgeToLine.m 2011-10-21 19:22:12 UTC (rev 8827) @@ -0,0 +1,56 @@ +%% Copyright (c) 2011, INRA +%% 2009-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} = } edgeToLine (@var{edge}) +%% Convert an edge to a straight line +%% +%% LINE = edgeToLine(EDGE); +%% Returns the line containing the edge EDGE. +%% +%% Example +%% edge = [2 3 4 5]; +%% line = edgeToLine(edge); +%% figure(1); hold on; axis([0 10 0 10]); +%% drawLine(line, 'color', 'g') +%% drawEdge(edge, 'linewidth', 2) +%% +%% @seealso{edges2d, lines2d} +%% @end deftypefn + +function line = edgeToLine(edge) + + line = [edge(:, 1:2) edge(:, 3:4)-edge(:, 1:2)]; + +endfunction + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeLength.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeLength.m 2011-10-21 19:17:25 UTC (rev 8826) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeLength.m 2011-10-21 19:22:12 UTC (rev 8827) @@ -1,66 +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 len = edgeLength(varargin) -%EDGELENGTH Return length of an edge -% -% L = edgeLength(EDGE); -% Returns the length of an edge, with parametric representation: -% [x1 y1 x2 y2]. -% -% The function also works for several edges, in this case input is a -% [N*4] array, containing parametric representation of each edge, and -% output is a [N*1] array containing length of each edge. -% -% See also: -% edges2d, edgeAngle -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 19/02/2004 -% - -% HISTORY -% 15/04/2005 changes definition for edge, uses [x1 y1 x2 y2] instead of -% [x0 y0 dx dy]. - -% TODO : specify norm (euclidian, taxi, ...). - -nargs = length(varargin); -if nargs == 1 - edge = varargin{1}; - len = sqrt(power(edge(:,3)-edge(:,1), 2) + power(edge(:,4)-edge(:,2), 2)); -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgePosition.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgePosition.m 2011-10-21 19:17:25 UTC (rev 8826) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgePosition.m 2011-10-21 19:22:12 UTC (rev 8827) @@ -1,97 +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 d = edgePosition(point, edge) -%EDGEPOSITION Return position of a point on an edge -% -% POS = edgePosition(POINT, EDGE); -% Computes position of point POINT on the edge EDGE, relative to the -% position of edge vertices. -% EDGE has the form [x1 y1 x2 y2], -% POINT has the form [x y], and is assumed to belong to edge. -% The position POS has meaning: -% POS<0: POINT is located before the first vertex -% POS=0: POINT is located on the first vertex -% 0<POS<1: POINT is located between the 2 vertices (on the edge) -% POS=1: POINT is located on the second vertex -% POS<0: POINT is located after the second vertex -% -% POS = edgePosition(POINT, EDGES); -% If EDGES is an array of NL edges, return NL positions, corresponding to -% each edge. -% -% POS = edgePosition(POINTS, EDGE); -% If POINTS is an array of NP points, return NP positions, corresponding -% to each point. -% -% POS = edgePosition(POINTS, EDGES); -% If POINTS is an array of NP points and edgeS is an array of NL edges, -% return an array of [NP NL] position, corresponding to each couple -% point-edge. -% -% See also: -% edges2d, createEdge, onEdge -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 25/05/2004. -% - -% HISTORY: -% 06/12/2009 created from linePosition - -% number of points and of edges -Nl = size(edge, 1); -Np = size(point, 1); - -if Np==Nl - dxl = edge(:, 3)-edge(:,1); - dyl = edge(:, 4)-edge(:,2); - dxp = point(:, 1) - edge(:, 1); - dyp = point(:, 2) - edge(:, 2); - - d = (dxp.*dxl + dyp.*dyl)./(dxl.*dxl+dyl.*dyl); - -else - % expand one of the array to have the same size - dxl = repmat((edge(:,3)-edge(:,1))', Np, 1); - dyl = repmat((edge(:,4)-edge(:,2))', Np, 1); - dxp = repmat(point(:,1), 1, Nl) - repmat(edge(:,1)', Np, 1); - dyp = repmat(point(:,2), 1, Nl) - repmat(edge(:,2)', Np, 1); - - d = (dxp.*dxl + dyp.*dyl)./(dxl.*dxl+dyl.*dyl); -end - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeToLine.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeToLine.m 2011-10-21 19:17:25 UTC (rev 8826) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/edgeToLine.m 2011-10-21 19:22:12 UTC (rev 8827) @@ -1,57 +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 = edgeToLine(edge) -%EDGETOLINE Convert an edge to a straight line -% -% LINE = edgeToLine(EDGE); -% Returns the line containing the edge EDGE. -% -% Example -% edge = [2 3 4 5]; -% line = edgeToLine(edge); -% figure(1); hold on; axis([0 10 0 10]); -% drawLine(line, 'color', 'g') -% drawEdge(edge, 'linewidth', 2) -% -% See also -% edges2d, lines2d -% -% ------ -% Author: David Legland -% e-mail: dav...@gr... -% Created: 2009-07-23, using Matlab 7.7.0.471 (R2008b) -% Copyright 2009 INRA - Cepia Software Platform. - -line = [edge(:, 1:2) edge(:, 3:4)-edge(:, 1:2)]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 19:44:36
|
Revision: 8828 http://octave.svn.sourceforge.net/octave/?rev=8828&view=rev Author: jpicarbajal Date: 2011-10-21 19:44:24 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. Geom2d done! Some tests missing and demos Added Paths: ----------- trunk/octave-forge/main/geometry/geom2d/inst/circleArcAsCurve.m trunk/octave-forge/main/geometry/geom2d/inst/circleAsPolygon.m trunk/octave-forge/main/geometry/geom2d/inst/crackPattern.m trunk/octave-forge/main/geometry/geom2d/inst/crackPattern2.m trunk/octave-forge/main/geometry/geom2d/inst/distancePointEdge.m trunk/octave-forge/main/geometry/geom2d/inst/distancePointLine.m trunk/octave-forge/main/geometry/geom2d/inst/ellipseAsPolygon.m trunk/octave-forge/main/geometry/geom2d/inst/enclosingCircle.m trunk/octave-forge/main/geometry/geom2d/inst/radicalAxis.m trunk/octave-forge/main/geometry/geom2d/inst/reverseEdge.m trunk/octave-forge/main/geometry/geom2d/inst/reverseLine.m Removed Paths: ------------- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleArcAsCurve.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleAsPolygon.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipLineRect.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern2.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePointEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePointLine.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipseAsPolygon.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/enclosingCircle.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/radicalAxis.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/reverseEdge.m trunk/octave-forge/main/geometry/matGeom_raw/geom2d/reverseLine.m Copied: trunk/octave-forge/main/geometry/geom2d/inst/circleArcAsCurve.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleArcAsCurve.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/circleArcAsCurve.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/circleArcAsCurve.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,79 @@ +%% Copyright (c) 2011, INRA +%% 2006-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{p} = } circleArcAsCurve (@var{arc}, @var{N}) +%% Convert a circle arc into a series of points +%% +%% P = circleArcAsCurve(ARC, N); +%% convert the circle ARC into a series of N points. +%% ARC is given in the format: [XC YC R THETA1 DTHETA] +%% where XC and YC define the center of the circle, R its radius, THETA1 +%% is the start of the arc and DTHETA is the angle extent of the arc. Both +%% angles are given in degrees. +%% N is the number of vertices of the resulting polyline, default is 65. +%% +%% The result is a N-by-2 array containing coordinates of the N points. +%% +%% [X Y] = circleArcAsCurve(ARC, N); +%% Return the result in two separate arrays with N lines and 1 column. +%% +%% +%% @seealso{circles2d, circleAsPolygon, drawCircle, drawPolygon} +%% @end deftypefn + +function varargout = circleArcAsCurve(arc, N) + + % default value for N + if nargin < 2 + N = 65; + end + + % vector of positions + t0 = deg2rad(arc(4)); + t1 = t0 + deg2rad(arc(5)); + t = linspace(t0, t1, N)'; + + % compute coordinates of vertices + x = arc(1) + arc(3) * cos(t); + y = arc(2) + arc(3) * sin(t); + + % format output + if nargout <= 1 + varargout = {[x y]}; + else + varargout = {x, y}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/circleAsPolygon.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleAsPolygon.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/circleAsPolygon.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/circleAsPolygon.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,74 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{P} = } circleAsPolygon (@var{circle}, @var{N}) +%% Convert a circle into a series of points +%% +%% P = circleAsPolygon(CIRCLE, N); +%% convert circle given as [x0 y0 r], where x0 and y0 are coordinate of +%% center, and r is the radius, into an array of [(N+1)x2] double, +%% containing x and y values of points. +%% The polygon is closed +%% +%% P = circleAsPolygon(CIRCLE); +%% uses a default value of N=64 points +%% +%% Example +%% circle = circleAsPolygon([10 0 5], 16); +%% figure; +%% drawPolygon(circle); +%% +%% @seealso{circles2d, polygons2d, createCircle} +%% @end deftypefn + +function varargout = circleAsPolygon(circle, varargin) + % determines number of points + N = 64; + if ~isempty(varargin) + N = varargin{1}; + end + + % create circle + t = linspace(0, 2*pi, N+1)'; + x = circle(1) + circle(3)*cos(t); + y = circle(2) + circle(3)*sin(t); + + if nargout==1 + varargout{1}=[x y]; + elseif nargout==2 + varargout{1}=x; + varargout{2}=y; + end + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/crackPattern.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/crackPattern.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/crackPattern.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,189 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{e} = } crackPattern (@var{box}, @var{points}, @var{alpha}) +%% Create a (bounded) crack pattern tessellation +%% +%% E = crackPattern2(BOX, POINTS, ALPHA) +%% create a crack propagation pattern wit following parameters : +%% - pattern is bounded by area BOX which is a polygon. +%% - each crack originates from points given in POINTS +%% - directions of each crack is given by a [NxM] array ALPHA, where M is +%% the number of rays emanating from each seed/ +%% - a crack stop when it reaches another already created crack. +%% - all cracks stop when they reach the border of the frame, given by box +%% (a serie of 4 points). +%% The result is a collection of edges, in the form [x1 y1 x2 y2]. +%% +%% E = crackPattern2(BOX, POINTS, ALPHA, SPEED) +%% Also specify speed of propagation of each crack. +%% +%% +%% See the result with : +%% figure; +%% drawEdge(E); +%% +%% @seealso{drawEdge} +%% @end deftypefn + +function edges = crackPattern(box, points, alpha, varargin) + + if ~isempty(varargin) + speed = varargin{1}; + else + speed = ones(size(points, 1), 1); + end + + % Compute line equations for each initial crack. + % The two 'Inf' at the end correspond to the position of the limit. + % If an intersection point is found with another line, but whose position + % is after this value, this means that another crack stopped it before it + % reach the intersection point. + % There is one 'end position' for each side of the crack. + lines = [points speed.*cos(alpha) speed.*sin(alpha) Inf*ones(size(points, 1), 2)]; + + % initialize lines for borders, but assign a very high speed, to be sure + % borders will stop all cracks. + dx = (box([2 3 4 1],1)-box([1 2 3 4],1))*max(speed)*5; + dy = (box([2 3 4 1],2)-box([1 2 3 4],2))*max(speed)*5; + + % add borders to the lines set + lines = [lines ; createLine(box, dx, dy) Inf*ones(4,2)]; + + edges = zeros(0, 4); + + + while true + modif = 0; + + % try to update each line + for i=1:size(points, 1) + + % compute intersections with all other lines + pi = intersectLines(lines(i,:), lines); + + % compute position of all intersection points on the current line + pos = linePosition(pi, lines(i,:)); + + % consider points to the right (positive position), and sort them + indr = find(pos>=0 & pos~=Inf); + [posr, indr2] = sort(pos(indr)); + + + % look for the closest intersection to the right + for i2=1:length(indr2) + + % index of intersected line + il = indr(indr2(i2)); + + % position of point relative to intersected line + pos2 = linePosition(pi(il, :), lines(il, :)); + + % depending on the sign of position, tests if the line2 can + % stop the current line, or if it was stopped before + if pos2>0 + if pos2<abs(posr(i2)) && pos2<lines(il, 5) + if lines(i, 5) ~= posr(i2) + edges(i, 3:4) = pi(il,:); + lines(i, 5) = posr(i2); + modif = 1; + end + break; + end + else + if abs(pos2)<abs(posr(i2)) && abs(pos2)<lines(il, 6) + if lines(i, 5) ~= posr(i2); + edges(i, 3:4) = pi(il,:); + lines(i, 5) = posr(i2); + modif = 1; + end + break; + end + end + + end % end processing of right points of the line + + + + % consider points to the left (negative position), and sort them + indl = find(pos<=0 && pos~=Inf); + [posl, indl2] = sort(abs(pos(indl))); + + % look for the closest intersection to the right + for i2=1:length(indl2) + % index of intersected line + il = indl(indl2(i2)); + + % position of point relative to intersected line + pos2 = linePosition(pi(il, :), lines(il, :)); + + % depending on the sign of position, tests if the line2 can + % stop the current line, or if it was stopped before + if pos2>0 + if pos2<abs(posl(i2)) && pos2<lines(il, 5) + if lines(i, 6) ~= abs(posl(i2)); + edges(i, 1:2) = pi(il, :); + lines(i, 6) = abs(posl(i2)); + modif = 1; + end + break; + end + else + if abs(pos2)<abs(posl(i2)) && abs(pos2)<lines(il, 6) + if lines(i, 6) ~= abs(posl(i2)); + edges(i, 1:2) = pi(il, :); + lines(i, 6) = abs(posl(i2)); + modif = 1; + end + break; + end + end + + end % end processing of left points of the line + + + end % end processing of all lines + + % break the infinite loop if no more modification was made + if ~modif + break; + end + end + + % add edges of the surronding box. + edges = [edges ; box(1,:) box(2,:) ; box(2,:) box(3,:); ... + box(3,:) box(4,:) ; box(4,:) box(1,:) ]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/crackPattern2.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern2.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/crackPattern2.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/crackPattern2.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,148 @@ +%% 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{e} = } crackPattern2 (@var{box}, @var{points}, @var{alpha}) +%% Create a (bounded) crack pattern tessellation +%% +%% E = crackPattern2(BOX, POINTS, ALPHA) +%% create a crack propagation pattern wit following parameters : +%% - pattern is bounded by area BOX which is a polygon. +%% - each crack originates from points given in POINTS +%% - directions of each crack is given by a [NxM] array ALPHA, where M is +%% the number of rays emanating from each seed/ +%% - a crack stop when it reaches another already created crack. +%% - all cracks stop when they reach the border of the frame, given by box +%% (a serie of 4 points). +%% The result is a collection of edges, in the form [x1 y1 x2 y2]. +%% +%% E = crackPattern2(BOX, POINTS, ALPHA, SPEED) +%% Also specify speed of propagation of each crack. +%% +%% +%% See the result with : +%% figure; +%% drawEdge(E); +%% +%% @seealso{drawEdge} +%% @end deftypefn + +function edges = crackPattern2(box, points, alpha, varargin) + + if ~isempty(varargin) + speed = varargin{1}; + else + speed = ones(size(points, 1), 1); + end + + % Compute line equations for each initial crack. + % The 'Inf' at the end correspond to the position of the limit. + % If an intersection point is found with another line, but whose position + % is after this value, this means that another crack stopped it before it + % reach the intersection point. + NP = size(points, 1); + lines = zeros(0, 5); + for i=1:size(alpha, 2) + lines = [lines; points speed.*cos(alpha(:,i)) speed.*sin(alpha(:,i)) Inf*ones(NP, 1)]; + end + NL = size(lines, 1); + + % initialize lines for borders, but assign a very high speed, to be sure + % borders will stop all cracks. + dx = (box([2 3 4 1],1)-box([1 2 3 4],1))*max(speed)*5; + dy = (box([2 3 4 1],2)-box([1 2 3 4],2))*max(speed)*5; + + % add borders to the lines set + lines = [lines ; createLine(box, dx, dy) Inf*ones(4,1)]; + + edges = zeros(0, 4); + + + while true + modif = 0; + + % try to update each line + for i=1:NL + + % initialize first point of edge + edges(i, 1:2) = lines(i, 1:2); + + % compute intersections with all other lines + pi = intersectLines(lines(i,:), lines); + + % compute position of all intersection points on the current line + pos = linePosition(pi, lines(i,:)); + + + % consider points to the right (positive position), and sort them + indr = find(pos>1e-12 & pos~=Inf); + [posr, indr2] = sort(pos(indr)); + + + % look for the closest intersection to the right + for i2=1:length(indr2) + + % index of intersected line + il = indr(indr2(i2)); + + % position of point relative to intersected line + pos2 = linePosition(pi(il, :), lines(il, :)); + + % depending on the sign of position, tests if the line2 can + % stop the current line, or if it was stopped before + if pos2>0 + if pos2<abs(posr(i2)) && pos2<lines(il, 5) + if lines(i, 5) ~= posr(i2) + edges(i, 3:4) = pi(il,:); + lines(i, 5) = posr(i2); + modif = 1; + end + break; + end + end + end % end processing of right points of the line + + + end % end processing of all lines + + % break the infinite loop if no more modification was made + if ~modif + break; + end + end + + % add edges of the surronding box. + edges = [edges ; box(1,:) box(2,:) ; box(2,:) box(3,:); ... + box(3,:) box(4,:) ; box(4,:) box(1,:) ]; + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/distancePointEdge.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePointEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/distancePointEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/distancePointEdge.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,85 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{dist} = } distancePointEdge (@var{point}, @var{edge}) +%% Minimum distance between a point and an edge +%% +%% DIST = distancePointEdge(POINT, EDGE); +%% Return the euclidean distance between edge EDGE and point POINT. +%% EDGE has the form: [x1 y1 x2 y2], and POINT is [x y]. +%% +%% If EDGE is N-by-4 array, result is N-by-1 array computed for each edge. +%% If POINT is a N-by-2 array, the result is computed for each point. +%% If both POINT and EDGE are array, they must have the same number of +%% rows, and the result is computed for each couple point(i,:);edge(i,:). +%% +%% [DIST POS] = distancePointEdge(POINT, EDGE); +%% Also returns the position of closest point on the edge. POS is +%% comprised between 0 (first point) and 1 (last point). +%% +%% @seealso{edges2d, points2d, distancePoints, distancePointLine} +%% @end deftypefn + +function varargout = distancePointEdge(point, edge) + % direction vector of each edge + dx = edge(:, 3) - edge(:,1); + dy = edge(:, 4) - edge(:,2); + + % compute position of points projected on the supporting line + % (Size of tp is the max number of edges or points) + delta = dx .* dx + dy .* dy; + tp = ((point(:, 1) - edge(:, 1)) .* dx + (point(:, 2) - edge(:, 2)) .* dy) ./ delta; + + % ensure degenerated edges are correclty processed (consider the first + % vertex is the closest) + tp(delta < eps) = 0; + + % change position to ensure projected point is located on the edge + tp(tp < 0) = 0; + tp(tp > 1) = 1; + + % coordinates of projected point + p0 = [edge(:,1) + tp .* dx, edge(:,2) + tp .* dy]; + + % compute distance between point and its projection on the edge + dist = sqrt((point(:,1) - p0(:,1)) .^ 2 + (point(:,2) - p0(:,2)) .^ 2); + + % process output arguments + varargout{1} = dist; + if nargout > 1 + varargout{2} = tp; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/distancePointLine.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/distancePointLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/distancePointLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/distancePointLine.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,77 @@ +%% 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{dist} = } distancePointLine (@var{point}, @var{line}) +%% Minimum distance between a point and a line +%% +%% D = distancePointLine(POINT, LINE) +%% Return the euclidean distance between line LINE and point POINT. +%% +%% LINE has the form : [x0 y0 dx dy], and POINT is [x y]. +%% +%% If LINE is N-by-4 array, result is N-by-1 array computes for each line. +%% +%% If POINT is N-by-2, then result is computed for each point. +%% +%% If both POINT and LINE are array, result is N-by-1, computed for each +%% corresponding point and line. +%% +%% +%% @seealso{lines2d, points2d, distancePoints, distancePointEdge} +%% @end deftypefn + +function dist = distancePointLine(point, line) + + if size(line, 1)==1 && size(point, 1)>1 + line = repmat(line, [size(point, 1) 1]); + end + + if size(point, 1)==1 && size(line, 1)>1 + point = repmat(point, [size(line, 1) 1]); + end + + dx = line(:, 3); + dy = line(:, 4); + + % compute position of points projected on line + tp = ((point(:, 2) - line(:, 2)).*dy + (point(:, 1) - line(:, 1)).*dx) ./ (dx.*dx+dy.*dy); + p0 = line(:, 1:2) + [tp tp].*[dx dy]; + + + % compute distances between points and their projections + dx = point - p0; + dist = sqrt(sum(dx.*dx, 2)); + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/ellipseAsPolygon.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/ellipseAsPolygon.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/ellipseAsPolygon.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/ellipseAsPolygon.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,93 @@ +%% 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{p} = } ellipseAsPolygon (@var{ell}, @var{n}) +%% Convert an ellipse into a series of points +%% +%% P = ellipseAsPolygon(ELL, N); +%% converts ELL given as [x0 y0 a b] or [x0 y0 a b theta] into a polygon +%% with N edges. The result P is (N+1)-by-2 array containing coordinates +%% of the N+1 vertices of the polygon. +%% The resulting polygon is closed, i.e. the last point is the same as the +%% first one. +%% +%% P = ellipseAsPolygon(ELL); +%% Use a default number of edges equal to 72. This result in one piont for +%% each 5 degrees. +%% +%% [X Y] = ellipseAsPolygon(...); +%% Return the coordinates o fvertices in two separate arrays. +%% +%% @seealso{ellipses2d, circleAsPolygon, rectAsPolygon, drawEllipse} +%% @end deftypefn + +function varargout = ellipseAsPolygon(ellipse, N) + + % default value for N + if nargin < 2 + N = 72; + end + + % angle of ellipse + theta = 0; + if size(ellipse, 2) > 4 + theta = ellipse(:,5); + end + + % get ellipse parameters + xc = ellipse(:,1); + yc = ellipse(:,2); + a = ellipse(:,3); + b = ellipse(:,4); + + % create time basis + t = linspace(0, 2*pi, N+1)'; + + % pre-compute trig functions (angles is in degrees) + cot = cosd(theta); + sit = sind(theta); + + % position of points + x = xc + a * cos(t) * cot - b * sin(t) * sit; + y = yc + a * cos(t) * sit + b * sin(t) * cot; + + % format output depending on number of a param. + if nargout == 1 + varargout = {[x y]}; + elseif nargout == 2 + varargout = {x, y}; + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/enclosingCircle.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/enclosingCircle.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/enclosingCircle.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/enclosingCircle.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,99 @@ +%% 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. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{circle} = } enclosingCircle (@var{pts}) +%% Find the minimum circle enclosing a set of points. +%% +%% CIRCLE = enclosingCircle(POINTS); +%% compute cirlce CIRCLE=[xc yc r] which enclose all points POINTS given +%% as an [Nx2] array. +%% +%% +%% Rewritten from a file from +%% Yazan Ahed (ya...@gm...) +%% +%% which was rewritten from a Java applet by Shripad Thite : +%% http://heyoka.cs.uiuc.edu/~thite/mincircle/ +%% +%% @seealso{circles2d, points2d, boxes2d} +%% @end deftypefn + +function circle = enclosingCircle(pts) + + % works on convex hull : it is faster + pts = pts(convhull(pts(:,1), pts(:,2)), :); + + circle = recurseCircle(size(pts, 1), pts, 1, zeros(3, 2)); + +endfunction + +function circ = recurseCircle(n, p, m, b) +% n: number of points given +% m: an argument used by the function. Always use 1 for m. +% bnry: an argument (3x2 array) used by the function to set the points that +% determines the circle boundry. You have to be careful when choosing this +% array's values. I think the values should be somewhere outside your points +% boundary. For my case, for example, I know the (x,y) I have will be something +% in between (-5,-5) and (5,5), so I use bnry as: +% [-10 -10 +% -10 -10 +% -10 -10] + + + if m==4 + circ = createCircle(b(1,:), b(2,:), b(3,:)); + return; + end + + circ = [Inf Inf 0]; + + if m == 2 + circ = [b(1,1:2) 0]; + elseif m == 3 + c = (b(1,:) + b(2,:))/2; + circ = [c distancePoints(b(1,:), c)]; + end + + + for i = 1:n + if distancePoints(p(i,:), circ(1:2)) > circ(3) + if sum(b(:,1)==p(i,1) & b(:,2)==p(i,2)) == 0 + b(m,:) = p(i,:); + circ = recurseCircle(i, p, m+1, b); + end + end + end + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/radicalAxis.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/radicalAxis.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/radicalAxis.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/radicalAxis.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,88 @@ +%% 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{line} = } radicalAxis (@var{circle1}, @var{circle2}) +%% Compute the radical axis (or radical line) of 2 circles +%% +%% L = radicalAxis(C1, C2) +%% Computes the radical axis of 2 circles. +%% +%% Example +%% C1 = [10 10 5]; +%% C2 = [60 50 30]; +%% L = radicalAxis(C1, C2); +%% hold on; axis equal;axis([0 100 0 100]); +%% drawCircle(C1);drawCircle(C2);drawLine(L); +%% +%% Ref: +%% http://mathworld.wolfram.com/RadicalLine.html +%% http://en.wikipedia.org/wiki/Radical_axis +%% +%% @seealso{lines2d, circles2d, createCircle} +%% +%% @end deftypefn + +function line = radicalAxis(circle1, circle2) + + % extract circles parameters + x1 = circle1(:,1); + x2 = circle2(:,1); + y1 = circle1(:,2); + y2 = circle2(:,2); + r1 = circle1(:,3); + r2 = circle2(:,3); + + % distance between each couple of centers + dist = sqrt((x2-x1).^2 + (y2-y1).^2); + + % relative position of intersection point of + % the radical line with the line joining circle centers + d = (dist.^2 + r1.^2 - r2.^2) * .5 ./ dist; + + % compute angle of radical axis + angle = lineAngle(createLine([x1 y1], [x2 y2])); + cot = cos(angle); + sit = sin(angle); + + % parameters of the line + x0 = x1 + d*cot; + y0 = y1 + d*sit; + dx = -sit; + dy = cot; + + % concatenate into one structure + line = [x0 y0 dx dy]; + +endfunction + Copied: trunk/octave-forge/main/geometry/geom2d/inst/reverseEdge.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/reverseEdge.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/reverseEdge.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/reverseEdge.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,50 @@ +%% 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} {@var{res} = } reverseEdge (@var{edge}) +%% Intervert the source and target vertices of edge +%% +%% REV = reverseEdge(EDGE); +%% Returns the opposite edge of EDGE. +%% EDGE has the format [X1 Y1 X2 Y2]. The resulting edge REV has value +%% [X2 Y2 X1 Y1]; +%% +%% @seealso{edges2d, createEdge, reverseLine} +%% @end deftypefn + +function res = reverseEdge(edge) + + res = [edge(:,3:4) edge(:,1:2)]; + +endfunction Copied: trunk/octave-forge/main/geometry/geom2d/inst/reverseLine.m (from rev 8818, trunk/octave-forge/main/geometry/matGeom_raw/geom2d/reverseLine.m) =================================================================== --- trunk/octave-forge/main/geometry/geom2d/inst/reverseLine.m (rev 0) +++ trunk/octave-forge/main/geometry/geom2d/inst/reverseLine.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -0,0 +1,52 @@ +%% 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{line} = } reverseLine (@var{line}) +%% Return same line but with opposite orientation +%% +%% INVLINE = reverseLine(LINE); +%% Returns the opposite line of LINE. +%% LINE has the format [x0 y0 dx dy], then INVLINE will have following +%% parameters: [x0 y0 -dx -dy]. +%% +%% @seealso{lines2d, createLine} +%% @end deftypefn + +function line = reverseLine(line) + + line(:, 3:4) = -line(:, 3:4); + +endfunction + + Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleArcAsCurve.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleArcAsCurve.m 2011-10-21 19:22:12 UTC (rev 8827) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleArcAsCurve.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -1,84 +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 = circleArcAsCurve(arc, N) -%CIRCLEARCASCURVE Convert a circle arc into a series of points -% -% P = circleArcAsCurve(ARC, N); -% convert the circle ARC into a series of N points. -% ARC is given in the format: [XC YC R THETA1 DTHETA] -% where XC and YC define the center of the circle, R its radius, THETA1 -% is the start of the arc and DTHETA is the angle extent of the arc. Both -% angles are given in degrees. -% N is the number of vertices of the resulting polyline, default is 65. -% -% The result is a N-by-2 array containing coordinates of the N points. -% -% [X Y] = circleArcAsCurve(ARC, N); -% Return the result in two separate arrays with N lines and 1 column. -% -% -% See also: -% circles2d, circleAsPolygon, drawCircle, drawPolygon -% -% -% --------- -% author : David Legland -% created the 22/05/2006. -% Copyright 2010 INRA - Cepia Software Platform. -% - -% HISTORY -% 2011-03-30 use angles in degrees, add default value for N - -% default value for N -if nargin < 2 - N = 65; -end - -% vector of positions -t0 = deg2rad(arc(4)); -t1 = t0 + deg2rad(arc(5)); -t = linspace(t0, t1, N)'; - -% compute coordinates of vertices -x = arc(1) + arc(3) * cos(t); -y = arc(2) + arc(3) * sin(t); - -% format output -if nargout <= 1 - varargout = {[x y]}; -else - varargout = {x, y}; -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleAsPolygon.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleAsPolygon.m 2011-10-21 19:22:12 UTC (rev 8827) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/circleAsPolygon.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -1,81 +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 = circleAsPolygon(circle, varargin) -%CIRCLEASPOLYGON Convert a circle into a series of points -% -% P = circleAsPolygon(CIRCLE, N); -% convert circle given as [x0 y0 r], where x0 and y0 are coordinate of -% center, and r is the radius, into an array of [(N+1)x2] double, -% containing x and y values of points. -% The polygon is closed -% -% P = circleAsPolygon(CIRCLE); -% uses a default value of N=64 points -% -% Example -% circle = circleAsPolygon([10 0 5], 16); -% figure; -% drawPolygon(circle); -% -% See also: -% circles2d, polygons2d, createCircle -% -% -% --------- -% author : David Legland -% created the 06/04/2005. -% Copyright 2010 INRA - Cepia Software Platform. -% - -% HISTORY -% 20/04/2007: return a closed polygon with N+1 vertices, use default N=64 - -% determines number of points -N = 64; -if ~isempty(varargin) - N = varargin{1}; -end - -% create circle -t = linspace(0, 2*pi, N+1)'; -x = circle(1) + circle(3)*cos(t); -y = circle(2) + circle(3)*sin(t); - -if nargout==1 - varargout{1}=[x y]; -elseif nargout==2 - varargout{1}=x; - varargout{2}=y; -end Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipLineRect.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipLineRect.m 2011-10-21 19:22:12 UTC (rev 8827) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/clipLineRect.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -1,85 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <dav...@gr...> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function edge = clipLineRect(line, rect) -%CLIPLINERECT clip a line with a polygon -% -% EDGE = clipLineRect(LINE, RECT); -% LINE: line in the form [x0 y0 dx dy] -% RECT: a rectangle in the form [xr yr wr hr] (xr and yr: coordinate of -% first point, wr and hr are width and height of rectangle) -% -% Deprecated: use function clipLine instead -% -% --------- -% author : David Legland -% created the 24/07/2006. -% Copyright 2010 INRA - Cepia Software Platform. -% - -% HISTORY - -if size(line, 1)==1 - line = repmat(line, size(rect, 1), 1); -elseif size(rect, 1)==1 - rect = repmat(rect, size(line, 1), 1); -elseif size(line, 1) ~= size(rect, 1) - error('bad sizes for input'); -end - -edge = zeros(size(line, 1), 4); -for i=1:size(line, 1) - x = rect(i, 1); y = rect(i, 2); w = rect(i, 3); h = rect(i, 4); - - % intersection with axis : x=xmin - px1 = intersectLineEdge(line(i,:), [x y x+w y]); - px2 = intersectLineEdge(line(i,:), [x+w y x+w y+h]); - py1 = intersectLineEdge(line(i,:), [x+w y+h x y+h]); - py2 = intersectLineEdge(line(i,:), [x y+h x y]); - - % sort points along the x coordinate, and draw a line between - % the two in the middle - points = sortrows([px1 ; px2 ; py1 ; py2], 1); - if points(2,1)>=x-1e-14 && points(2,1)<=x+w+1e-14 - if isfinite(points(3,1)) - edge(i, 1:4) = [points(2,:) points(3,:)]; - else - edge(i, 1:4) = [points(1,:) points(2,:)]; - end - else - % line outside the rectangle - edge(i, 1:4) = [0 0 0 0]; - end -end - Deleted: trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern.m =================================================================== --- trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern.m 2011-10-21 19:22:12 UTC (rev 8827) +++ trunk/octave-forge/main/geometry/matGeom_raw/geom2d/crackPattern.m 2011-10-21 19:44:24 UTC (rev 8828) @@ -1,192 +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 edges = crackPattern(box, points, alpha, varargin) -%CRACKPATTERN C... [truncated message content] |
From: <jpi...@us...> - 2011-10-21 20:27:19
|
Revision: 8832 http://octave.svn.sourceforge.net/octave/?rev=8832&view=rev Author: jpicarbajal Date: 2011-10-21 20:27:11 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. Adding what was missing Added Paths: ----------- trunk/octave-forge/main/geometry/COPYING trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/PKG_ADD trunk/octave-forge/main/geometry/devel/ trunk/octave-forge/main/geometry/devel/@svg/ trunk/octave-forge/main/geometry/devel/@svg/display.m trunk/octave-forge/main/geometry/devel/@svg/getpath.m trunk/octave-forge/main/geometry/devel/@svg/inkex.py trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m trunk/octave-forge/main/geometry/devel/@svg/parsePath.py trunk/octave-forge/main/geometry/devel/@svg/plot.m trunk/octave-forge/main/geometry/devel/@svg/simplepath.py trunk/octave-forge/main/geometry/devel/@svg/subsref.m trunk/octave-forge/main/geometry/devel/@svg/svg.m trunk/octave-forge/main/geometry/devel/shapearea.m Added: trunk/octave-forge/main/geometry/COPYING =================================================================== --- trunk/octave-forge/main/geometry/COPYING (rev 0) +++ trunk/octave-forge/main/geometry/COPYING 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. Added: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX (rev 0) +++ trunk/octave-forge/main/geometry/INDEX 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,126 @@ +geometry >> Computational Geometry +Geometry 2D + angle2Points + angle3Points + angleAbsDiff + angleDiff + angles2d + angleSort + bisector + boxes2d + cartesianLine + cbezier2poly + centroid + circleArcAsCurve + circleAsPolygon + circles2d + clipEdge + clipLine + clipPoints + clipRay + Contents + crackPattern2 + crackPattern + createBasisTransform + createCircle + createDirectedCircle + createEdge + createHomothecy + createLine + createLineReflection + createRay + createRotation + createScaling + createTranslation + createVector + deg2rad + distancePointEdge + distancePointLine + distancePoints + drawArrow + drawBezierCurve + drawBox + drawCenteredEdge + drawCircleArc + drawCircle + drawEdge + drawEllipseArc + drawEllipse + drawLabels + drawLine + drawOrientedBox + drawParabola + drawPoint + drawRay + drawRect + drawShape + edgeAngle + edgeLength + edgePosition + edges2d + edgeToLine + ellipseAsPolygon + ellipses2d + enclosingCircle + fitAffineTransform2d + hexagonalGrid + inertiaEllipse + intersectBoxes + intersectCircles + intersectEdges + intersectLineCircle + intersectLineEdge + intersectLines + isCounterClockwise + isLeftOriented + isParallel + isPerpendicular + isPointInCircle + isPointInEllipse + isPointOnCircle + isPointOnEdge + isPointOnLine + isPointOnRay + lineAngle + linePosition + lines2d + medianLine + mergeBoxes + midPoint + minDistancePoints + normalizeAngle + normalizeVector + orthogonalLine + parallelLine + pointOnLine + points2d + polarPoint + projPointOnLine + rad2deg + radicalAxis + randomPointInBox + rays2d + reverseEdge + reverseLine + rotateVector + squareGrid + transformEdge + transformLine + transformPoint + transforms2d + transformVector + triangleGrid + vectorAngle + vectorNorm + vectors2d +Input + svgload + svgnormalize + svgpath2polygon +Output + data2geo +Geometry 3D +Graphs + + + Added: trunk/octave-forge/main/geometry/PKG_ADD =================================================================== --- trunk/octave-forge/main/geometry/PKG_ADD (rev 0) +++ trunk/octave-forge/main/geometry/PKG_ADD 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,12 @@ +dirlist = {"geom2d"}; +dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); + +fullfile (dirname, "inst") +%if (! exist (fullfile (dirname, "inst"), "dir")) +% for ii=1:length (dirlist) +% addpath ( [ dirname "/../" dirlist{ii}],"-end") +% endfor +%endif + +warning('off', 'Octave:fopen-file-in-path'); +clear dirlist dirname Added: trunk/octave-forge/main/geometry/devel/@svg/display.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/display.m (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/display.m 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,25 @@ +## Copyright (C) 2011 Carnë Draug <car...@gm...> +## Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (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/>. + +function display (obj) + + fields = fieldnames (obj); + for i = 1 : numel(fields) + printf ("%s\n", fields{i}); + obj.(fields{i}) + end + +endfunction Added: trunk/octave-forge/main/geometry/devel/@svg/getpath.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/getpath.m (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/getpath.m 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,73 @@ +## Copyright (C) 2011 Carnë Draug <car...@gm...> +## Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (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/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} function_name () +## @end deftypefn + +function paths = getpath(obj, ids={}) + + if !isempty(ids) + + if iscell (ids) && iscell(ids{1}) % dealing with ids given as cell + ids = ids{1}; + + if !all ( cellfun (@ischar, ids) ) + print_usage + end + + elseif !all ( cellfun (@ischar, ids) ) + print_usage + end + + else + paths = obj.Path; + return + end + + tf = ismember (ids, fieldnames (obj.Path)); + + cellfun (@(s) printf("'%s' is not a valid path id.\n", s) , {ids{!tf}}); + + paths = []; + if any (tf) + stuff = {ids{tf}}; + %{ + for i = 1: numel(stuff) + paths{i} = obj.Path.(ids{i}).data; + endfor + %} + + % Variation +% paths = cellfun(@(s) obj.Path.(s).data, stuff,'UniformOutput',false); + + % Another variation +% paths = cellfun(@(s) getfield(obj,'Path').(s).data, stuff,'UniformOutput',false); + + % Yet another +% paths = cellfun(@(s) getfield(obj.Path,s).data, stuff,'UniformOutput',false); + + % Yet yet another + dummy = @(s) obj.Path.(s).data; + paths = cellfun(dummy, stuff,'UniformOutput',false); + + if numel(paths) == 1 + paths = paths{1}; + end + end + +endfunction + Added: trunk/octave-forge/main/geometry/devel/@svg/inkex.py =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/inkex.py (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/inkex.py 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,235 @@ +#!/usr/bin/env python +""" +inkex.py +A helper module for creating Inkscape extensions + +Copyright (C) 2005,2007 Aaron Spike, aa...@ek... + +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 2 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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" +import sys, copy, optparse, random, re +import gettext +from math import * +_ = gettext.gettext + +#a dictionary of all of the xmlns prefixes in a standard inkscape doc +NSS = { +u'sodipodi' :u'http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd', +u'cc' :u'http://creativecommons.org/ns#', +u'ccOLD' :u'http://web.resource.org/cc/', +u'svg' :u'http://www.w3.org/2000/svg', +u'dc' :u'http://purl.org/dc/elements/1.1/', +u'rdf' :u'http://www.w3.org/1999/02/22-rdf-syntax-ns#', +u'inkscape' :u'http://www.inkscape.org/namespaces/inkscape', +u'xlink' :u'http://www.w3.org/1999/xlink', +u'xml' :u'http://www.w3.org/XML/1998/namespace' +} + +#a dictionary of unit to user unit conversion factors +uuconv = {'in':90.0, 'pt':1.25, 'px':1, 'mm':3.5433070866, 'cm':35.433070866, 'm':3543.3070866, + 'km':3543307.0866, 'pc':15.0, 'yd':3240 , 'ft':1080} +def unittouu(string): + '''Returns userunits given a string representation of units in another system''' + unit = re.compile('(%s)$' % '|'.join(uuconv.keys())) + param = re.compile(r'(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)') + + p = param.match(string) + u = unit.search(string) + if p: + retval = float(p.string[p.start():p.end()]) + else: + retval = 0.0 + if u: + try: + return retval * uuconv[u.string[u.start():u.end()]] + except KeyError: + pass + return retval + +def uutounit(val, unit): + return val/uuconv[unit] + +try: + from lxml import etree +except: + sys.exit(_('The fantastic lxml wrapper for libxml2 is required by inkex.py and therefore this extension. Please download and install the latest version from http://cheeseshop.python.org/pypi/lxml/, or install it through your package manager by a command like: sudo apt-get install python-lxml')) + +def debug(what): + sys.stderr.write(str(what) + "\n") + return what + +def errormsg(msg): + """Intended for end-user-visible error messages. + + (Currently just writes to stderr with an appended newline, but could do + something better in future: e.g. could add markup to distinguish error + messages from status messages or debugging output.) + + Note that this should always be combined with translation: + + import gettext + _ = gettext.gettext + ... + inkex.errormsg(_("This extension requires two selected paths.")) + """ + sys.stderr.write((unicode(msg) + "\n").encode("UTF-8")) + +def check_inkbool(option, opt, value): + if str(value).capitalize() == 'True': + return True + elif str(value).capitalize() == 'False': + return False + else: + raise optparse.OptionValueError("option %s: invalid inkbool value: %s" % (opt, value)) + +def addNS(tag, ns=None): + val = tag + if ns!=None and len(ns)>0 and NSS.has_key(ns) and len(tag)>0 and tag[0]!='{': + val = "{%s}%s" % (NSS[ns], tag) + return val + +class InkOption(optparse.Option): + TYPES = optparse.Option.TYPES + ("inkbool",) + TYPE_CHECKER = copy.copy(optparse.Option.TYPE_CHECKER) + TYPE_CHECKER["inkbool"] = check_inkbool + +class Effect: + """A class for creating Inkscape SVG Effects""" + + def __init__(self, *args, **kwargs): + self.document=None + self.ctx=None + self.selected={} + self.doc_ids={} + self.options=None + self.args=None + self.OptionParser = optparse.OptionParser(usage="usage: %prog [options] SVGfile",option_class=InkOption) + self.OptionParser.add_option("--id", + action="append", type="string", dest="ids", default=[], + help="id attribute of object to manipulate") + + def effect(self): + pass + + def getoptions(self,args=sys.argv[1:]): + """Collect command line arguments""" + self.options, self.args = self.OptionParser.parse_args(args) + + def parse(self,file=None): + """Parse document in specified file or on stdin""" + try: + try: + stream = open(file,'r') + except: + stream = open(self.svg_file,'r') + except: + stream = sys.stdin + self.document = etree.parse(stream) + stream.close() + + def getposinlayer(self): + #defaults + self.current_layer = self.document.getroot() + self.view_center = (0.0,0.0) + + layerattr = self.document.xpath('//sodipodi:namedview/@inkscape:current-layer', namespaces=NSS) + if layerattr: + layername = layerattr[0] + layer = self.document.xpath('//svg:g[@id="%s"]' % layername, namespaces=NSS) + if layer: + self.current_layer = layer[0] + + xattr = self.document.xpath('//sodipodi:namedview/@inkscape:cx', namespaces=NSS) + yattr = self.document.xpath('//sodipodi:namedview/@inkscape:cy', namespaces=NSS) + doc_height = unittouu(self.document.getroot().get('height')) + if xattr and yattr: + x = xattr[0] + y = yattr[0] + if x and y: + self.view_center = (float(x), doc_height - float(y)) # FIXME: y-coordinate flip, eliminate it when it's gone in Inkscape + + def getselected(self): + """Collect selected nodes""" + for i in self.options.ids: + path = '//*[@id="%s"]' % i + for node in self.document.xpath(path, namespaces=NSS): + self.selected[i] = node + + def getElementById(self, id): + path = '//*[@id="%s"]' % id + el_list = self.document.xpath(path, namespaces=NSS) + if el_list: + return el_list[0] + else: + return None + + def getParentNode(self, node): + for parent in self.document.getiterator(): + if node in parent.getchildren(): + return parent + break + + + def getdocids(self): + docIdNodes = self.document.xpath('//@id', namespaces=NSS) + for m in docIdNodes: + self.doc_ids[m] = 1 + + def getNamedView(self): + return self.document.xpath('//sodipodi:namedview', namespaces=NSS)[0] + + def createGuide(self, posX, posY, angle): + atts = { + 'position': str(posX)+','+str(posY), + 'orientation': str(sin(radians(angle)))+','+str(-cos(radians(angle))) + } + guide = etree.SubElement( + self.getNamedView(), + addNS('guide','sodipodi'), atts ) + return guide + + def output(self): + """Serialize document into XML on stdout""" + self.document.write(sys.stdout) + + def affect(self, args=sys.argv[1:], output=True): + """Affect an SVG document with a callback effect""" + self.svg_file = args[-1] + self.getoptions(args) + self.parse() + self.getposinlayer() + self.getselected() + self.getdocids() + self.effect() + if output: self.output() + + def uniqueId(self, old_id, make_new_id = True): + new_id = old_id + if make_new_id: + while new_id in self.doc_ids: + new_id += random.choice('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') + self.doc_ids[new_id] = 1 + return new_id + + def xpathSingle(self, path): + try: + retval = self.document.xpath(path, namespaces=NSS)[0] + except: + errormsg(_("No matching node for expression: %s") % path) + retval = None + return retval + + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99 Property changes on: trunk/octave-forge/main/geometry/devel/@svg/inkex.py ___________________________________________________________________ Added: svn:executable + * Added: trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,124 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +function Paths = loadpaths (obj, svg, varargin) + + here = which ("@svg/loadpaths"); + here = fileparts (here); + script = fullfile (here, 'parsePath.py'); + + %% Call python script + if exist (svg,'file') + % read from file + [st str]=system (sprintf ('python %s %s', script, svg)); + + else + % inline SVG + [st str]=system (sprintf ('python %s < %s', script, svg)); + end + + %% Parse ouput + strpath = strsplit (str(1:end-1), '$', true); + + npaths = numel (strpath); + + %% Convert path data to polygons + for ip = 1:npaths + + eval (strpath{ip}); + %% FIXME: intialize struct with cell field + svgpath2.cmd = svgpath(1).cmd; + svgpath2.data = {svgpath.data}; + + nD = length(svgpath2.cmd); + pathdata = cell (nD-1,1); + + point_end=[]; + %% If the path is closed, last command is Z and we set initial point == final + if svgpath2.cmd(end) == 'Z' + nD -= 1; + point_end = svgpath2.data{1}; + svgpath2.data(end) = []; + end + + %% Initial point + points(1,:) = svgpath2.data{1}; + + for jp = 2:nD + switch svgpath2.cmd(jp) + case 'L' + %% Straigth segment to polygon + points(2,:) = svgpath2.data{jp}; + pp = [(points(2,:)-points(1,:))' points(1,:)']; + clear points + points(1,:) = [polyval(pp(1,:),1) polyval(pp(2,:),1)]; + + case 'C' + %% Cubic bezier to polygon + points(2:4,:) = reshape (svgpath2.data{jp}, 2, 3).'; + pp = cbezier2poly (points); + clear points + points(1,:) = [polyval(pp(1,:),1) polyval(pp(2,:),1)]; + end + + pathdata{jp-1} = pp; + end + + if ~isempty(point_end) + %% Straight segmet to close the path + points(2,:) = point_end; + pp = [(points(2,:)-points(1,:))' points(1,:)']; + + if all ( abs(pp(:,1)) < sqrt(eps) ) + % Final point of last segment is already initial point + pathdata(end) = []; + else + pathdata{end} = pp; + end + + end + + Paths.(svgpathid).data = pathdata; + end +endfunction + +%!test +%! figure(1) +%! hold on +%! paths = getSVGPaths_py ('../drawing.svg'); +%! +%! % Get path ids +%! ids = fieldnames(paths); +%! npath = numel(ids); +%! +%! t = linspace (0, 1, 64); +%! +%! for i = 1:npath +%! x = []; y = []; +%! data = paths.(ids(i)).data; +%! +%! for j = 1:numel(data) +%! x = cat (2, x, polyval (data{j}(1,:),t)); +%! y = cat (2, y, polyval (data{j}(2,:),t)); +%! end +%! +%! plot(x,y,'-'); +%! end +%! axis ij +%! if strcmpi(input('You should see drawing.svg [y/n] ','s'),'n') +%! error ("didn't get what was expected."); +%! end +%! close + Added: trunk/octave-forge/main/geometry/devel/@svg/parsePath.py =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/parsePath.py (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/parsePath.py 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +import inkex, simplepath +import sys +#import getopt + +def parsePaths (filen=None): + + svg = inkex.Effect () + svg.parse (filen) + + paths = svg.document.xpath ('//svg:path', namespaces=inkex.NSS) + for path in paths: + D = simplepath.parsePath (path.attrib['d']) + cmdlst = []; + parlst = []; + for cmd,params in D: + cmdlst.append(cmd) + parlst.append(params) + + print 'svgpath = struct("cmd","{0}","data",{{{1}}});' \ + .format(''.join(cmdlst),str(parlst).replace('[[','[').replace(']]',']')) + + print 'svgpathid = "{0}"; $'.format(path.attrib['id']) + + + +# ---------------------------- + +if __name__=="__main__": + ''' + try: + optlist,args = getopt.getopt(sys.argv[1:],"thdp") + except getopt.GetoptError: + usage() + sys.exit(2) + + doHelp = 0 + c = Context() + c.doPrint = 1 + for opt in optlist: + if opt[0] == "-d": c.debug = 1 + if opt[0] == "-p": c.plot = 1 + if opt[0] == "-t": c.triangulate = 1 + if opt[0] == "-h": doHelp = 1 + + if not doHelp: + pts = [] + fp = sys.stdin + if len(args) > 0: + fp = open(args[0],'r') + for line in fp: + fld = line.split() + x = float(fld[0]) + y = float(fld[1]) + pts.append(Site(x,y)) + if len(args) > 0: fp.close() + + if doHelp or len(pts) == 0: + usage() + sys.exit(2) + ''' + svg = sys.argv[1] + parsePaths(svg) Added: trunk/octave-forge/main/geometry/devel/@svg/plot.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/plot.m (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/plot.m 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,45 @@ +## Copyright (C) 2011 Carnë Draug <car...@gm...> +## Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (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/>. + + +function h = plot(obj, varargin) + + % Get path ids + ids = fieldnames(obj.Path); + npath = numel(ids); + + t = linspace (0, 1, 64); + + for i = 1:npath + x = []; y = []; + data = obj.Path.(ids(i)).data; + + for j = 1:numel(data) + x = cat (2, x, polyval (data{j}(1,:),t)); + y = cat (2, y, polyval (data{j}(2,:),t)); + end + + h = plot(x,y,'-'); + if i == 1 + hold on + end + end + hold off + axis ij + axis equal + +endfunction + Added: trunk/octave-forge/main/geometry/devel/@svg/simplepath.py =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/simplepath.py (rev 0) +++ trunk/octave-forge/main/geometry/devel/@svg/simplepath.py 2011-10-21 20:27:11 UTC (rev 8832) @@ -0,0 +1,212 @@ +#!/usr/bin/env python +""" +simplepath.py +functions for digesting paths into a simple list structure + +Copyright (C) 2005 Aaron Spike, aa...@ek... + +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 2 of the License, or +(at your option) any later version. + +This program... [truncated message content] |
From: <jpi...@us...> - 2011-10-21 21:02:48
|
Revision: 8840 http://octave.svn.sourceforge.net/octave/?rev=8840&view=rev Author: jpicarbajal Date: 2011-10-21 21:02:41 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. Optimizing Packaging Modified Paths: -------------- trunk/octave-forge/main/geometry/PKG_ADD Added Paths: ----------- trunk/octave-forge/main/geometry/PKG_DEL Modified: trunk/octave-forge/main/geometry/PKG_ADD =================================================================== --- trunk/octave-forge/main/geometry/PKG_ADD 2011-10-21 20:54:00 UTC (rev 8839) +++ trunk/octave-forge/main/geometry/PKG_ADD 2011-10-21 21:02:41 UTC (rev 8840) @@ -1,12 +1,12 @@ -dirlist = {"geom2d"}; +%1 +dirlist = {"geom2d","io"}; dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); -fullfile (dirname, "inst") -%if (! exist (fullfile (dirname, "inst"), "dir")) -% for ii=1:length (dirlist) -% addpath ( [ dirname "/../" dirlist{ii}],"-end") -% endfor -%endif +if (! exist (fullfile (dirname, "inst"), "dir")) + for ii=1:length (dirlist) + addpath ( [ dirname filesep dirlist{ii}],"-end") + endfor +endif warning('off', 'Octave:fopen-file-in-path'); clear dirlist dirname Added: trunk/octave-forge/main/geometry/PKG_DEL =================================================================== --- trunk/octave-forge/main/geometry/PKG_DEL (rev 0) +++ trunk/octave-forge/main/geometry/PKG_DEL 2011-10-21 21:02:41 UTC (rev 8840) @@ -0,0 +1,12 @@ +%1 +dirlist = {"geom2d","io"}; +dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); + +if (! exist (fullfile (dirname, "inst"), "dir")) + for ii=1:length (dirlist) + ## Run this if the package is installed + rmpath ( [ dirname filesep dirlist{ii}]) + end +end + +clear dirlist dirname This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-10-21 22:00:51
|
Revision: 8842 http://octave.svn.sourceforge.net/octave/?rev=8842&view=rev Author: jpicarbajal Date: 2011-10-21 22:00:45 +0000 (Fri, 21 Oct 2011) Log Message: ----------- geometry. Re-organized INDEX and updated content Modified Paths: -------------- trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/inst/geom2d/Contents.m Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-10-21 21:09:37 UTC (rev 8841) +++ trunk/octave-forge/main/geometry/INDEX 2011-10-21 22:00:45 UTC (rev 8842) @@ -1,126 +1,133 @@ geometry >> Computational Geometry -Geometry 2D +2D Descriptive + Contents + points2d + vectors2d + angles2d + edges2d + rays2d + lines2d + boxes2d + circles2d + ellipses2d + transforms2d +2D Points + centroid + distancePoints + drawPoint + isPointOnRay + isPointInCircle + isPointOnCircle + isPointOnLine + isPointInEllipse + midPoint + minDistancePoints + polarPoint +2D Vectors + createVector + vectorNorm + normalizeVector + rotateVector +2D Angles angle2Points angle3Points angleAbsDiff angleDiff - angles2d + normalizeAngle + vectorAngle angleSort - bisector - boxes2d - cartesianLine - cbezier2poly - centroid - circleArcAsCurve - circleAsPolygon - circles2d - clipEdge - clipLine - clipPoints - clipRay - Contents - crackPattern2 - crackPattern - createBasisTransform - createCircle - createDirectedCircle + lineAngle + edgeAngle + deg2rad + rad2deg +2D Edges createEdge - createHomothecy - createLine - createLineReflection - createRay - createRotation - createScaling - createTranslation - createVector - deg2rad distancePointEdge - distancePointLine - distancePoints - drawArrow - drawBezierCurve - drawBox drawCenteredEdge - drawCircleArc - drawCircle drawEdge - drawEllipseArc - drawEllipse - drawLabels - drawLine - drawOrientedBox - drawParabola - drawPoint - drawRay - drawRect - drawShape - edgeAngle edgeLength edgePosition - edges2d edgeToLine - ellipseAsPolygon - ellipses2d - enclosingCircle - fitAffineTransform2d - hexagonalGrid - inertiaEllipse - intersectBoxes - intersectCircles intersectEdges - intersectLineCircle intersectLineEdge + reverseEdge + transformEdge + isPointOnEdge +2D Rays + drawRay + createRay +2D Lines + cartesianLine + createLine + distancePointLine + drawLine intersectLines - isCounterClockwise - isLeftOriented isParallel isPerpendicular - isPointInCircle - isPointInEllipse - isPointOnCircle - isPointOnEdge - isPointOnLine - isPointOnRay - lineAngle linePosition - lines2d medianLine - mergeBoxes - midPoint - minDistancePoints - normalizeAngle - normalizeVector + isLeftOriented orthogonalLine parallelLine pointOnLine - points2d - polarPoint projPointOnLine - rad2deg + reverseLine +2D Boxes + clipEdge + clipLine + clipPoints + clipRay + mergeBoxes + intersectBoxes + drawBox + randomPointInBox + drawRect + drawOrientedBox +2D Circles + createCircle + createDirectedCircle + circleArcAsCurve + circleAsPolygon + drawCircleArc + drawCircle + enclosingCircle + intersectCircles + intersectLineCircle radicalAxis - randomPointInBox - rays2d - reverseEdge - reverseLine - rotateVector - squareGrid - transformEdge +2D Ellipses + ellipseAsPolygon + drawEllipseArc + drawEllipse + inertiaEllipse +2D Transformations transformLine transformPoint - transforms2d transformVector + createBasisTransform + createHomothecy + createLineReflection + createRotation + createScaling + createTranslation + fitAffineTransform2d +2D Cubic Bezier + drawBezierCurve + cbezier2poly +2D Others + bisector + crackPattern2 + crackPattern + drawArrow + drawLabels + drawParabola + drawShape + hexagonalGrid + isCounterClockwise + squareGrid triangleGrid - vectorAngle - vectorNorm - vectors2d Input svgload svgnormalize svgpath2polygon Output data2geo -Geometry 3D -Graphs - - - Modified: trunk/octave-forge/main/geometry/inst/geom2d/Contents.m =================================================================== --- trunk/octave-forge/main/geometry/inst/geom2d/Contents.m 2011-10-21 21:09:37 UTC (rev 8841) +++ trunk/octave-forge/main/geometry/inst/geom2d/Contents.m 2011-10-21 22:00:45 UTC (rev 8842) @@ -33,8 +33,8 @@ %% -*- texinfo -*- %% @deftypefn {Function File} Contents () -%% GEOM2D Geometry 2D Toolbox -%% Version 1.0 21-Mar-2011 . +%% Geometry 2D Toolbox +%% Version 1.2.0 21-Oct-2011 . %% %% Library to handle and visualize geometric primitives such as points, %% lines, circles and ellipses, polygons... This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-01 10:17:06
|
Revision: 8904 http://octave.svn.sourceforge.net/octave/?rev=8904&view=rev Author: jpicarbajal Date: 2011-11-01 10:16:55 +0000 (Tue, 01 Nov 2011) Log Message: ----------- geometry. Shape of area defined with piece smooth polynomials Added Paths: ----------- trunk/octave-forge/main/geometry/inst/shapearea.m Removed Paths: ------------- trunk/octave-forge/main/geometry/devel/shapearea.m Deleted: trunk/octave-forge/main/geometry/devel/shapearea.m =================================================================== --- trunk/octave-forge/main/geometry/devel/shapearea.m 2011-11-01 07:55:22 UTC (rev 8903) +++ trunk/octave-forge/main/geometry/devel/shapearea.m 2011-11-01 10:16:55 UTC (rev 8904) @@ -1,74 +0,0 @@ -%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> -%% -%% This program is free software; you can redistribute it and/or modify -%% it under the terms of the GNU General Public License as published by -%% the Free Software Foundation; either version 3 of the License, or -%% (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/>. - -%% -*- texinfo -*- -%% @deftypefn {Function File} { @var{a} =} areashape (@var{pp}) -%% Shape is defined with piecewise smooth polynomials. @var{pp} is a -%% cell where each elements is a 2-by-(poly_degree+1) array containing px(i,:) = -%% pp{i}(1,:) and py(i,:) = pp{i}(2,:). -%% -%% @end deftypefn - -function A = shapearea (pp, tol=sqrt(eps)*[1 1]) - - A = 0; - - integrand = @(t_, px_, py_) polyval (px_, t_) .* polyval ( polyderiv (py_), t_); - d3_integral = @(px,py) py(1) * ( 20*px(4) + 15*px(3) + 12*px(2) + 10*px(1)) / 20 + ... - py(2) * ( 30*px(4) + 20*px(3) + 15*px(2) + 12*px(1)) / 30 + ... - py(3) * ( 12*px(4) + 6*px(3) + 4*px(2) + 3*px(1)) / 12; - - for is = 1:numel(pp) - px = pp{is}(1,:); - py = pp{is}(2,:); - - if length(px) > 4 - % degree> 3 - A += quad(@(t) integrand (t, px, py), 0, 1, tol); - else - % cubic polynomial - px = padarray(px,[0 4-length(px)],0,'pre') - py = padarray(py,[0 4-length(py)],0,'pre'); - A += d3_integral(px,py); - end - - end - -endfunction - -%!demo % non-convex bezier shape -%! weirdhearth ={[-17.6816 -34.3989 7.8580 3.7971; ... -%! 15.4585 -28.3820 -18.7645 9.8519]; ... -%! [-27.7359 18.1039 -34.5718 3.7878; ... -%! -40.7440 49.7999 -25.5011 2.2304]}; -%! A = shapearea (weirdhearth) - -%!test -%! triangle = {[1 0; 0 0]; [-0.5 1; 1 0]; [-0.5 0.5; -1 1]}; -%! A = shapearea (triangle); -%! assert (0.5, A); - -%!test -%! circle = {[1.715729 -6.715729 0 5; ... -%! -1.715729 -1.568542 8.284271 0]; ... -%! [1.715729 1.568542 -8.284271 0; ... -%! 1.715729 -6.715729 0 5]; ... -%! [-1.715729 6.715729 0 -5; ... -%! 1.715729 1.568542 -8.284271 0]; ... -%! [-1.715729 -1.568542 8.284271 0; ... -%! -1.715729 6.715729 0 -5]}; -%! A = shapearea (circle); -%! assert (pi*5^2, A, 5e-2); - Copied: trunk/octave-forge/main/geometry/inst/shapearea.m (from rev 8848, trunk/octave-forge/main/geometry/devel/shapearea.m) =================================================================== --- trunk/octave-forge/main/geometry/inst/shapearea.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/shapearea.m 2011-11-01 10:16:55 UTC (rev 8904) @@ -0,0 +1,64 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software; you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation; either version 3 of the License, or +%% (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/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} { @var{a} =} shapearea (@var{pp}) +%% Shape is defined with piecewise smooth polynomials. @var{pp} is a +%% cell where each elements is a 2-by-(poly_degree+1) array containing px(i,:) = +%% pp{i}(1,:) and py(i,:) = pp{i}(2,:). +%% +%% @end deftypefn + +function A = shapearea (shape) + + A = sum(cellfun (@Aint, shape)); + +endfunction + +function dA = Aint (x) + + px = x(1,:); + py = x(2,:); + + P = polyint (conv (px, polyderiv(py))); + + dA = diff(polyval(P,[0 1])); + +end + +%!demo % non-convex bezier shape +%! weirdhearth ={[-17.6816 -34.3989 7.8580 3.7971; ... +%! 15.4585 -28.3820 -18.7645 9.8519]; ... +%! [-27.7359 18.1039 -34.5718 3.7878; ... +%! -40.7440 49.7999 -25.5011 2.2304]}; +%! A = shapearea (weirdhearth) + +%!test +%! triangle = {[1 0; 0 0]; [-0.5 1; 1 0]; [-0.5 0.5; -1 1]}; +%! A = shapearea (triangle); +%! assert (0.5, A); + +%!test +%! circle = {[1.715729 -6.715729 0 5; ... +%! -1.715729 -1.568542 8.284271 0]; ... +%! [1.715729 1.568542 -8.284271 0; ... +%! 1.715729 -6.715729 0 5]; ... +%! [-1.715729 6.715729 0 -5; ... +%! 1.715729 1.568542 -8.284271 0]; ... +%! [-1.715729 -1.568542 8.284271 0; ... +%! -1.715729 6.715729 0 -5]}; +%! A = shapearea (circle); +%! assert (pi*5^2, A, 5e-2); + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-01 10:46:05
|
Revision: 8905 http://octave.svn.sourceforge.net/octave/?rev=8905&view=rev Author: jpicarbajal Date: 2011-11-01 10:45:54 +0000 (Tue, 01 Nov 2011) Log Message: ----------- geometry. Adding @svg Modified Paths: -------------- trunk/octave-forge/main/geometry/devel/@svg/getpath.m trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m trunk/octave-forge/main/geometry/devel/@svg/svg.m trunk/octave-forge/main/geometry/inst/io/@svg/getpath.m trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m trunk/octave-forge/main/geometry/inst/io/@svg/svg.m Added Paths: ----------- trunk/octave-forge/main/geometry/inst/io/@svg/ Modified: trunk/octave-forge/main/geometry/devel/@svg/getpath.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/getpath.m 2011-11-01 10:16:55 UTC (rev 8904) +++ trunk/octave-forge/main/geometry/devel/@svg/getpath.m 2011-11-01 10:45:54 UTC (rev 8905) @@ -45,12 +45,12 @@ paths = []; if any (tf) stuff = {ids{tf}}; - %{ + for i = 1: numel(stuff) paths{i} = obj.Path.(ids{i}).data; endfor - %} + % Variation % paths = cellfun(@(s) obj.Path.(s).data, stuff,'UniformOutput',false); @@ -61,8 +61,8 @@ % paths = cellfun(@(s) getfield(obj.Path,s).data, stuff,'UniformOutput',false); % Yet yet another - dummy = @(s) obj.Path.(s).data; - paths = cellfun(dummy, stuff,'UniformOutput',false); +% dummy = @(s) obj.Path.(s).data; +% paths = cellfun(dummy, stuff,'UniformOutput',false); if numel(paths) == 1 paths = paths{1}; Modified: trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m 2011-11-01 10:16:55 UTC (rev 8904) +++ trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m 2011-11-01 10:45:54 UTC (rev 8905) @@ -93,32 +93,3 @@ Paths.(svgpathid).data = pathdata; end endfunction - -%!test -%! figure(1) -%! hold on -%! paths = getSVGPaths_py ('../drawing.svg'); -%! -%! % Get path ids -%! ids = fieldnames(paths); -%! npath = numel(ids); -%! -%! t = linspace (0, 1, 64); -%! -%! for i = 1:npath -%! x = []; y = []; -%! data = paths.(ids(i)).data; -%! -%! for j = 1:numel(data) -%! x = cat (2, x, polyval (data{j}(1,:),t)); -%! y = cat (2, y, polyval (data{j}(2,:),t)); -%! end -%! -%! plot(x,y,'-'); -%! end -%! axis ij -%! if strcmpi(input('You should see drawing.svg [y/n] ','s'),'n') -%! error ("didn't get what was expected."); -%! end -%! close - Modified: trunk/octave-forge/main/geometry/devel/@svg/svg.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/svg.m 2011-11-01 10:16:55 UTC (rev 8904) +++ trunk/octave-forge/main/geometry/devel/@svg/svg.m 2011-11-01 10:45:54 UTC (rev 8905) @@ -56,14 +56,12 @@ endfunction %!test -%! dc = svg('../inst/drawing5.svg'); -%! dc.path -%! dc.Path +%! dc = svg('/home/juanpi/Resources/3rdPartyCode/octave-forge/main/geometry/inst/io/drawing5.svg'); %! dc.getpath() %! dc.pathid %! dc.getpath('path3756') %! -%! dc = svg('../inst/drawing.svg'); +%! dc = svg('/home/juanpi/Resources/3rdPartyCode/octave-forge/main/geometry/inst/io/drawing.svg'); %! ids = dc.pathid; -%! dc.path({ids{[1 3]}}) +%! dc.getpath({ids{[1 3]}}) Modified: trunk/octave-forge/main/geometry/inst/io/@svg/getpath.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/getpath.m 2011-10-24 11:25:44 UTC (rev 8848) +++ trunk/octave-forge/main/geometry/inst/io/@svg/getpath.m 2011-11-01 10:45:54 UTC (rev 8905) @@ -45,12 +45,12 @@ paths = []; if any (tf) stuff = {ids{tf}}; - %{ + for i = 1: numel(stuff) paths{i} = obj.Path.(ids{i}).data; endfor - %} + % Variation % paths = cellfun(@(s) obj.Path.(s).data, stuff,'UniformOutput',false); @@ -61,8 +61,8 @@ % paths = cellfun(@(s) getfield(obj.Path,s).data, stuff,'UniformOutput',false); % Yet yet another - dummy = @(s) obj.Path.(s).data; - paths = cellfun(dummy, stuff,'UniformOutput',false); +% dummy = @(s) obj.Path.(s).data; +% paths = cellfun(dummy, stuff,'UniformOutput',false); if numel(paths) == 1 paths = paths{1}; Modified: trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/loadpaths.m 2011-10-24 11:25:44 UTC (rev 8848) +++ trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m 2011-11-01 10:45:54 UTC (rev 8905) @@ -93,32 +93,3 @@ Paths.(svgpathid).data = pathdata; end endfunction - -%!test -%! figure(1) -%! hold on -%! paths = getSVGPaths_py ('../drawing.svg'); -%! -%! % Get path ids -%! ids = fieldnames(paths); -%! npath = numel(ids); -%! -%! t = linspace (0, 1, 64); -%! -%! for i = 1:npath -%! x = []; y = []; -%! data = paths.(ids(i)).data; -%! -%! for j = 1:numel(data) -%! x = cat (2, x, polyval (data{j}(1,:),t)); -%! y = cat (2, y, polyval (data{j}(2,:),t)); -%! end -%! -%! plot(x,y,'-'); -%! end -%! axis ij -%! if strcmpi(input('You should see drawing.svg [y/n] ','s'),'n') -%! error ("didn't get what was expected."); -%! end -%! close - Modified: trunk/octave-forge/main/geometry/inst/io/@svg/svg.m =================================================================== --- trunk/octave-forge/main/geometry/devel/@svg/svg.m 2011-10-24 11:25:44 UTC (rev 8848) +++ trunk/octave-forge/main/geometry/inst/io/@svg/svg.m 2011-11-01 10:45:54 UTC (rev 8905) @@ -56,14 +56,12 @@ endfunction %!test -%! dc = svg('../inst/drawing5.svg'); -%! dc.path -%! dc.Path +%! dc = svg('../drawing5.svg'); %! dc.getpath() %! dc.pathid %! dc.getpath('path3756') %! -%! dc = svg('../inst/drawing.svg'); +%! dc = svg('../drawing.svg'); %! ids = dc.pathid; -%! dc.path({ids{[1 3]}}) +%! dc.getpath({ids{[1 3]}}) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-01 21:08:04
|
Revision: 8914 http://octave.svn.sourceforge.net/octave/?rev=8914&view=rev Author: jpicarbajal Date: 2011-11-01 21:07:57 +0000 (Tue, 01 Nov 2011) Log Message: ----------- geometry. Updating description and index Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/INDEX Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-01 17:28:27 UTC (rev 8913) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-01 21:07:57 UTC (rev 8914) @@ -1,6 +1,6 @@ Name: Geometry -Version: 1.2.0 -Date: 2011-10-21 +Version: 1.2.1 +Date: 2011-11-1 Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Title: Computational Geometry Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-11-01 17:28:27 UTC (rev 8913) +++ trunk/octave-forge/main/geometry/INDEX 2011-11-01 21:07:57 UTC (rev 8914) @@ -129,5 +129,6 @@ svgload svgnormalize svgpath2polygon + @svg Output data2geo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-02 01:22:46
|
Revision: 8919 http://octave.svn.sourceforge.net/octave/?rev=8919&view=rev Author: jpicarbajal Date: 2011-11-02 01:22:39 +0000 (Wed, 02 Nov 2011) Log Message: ----------- geometry. cleaning up Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/INDEX trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m trunk/octave-forge/main/geometry/inst/io/@svg/svg.m trunk/octave-forge/main/geometry/inst/io/data2geo.m trunk/octave-forge/main/geometry/inst/io/drawing6.svg trunk/octave-forge/main/geometry/inst/shapearea.m Removed Paths: ------------- trunk/octave-forge/main/geometry/devel/@svg/ Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-02 01:22:39 UTC (rev 8919) @@ -1,6 +1,6 @@ Name: Geometry Version: 1.2.1 -Date: 2011-11-1 +Date: 2011-11-2 Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Title: Computational Geometry Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/INDEX 2011-11-02 01:22:39 UTC (rev 8919) @@ -129,6 +129,9 @@ svgload svgnormalize svgpath2polygon - @svg + @svg/svg + @svg/plot + @svg/getpath + @svg/path2polygon Output data2geo Modified: trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/inst/io/@svg/loadpaths.m 2011-11-02 01:22:39 UTC (rev 8919) @@ -34,7 +34,7 @@ npaths = numel (strpath); - %% Convert path data to polygons + %% Convert path data to polynoms for ip = 1:npaths eval (strpath{ip}); @@ -77,7 +77,7 @@ end if ~isempty(point_end) - %% Straight segmet to close the path + %% Straight segment to close the path points(2,:) = point_end; pp = [(points(2,:)-points(1,:))' points(1,:)']; @@ -89,6 +89,8 @@ end end + %% TODO + % pathdata = shapetransform(pathdata); Paths.(svgpathid).data = pathdata; end Modified: trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m 2011-11-02 01:22:39 UTC (rev 8919) @@ -68,6 +68,15 @@ error (typeNotImplemented,[method idx(2).type], class (obj)); end + case 'normalize' + if numel (idx) == 1 % obj.path2polygon doesn't exists + error (method4field, class (obj), method, method); + elseif strcmp (idx(2).type, '()') + out = normalize (obj, idx(2).subs); + else + error (typeNotImplemented,[method idx(2).type], class (obj)); + end + otherwise error ("invalid index for reference of class %s", class (obj) ); endswitch Modified: trunk/octave-forge/main/geometry/inst/io/@svg/svg.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/@svg/svg.m 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/inst/io/@svg/svg.m 2011-11-02 01:22:39 UTC (rev 8919) @@ -22,7 +22,6 @@ ## If no input argument is provided the object is empty. @var{str} can be a filename ## or a string defining an inline SVG. ## -## @seealso{@svn/parsePaths} ## @end deftypefn function svg = svg(name='') @@ -31,7 +30,7 @@ ## SVG data. All the attributes of the <svg> node. ## The field unparsed contains all the attributes that are not being parsed. - svg.Data = struct('height',[],'width',[],'id','null','unparsed',' '); + svg.Data = struct('height',[],'width',[],'id','null','normalized',false); ## SVG metadata. All the attributes of the <metadata> node. ## The field unparsed contains all the attributes that are not being parsed. @@ -48,6 +47,9 @@ if !isempty (name) paths = loadpaths(svg, name); svg.Path = paths; + data = loadsvgdata(svg, name); + svg.Data = data; + svg.Data.normalized = false; elseif !ischar(name) print_usage ; endif Modified: trunk/octave-forge/main/geometry/inst/io/data2geo.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/data2geo.m 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/inst/io/data2geo.m 2011-11-02 01:22:39 UTC (rev 8919) @@ -24,7 +24,7 @@ %% to write. 'spehrical' following by a real number @var{r} indcating that the % polygon describes a spherical surface of radious @var{r}. %% -%% @seealso{polygon2d, @svg/path2polygon} +%% @seealso{polygon2d, @@svg/path2polygon} %% @end deftypefn function strFile = data2geo(data,lc,varargin) @@ -84,7 +84,7 @@ fclose(fid); disp(['DATA2GEO: Geometry file saved to ' outfile]) end -end +endfunction %!demo %! points = [0 0 0; 0.1 0 0; 0.1 .3 0; 0 0.3 0]; @@ -103,9 +103,8 @@ %! T = msh2m_gmsh(filename); %! pdemesh(T.p,T.e,T.t) %! -%! ---------------------------------------------------------------------------- -%! -%! We load the drawing6.svg file into Octave and transform it into a polygon. -%! Teh we create a temporary fiel where the .geo mesh will be written. -%! If the packages msh and fplare available, a mesh is created from the .geo file. - +%! % -------------------------------------------------------------------------- +%! % We load the drawing6.svg file into Octave and transform it into a polygon. +%! % Teh we create a temporary fiel where the .geo mesh will be written. +%! % If the packages msh and fplare available, a mesh is created from the .geo +%! % file. Modified: trunk/octave-forge/main/geometry/inst/io/drawing6.svg =================================================================== --- trunk/octave-forge/main/geometry/inst/io/drawing6.svg 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/inst/io/drawing6.svg 2011-11-02 01:22:39 UTC (rev 8919) @@ -7,38 +7,12 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="124.01972" - height="153.4819" - id="svg2" version="1.1" - inkscape:version="0.48.2 r9819" - sodipodi:docname="drawing6.svg"> + width="119.45756" + height="143.3053" + id="svg2"> <defs id="defs4" /> - <sodipodi:namedview - id="base" - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1.0" - inkscape:pageopacity="0.0" - inkscape:pageshadow="2" - inkscape:zoom="1.979899" - inkscape:cx="112.40798" - inkscape:cy="108.88861" - inkscape:document-units="px" - inkscape:current-layer="layer1" - showgrid="false" - fit-margin-top="0" - fit-margin-left="0" - fit-margin-right="0" - fit-margin-bottom="0" - inkscape:window-width="1440" - inkscape:window-height="817" - inkscape:window-x="0" - inkscape:window-y="27" - inkscape:window-maximized="1" /> <metadata id="metadata7"> <rdf:RDF> @@ -47,20 +21,16 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title /> + <dc:title></dc:title> </cc:Work> </rdf:RDF> </metadata> <g - inkscape:label="Layer 1" - inkscape:groupmode="layer" - id="layer1" - transform="translate(-234.51469,-444.48191)"> + transform="translate(-239.12157,-454.58174)" + id="layer1"> <path - style="fill:none;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none" d="m 260.96378,516.60238 c 30.24071,-2.69283 -21.42438,-1.97992 -11.85009,-13.65203 l 21.42457,-26.11886 c 13.05645,-15.91722 30.86608,-35.97287 54.50085,-2.94599 23.63477,33.02688 45.79537,-26.11007 21.35844,51.55486 -24.43694,77.66493 -14.74615,-18.4048 -36.8249,43.45338 -22.07875,61.85819 -8.61317,-1.90227 -22.09494,13.25697 -13.48177,15.15924 0.70519,-11.24233 -25.04093,-25.77743 -25.74613,-14.53511 -31.71371,-37.07807 -1.473,-39.7709 z" id="path2985" - inkscape:connector-curvature="0" - sodipodi:nodetypes="zsszzzzzz" /> + style="fill:none;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none" /> </g> </svg> Modified: trunk/octave-forge/main/geometry/inst/shapearea.m =================================================================== --- trunk/octave-forge/main/geometry/inst/shapearea.m 2011-11-01 23:30:54 UTC (rev 8918) +++ trunk/octave-forge/main/geometry/inst/shapearea.m 2011-11-02 01:22:39 UTC (rev 8919) @@ -17,7 +17,7 @@ %% @deftypefn {Function File} { @var{a} =} shapearea (@var{pp}) %% Shape is defined with piecewise smooth polynomials. @var{pp} is a %% cell where each elements is a 2-by-(poly_degree+1) array containing -%% @code{px(i,:) = pp{i}(1,:) and py(i,:) = pp{i}(2,:)}. +%% @code{px(i,:) = pp@{i@}(1,:)} and @code{py(i,:) = pp@{i@}(2,:)}. %% %% @end deftypefn This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-02 15:47:13
|
Revision: 8931 http://octave.svn.sourceforge.net/octave/?rev=8931&view=rev Author: jpicarbajal Date: 2011-11-02 15:47:06 +0000 (Wed, 02 Nov 2011) Log Message: ----------- geometry. Adding some functions to manipulate piecewise smooth polygons Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/PKG_ADD trunk/octave-forge/main/geometry/PKG_DEL trunk/octave-forge/main/geometry/inst/shapearea.m Added Paths: ----------- trunk/octave-forge/main/geometry/inst/polygon2shape.m trunk/octave-forge/main/geometry/inst/polygons2d/ trunk/octave-forge/main/geometry/inst/polygons2d/drawPolygon.m trunk/octave-forge/main/geometry/inst/polygons2d/polygons2d.m trunk/octave-forge/main/geometry/inst/shape2polygon.m trunk/octave-forge/main/geometry/inst/shapecentroid.m trunk/octave-forge/main/geometry/inst/shapeplot.m trunk/octave-forge/main/geometry/inst/shapetransform.m trunk/octave-forge/main/geometry/inst/simplifypolygon.m Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-02 15:01:46 UTC (rev 8930) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-02 15:47:06 UTC (rev 8931) @@ -1,6 +1,6 @@ Name: Geometry -Version: 1.2.1 -Date: 2011-11-2 +Version: 1.2.2 +Date: 2011-11-9 Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Title: Computational Geometry Modified: trunk/octave-forge/main/geometry/PKG_ADD =================================================================== --- trunk/octave-forge/main/geometry/PKG_ADD 2011-11-02 15:01:46 UTC (rev 8930) +++ trunk/octave-forge/main/geometry/PKG_ADD 2011-11-02 15:47:06 UTC (rev 8931) @@ -1,5 +1,5 @@ %1 -dirlist = {"geom2d","io"}; +dirlist = {"geom2d","io","polygons2d"}; dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); if (! exist (fullfile (dirname, "inst"), "dir")) Modified: trunk/octave-forge/main/geometry/PKG_DEL =================================================================== --- trunk/octave-forge/main/geometry/PKG_DEL 2011-11-02 15:01:46 UTC (rev 8930) +++ trunk/octave-forge/main/geometry/PKG_DEL 2011-11-02 15:47:06 UTC (rev 8931) @@ -1,5 +1,5 @@ %1 -dirlist = {"geom2d","io"}; +dirlist = {"geom2d","io","polygons2d"}; dirname = fileparts (canonicalize_file_name (mfilename ("fullpath"))); if (! exist (fullfile (dirname, "inst"), "dir")) Copied: trunk/octave-forge/main/geometry/inst/polygon2shape.m (from rev 8918, trunk/octave-forge/main/mechanics/inst/private/polygon2shape.m) =================================================================== --- trunk/octave-forge/main/geometry/inst/polygon2shape.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/polygon2shape.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,34 @@ +## Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (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/>. + +function shape = polygon2shape (polygon) + + # Filter colinear points + polygon = simplifypolygon (polygon); + + np = size(polygon,1); + # polygonal shapes are memory inefficient!! + # TODO filter the regions where edge angles are canging slowly and fit + # polynomial of degree 3; + pp = nan (2*np,2); + + # Transform edges into polynomials of degree 1; + # pp = [(p1-p0) p0]; + pp(:,1) = diff(polygon([1:end 1],:)).'(:); + pp(:,2) = polygon.'(:); + + shape = mat2cell(pp, 2*ones (1,np), 2); + +endfunction Added: trunk/octave-forge/main/geometry/inst/polygons2d/drawPolygon.m =================================================================== --- trunk/octave-forge/main/geometry/inst/polygons2d/drawPolygon.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/polygons2d/drawPolygon.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,144 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <dav...@gr...> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <car...@if...> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{h} = } drawPolygon (@var{coord}) +%% @deftypefnx {Function File} {@var{h} = } drawPolygon (@var{px}, @var{py}) +%% @deftypefnx {Function File} {@var{h} = } drawPolygon (@var{polys}) +%% Draw a polygon specified by a list of points. +%% +%% drawPolygon(COORD); +%% Packs coordinates in a single [N*2] array. +%% +%% drawPolygon(PX, PY); +%% Specifies coordinates in separate arrays. +%% +%% drawPolygon(POLYS) +%% Packs coordinate of several polygons in a cell array. Each element of +%% the array is a Ni*2 double array. +%% +%% H = drawPolygon(...); +%% Also return a handle to the list of line objects. +%% +%% +%% @seealso{polygons2d, drawCurve} +%% @end deftypefn + +function varargout = drawPolygon(varargin) + + % check input + if isempty(varargin) + error('need to specify a polygon'); + end + + var = varargin{1}; + + %% Manage cell arrays of polygons + + % case of a set of polygons stored in a cell array + if iscell(var) + N = length(var); + h = zeros(N, 1); + for i = 1:N + state = ishold(gca); + hold on; + % check for empty polygons + if ~isempty(var{i}) + h(i) = drawPolygon(var{i}, varargin{2:end}); + end + if ~state + hold off + end + end + + if nargout > 0 + varargout = {h}; + end + + return; + end + + + %% Parse coordinates and options + + % Extract coordinates of polygon vertices + if size(var, 2) > 1 + % first argument is a polygon array + px = var(:, 1); + py = var(:, 2); + varargin(1) = []; + else + % arguments 1 and 2 correspond to x and y coordinate respectively + if length(varargin) < 2 + error('Should specify either a N-by-2 array, or 2 N-by-1 vectors'); + end + + px = varargin{1}; + py = varargin{2}; + varargin(1:2) = []; + end + + % set default line format + if isempty(varargin) + varargin = {'b-'}; + end + + % check case of polygons with holes + if sum(isnan(px(:))) > 0 + polygons = splitPolygons([px py]); + h = drawPolygon(polygons); + + if nargout > 0 + varargout = {h}; + end + + return; + end + + + %% Draw the polygon + + % ensure last point is the same as the first one + px(size(px, 1)+1, :) = px(1,:); + py(size(py, 1)+1, :) = py(1,:); + + % draw the polygon outline + h = plot(px, py, varargin{:}); + + % format output arg + if nargout > 0 + varargout = {h}; + end + +endfunction + Added: trunk/octave-forge/main/geometry/inst/polygons2d/polygons2d.m =================================================================== --- trunk/octave-forge/main/geometry/inst/polygons2d/polygons2d.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/polygons2d/polygons2d.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,180 @@ +%% 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} {} polygons2d () +%% MATGEOM-POLYGONS +%% +%% The 'polygons' module contains functions operating on shapes composed +%% of a vertex list, like polygons or polylines. +%% +%% We call 'polyline' the curve defined by a series of vertices. +%% A polyline can be either closed or open, depending on whether the last +%% vertex is connected to the first one or not. This can be given as an +%% option is some functions in the module. +%% A 'polygon' is the planar domain delimited by a closed polyline. We +%% sometimes want to consider 'complex polygons', whose boundary is +%% composed of several disjoint domains. The domain defined by a single +%% closed polyline is called 'simple polygon'. +%% We call 'curve' a polyline with many vertices, such that the polyline +%% can be considered as a discrete approximation of a "real" curve. +%% +%% A simple polygon or polyline is represented by a N-by-2 array, each row +%% of the array representing the coordinates of a vertex. +%% Simple polygons are assumed to be closed, so there is no need to repeat +%% the first vertex at the end. +%% As both polygons and polylines can be represented by a list of vertex +%% coordinates, some functions also consider the vertex list itself. Such +%% functions are prefixed by 'pointSet'. Also, many functions prefixed by +%% 'polygon' or 'polyline' works also on the other type of shape. +%% +%% For multiple-connected polygons, the different connected boundaries are +%% separated by a row [NaN NaN]. +%% +%% For some functions, the orientation of the polygon can be relevant: CCW +%% stands for 'Conter-Clockwise' (positive orientation), CW stands for +%% 'Clockwise'. +%% +%% Polylines are parametrized in the following way: +%% * the i-th vertex is located at position i-1 +%% * points of the i-th edge have positions ranging linearly from i-1 to i +%% The parametrization domain for an open polyline is from 0 to Nv-1, and +%% from 0 to Nv for a closed polyline (positions 0 and Nv correspond to +%% the same point). +%% +%% Example: +%% % Simple polygon: +%% P1 = [1 1;2 1;2 2;1 2]; +%% drawPolygon(P1); +%% axis([0 5 0 5]); +%% % Multiple polygon: +%% P2 = [10 10;40 10;40 40;10 40;NaN NaN;20 20;20 30;30 30;30 20]; +%% figure;drawPolygon(P2); axis([0 50 0 50]); +%% +%% +%% Point Sets +%% pointSetBounds - Bounding box of a set of points +%% pointSetsAverage - Compute the average of several point sets +%% minimumCaliperDiameter - Minimum caliper diameter of a set of points +%% findPoint - Find index of a point in an set from its coordinates +%% +%% Polylines +%% polylinePoint - Extract a point from a polyline +%% polylineLength - Return length of a polyline given as a list of points +%% polylineCentroid - Compute centroid of a curve defined by a series of points +%% polylineSubcurve - Extract a portion of a polyline +%% reversePolyline - Reverse a polyline, by iterating vertices from the end +%% isPointOnPolyline - Test if a point belongs to a polyline +%% projPointOnPolyline - Compute position of a point projected on a polyline +%% distancePointPolyline - Compute shortest distance between a point and a polyline +%% distancePolylines - Compute the shortest distance between 2 polylines +%% intersectPolylines - Find the common points between 2 polylines +%% polylineSelfIntersections - Find self-intersections points of a polyline +%% +%% Curves (polylines with lot of vertices) +%% parametrize - Parametrization of a curve, based on edges length +%% curvature - Estimate curvature of a polyline defined by points +%% cart2geod - Convert cartesian coordinates to geodesic coord. +%% geod2cart - Convert geodesic coordinates to cartesian coord. +%% curveMoment - Compute inertia moment of a 2D curve +%% curveCMoment - Compute centered inertia moment of a 2D curve +%% curveCSMoment - Compute centered scaled moment of a 2D curve +%% +%% Polygons +%% polygonPoint - Extract a point from a polygon +%% polygonSubcurve - Extract a portion of a polygon +%% reversePolygon - Reverse a polygon, by iterating vertices from the end +%% projPointOnPolygon - Compute position of a point projected on a polygon +%% splitPolygons - Convert a NaN separated polygon list to a cell array of polygons +%% clipPolygon - Clip a polygon with a rectangular box +%% clipPolygonHP - Clip a polygon with a Half-plane defined by a directed line +%% intersectLinePolygon - Intersection points between a line and a polygon +%% intersectRayPolygon - Intersection points between a ray and a polygon +%% polygonSelfIntersections - Find-self intersection points of a polygon +%% convexHull - Convex hull of a set of points +%% polygonLoops - Divide a possibly self-intersecting polygon into a set of simple loops +%% expandPolygon - Expand a polygon by a given (signed) distance +%% medialAxisConvex - Compute medial axis of a convex polygon +%% +%% Measures on Polygons +%% isPointInPolygon - Test if a point is located inside a polygon +%% polygonContains - Test if a point is contained in a multiply connected polygon +%% polygonCentroid - Compute the centroid (center of mass) of a polygon +%% polygonArea - Compute the signed area of a polygon +%% polygonLength - Perimeter of a polygon +%% polygonNormalAngle - Compute the normal angle at a vertex of the polygon +%% polygonBounds - Compute the bounding box of a polygon +%% distancePointPolygon - Compute shortest distance between a point and a polygon +%% distancePolygons - Compute the shortest distance between 2 polygons +%% +%% Triangles +%% isPointInTriangle - Test if a point is located inside a triangle +%% triangleArea - Area of a triangle +%% +%% Functions from stochastic geometry +%% steinerPoint - Compute steiner point (weighted centroid) of a polygon +%% steinerPolygon - Create a Steiner polygon from a set of vectors +%% supportFunction - Compute support function of a polygon +%% convexification - Compute the convexification of a polygon +%% +%% Input, Output and conversions +%% readPolygon - Read a polygon stored in a file +%% polygonToRow - Convert polygon coordinates to a row vector +%% rowToPolygon - Create a polygon from a row vector +%% rectAsPolygon - Convert a (centered) rectangle into a series of points +%% +%% Drawing functions +%% drawPolyline - Draw a polyline specified by a list of points +%% drawPolygon - Draw a polygon specified by a list of points +%% fillPolygon - Fill a polygon specified by a list of points +%% +%% +%% Credits: +%% * function intersectPolylines uses the 'interX' contribution from "NS" +%% (file exchange 22441, called 'curve-intersections') +%% +%% ----- +%% Author: David Legland +%% e-mail: dav...@gr... +%% created the 07/11/2005. +%% Homepage: http://matgeom.sourceforge.net/ +%% http://www.pfl-cepia.inra.fr/index.php?page=geom2d +%% Copyright INRA - Cepia Software Platform. +%% +%% @end deftypefn% + +function polygons2d () + +help('polygons2d'); + +endfunction Copied: trunk/octave-forge/main/geometry/inst/shape2polygon.m (from rev 8918, trunk/octave-forge/main/mechanics/inst/private/shape2polygon.m) =================================================================== --- trunk/octave-forge/main/geometry/inst/shape2polygon.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/shape2polygon.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,46 @@ +## Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (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/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{polygon} = } shape2polygon (@var{shape}) +%% @deftypefnx {Function File} {@var{polygon} = } shape2polygon (@var{shape},@var{N}) +%% Transforms a 2D shape described by piecewise smooth polynomials into a polygon. +%% +%% @seealso{drawPolygon} +%% @end deftypefn +function polygon = shape2polygon (shape, N=16) + + polygon = cell2mat ( ... + cellfun(@(x) func (x,N), shape,'UniformOutput',false) ); + + if size(polygon, 1) == 1 + polygon(2,1) = polyval(shape{1}(1,:),1); + polygon(2,2) = polyval(shape{1}(2,:),1); + end + +endfunction + +function y = func(x,N) + + if size(x,2) > 2 + t = linspace(0,1-1/N,N).'; + y(:,1) = polyval(x(1,:),t); + y(:,2) = polyval(x(2,:),t); + else + y = x(:,2).'; + end + +endfunction + Modified: trunk/octave-forge/main/geometry/inst/shapearea.m =================================================================== --- trunk/octave-forge/main/geometry/inst/shapearea.m 2011-11-02 15:01:46 UTC (rev 8930) +++ trunk/octave-forge/main/geometry/inst/shapearea.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -24,7 +24,10 @@ function A = shapearea (shape) A = sum(cellfun (@Aint, shape)); - + if A < 0 + A = -A; + end + endfunction function dA = Aint (x) Added: trunk/octave-forge/main/geometry/inst/shapecentroid.m =================================================================== --- trunk/octave-forge/main/geometry/inst/shapecentroid.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/shapecentroid.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,71 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software; you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation; either version 3 of the License, or +%% (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/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} { @var{cm} =} shapecentroid (@var{pp}) +%% Centroid of a plane shape. +%% +%% The shape is defined with piecewise smooth polynomials. @var{pp} is a +%% cell where each elements is a 2-by-(poly_degree+1) matrix containing +%% @code{px(i,:) = pp@{i@}(1,:)} and @code{py(i,:) = pp@{i@}(2,:)}. +%% +%% @seealso{shapearea} +%% @end deftypefn + +function cm = shapecentroid (shape) + + cm = sum( cell2mat ( cellfun (@CMint, shape, 'UniformOutput', false))); + A = shapearea(shape); + cm = cm / A; + +endfunction + +function dcm = CMint (x) + + px = x(1,:); + py = x(2,:); + Px = polyint (conv(conv (px , px)/2 , polyderiv (py))); + Py = polyint (conv(-conv (py , py)/2 , polyderiv (px))); + + dcm = zeros (1,2); + dcm(1) = diff(polyval(Px,[0 1])); + dcm(2) = diff(polyval(Py,[0 1])); + +endfunction + +%!demo % non-convex bezier shape +%! weirdhearth ={[-17.6816 -34.3989 7.8580 3.7971; ... +%! 15.4585 -28.3820 -18.7645 9.8519]; ... +%! [-27.7359 18.1039 -34.5718 3.7878; ... +%! -40.7440 49.7999 -25.5011 2.2304]}; +%! CoM = shapecentroid (weirdhearth) + +%!test +%! square = {[1 -0.5; 0 -0.5]; [0 0.5; 1 -0.5]; [-1 0.5; 0 0.5]; [0 -0.5; -1 0.5]}; +%! CoM = shapecentroid (square); +%! assert (CoM, [0 0], sqrt(eps)); + +%!test +%! circle = {[1.715729 -6.715729 0 5; ... +%! -1.715729 -1.568542 8.284271 0]; ... +%! [1.715729 1.568542 -8.284271 0; ... +%! 1.715729 -6.715729 0 5]; ... +%! [-1.715729 6.715729 0 -5; ... +%! 1.715729 1.568542 -8.284271 0]; ... +%! [-1.715729 -1.568542 8.284271 0; ... +%! -1.715729 6.715729 0 -5]}; +%! CoM = shapecentroid (circle); +%! assert (CoM , [0 0], 5e-3); + Added: trunk/octave-forge/main/geometry/inst/shapeplot.m =================================================================== --- trunk/octave-forge/main/geometry/inst/shapeplot.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/shapeplot.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,28 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{h} = } shapeplot (@var{shape}) +%% @deftypefnx {Function File} {@var{h} = } shapeplot (@var{shape}, @var{N}) +%% Pots a 2D shape defined by piecewise smooth polynomials. +%% +%% @end deftypefn + +function h = shapeplot(shape, N = 16, varargin) + + p = shape2polygon(shape, N); + h = drawPolygon(p,varargin{:}); + +endfunction Added: trunk/octave-forge/main/geometry/inst/shapetransform.m =================================================================== --- trunk/octave-forge/main/geometry/inst/shapetransform.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/shapetransform.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,137 @@ +%% Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +%% +%% This program is free software: you can redistribute it and/or modify +%% it under the terms of the GNU General Public License as published by +%% the Free Software Foundation, either version 3 of the License, or +%% any later version. +%% +%% This program is distributed in the hope that it will be useful, +%% but WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +%% GNU General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License +%% along with this program. If not, see <http://www.gnu.org/licenses/>. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{nshape} = } shapetransform (@var{shape}, @var{T}) +%% Applies transformation to a shape defined by piecewise smooth polynomials. +%% +%% Format of @var{T} can be one of : +%% [c] , [a b] , [a b c] or [a b c] +%% [f] [d e] [d e f] [d e f] +%% [0 0 1] +%% +%% @end deftypefn + +function nshape = shapetransform (shape, Trans) + + if size(Trans,1) < 2 + error("geometry:shapetransform:InvalidArgument", ... + "Transformation can be 2x1, 2x2, 2x3 or 3x3. See help."); + end + + if ~iscell(shape) + error("geometry:shapetransform:InvalidArgument", "Shape must be a cell of 2D polynomials."); + end + + A =[]; + v = []; + + switch size(Trans,2) + case 1 + % Just translation + v = Trans; + + case 2 + % Just linear transformation + A = Trans; + + case 3 + % Affine transform + A = Trans(1:2,1:2); + v = Trans(1:2,3); + end + + nshape = cellfun (@(x)polytransform (x,A,v), shape, 'UniformOutput',false); + +endfunction + +function np = polytransform(p,A,v) + + np = p; + if ~isempty (A) + np = A*np; + end + if ~isempty (v) + np(:,end) = np(:,end) + v; + end + +endfunction + +%!demo +%! shape = {[-93.172 606.368 -476.054 291.429; ... +%! -431.196 637.253 11.085 163.791]; ... +%! [-75.3626 -253.2337 457.1678 328.5714; ... +%! 438.7659 -653.6278 -7.9953 380.9336]; ... +%! [-89.5841 344.9716 -275.3876 457.1429; ... +%! -170.3613 237.8858 1.0469 158.0765];... +%! [32.900 -298.704 145.804 437.143; ... +%! -243.903 369.597 -34.265 226.648]; ... +%! [-99.081 409.127 -352.903 317.143; ... +%! 55.289 -114.223 -26.781 318.076]; ... +%! [-342.231 191.266 168.108 274.286; ... +%! 58.870 -38.083 -89.358 232.362]}; +%! +%! A = shapearea (shape); +%! T = eye(2)/sqrt(A); +%! shape = shapetransform (shape,T); +%! T = shapecentroid (shape)(:); +%! shape = shapetransform (shape,-T + [2; 0]); +%! +%! cla +%! shapeplot (shape,10,'-r','linewidth',2) +%! hold on +%! for i = 1:9 +%! T = createRotation (i*pi/5)(1:2,1:2)/exp(0.3*i); +%! shapeplot (shapetransform(shape, T), 10, 'color',rand(1,3),'linewidth',2); +%! end +%! hold off +%! axis tight +%! axis square + + +%!shared shape +%! shape = {[-93.172 606.368 -476.054 291.429; ... +%! -431.196 637.253 11.085 163.791]; ... +%! [-75.3626 -253.2337 457.1678 328.5714; ... +%! 438.7659 -653.6278 -7.9953 380.9336]; ... +%! [-89.5841 344.9716 -275.3876 457.1429; ... +%! -170.3613 237.8858 1.0469 158.0765];... +%! [32.900 -298.704 145.804 437.143; ... +%! -243.903 369.597 -34.265 226.648]; ... +%! [-99.081 409.127 -352.903 317.143; ... +%! 55.289 -114.223 -26.781 318.076]; ... +%! [-342.231 191.266 168.108 274.286; ... +%! 58.870 -38.083 -89.358 232.362]}; + +%!test +%! v = shapecentroid (shape)(:); +%! nshape = shapetransform (shape, -v); +%! vn = shapecentroid (nshape)(:); +%! assert(vn,[0; 0],1e-2); + +%!test +%! v = shapecentroid (shape)(:); +%! T = createLineReflection([0 0 1 0]); +%! nshape = shapetransform (shape, T); +%! vn = shapecentroid (nshape)(:); +%! assert(vn,T(1:2,1:2)*v); + +%!test +%! v = shapecentroid (shape)(:); +%! T = createRotation(v.',pi/2); +%! nshape = shapetransform (shape, T); +%! vn = shapecentroid (nshape)(:); +%! assert(vn,v,1e-2); + Copied: trunk/octave-forge/main/geometry/inst/simplifypolygon.m (from rev 8918, trunk/octave-forge/main/mechanics/inst/private/simplifypolygon.m) =================================================================== --- trunk/octave-forge/main/geometry/inst/simplifypolygon.m (rev 0) +++ trunk/octave-forge/main/geometry/inst/simplifypolygon.m 2011-11-02 15:47:06 UTC (rev 8931) @@ -0,0 +1,29 @@ +## Copyright (c) 2011 Juan Pablo Carbajal <car...@if...> +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (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/>. + +function polygonsimp = simplifypolygon (polygon) + + # Filter colinear points + edges = diff(polygon([1:end 1],:)); + ned = size(edges,1); + nxt = [2:ned 1]; + + # check if consecutive edges are parallel + para = edges(:,1).*edges(nxt,2) - edges(:,2).*edges(nxt,1); + ind = abs(para) > sqrt(eps); + + polygonsimp = polygon(circshift (ind,1),:); + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-03 19:40:44
|
Revision: 8957 http://octave.svn.sourceforge.net/octave/?rev=8957&view=rev Author: jpicarbajal Date: 2011-11-03 19:40:37 +0000 (Thu, 03 Nov 2011) Log Message: ----------- geometry. Embettered subref Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/PKG_ADD trunk/octave-forge/main/geometry/PKG_DEL trunk/octave-forge/main/geometry/inst/io/@svg/normalize.m trunk/octave-forge/main/geometry/inst/io/@svg/plot.m trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-03 18:49:11 UTC (rev 8956) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-03 19:40:37 UTC (rev 8957) @@ -1,5 +1,5 @@ Name: Geometry -Version: 1.2.2 +Version: 1.2.3 Date: 2011-11-9 Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Modified: trunk/octave-forge/main/geometry/PKG_ADD =================================================================== --- trunk/octave-forge/main/geometry/PKG_ADD 2011-11-03 18:49:11 UTC (rev 8956) +++ trunk/octave-forge/main/geometry/PKG_ADD 2011-11-03 19:40:37 UTC (rev 8957) @@ -6,6 +6,11 @@ for ii=1:length (dirlist) addpath ( [ dirname filesep dirlist{ii}],"-end") endfor +else + warning("geometry:Devel","Adding path for testing."); + for ii=1:length(dirlist) + addpath ([ dirname "/inst/" dirlist{ii}]) + endfor endif warning('off', 'Octave:fopen-file-in-path'); Modified: trunk/octave-forge/main/geometry/PKG_DEL =================================================================== --- trunk/octave-forge/main/geometry/PKG_DEL 2011-11-03 18:49:11 UTC (rev 8956) +++ trunk/octave-forge/main/geometry/PKG_DEL 2011-11-03 19:40:37 UTC (rev 8957) @@ -7,6 +7,11 @@ ## Run this if the package is installed rmpath ( [ dirname filesep dirlist{ii}]) end -end +else + warning("geometry:Devel","Removing path for testing."); + for ii=1:length(dirlist) + rmpath ([ dirname "/inst/" dirlist{ii}]) + endfor +endif clear dirlist dirname Modified: trunk/octave-forge/main/geometry/inst/io/@svg/normalize.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/@svg/normalize.m 2011-11-03 18:49:11 UTC (rev 8956) +++ trunk/octave-forge/main/geometry/inst/io/@svg/normalize.m 2011-11-03 19:40:37 UTC (rev 8957) @@ -20,8 +20,6 @@ function [SVGn bb] = normalize (obj) - warning("svg:Devel","This function is under development and is not working correctly."); - SVGn = obj; bb = []; if ! obj.Data.normalized Modified: trunk/octave-forge/main/geometry/inst/io/@svg/plot.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/@svg/plot.m 2011-11-03 18:49:11 UTC (rev 8956) +++ trunk/octave-forge/main/geometry/inst/io/@svg/plot.m 2011-11-03 19:40:37 UTC (rev 8957) @@ -43,7 +43,7 @@ end end hold off + axis tight axis equal - endfunction Modified: trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m =================================================================== --- trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m 2011-11-03 18:49:11 UTC (rev 8956) +++ trunk/octave-forge/main/geometry/inst/io/@svg/subsref.m 2011-11-03 19:40:37 UTC (rev 8957) @@ -19,87 +19,113 @@ ## @end deftypefn function varargout = subsref (obj, idx) + + persistent __method__ + if isempty(__method__) + + __method__ = struct(); + + __method__.plot = @(o,a) plot (o, a); + __method__.getpath = @(o,a) getpath (o, a); + __method__.pathid = @(o,a) fieldnames(o.Path); + __method__.path2polygon = @(o,a) path2polygon (o, a); + __method__.normalize = @(o,a) normalize (o, a); + __method__.height = @(o,a) o.Data.height; + __method__.width = @(o,a) o.Data.width; + + debug="first call" + end + if ( !strcmp (class (obj), 'svg') ) - error ("object must be of the svg class but '%s' was used", class (obj) ); + error ("Object must be of the svg class but '%s' was used", class (obj) ); elseif ( idx(1).type != '.' ) - error ("invalid index for class %s", class (obj) ); + error ("Invalid index for class %s", class (obj) ); endif - ## the following at the end may allow to use the obj.method notation one day -# ori = inputname(1); -# assignin('caller', ori, inPar); + # Error strings + method4field = "Class %s has no field %s. Use %s() for the method."; + typeNotImplemented = "%s no implemented for class %s."; -# Error strings - method4field = "Class %s has no field %s. Use %s() for the method."; - typeNotImplemented = "%s no implemented for Class %s."; + method = idx(1).subs + debug="Following calls" + if ~isfield(__method__, method) + error('Unknown method %s.',method); + else + fhandle = __method__.(method); + end + + if strcmp(method,'normalize') + warning("svg:Devel","Not returning second output argument of %s use method(obj) API to get it",method); + end + + if numel (idx) == 1 % can't access properties, only methods + + error (method4field, class (obj), method, method); + + end + + if strcmp (idx(2).type, '()') + + args = idx(2).subs; + out = fhandle (obj, args{:}); + + else + + error (typeNotImplemented,[method idx(2).type], class (obj)); + + end + +endfunction + +%{ +06:42:38 PM) jwe: KaKiLa: yes, I looked at it. I still don't think you should try to fake the obj.method() style, but if you insist, you could probably shorten your code by just using case {'meth1', 'meth2', ...} and then retval = feval (method, args); ... +(06:43:12 PM) jwe: I don't see why you should repeat the same code when the only thing that changes is the method name. +(06:44:35 PM) jwe: Or, I think you could create a persistent structure with all the method names as fields, and each field would hold a function handle for that method. +(06:45:28 PM) jwe: then I think you could write fhandle = s(method); retval = fhandle (args); +(06:45:38 PM) KaKiLa: jwe: you are right, of course. I was no improving code yet...want to get to minimal functionality...very close now. I will implement one of your suggestions in the next release. Thanks! +(06:45:46 PM) jwe: sorry, fhandle = s.(method); + +persistent __method__ +if isempty(__method__) + + __method__ = struct(); - method = idx(1).subs; + __method__.plot = @(o,a) plot (o, a); + __method__.getpath = @(o,a) getpath (o, a); + __method__.pathid = @(o,a) fieldnames(o.Path); + __method__.path2polygon = @(o,a) path2polygon (o, a); + __method__.normalize = @(o,a) normalize (o, a); + __method__.height = @(o,a) o.Data.height; + __method__.width = @(o,a) o.Data.width; - switch method - case 'plot' - - if numel (idx) == 1 % obj.plot doesn't exists - error (method4field, class (obj), method, method); - elseif strcmp (idx(2).type, '()') - out = plot (obj, idx(2).subs); - if nargout >= 1 - varargout{1} = out; - end - else - error (typeNotImplemented,[method idx(2).type], class (obj)); - end - - case 'getpath' +end - if numel (idx) == 1 % obj.getpath doesn't exists - error (method4field, class (obj), method, method); - elseif strcmp (idx(2).type, '()') - out = getpath (obj, idx(2).subs); - if nargout >= 1 - varargout{1} = out; - end - else - error (typeNotImplemented,[method idx(2).type], class (obj)); - end +method = idx(1).subs; +if ~isfield(__method__, method) + error('Unknown method %s.',method); +else + fhandle = __method__.(method); +end - case 'pathid' - out = fieldnames(obj.Path); - if nargout >= 1 - varargout{1} = out; - end +if strcmp(method,'normalize') + warning("svg:Devel","Not returning second output argument of %s use method(obj) API to get it",method); +end - case 'path2polygon' - if numel (idx) == 1 % obj.path2polygon doesn't exists - error (method4field, class (obj), method, method); - elseif strcmp (idx(2).type, '()') - out = path2polygon (obj, idx(2).subs); - if nargout >= 1 - varargout{1} = out; - end +if numel (idx) == 1 % can't access properties, only methods - else - error (typeNotImplemented,[method idx(2).type], class (obj)); - end + error (method4field, class (obj), method, method); - case 'normalize' - if numel (idx) == 1 % obj.path2polygon doesn't exists - error (method4field, class (obj), method, method); - elseif strcmp (idx(2).type, '()') - [out out2] = normalize (obj, idx(2).subs); - pause - if nargout >= 1 - varargout{1} = out; - if nargout >= 2 - varargout{2} = out2; - end - end - varargout - else - error (typeNotImplemented,[method idx(2).type], class (obj)); - end +end - otherwise - error ("invalid index for reference of class %s", class (obj) ); - endswitch +if strcmp (idx(2).type, '()') -endfunction + args = idx(2).subs; + out = fhandle (obj, args{:}); + +else + + error (typeNotImplemented,[method idx(2).type], class (obj)); + +end + +}% This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jpi...@us...> - 2011-11-03 22:12:58
|
Revision: 8967 http://octave.svn.sourceforge.net/octave/?rev=8967&view=rev Author: jpicarbajal Date: 2011-11-03 22:12:52 +0000 (Thu, 03 Nov 2011) Log Message: ----------- geometry. DESCRIPTION and INDEX Modified Paths: -------------- trunk/octave-forge/main/geometry/DESCRIPTION trunk/octave-forge/main/geometry/INDEX Modified: trunk/octave-forge/main/geometry/DESCRIPTION =================================================================== --- trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-03 21:58:07 UTC (rev 8966) +++ trunk/octave-forge/main/geometry/DESCRIPTION 2011-11-03 22:12:52 UTC (rev 8967) @@ -1,5 +1,5 @@ Name: Geometry -Version: 1.2.3 +Version: 1.2.2 Date: 2011-11-9 Author: David Legland <dav...@gr...>, Juan Pablo Carbajal <car...@if...> Maintainer: Juan Pablo Carbajal <car...@if...> Modified: trunk/octave-forge/main/geometry/INDEX =================================================================== --- trunk/octave-forge/main/geometry/INDEX 2011-11-03 21:58:07 UTC (rev 8966) +++ trunk/octave-forge/main/geometry/INDEX 2011-11-03 22:12:52 UTC (rev 8967) @@ -143,6 +143,9 @@ @svg/plot @svg/getpath @svg/path2polygon + @svg/normalize + @svg/pathid + @svg/height + @svg/width Output data2geo - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |