Mercurial > forge
changeset 8635:00f1937ddf32 octave-forge
geometry. Adding all draw functions
author | jpicarbajal |
---|---|
date | Fri, 21 Oct 2011 18:40:53 +0000 |
parents | c9536da4e0ec |
children | 9efa95ad18cf |
files | main/geometry/geom2d/inst/drawCenteredEdge.m main/geometry/geom2d/inst/drawCircle.m main/geometry/geom2d/inst/drawCircleArc.m main/geometry/geom2d/inst/drawEllipse.m main/geometry/geom2d/inst/drawEllipseArc.m main/geometry/geom2d/inst/drawLabels.m main/geometry/geom2d/inst/drawOrientedBox.m main/geometry/geom2d/inst/drawParabola.m main/geometry/geom2d/inst/drawRect.m main/geometry/geom2d/inst/drawShape.m main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m main/geometry/matGeom_raw/geom2d/drawCircle.m main/geometry/matGeom_raw/geom2d/drawCircleArc.m main/geometry/matGeom_raw/geom2d/drawEllipse.m main/geometry/matGeom_raw/geom2d/drawEllipseArc.m main/geometry/matGeom_raw/geom2d/drawLabels.m main/geometry/matGeom_raw/geom2d/drawOrientedBox.m main/geometry/matGeom_raw/geom2d/drawParabola.m main/geometry/matGeom_raw/geom2d/drawRect.m main/geometry/matGeom_raw/geom2d/drawRect2.m main/geometry/matGeom_raw/geom2d/drawShape.m |
diffstat | 21 files changed, 1283 insertions(+), 1444 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawCenteredEdge.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,152 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawCircle.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,132 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawCircleArc.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,123 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawEllipse.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,140 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawEllipseArc.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,161 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawLabels.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,108 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} 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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawOrientedBox.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,113 @@ +%% Copyright (c) 2011, INRA +%% 2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawParabola.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,141 @@ +%% Copyright (c) 2011, INRA +%% 2006-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawRect.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,104 @@ +%% Copyright (c) 2011, INRA +%% 2003-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} {@var{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 +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/geom2d/inst/drawShape.m Fri Oct 21 18:40:53 2011 +0000 @@ -0,0 +1,109 @@ +%% Copyright (c) 2011, INRA +%% 2005-2011, David Legland <david.legland@grignon.inra.fr> +%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +%% +%% All rights reserved. +%% (simplified BSD License) +%% +%% Redistribution and use in source and binary forms, with or without +%% modification, are permitted provided that the following conditions are met: +%% +%% 1. Redistributions of source code must retain the above copyright notice, this +%% list of conditions and the following disclaimer. +%% +%% 2. Redistributions in binary form must reproduce the above copyright notice, +%% this list of conditions and the following disclaimer in the documentation +%% and/or other materials provided with the distribution. +%% +%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +%% POSSIBILITY OF SUCH DAMAGE. +%% +%% The views and conclusions contained in the software and documentation are +%% those of the authors and should not be interpreted as representing official +%% policies, either expressed or implied, of copyright holder. + +%% -*- texinfo -*- +%% @deftypefn {Function File} 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 +
--- a/main/geometry/matGeom_raw/geom2d/drawCenteredEdge.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function 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
--- a/main/geometry/matGeom_raw/geom2d/drawCircle.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function 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
--- a/main/geometry/matGeom_raw/geom2d/drawCircleArc.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawCircleArc(varargin) -%DRAWCIRCLEARC 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') -% -% See also: -% circles2d, drawCircle, drawEllipse -% -% -------- -% author: David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 12/12/2003. -% - -% HISTORY -% 2004-05-03 angles are given as radians -% 2007-06-27 Now uses angle extent -% 2011-03-30 use angles in degrees -% 2011-06-09 add support for line styles - -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
--- a/main/geometry/matGeom_raw/geom2d/drawEllipse.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,150 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawEllipse(varargin) -%DRAWELLIPSE 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; -% -% See also: -% ellipses2d, drawCircle, drawEllipseArc, ellipseAsPolygon -% -% --------- -% author : David Legland -% e-mail: david.legland@grignon.inra.fr -% INRA - TPV URPOI - BIA IMASTE -% created the 11/12/2003. -% - -% HISTORY -% 2004-01-08 returns coord of points when 2 output args are asked -% 2004-01-08 fix bug in extraction of input parameters, theta was not -% initialized in case of array of size 1*5 -% 2005-08-13 uses radians instead of degrees -% 2008-02-21 add support for drawing styles, code cleanup -% 2011-03-30 use degrees instead of radians, remove [x y] = ... format - - -%% 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 - -% 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 -
--- a/main/geometry/matGeom_raw/geom2d/drawEllipseArc.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,166 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawEllipseArc(varargin) -%DRAWELLIPSEARC 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) -% -% See also: -% ellipses2d, drawEllipse, drawCircleArc -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 12/12/2003. -% - - -% HISTORY -% 2008/10/10 uses fixed number of points for arc. -% 2011-03-30 use angles in degrees - -%% 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
--- a/main/geometry/matGeom_raw/geom2d/drawLabels.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawLabels(varargin) -%DRAWLABELS 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. -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 15/12/2003. -% - -% HISTORY -% 09/03/2007: (re)implement it... - -% 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
--- a/main/geometry/matGeom_raw/geom2d/drawOrientedBox.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawOrientedBox(box, varargin) -%DRAWORIENTEDBOX 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); -% -% See also -% drawPolygon, drawRect, drawBox -% -% ------ -% Author: David Legland -% e-mail: david.legland@grignon.inra.fr -% Created: 2011-05-09, using Matlab 7.9.0.529 (R2009b) -% Copyright 2011 INRA - Cepia Software Platform. - -% HISTORY -% 2011-07-22 simplifies code - - -%% 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
--- a/main/geometry/matGeom_raw/geom2d/drawParabola.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawParabola(varargin) -%DRAWPARABOLA 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; -% -% See Also: -% drawCircle, drawEllipse -% -% --------- -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 02/06/2006. -% - -% HISTORY -% 2010-11-17 rewrite, change parametrisation, update doc -% 2011-03-30 use degrees for angle - -% 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 -
--- a/main/geometry/matGeom_raw/geom2d/drawRect.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawRect(varargin) -%DRAWRECT 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. -% -% -% See Also: -% drawRect2, drawBox, drawOrientedBox -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 10/12/2003. -% - -% HISTORY : -% 2003-12-12 add support for multiple rectangles - - -% 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
--- a/main/geometry/matGeom_raw/geom2d/drawRect2.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawRect2(varargin) -%DRAWRECT2 Draw centered rectangle on the current axis -% -% r = drawRect2(x, y, w, h) draw rectangle with width W and height H, -% whose center is located at (x, y); -% -% The four corners of rectangle are then : -% (X-W/2, Y-H/2), (X+W/2, Y-H/2), (X+W/2, Y+H/2), (X-W/2, Y+H/2). -% -% r = drawRect2(x, y, w, h, theta) also specifies orientation for -% rectangle. Theta is given in radians. -% -% r = drawRect2(coord) is the same as DRAWRECT2(X,Y,W,H), but all -% parameters are packed into one array, whose dimensions is 4*1 or 5*1. -% -% deprecated: use 'drawOrientedBox' instead -% -% See Also : -% drawRect -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 04/05/2004. -% - -warning('polygons2d:deprecated', ... - 'This function is deprecated, use "drawOrientedBox" instead'); - -% 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}; - end -else - coord = varargin{1}; - x = coord(:, 1); - y = coord(:, 2); - w = coord(:, 3); - h = coord(:, 4); - - if length(coord)>4 - theta = coord(:, 5); - else - theta = zeros(size(x)); - end -end - -% use only the half length of each rectanhle -w = w/2; -h = h/2; - -hr = zeros(length(x), 1); -for i=1:length(x) - tx = zeros(5, 1); - ty = zeros(5, 1); - - tx(1) = x(i) - w(i)*cos(theta(i)) + h(i)*sin(theta(i)); - ty(1) = y(i) - w(i)*sin(theta(i)) - h(i)*cos(theta(i)); - - tx(2) = x(i) + w(i)*cos(theta(i)) + h(i)*sin(theta(i)); - ty(2) = y(i) + w(i)*sin(theta(i)) - h(i)*cos(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) - w(i)*cos(theta(i)) - h(i)*sin(theta(i)); - ty(4) = y(i) - w(i)*sin(theta(i)) + h(i)*cos(theta(i)); - - tx(5) = x(i) - w(i)*cos(theta(i)) + h(i)*sin(theta(i)); - ty(5) = y(i) - w(i)*sin(theta(i)) - h(i)*cos(theta(i)); - - hr(i) = line(tx, ty); -end - -if nargout > 0 - varargout{1} = hr; -end
--- a/main/geometry/matGeom_raw/geom2d/drawShape.m Fri Oct 21 18:03:57 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -%% Copyright (c) 2011, INRA -%% 2007-2011, David Legland <david.legland@grignon.inra.fr> -%% 2011 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -%% -%% All rights reserved. -%% (simplified BSD License) -%% -%% Redistribution and use in source and binary forms, with or without -%% modification, are permitted provided that the following conditions are met: -%% -%% 1. Redistributions of source code must retain the above copyright notice, this -%% list of conditions and the following disclaimer. -%% -%% 2. Redistributions in binary form must reproduce the above copyright notice, -%% this list of conditions and the following disclaimer in the documentation -%% and/or other materials provided with the distribution. -%% -%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -%% POSSIBILITY OF SUCH DAMAGE. -%% -%% The views and conclusions contained in the software and documentation are -%% those of the authors and should not be interpreted as representing official -%% policies, either expressed or implied, of copyright holder. - - -function varargout = drawShape(type, param, varargin) -%DRAWSHAPE 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'. -% -% --------- -% -% author : David Legland -% INRA - TPV URPOI - BIA IMASTE -% created the 07/04/2005. -% - -% HISTORY - -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