./PaxHeaders.19757/matgeom-1.2.30000644000000000000000000000013214055375162013007 xustar0030 mtime=1622538866.146813311 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/0000755000175000017500000000000014055375162014014 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/PaxHeaders.19757/inst0000644000000000000000000000013214055375162013627 xustar0030 mtime=1622538866.118813416 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/0000755000175000017500000000000014055375162014771 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/PaxHeaders.19757/geom3d0000644000000000000000000000013214055375161015004 xustar0030 mtime=1622538865.994813885 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/0000755000175000017500000000000014055375161016146 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/transforms3d.m0000644000000000000000000000013214055375162017665 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/transforms3d.m0000644000175000017500000000520614055375162020755 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function transforms3d(varargin) %TRANSFORMS3D Conventions for manipulating 3D affine transforms. % % By 'transform' we mean an affine transform. A 3D affine transform % is represented by a 4*4 matrix. The last row of the matrix is equal to % [0 0 0 1]. % % % % Example: % % create a translation by the vector [10 20 30]: % T = createTranslation3d([10 20 30]); % % Transform a basic point: % PT1 = [4 5 6]; % PT2 = transformPoint3d(PT1, T) % % returns: % PT2 = % 14 25 36 % % See also % createTranslation3d, createScaling3d, , createBasisTransform3d % createRotationOx, createRotationOy, createRotationOz % rotation3dAxisAndAngle, rotation3dToEulerAngles, % createRotation3dLineAngle, eulerAnglesToRotation3d % transformPoint3d, transformVector3d, transformLine3d, transformPlane3d % composeTransforms3d, recenterTransform3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawPlane3d.m0000644000000000000000000000013214055375162017404 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawPlane3d.m0000644000175000017500000001261014055375162020471 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = drawPlane3d(plane, varargin) %DRAWPLANE3D Draw a plane clipped by the current axes. % % drawPlane3d(PLANE) draws a plane of the format: % [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % % drawPlane3d(...,'PropertyName',PropertyValue,...) sets the value of the % specified patch property. Multiple property values can be set with % a single statement. See function patch for details. % % drawPlane3d(AX,...) plots into AX instead of GCA. % % H = drawPlane3d(...) returns a handle H to the patch object. % % Example % % p0 = [1 2 3]; % v1 = [1 0 1]; % v2 = [0 -1 1]; % plane = [p0 v1 v2]; % axis([-10 10 -10 10 -10 10]); % drawPlane3d(plane) % drawLine3d([p0 v1]) % drawLine3d([p0 v2]) % set(gcf, 'renderer', 'zbuffer'); % % See also % planes3d, createPlane, patch % ------ % Author: David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % % HISTORY % 2008-10-30 replace intersectPlaneLine by intersectLinePlane, add doc % 2010-10-04 fix a bug for planes touching box by one corner % 2011-07-19 fix a bug for param by Xin KANG (Ben) % % Parse and check inputs valFun = @(x) size(x,1)==1 && isPlane(x); defOpts.FaceColor = 'm'; [hAx, plane, varargin] = ... parseDrawInput(plane, valFun, 'patch', defOpts, varargin{:}); % extract axis bounds to crop plane lim = get(hAx, 'xlim'); xmin = lim(1); xmax = lim(2); lim = get(hAx, 'ylim'); ymin = lim(1); ymax = lim(2); lim = get(hAx, 'zlim'); zmin = lim(1); zmax = lim(2); % create lines corresponding to cube edges lineX00 = [xmin ymin zmin 1 0 0]; lineX01 = [xmin ymin zmax 1 0 0]; lineX10 = [xmin ymax zmin 1 0 0]; lineX11 = [xmin ymax zmax 1 0 0]; lineY00 = [xmin ymin zmin 0 1 0]; lineY01 = [xmin ymin zmax 0 1 0]; lineY10 = [xmax ymin zmin 0 1 0]; lineY11 = [xmax ymin zmax 0 1 0]; lineZ00 = [xmin ymin zmin 0 0 1]; lineZ01 = [xmin ymax zmin 0 0 1]; lineZ10 = [xmax ymin zmin 0 0 1]; lineZ11 = [xmax ymax zmin 0 0 1]; % compute intersection points with each plane piX00 = intersectLinePlane(lineX00, plane); piX01 = intersectLinePlane(lineX01, plane); piX10 = intersectLinePlane(lineX10, plane); piX11 = intersectLinePlane(lineX11, plane); piY00 = intersectLinePlane(lineY00, plane); piY01 = intersectLinePlane(lineY01, plane); piY10 = intersectLinePlane(lineY10, plane); piY11 = intersectLinePlane(lineY11, plane); piZ00 = intersectLinePlane(lineZ00, plane); piZ01 = intersectLinePlane(lineZ01, plane); piZ10 = intersectLinePlane(lineZ10, plane); piZ11 = intersectLinePlane(lineZ11, plane); % concatenate points into one array points = [... piX00;piX01;piX10;piX11; ... piY00;piY01;piY10;piY11; ... piZ00;piZ01;piZ10;piZ11;]; % check validity: keep only points inside window (with tolerance) ac = sqrt (eps); ivx = points(:,1) >= xmin-ac & points(:,1) <= xmax+ac; ivy = points(:,2) >= ymin-ac & points(:,2) <= ymax+ac; ivz = points(:,3) >= zmin-ac & points(:,3) <= zmax+ac; valid = ivx & ivy & ivz; pts = unique(points(valid, :), 'rows'); % If there is no intersection point, escape. if size(pts, 1) < 3 disp('plane is outside the drawing window'); if nargout > 0 h = []; end return; end % the two spanning lines of the plane d1 = plane(:, [1:3 4:6]); d2 = plane(:, [1:3 7:9]); % position of intersection points in plane coordinates u1 = linePosition3d(pts, d1); u2 = linePosition3d(pts, d2); % reorder vertices in the correct order ind = convhull(u1, u2); ind = ind(1:end-1); % draw the patch htmp = patch( ... 'XData', pts(ind,1), ... 'YData', pts(ind,2), ... 'ZData', pts(ind,3), ... 'Parent', hAx, varargin{:}); % Do not return axis if not requested % avoids output when called without semicolon if nargout > 0 h = htmp; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotationAboutPoint3d.m0000644000000000000000000000013214055375162022457 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotationAboutPoint3d.m0000644000175000017500000000450314055375162023546 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function TFM = createRotationAboutPoint3d(ROT, point) %CREATEROTATIONABOUTPOINT3D Rotate about a point using a rotation matrix. % % TFM = createRotationAboutPoint3d(ROT, POINT) Returns the transformation % matrix corresponding to a translation(-POINT), rotation with ROT and % translation(POINT). Ignores a possible translation in ROT(1:3,4). % % See also: % transforms3d, transformPoint3d, createRotationOx, createRotationOy, % createRotationOz, createRotation3dLineAngle, createRotationVector3d, % createRotationVectorPoint3d % % --------- % Author: oqilipo % Created: 2021-01-31 % Copyright 2021 % Extract only the rotation ROT = [ROT(1:3,1:3), [0 0 0]'; [0 0 0 1]]; TFM = createTranslation3d(point) * ROT * createTranslation3d(-point); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/boxes3d.m0000644000000000000000000000013214055375162016607 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/boxes3d.m0000644000175000017500000000434014055375162017675 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function boxes3d(varargin) %BOXES3D Description of functions operating on 3D boxes. % % A box defined by its coordinate extents: % BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX]. % % Example % % Draw a polyhedron together with its bounding box % [n e f]= createIcosahedron; % drawPolyhedron(n, f); % hold on; % drawBox3d(point3dBounds(n)) % % % See also % boundingBox3d, box3dVolume, drawBox3d % intersectBoxes3d, mergeBoxes3d, randomPointInBox3d % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/reversePlane.m0000644000000000000000000000013214055375162017673 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/reversePlane.m0000644000175000017500000000431514055375162020763 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function plane = reversePlane(plane) %REVERSEPLANE Return same 3D plane but with opposite orientation. % % IP = reversePlane(PLANE); % Returns a plane contining the same ppints but with normal opposite to % that of PLANE. % If PLANE has the format [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2], then IP % will have following parameters: [x0 y0 z0 dx1 dy1 dz1 -dx2 -dy2 -dz2]. % % See also: % createPlane, reverseLine3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-05-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. plane(:, 7:9) = -plane(:, 7:9); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createTranslation3d.m0000644000000000000000000000013214055375162021151 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createTranslation3d.m0000644000175000017500000000545414055375162022246 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createTranslation3d(varargin) %CREATETRANSLATION3D Create the 4x4 matrix of a 3D translation. % % usage: % TRANS = createTranslation3d(DX, DY, DZ); % return the translation corresponding to DX and DY. % The returned matrix has the form : % [1 0 0 DX] % [0 1 0 DY] % [0 0 1 DZ] % [0 0 0 1] % % TRANS = createTranslation3d(VECT); % return the translation corresponding to the given vector [x y z]. % % % See also: % transforms3d, transformPoint3d, transformVector3d, % createRotationOx, createRotationOy, createRotationOz, createScaling3d % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 22/04/2009 rename as createTranslation3d if isempty(varargin) % assert translation with null vector dx = 0; dy = 0; dz = 0; elseif length(varargin)==1 % translation vector given in a single argument var = varargin{1}; dx = var(1); dy = var(2); dz = var(3); else % translation vector given in 3 arguments dx = varargin{1}; dy = varargin{2}; dz = varargin{3}; end % create the translation matrix trans = [1 0 0 dx ; 0 1 0 dy ; 0 0 1 dz; 0 0 0 1]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/randomAngle3d.m0000644000000000000000000000013214055375162017716 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/randomAngle3d.m0000644000175000017500000000556714055375162021020 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = randomAngle3d(varargin) %RANDOMANGLE3D Return a 3D angle uniformly distributed on unit sphere. % % usage % [THETA PHI] = randomAngle3d % Generate an angle unformly distributed on the surface of the unit % sphere. % % "Mathematical" convention is used: theta is the colatitude (angle with % vertical axis, 0 for north pole, +pi for south pole, pi/2 for points at % equator) with z=0. % phi is the same as matlab cart2sph: angle from Ox axis, counted % positively counter-clockwise. % % [THETA PHI] = randomAngle3d(N) % generates N random angles (N is a scalar). The result is a N-by-2 % array. % % Example: % % Draw some points on the surface of a sphere % figure; % drawSphere; hold on; % drawPoint3d(pts, '.'); % axis equal; % % See also: % angles3d, sph2cart2, cart2sph2 % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % created the 18/02/2005. % Copyright INRA - Cepia Software platform % HISTORY % 2007-01-04 change angle order, update doc % 2011-06-27 fix bug in input parsing, add doc N = 1; if ~isempty(varargin) N = varargin{1}; end phi = 2*pi*rand(N, 1); theta = asin(2*rand(N, 1)-1) + pi/2; if nargout<2 var = [theta phi]; varargout{1} = var; else varargout{1} = theta; varargout{2} = phi; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/cyl2cart.m0000644000000000000000000000013214055375162016763 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/cyl2cart.m0000644000175000017500000000566514055375162020064 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cyl2cart(varargin) %CYL2CART Convert cylindrical to cartesian coordinates. % % CART = cyl2cart(CYL) % convert the 3D cylindrical coordinates of points CYL (given by % [THETA R Z] where THETA, R, and Z have the same size) into cartesian % coordinates CART, given by [X Y Z]. % The transforms is the following : % X = R*cos(THETA); % Y = R*sin(THETA); % Z remains inchanged. % % CART = cyl2cart(THETA, R, Z) % provides coordinates as 3 different parameters % % Example % cyl2cart([-1 0 2]) % gives : 4.7124 1.0000 2.0000 % % See also angles3d, cart2pol, cart2sph2, cart2cyl % % % ------ % Author: David Legland % e-mail: david.legland@jouy.inra.fr % Created: 2006-03-23 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % process input parameters if length(varargin)==1 var = varargin{1}; theta = var(:,1); r = var(:,2); z = var(:,3); elseif length(varargin)==3 theta = varargin{1}; r = varargin{2}; z = varargin{3}; end % convert coordinates dim = size(theta); x = reshape(r(:).*cos(theta(:)), dim); y = reshape(r(:).*sin(theta(:)), dim); % process output parameters if nargout==0 ||nargout==1 if length(dim)>2 || dim(2)>1 varargout{1} = {x y z}; else varargout{1} = [x y z]; end elseif nargout==3 varargout{1} = x; varargout{2} = y; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawCylinder.m0000644000000000000000000000013214055375162017667 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawCylinder.m0000644000175000017500000001645214055375162020764 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCylinder(varargin) % Draw a cylinder. % % drawCylinder(CYL) % Draws the cylinder CYL on the current axis. % CYL is a 1-by-7 row vector in the form [x1 y1 z1 x2 y2 z2 r] where: % * [x1 y1 z1] are the coordinates of starting point, % * [x2 y2 z2] are the coordinates of ending point, % * R is the radius of the cylinder % % drawCylinder(CYL, N) % Uses N points for discretizating the circles of the cylinder. Default % value is 32. % % drawCylinder(..., OPT) % with OPT = 'open' (default) or 'closed', specify if the bases of the % cylinder should be drawn. % % drawCylinder(..., 'FaceColor', COLOR) % Specifies the color of the cylinder. Any couple of parameters name and % value can be given as argument, and will be transfered to the 'surf' % matlab function % % drawCylinder(..., 'FaceAlpha', ALPHA) % Specifies the transparency of the cylinder and of the optionnal caps. % % drawCylinder(AX, ...) % Specifies the axis to draw on. AX should be a valid axis handle. % % H = drawCylinder(...) % Returns a handle to the patch representing the cylinder. % % % Examples: % % basic example % figure; drawCylinder([0 0 0 10 20 30 5]); % % % draw hollow cylinders % figure; drawCylinder([0 0 0 10 20 30 5], 'open'); % % % change cylinder color % figure; drawCylinder([0 0 0 10 20 30 5], 'FaceColor', 'r'); % % % change cylinder color using graphical handle % figure; % h = drawCylinder([0 0 0 10 20 30 5]); % set(h, 'facecolor', 'b'); % % % Draw three mutually intersecting cylinders % p0 = [10 10 10]; % p1 = p0 + 80 * [1 0 0]; % p2 = p0 + 80 * [0 1 0]; % p3 = p0 + 80 * [0 0 1]; % figure; axis equal; axis([0 100 0 100 0 100]); hold on % drawCylinder([p0 p1 10], 'FaceColor', 'r'); % drawCylinder([p0 p2 10], 'FaceColor', 'g'); % drawCylinder([p0 p3 10], 'FaceColor', 'b'); % axis equal % set(gcf, 'renderer', 'opengl') % view([60 30]); light; % % % draw cube skeleton % [v, e, f] = createCube; % figure; axis equal; axis([-0.2 1.2 -0.2 1.2 -0.2 1.2]); hold on; view(3); % cyls = [v(e(:,1), :) v(e(:,2),:) repmat(0.1, size(e, 1), 1)]; % drawCylinder(cyls); % light % % See Also: % cylinderMesh, drawEllipseCylinder, drawSphere, drawLine3d, surf % intersectLineCylinder, cylinderSurfaceArea % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/09/2005 % % HISTORY % 2006/12/14 bug for coordinate conversion, vectorize transforms % 04/01/2007 better input processing, manage end caps of cylinder % 19/06/2009 use function localToGlobal3d, add docs % 2011-06-29 use sph2cart2d, code cleanup % 2018-01-02 add transparency managements %% Input argument processing % parse axis handle if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1) = []; else hAx = gca; end % input argument representing cylinders cyl = varargin{1}; varargin(1) = []; % process the case of multiple cylinders if iscell(cyl) hCyls = gobjects(length(cyl), 1); for i = 1:length(cyl) hCyls(i) = drawCylinder(hAx, cyl{i}, varargin{:}); end if nargout > 0 varargout{1} = hCyls; end return; elseif size(cyl, 1) > 1 hCyls = gobjects(size(cyl, 1), 1); for i = 1:size(cyl, 1) hCyls(i) = drawCylinder(hAx, cyl(i, :), varargin{:}); end if nargout > 0 varargout{1} = hCyls; end return; end % default values N = 32; closed = true; % check number of discretization steps if ~isempty(varargin) var = varargin{1}; if isnumeric(var) N = var; varargin = varargin(2:end); end end % check if cylinder must be closed or open if ~isempty(varargin) var = varargin{1}; if ischar(var) if strncmpi(var, 'open', 4) closed = false; varargin = varargin(2:end); elseif strncmpi(var, 'closed', 5) closed = true; varargin = varargin(2:end); end end end faceColor = 'g'; ind = find(strcmpi(varargin, 'FaceColor'), 1, 'last'); if ~isempty(ind) faceColor = varargin{ind+1}; varargin(ind:ind+1) = []; end % extract transparency alpha = 1; ind = find(strcmpi(varargin, 'FaceAlpha'), 1, 'last'); if ~isempty(ind) alpha = varargin{ind+1}; varargin(ind:ind+1) = []; end % add default drawing options varargin = [{'FaceColor', faceColor, 'edgeColor', 'none', 'FaceAlpha', alpha} varargin]; %% Computation of mesh coordinates % extreme points of cylinder p1 = cyl(1:3); p2 = cyl(4:6); % radius of cylinder r = cyl(7); % compute orientation angle of cylinder [theta, phi, rho] = cart2sph2d(p2 - p1); dphi = linspace(0, 2*pi, N+1); % generate a cylinder oriented upwards x = repmat(cos(dphi) * r, [2 1]); y = repmat(sin(dphi) * r, [2 1]); z = repmat([0 ; rho], [1 length(dphi)]); % transform points trans = localToGlobal3d(p1, theta, phi, 0); pts = transformPoint3d([x(:) y(:) z(:)], trans); % reshape transformed points x2 = reshape(pts(:,1), size(x)); y2 = reshape(pts(:,2), size(x)); z2 = reshape(pts(:,3), size(x)); %% Display cylinder mesh % plot the cylinder as a surface hCyl(1) = surf(hAx, x2, y2, z2, varargin{:}); % eventually plot the ends of the cylinder if closed hCyl(2)=patch(hAx, x2(1,:)', y2(1,:)', z2(1,:)', faceColor, 'edgeColor', 'none', 'FaceAlpha', alpha); hCyl(3)=patch(hAx, x2(2,:)', y2(2,:)', z2(2,:)', faceColor, 'edgeColor', 'none', 'FaceAlpha', alpha); gh = hggroup(hAx); set(hCyl,'Parent',gh) hCyl = gh; end % format ouptut if nargout == 1 varargout{1} = hCyl; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawCuboid.m0000644000000000000000000000013214055375162017323 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawCuboid.m0000644000175000017500000001035414055375162020413 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCuboid(cuboid, varargin) % Draw a 3D cuboid, eventually rotated. % % drawCuboid(CUBOID) % Displays a 3D cuboid on current axis. CUBOID is given by: % [XC YC ZC L W D YAW PITCH ROLL], % where (XC, YC, ZC) is the cuboid center, L, W and H are the lengths of % the cuboid main axes, and YAW PITCH ROLL are Euler angles representing % the cuboid orientation, in degrees. % % If cuboid is axis-aligned, it can be specified using only center and % side lengths: % CUBOID = [XC YC ZC L W H] % % Example % % Draw a basic rotated cuboid % figure; hold on; % drawCuboid([10 20 30 90 40 10 10 20 30], 'FaceColor', 'g'); % axis equal; % view(3); % % % Draw three "borromean" cuboids % figure; hold on; % drawCuboid([10 20 30 90 50 10], 'FaceColor', 'r'); % drawCuboid([10 20 30 50 10 90], 'FaceColor', 'g'); % drawCuboid([10 20 30 10 90 50], 'FaceColor', 'b'); % view(3); axis equal; % set(gcf, 'renderer', 'opengl') % % See also % meshes3d, polyhedra, createCube, drawEllipsoid, drawCube % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-06-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. phi = 0; theta = 0; psi = 0; %% Parses the input if nargin == 0 % no input: assumes cuboid with default shape xc = 0; yc = 0; zc = 0; a = 5; b = 4; c = 3; else % one argument: parses elements xc = cuboid(:,1); yc = cuboid(:,2); zc = cuboid(:,3); a = cuboid(:,4); b = cuboid(:,5); c = cuboid(:,6); if size(cuboid, 2) >= 9 k = pi / 180; phi = cuboid(:,7) * k; theta = cuboid(:,8) * k; psi = cuboid(:,9) * k; end end %% Compute cuboid coordinates % create unit centered cube [v, f] = createCube; v = bsxfun(@minus, v, mean(v, 1)); % convert unit basis to ellipsoid basis sca = createScaling3d(a, b, c); rotZ = createRotationOz(phi); rotY = createRotationOy(theta); rotX = createRotationOx(psi); tra = createTranslation3d([xc yc zc]); % concatenate transforms trans = tra * rotZ * rotY * rotX * sca; % transform mesh vertices [x, y, z] = transformPoint3d(v, trans); %% Process output if nargout == 0 % no output: draw the cuboid drawMesh([x y z], f, varargin{:}); elseif nargout == 1 % one output: draw the cuboid and return handle varargout{1} = drawMesh([x y z], f, varargin{:}); elseif nargout == 3 % 3 outputs: return computed coordinates varargout{1} = x; varargout{2} = y; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/registerPoints3dAffine.m0000644000000000000000000000013214055375162021621 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/registerPoints3dAffine.m0000644000175000017500000000603414055375162022711 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [trans, points] = registerPoints3dAffine(points, target, varargin) % Fit 3D affine transform using iterative algorithm. % % TRANS = registerPoints3dAffine(POINTS, TARGET) % Computes the affine transform that maps the shape defines by POINTS % onto the shape defined by the points TARGET. Both POINTS and TARGET are % N-by-3 array of point coordinates, not necessarily the same size. % The result TRANS is a 4-by-4 affine transform. % % TRANS = registerPoints3dAffine(POINTS, TARGET, NITER) % Specifies the number of iterations for the algorithm. % % [TRANS, POINTS2] = registerPoints3dAffine(...) % Also returns the set of transformed points. % % Example % registerPoints3dAffine % % See also % transforms3d, fitAffineTransform3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2015-02-24, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. nIters = 10; if ~isempty(varargin) nIters = varargin{1}; end % keep original points to transform them at each trans = [1 0 0 0;0 1 0 0;0 0 1 0;0 0 0 1]; for i = 1:nIters % identify target points for each source point inds = findClosestPoint(points, target); corrPoints = target(inds, :); % compute transform for current iteration trans_i = fitAffineTransform3d(points, corrPoints); % apply transform, and update cumulated transform points = transformPoint3d(points, trans_i); trans = trans_i * trans; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/polygon3dNormalAngle.m0000644000000000000000000000013214055375162021276 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/polygon3dNormalAngle.m0000644000175000017500000000564214055375162022372 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = polygon3dNormalAngle(points, ind) %POLYGON3DNORMALANGLE Normal angle at a vertex of the 3D polygon. % % THETA = polygon3DNormalAngle(POLYGON, IND) % where POLYGON is a set of points, and IND is index of a point in % polygon. The function compute the angle of the normal cone localized at % this vertex. % If IND is a vector of indices, normal angle is computed for each vertex % specified by IND. % % Example % % create an equilateral triangle in space % poly3d = [1 1 0;-1 0 1;0 -1 -1]; % % compute each normal angle % theta = polygon3dNormalAngle(poly3d, 1:size(poly3d, 1)); % % sum of normal angles must be equal to 2*PI for simple polygons % sum(theta) % % IMPORTANT NOTE: works only for convex angles ! ! ! ! % % See also % polygons3d, faceNormalAngle % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2005-11-30 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % number of points np = size(points, 1); % number of angles to compute nv = length(ind); theta = zeros(nv, 1); for i=1:nv p0 = points(ind(i), :); if ind(i)==1 p1 = points(np, :); else p1 = points(ind(i)-1, :); end if ind(i)==np p2 = points(1, :); else p2 = points(ind(i)+1, :); end theta(i) = pi - anglePoints3d(p1, p0, p2); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/cylinderSurfaceArea.m0000644000000000000000000000013214055375162021153 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/cylinderSurfaceArea.m0000644000175000017500000000474514055375162022252 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function S = cylinderSurfaceArea(cyl) %CYLINDERSURFACEAREA Surface area of a cylinder. % % S = cylinderSurfaceArea(CYL) % Computes the surface area of the cylinder defined by: % CYL = [X1 Y1 Z1 X2 Y2 Z2 R], % where [X1 Y1 Z1] and [X2 Y2 Z2] are the coordinates of the cylinder % extremities, and R is the cylinder radius. % The surface area of the cylinder comprises the surface area of the two % disk-shape end caps. % % Example % cyl = [0 0 0 1 0 0 1]; % cylinderSurfaceArea(cyl) % ans = % 12.5664 % % equals to 4*pi % % See also % geom3d, ellipsoidSurfaceArea, intersectLineCylinder % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-11-02, using Matlab 9.3.0.713579 (R2017b) % Copyright 2017 INRA - Cepia Software Platform. H = distancePoints3d(cyl(:, 1:3), cyl(:, 4:6)); R = cyl(:,7); S1 = 2*pi*R .* H; S2 = 2 * (pi * R.^2); S = S1 + S2; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/projLineOnPlane.m0000644000000000000000000000013214055375162020277 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/projLineOnPlane.m0000644000175000017500000000522414055375162021367 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [newLine, isOrthogonal] = projLineOnPlane(line, plane) %PROJLINEONPLANE Return the orthogonal projection of a line on a plane. % % NEWLINE = PROJLINEONPLANE(LINE, PLANE) Returns the orthogonal % projection of LINE or multiple lines on the PLANE. % % [..., ISORTHOGONAL] = PROJLINEONPLANE(LINE, PLANE) Also returns if the % LINE is orthogonal to the PLANE. % % Example % plane = [.1 .2 .3 .4 .5 .6 .7 .8 .9]; % lines = [0 .3 0 1 0 0;0 .5 .5 0 0 1;... % .4 .1 .5 1 0 2;.2 .7 .1 0 1 0;... % plane(1:3) planeNormal(plane)]; % [newLines, isOrthogonal] = projLineOnPlane(lines, plane); % figure('color','w'); axis equal; view(3) % drawLine3d(lines,'b') % drawPlane3d(plane) % drawLine3d(newLines(~isOrthogonal,:), 'r') % % See also: % planes3d, lines3d, intersectLinePlane, projPointOnPlane % % --------- % Author: oqilipo % Created: 2017-08-06 % Copyright 2017 p1 = projPointOnPlane(line(:,1:3), plane); p2 = projPointOnPlane(line(:,1:3)+line(:,4:6), plane); newLine=createLine3d(p1, p2); isOrthogonal = ismembertol(p1,p2,'ByRows',true); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createSphere.m0000644000000000000000000000013214055375162017652 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createSphere.m0000644000175000017500000000503714055375162020744 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function sphere = createSphere(varargin) %CREATESPHERE Create a sphere containing 4 points. % % s = createSphere(p1, p2, p3, p4); % return in s the sphere common to the 4 pointsp1, p2, p3 and p4. % % Ref: P. Bourke % http://astronomy.swin.edu.au/~pbourke/geometry/spherefrom4/ % % See also % spheres, circles3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 22/03/2005. % if length(varargin)==4 pts = [varargin{1};varargin{2};varargin{3};varargin{4}]; elseif length(varargin)==1 pts = varargin{1}; else error('wrong number of arguments in createSphere'); end m1 = det([pts ones(4,1)]); s2 = sum(pts.*pts, 2); m2 = det([s2 pts(:,2) pts(:,3) ones(4,1)]); m3 = det([pts(:,1) s2 pts(:,3) ones(4,1)]); m4 = det([pts(:,1) pts(:,2) s2 ones(4,1)]); m5 = det([s2 pts]); x0 = m2*.5/m1; y0 = m3*.5/m1; z0 = m4*.5/m1; r = sqrt(x0*x0 + y0*y0 + z0*z0 - m5/m1); sphere = [x0 y0 z0 r]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectLineSphere.m0000644000000000000000000000013214055375162021217 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectLineSphere.m0000644000175000017500000001106014055375162022302 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = intersectLineSphere(line, sphere, varargin) %INTERSECTLINESPHERE Return intersection points between a line and a sphere. % % PTS = intersectLineSphere(LINE, SPHERE); % Returns the two points which are the intersection of the given line and % sphere. % LINE : [x0 y0 z0 dx dy dz] % SPHERE : [xc yc zc R] % PTS : [x1 y1 z1 ; x2 y2 z2] % If there is no intersection between the line and the sphere, return a % 2-by-3 array containing only NaN. % % Example % % draw the intersection between a sphere and a collection of parallel % % lines % sphere = [50.12 50.23 50.34 40]; % [x, y] = meshgrid(10:10:90, 10:10:90); % n = numel(x); % lines = [x(:) y(:) zeros(n,1) zeros(n,2) ones(n,1)]; % figure; hold on; axis equal; % axis([0 100 0 100 0 100]); view(3); % drawSphere(sphere); % drawLine3d(lines); % pts = intersectLineSphere(lines, sphere); % drawPoint3d(pts, 'rx'); % % % apply rotation on set of lines to check with non vertical lines % rot = eulerAnglesToRotation3d(20, 30, 10); % rot2 = recenterTransform3d(rot, [50 50 50]); % lines2 = transformLine3d(lines, rot2); % figure; hold on; axis equal; % axis([0 100 0 100 0 100]); view(3); % drawSphere(sphere); % drawLine3d(lines2); % pts2 = intersectLineSphere(lines2, sphere); % drawPoint3d(pts, 'rx'); % % See also % spheres, circles3d, intersectPlaneSphere % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 2011-06-21 bug for tangent lines, add tolerance %% Process input arguments % check if user-defined tolerance is given tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % difference between centers dc = bsxfun(@minus, line(:, 1:3), sphere(:, 1:3)); % equation coefficients a = sum(line(:, 4:6) .* line(:, 4:6), 2); b = 2 * sum(bsxfun(@times, dc, line(:, 4:6)), 2); c = sum(dc.*dc, 2) - sphere(:,4).*sphere(:,4); % solve equation delta = b.*b - 4*a.*c; % initialize empty results points = NaN * ones(2 * size(delta, 1), 3); %% process couples with two intersection points % process couples with two intersection points inds = find(delta > tol); if ~isempty(inds) % delta positive: find two roots of second order equation u1 = (-b(inds) -sqrt(delta(inds))) / 2 ./ a(inds); u2 = (-b(inds) +sqrt(delta(inds))) / 2 ./ a(inds); % convert into 3D coordinate points(inds, :) = line(inds, 1:3) + bsxfun(@times, u1, line(inds, 4:6)); points(inds+length(delta),:) = line(inds, 1:3) + bsxfun(@times, u2, line(inds, 4:6)); end %% process couples with one intersection point % proces couples with two intersection points inds = find(abs(delta) < tol); if ~isempty(inds) % delta around zero: find unique root, and convert to 3D coord. u = -b(inds) / 2 ./ a(inds); % convert into 3D coordinate pts = line(inds, 1:3) + bsxfun(@times, u, line(inds, 4:6)); points(inds, :) = pts; points(inds+length(delta),:) = pts; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectRayPolygon3d.m0000644000000000000000000000013214055375162021513 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectRayPolygon3d.m0000644000175000017500000000762414055375162022611 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [inter, inside]= intersectRayPolygon3d(ray, poly) %INTERSECTRAYPOLYGON3D Intersection point of a 3D ray and a 3D polygon. % % INTER = intersectRayPolygon3d(RAY, POLY) % Compute coordinates of intersection point between the 3D ray RAY and % the 3D polygon POLY. RAY is a 1-by-6 row vector containing origin and % direction vector of the ray, POLY is a Np-by-3 array containing % coordinates of 3D polygon vertices. % INTER is a 1-by-3 row vector containing coordinates of intersection % point, or [NaN NaN NaN] if ray and polygon do not intersect. % % INTERS = intersectRayPolygon3d(RAYS, POLY) % If RAYS is a N-by-6 array representing several rays, the result % INTERS is a N-by-3 array containing coordinates of intersection of each % ray with the polygon. % % [INTER INSIDE] = intersectRayPolygon3d(RAY, POLY) % Also return a N-by-1 boolean array containing TRUE if both the polygon % and the corresponding ray contain the intersection point. % % Example % % Compute intersection between a 3D ray and a 3D triangle % pts3d = [3 0 0; 0 6 0;0 0 9]; % ray1 = [0 0 0 3 6 9]; % inter = intersectRayPolygon3d(ray1, pts3d) % inter = % 1 2 3 % % % keep only valid intersections with several rays % pts3d = [3 0 0; 0 6 0;0 0 9]; % rays = [0 0 0 3 6 9;10 0 0 1 2 3;3 6 9 3 6 9]; % [inter inside] = intersectRayPolygon3d(rays, pts3d); % inter(inside, :) % ans = % 1 2 3 % % See Also % intersectRayPolygon, intersectLinePolygon3d, intersectLineTriangle3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % supporting plane of polygon vertices plane = createPlane(poly(1:3, :)); % intersection of 3D ray with the plane inter = intersectLinePlane(ray, plane); % project all points on reference plane pts2d = planePosition(projPointOnPlane(poly, plane), plane); pInt2d = planePosition(projPointOnPlane(inter, plane), plane); % need to check polygon orientation inPoly = xor(isPointInPolygon(pInt2d, pts2d), polygonArea(pts2d) < 0); onRay = linePosition3d(inter, ray) >= 0; inside = inPoly & onRay; % intersection points outside the polygon are set to NaN inter(~inside, :) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/edgeLength3d.m0000644000000000000000000000013214055375162017535 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/edgeLength3d.m0000644000175000017500000000443614055375162020631 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function len = edgeLength3d(edge, varargin) %EDGELENGTH3D Return the length of a 3D edge. % % L = edgeLength3D(EDGE); % Returns the length of a 3D edge, with following representation: % [x1 y1 z1 x2 y2 z2]. % % Example % p1 = [1 1 1]; % p2 = [3 4 5]; % edge = createEdge3d(p1, p2); % edgeLength3d(edge) % ans = % 5.3852 % % See also % edges3d, createEdge3d, drawEdge3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-08-29, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. if nargin == 1 dp = edge(:, 4:6) - edge(:, 1:3); else dp = varargin{1} - edge; end len = hypot(hypot(dp(:,1), dp(:,2)), dp(:,3)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/transformPlane3d.m0000644000000000000000000000013214055375162020462 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/transformPlane3d.m0000644000175000017500000000504414055375162021552 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function plane2 = transformPlane3d(plane, trans) %TRANSFORMPLANE3D Transform a 3D plane with a 3D affine transform. % % PLANE2 = transformPlane3d(PLANE, TRANS) % % Example % p1 = [10 20 30]; % p2 = [30 40 50]; % p3 = [0 -10 -20]; % plane = createPlane(p1, p2, p3); % rot = createRotationOx(p1, pi/6); % plane2 = transformPlane3d(plane, rot); % figure; hold on; % axis([0 100 0 100 0 100]); view(3); % drawPlane3d(plane, 'b'); % drawPlane3d(plane2, 'm'); % % See also: % lines3d, transforms3d, transformPoint3d, transformVector3d, % transformLine3d % % ------ % Author: David Legland, oqilipo % e-mail: david.legland@inra.fr % Created: 2017-07-09 % Copyright 2017 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. plane2 = [... transformPoint3d( plane(:,1:3), trans) ... % transform origin point transformVector3d(plane(:,4:6), trans) ... % transform 1st dir. vect. transformVector3d(plane(:,7:9), trans)]; % transform 2nd dir. vect. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/distancePointEdge3d.m0000644000000000000000000000013214055375162021060 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/distancePointEdge3d.m0000644000175000017500000000654114055375162022153 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [dist, t] = distancePointEdge3d(point, edge) %DISTANCEPOINTEDGE3D Minimum distance between a 3D point and a 3D edge. % % DIST = distancePointEdge3d(POINT, EDGE); % Return the euclidean distance between edge EDGE and point POINT. % EDGE has the form: [x1 y1 z1 x2 y2 z2], and POINT is [x y z]. % % If EDGE is N-by-6 array, result is N-by-1 array computed for each edge. % If POINT is a N-by-3 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] = distancePointEdge3d(POINT, EDGE); % Also returns the position of closest point on the edge. POS is % comprised between 0 (first point) and 1 (last point). % % See also: % edges3d, points3d, distancePoints3d, distancePointLine3d % % --------- % author : David Legland % INRA - CEPIA URPOI - MIA MathCell % created the 07/04/2004. % % HISTORY % 2005-06-24 rename, and change arguments sequence % 2009-04-30 add possibility to return position of closest point % 2011-04-14 add checkup for degenerate edges, improve speed, update doc % direction vector of each edge vl = edge(:, 4:6) - edge(:, 1:3); % compute position of points projected on the supporting line % (Size of t is the max number of edges or points) t = linePosition3d(point, [edge(:,1:3) vl]); % change position to ensure projected point is located on the edge t(t < 0) = 0; t(t > 1) = 1; % difference of coordinates between projected point and base point p0 = bsxfun(@plus, edge(:,1:3), [t .* vl(:,1) t .* vl(:,2) t .* vl(:,3)]); p0 = bsxfun(@minus, point, p0); % compute distance between point and its projection on the edge dist = sqrt(sum(p0 .* p0, 2)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/clipRay3d.m0000644000000000000000000000013214055375162017072 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/clipRay3d.m0000644000175000017500000001156214055375162020164 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = clipRay3d(ray, box) % Clip a 3D ray with a box and return a 3D edge. % % EDGE = clipRay3d(RAY, BOX) % Clips the ray RAY with the bounds given in BOX, and returns the % corresponding edge. % RAY is given as origin + direction vector: [X0 Y0 Z0 DX DY DZ] % BOX is given as [XMIN XMAX YMIN YMAX ZMIN ZMAX]. % The result EDGE is given as [X1 Y1 Z1 X2 Y2 Z2]. % % Example % % generate 50 random 3D rays % origin = [29 28 27]; % v = rand(50, 3); % v = v - centroid(v); % ray = [repmat(origin, size(v,1),1) v]; % % clip the rays with a 3D box % box = [10 40 10 40 10 40]; % edges = clipRay3d(ray, box); % % draw the resulting 3D edges % figure; axis equal; axis([0 50 0 50 0 50]); hold on; view(3); % drawBox3d(box); % drawEdge3d(edges, 'g'); % % See also % clipLine3d % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-05-25, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. % get box limits xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); zmin = box(5); zmax = box(6); % extreme corners of the box p000 = [xmin ymin zmin]; p111 = [xmax ymax zmax]; % main vectors ex = [1 0 0]; ey = [0 1 0]; ez = [0 0 1]; % box faces parallel to Oxy planeZ0 = [p000 ex ey]; planeZ1 = [p111 ex ey]; % box faces parallel to Oxz planeY0 = [p000 ex ez]; planeY1 = [p111 ex ez]; % box faces parallel to Oyz planeX0 = [p000 ey ez]; planeX1 = [p111 ey ez]; % number of rays nRays = size(ray, 1); % allocate memory for result edge = NaN * ones(nRays, 6); % iterate over rays to clip for i = 1:nRays % compute intersection point of supporting line with each clipping plane ipZ0 = intersectLinePlane(ray(i,:), planeZ0); ipZ1 = intersectLinePlane(ray(i,:), planeZ1); ipY0 = intersectLinePlane(ray(i,:), planeY0); ipY1 = intersectLinePlane(ray(i,:), planeY1); ipX1 = intersectLinePlane(ray(i,:), planeX1); ipX0 = intersectLinePlane(ray(i,:), planeX0); % concatenate resulting points points = [ipX0;ipX1;ipY0;ipY1;ipZ0;ipZ1]; % compute position of each point on the ray pos = linePosition3d(points, ray(i,:)); % keep only defined points ind = find(~isnan(pos)); pos = pos(ind); points = points(ind,:); if isempty(pos) continue; end % sort points with respect to their position [pos, ind] = sort(pos); points = points(ind, :); % keep median points wrt to position. These points define the limit of % the clipped edge. nv = length(ind)/2; pos = pos([nv, nv+1]); points = points([nv nv+1], :); % case of second edge extremity before ray origin if pos(2) < 0 continue; end % case of first edge extremity before ray origin if pos(1) < 0 points(1,1:3) = ray(i,1:3); end % create resulting edge. edge(i,:) = [points(1, :) points(2, :)]; end % check that middle point of the edge is contained in the box midX = mean(edge(:, [1 4]), 2); xOk = xmin <= midX & midX <= xmax; midY = mean(edge(:, [2 5]), 2); yOk = ymin <= midY & midY <= ymax; midZ = mean(edge(:, [3 6]), 2); zOk = zmin <= midZ & midZ <= zmax; % if one of the bounding condition is not met, set edge to NaN edge (~(xOk & yOk & zOk), :) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawCapsule.m0000644000000000000000000000013214055375162017512 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawCapsule.m0000644000175000017500000001464214055375162020606 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCapsule(varargin) % Draw a capsule. % % drawCapsule(CAP) % Draws the capsule CAP on the current axis. % CAP is a 1-by-7 row vector in the form [x1 y1 z1 x2 y2 z2 r] where: % * [x1 y1 z1] are the coordinates of starting point, % * [x2 y2 z2] are the coordinates of ending point, % * R is the radius of the cylinder and the two semi-spheres at the ends % % drawCapsule(CAP, N) % Uses N points for discretizating the circles of the cylinder and the % semi-spheres (domes). Default value is 32. % % drawCapsule(..., 'FaceColor', COLOR) % Specifies the color of the capsule. Any couple of parameters name and % value can be given as argument, and will be transfered to the 'surf' % matlab function % % drawCapsule(..., 'FaceAlpha', ALPHA) % Specifies the transparency of the capsule and of the semi-spheres. % % drawCapsule(..., NAME, VALUE); % Specifies one or several options using parameter name-value pairs. % Available options are usual drawing options, as well as: % 'nPhi' the number of arcs used for drawing the meridians % (for the semi-spheres and the cylinder( % 'nTheta' the number of circles used for drawing the parallels % (only for the semi-spheres at the ends of the capsule) % % drawCapsule(AX, ...) % Specifies the axis to draw on. AX should be a valid axis handle. % % H = drawCapsule(...) % Returns a handle to the patch representing the capsule. % % % Examples: % % basic example % figure; drawCapsule([0 0 0 10 20 30 5]); % % % change capsule color % figure; drawCapsule([0 0 0 10 20 30 5], 'FaceColor', 'r'); % % % change capsule color using graphical handle % figure; % h = drawCapsule([0 0 0 10 20 30 5]); % set(h, 'facecolor', 'b'); % % % Draw three mutually intersecting capsules % p0 = [10 10 10]; % p1 = p0 + 80 * [1 0 0]; % p2 = p0 + 80 * [0 1 0]; % p3 = p0 + 80 * [0 0 1]; % figure; axis equal; axis([0 100 0 100 0 100]); hold on % drawCapsule([p0 p1 10], 'FaceColor', 'r'); % drawCapsule([p0 p2 10], 'FaceColor', 'g'); % drawCapsule([p0 p3 10], 'FaceColor', 'b'); % axis equal % set(gcf, 'renderer', 'opengl') % view([60 30]); light; % % % draw cube skeleton % [v, e, f] = createCube; % figure; axis equal; axis([-0.2 1.2 -0.2 1.2 -0.2 1.2]); hold on; view(3); % caps = [v(e(:,1), :) v(e(:,2),:) repmat(0.1, size(e, 1), 1)]; % drawCapsule(caps); % light % % % Draw a capsule with high resolution % figure; % h = drawCapsule([10,20,10,50,70,40,6], 'nPhi', 360, 'nTheta', 180); % l = light; view(3); % % % See Also: % crawCylinder, drawDome, drawSphere % % --------- % author: Moritz Schappler % created the 27/07/2013 % % HISTORY % 2013-07-27 initial version as copy of drawCylinder % 2020-05-18 changes based on current version of geom3d %% Input argument processing % parse axis handle if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1) = []; else hAx = gca; end % input argument representing capsules cap = varargin{1}; varargin(1) = []; % process the case of multiple capsules if iscell(cap) hCaps = gobjects(length(cap), 1); for i = 1:length(cap) hCaps(i) = drawCapsule(hAx, cap{i}, varargin{:}); end if nargout > 0 varargout{1} = hCaps; end return; elseif size(cap, 1) > 1 hCaps = gobjects(size(cap, 1), 3); for i = 1:size(cap, 1) hCaps(i,:) = drawCapsule(hAx, cap(i, :), varargin{:}); end if nargout > 0 varargout{1} = hCaps; end return; end faceColor = 'g'; ind = find(strcmpi(varargin, 'FaceColor'), 1, 'last'); if ~isempty(ind) faceColor = varargin{ind+1}; varargin(ind:ind+1) = []; end % extract transparency alpha = 1; ind = find(strcmpi(varargin, 'FaceAlpha'), 1, 'last'); if ~isempty(ind) alpha = varargin{ind+1}; varargin(ind:ind+1) = []; end % add default drawing options varargin = [{'FaceColor', faceColor, 'edgeColor', 'none', 'FaceAlpha', alpha} varargin]; % adjust drawing options for the cylinder. Options nPhi and nTheta may only % be given to the function drawDome, not drawCylinder options_cyl = ['open', varargin]; ind = find(strcmpi(options_cyl, 'nPhi'), 1, 'last'); if ~isempty(ind) ind = ind(1); nPhi = options_cyl{ind+1}; options_cyl(ind:ind+1) = []; options_cyl = [nPhi, options_cyl]; end ind = find(strcmpi(options_cyl, 'nTheta'), 1, 'last'); if ~isempty(ind) options_cyl(ind:ind+1) = []; end hold on if all(cap(1:3) == cap(4:6)) % the capsule is only a sphere. take arbitrary axis to be able to plot cap(4:6) = cap(1:3)+eps*([0 0 1]); h1 = 0; else h1 = drawCylinder(cap, options_cyl{:}); end h2 = drawDome(cap([1:3,7]), (cap(1:3)-cap(4:6)), varargin{:}); h3 = drawDome(cap([4:6,7]), -(cap(1:3)-cap(4:6)), varargin{:}); % return handles if nargout == 1 varargout{1} = [h1, h2, h3]; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/box3dVolume.m0000644000000000000000000000013214055375162017447 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/box3dVolume.m0000644000175000017500000000430014055375162020531 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vol = box3dVolume(box) %BOX3DVOLUME Volume of a 3-dimensional box. % % V = box3dVolume(BOX) % % A box is represented as a set of limits in each direction: % BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX]. % % Example % [n e f] = createCubeOctahedron; % box = boundingBox3d(n); % vol = box3dVolume(box) % vol = % 8 % % % See also % boxes3d, boundingBox3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. vol = prod(box(:, 2:2:end) - box(:, 1:2:end), 2); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectLineCylinder.m0000644000000000000000000000013214055375162021542 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectLineCylinder.m0000644000175000017500000001421214055375162022627 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = intersectLineCylinder(line, cylinder, varargin) %INTERSECTLINECYLINDER Compute intersection points between a line and a cylinder. % % POINTS = intersectLineCylinder(LINE, CYLINDER) % Returns intersection points between a line and a cylinder. % % Input parameters: % LINE = [x0 y0 z0 dx dy dz] % CYLINDER = [x1 y1 z1 x2 y2 z2 R] % % Output: % POINTS = [x1 y1 z1 ; x2 y2 z2] % % POINTS = intersectLineCylinder(LINE, CYLINDER, 'checkBounds', B) % Where B is a boolean (TRUE by default), check if the points are within % the bounds defined by the two extreme points. If B is false, the % cylinder is considered to be infinite. % % Example % % Compute intersection between simple vertical cylinder and line % line = [60 60 60 1 2 3]; % cylinder = [20 50 50 80 50 50 30]; % points = intersectLineCylinder(line, cylinder); % % Display the different shapes % figure; % drawCylinder(cylinder); % hold on; light; % axis([0 100 0 100 0 100]); % drawLine3d(line); % drawPoint3d(points, 'ko'); % % % % Compute intersections when one of the points is outside the % % cylinder % line = [80 60 60 1 2 3]; % cylinder = [20 50 50 80 50 50 30]; % intersectLineCylinder(line, cylinder) % ans = % 67.8690 35.7380 23.6069 % % % See also % lines3d, intersectLinePlane, drawCylinder, cylinderSurfaceArea % % References % See the link: % http://www.gamedev.net/community/forums/topic.asp?topic_id=467789 % % --- % Author: David Legland, from a file written by Daniel Trauth (RWTH) % e-mail: david.legland@inra.fr % Created: 2007-01-27 % HISTORY % 2010-10-21 change cylinder argument convention, add bounds check and doc % 2010-10-21 add check for points on cylinders, update doc %% Parse input arguments % default arguments checkBounds = true; % type of cylinder, one of {'closed', 'open', 'infinite'} type = 'closed'; % parse inputs while length(varargin)>1 var = varargin{1}; if strcmpi(var, 'checkbounds') checkBounds = varargin{2}; elseif strcmpi(var, 'type') type = varargin{2}; else error(['Unkown argument: ' var]); end varargin(1:2) = []; end %% Parse cylinder parameters % Starting point of the line l0 = line(1:3); % Direction vector of the line dl = line(4:6); % position of cylinder extremities c1 = cylinder(1:3); c2 = cylinder(4:6); % Direction vector of the cylinder dc = c2 - c1; % Radius of the cylinder r = cylinder(7); %% Resolution of a quadratic equation to find the increment % normalisation coefficient corresponding to direction of vector coef = dc / dot(dc, dc); % Substitution of parameters e = dl - dot(dl,dc) * coef; f = (l0-c1) - dot(l0-c1, dc) * coef; % Coefficients of 2-nd order equation A = dot(e, e); B = 2 * dot(e,f); C = dot(f,f) - r^2; % compute discriminant delta = B^2 - 4*A*C; % check existence of solution(s) if delta < 0 points = zeros(0, 3); return; end % extract roots pos1 = (-B + sqrt(delta)) / (2*A); pos2 = (-B - sqrt(delta)) / (2*A); posList = [pos1;pos2]; %% Estimation of point positions % process the smallest position pos1 = min(posList); % Point on the line: l0 + x*dl = p point1 = l0 + pos1 * dl; % process the greatest position pos2 = max(posList); % Point on the line: l0 + x*dl = p point2 = l0 + pos2 * dl; % Format result points = [point1 ; point2]; %% Check if points are located between bounds % if checkBounds option is not set, we can simply skip the rest if ~checkBounds || strncmpi(type, 'infinite', 1) return; end % compute cylinder axis axis = [c1 dc]; % compute position on axis ts = linePosition3d(points, axis); % check bounds for open cylinder % (keep only intersection points whose projection is between the two % cylinder extremities) if strncmpi(type, 'open', 1) ind = ts>=0 & ts<=1; points = points(ind, :); return; end % which intersection fall before and after bounds ind1 = find(ts < 0); ind2 = find(ts > 1); % case of both intersection on the same side -> no intersection if length(ind1) == 2 || length(ind2) == 2 points = zeros(0, 3); return; end % Process the remaining case of closed cylinder % -> compute eventual intersection(s) with end faces if ~isempty(ind1) plane = createPlane(c1, dc); points(ind1, :) = intersectLinePlane(line, plane); end if ~isempty(ind2) plane = createPlane(c2, dc); points(ind2, :) = intersectLinePlane(line, plane); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawRay3d.m0000644000000000000000000000013214055375162017100 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawRay3d.m0000644000175000017500000000614714055375162020175 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = drawRay3d(ray, varargin) % Draw a 3D ray on the current axis. % % drawRay3d(RAY) % With RAY having the syntax: [x0 y0 z0 dx dy dz], draws the ray starting % from point (x0 y0 z0) and going to direction (dx dy dz), clipped with % the current window axis. % % drawRay3d(RAY, PARAMS, VALUE) % Can specify parameter name-value pairs to change draw style. % % H = drawRay3d(...) % Returns handle on line object % % See also: % rays2d, drawLine % % Example % % generate 50 random 3D rays % origin = [29 28 27]; % v = rand(50, 3); % v = v - centroid(v); % ray = [repmat(origin, size(v,1),1) v]; % % draw the rays in the current axis % figure; axis equal; axis([0 50 0 50 0 50]); hold on; view(3); % drawRay3d(ray); % % See also % drawLine3d, clipRay3d % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-05-25, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. % extract handle of axis to draw in if isAxisHandle(ray) hAx = ray; ray = varargin{1}; varargin(1) = []; else hAx = gca; end % get bounding box limits box = axis(hAx); % clip the ray(s) with the limits of the current axis edge = clipLine3d(ray, box); % identify valid edges inds = sum(isnan(edge), 2) == 0; % draw the clipped line hh = []; if any(inds) edge = edge(inds, :); hh = drawEdge3d(hAx, edge); if ~isempty(varargin) set(hh, varargin{:}); end end % process output if nargout > 0 h = hh; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/triangleArea3d.m0000644000000000000000000000013214055375162020065 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/triangleArea3d.m0000644000175000017500000000575414055375162021165 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function area = triangleArea3d(pt1, pt2, pt3) %TRIANGLEAREA3D Area of a 3D triangle. % % AREA = triangleArea3d(P1, P2, P3) % Computes area of the 3D triangle whose vertices are given by P1, P2 and % P3. Each vertex is either a 1-by-3 row vector, or an array with 3 % columns, each column representing coordinate of a vertex. % The result AREA has as many rows as the number of rows of the largest % input array. % Compared to polygonArea3d, this function is assumed to be faster, as it % does not requires iteration over vertices. Moreover, it can be used to % computes the area of several triangles simultaneously. % % AREA = triangleArea3d(PTS) % Concatenates vertex coordinates in a 3-by-3 array. Each row of the % array contains coordinates of one vertex. % % % Example % triangleArea3d([10 10 10], [30 10 10], [10 40 10]) % ans = % 300 % % See also % polygons3d, polygonArea3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-08-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % if data is given as one array, split vertices if nargin == 1 pt2 = pt1(2,:); pt3 = pt1(3,:); pt1 = pt1(1,:); end % compute individual vectors v12 = bsxfun(@minus, pt2, pt1); v13 = bsxfun(@minus, pt3, pt1); % compute area from cross product area = vectorNorm3d(cross(v12, v13, 2)) / 2; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isPerpendicular3d.m0000644000000000000000000000013214055375162020620 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isPerpendicular3d.m0000644000175000017500000000537314055375162021715 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPerpendicular3d(v1, v2, varargin) %ISPERPENDICULAR3D Check orthogonality of two 3D vectors. % % B = isPerpendicular3d(V1, V2) % where V1 and V2 are 2 [1x3] arrays, returns 1 if the vectors are % orthogonal, and 0 otherwise. % % Also works when V1 and V2 are two [Nx3] arrays with same number of % rows. In this case, return a [Nx1] array containing 1 at the positions % of parallel vectors. % % Also works when one of V1 or V2 is scalar and the other one is [Nx3] % array, in this case return [Nx1] results. % % B = isPerpendicular3d(V1, V2, TOL) % Specifies the absolute tolerance (default is 1e-14). % % % Example % isPerpendicular3d([1 0 0], [0 1 0]) % ans = % 1 % % isPerpendicular3d([1 0 1], [1 0 0]) % ans = % 0 % % See also % vectors3d, isParallel3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-04-25 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % 2011.03.20 add support for tolerance, fix computation % check if tolerance is specified tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % compute perpendicularity test b = abs(sum(bsxfun(@times, v1, v2), 2)) < tol; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/planes3d.m0000644000000000000000000000013214055375162016751 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/planes3d.m0000644000175000017500000000457614055375162020052 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function planes3d(varargin) %PLANES3D Description of functions operating on 3D planes. % % Planes are represented by a 3D point (the plane origin) and 2 direction % vectors, which should not be colinear. % PLANE = [X0 Y0 Z0 DX1 DY1 DZ1 DX2 DY2 DZ2]; % % See also % createPlane, normalizePlane, medianPlane, planeNormal, parallelPlane % distancePointPlane, projPointOnPlane, planePosition, isBelowPlane % intersectPlanes, intersectLinePlane, intersectEdgePlane % dihedralAngle, planesBisector, polyhedronSlice, clipConvexPolyhedronHP % fitPlane, drawPlane3d, transformPlane3d, isPlane % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('planes3d'); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fitSphere.m0000644000000000000000000000013214055375162017171 xustar0030 mtime=1622538866.034813734 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fitSphere.m0000644000175000017500000000776214055375162020272 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [sphere, residuals] = fitSphere(x,y,z) %FITSPHERE Fit a sphere to 3D points using the least squares approach. % % SPHERE = fitSphere(PTS) % Fits the equation of a sphere in Cartesian coordinates to the N-by-3 % array PTS using the least squares approach. The sphere is represented % by its center [xc yc zc] and its radius r: SPHERE = [xc yc zc r]. % % SPHERE = fitSphere(X, Y, Z) % Use three vectors X, Y and Z with the length N instead of a the % N-by-3 array PTS. % % [SPHERE, RESIDUALS] = fitSphere(...) % Additionally outputs the residuals in the radial direction. % % Example: % center=-100 + 200*rand(1,3); % radius = randi([10 100]); % [x,y,z]=drawSphere(center, radius); % x=x+rand(size(x)); y=y+rand(size(y)); z=z+rand(size(z)); % sampleIdx = randi(numel(x),[1,randi([4, numel(x)])]); % x=x(sampleIdx); y=y(sampleIdx); z=z(sampleIdx); % sphere = fitSphere(x,y,z); % figure('color','w'); hold on; axis equal tight; view(3) % drawPoint3d(x,y,z) % drawSphere(sphere,'FaceAlpha',0.5) % % See also: % createSphere, drawSphere, intersectLineSphere, intersectPlaneSphere % % Source: % Levente Hunyadi - Fitting quadratic curves and surfaces: % https://de.mathworks.com/matlabcentral/fileexchange/45356 % ------ % Author: Levente Hunyadi, oqilipo (minor adaptions for matGeom) % Created: 2010 % Copyright 2010 Levente Hunyadi narginchk(1,3); switch nargin % n x 3 matrix case 1 n = size(x,1); validateattributes(x, {'numeric'}, {'2d','real','size',[n,3]}); z = x(:,3); y = x(:,2); x = x(:,1); otherwise % three x,y,z vectors n = length(x(:)); x = x(:); % force into columns y = y(:); z = z(:); validateattributes(x, {'numeric'}, {'real','size',[n,1]}); validateattributes(y, {'numeric'}, {'real','size',[n,1]}); validateattributes(z, {'numeric'}, {'real','size',[n,1]}); end % need four or more data points if n < 4 error('spherefit:InsufficientData', ... 'At least four points are required to fit a unique sphere.'); end % solve linear system of normal equations A = [x, y, z, ones(size(x))]; b = -(x.^2 + y.^2 + z.^2); a = A \ b; % return center coordinates and sphere radius center = -a(1:3)./2; radius = realsqrt(sum(center.^2)-a(4)); sphere = [center' radius]; % calculate residuals residuals = radius - sqrt(sum(bsxfun(@minus,[x y z],center.').^2,2)); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/sphericalAngle.m0000644000000000000000000000013114055375162020160 xustar0029 mtime=1622538866.03881372 30 atime=1622538866.034813734 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/sphericalAngle.m0000644000175000017500000001002014055375162021237 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function alpha = sphericalAngle(p1, p2, p3) %SPHERICALANGLE Compute angle between points on the sphere. % % ALPHA = sphericalAngle(P1, P2, P3) % Computes angle (P1, P2, P3), i.e. the angle, measured at point P2, % between the direction (P2, P1) and the direction (P2, P3). % The result is given in radians, between 0 and 2*PI. % % Points are given either as [x y z] (there will be normalized to lie on % the unit sphere), or as [phi theta], with phi being the longitude in [0 % 2*PI] and theta being the elevation on horizontal [-pi/2 pi/2]. % % % NOTE: % this is an 'oriented' version of the angle computation, that is, the % result of sphericalAngle(P1, P2, P3) equals % 2*pi-sphericalAngle(P3,P2,P1). To have the more classical relation % (with results given betwen 0 and PI), it suffices to take the minimum % of angle and 2*pi-angle. % % Examples % % Use inputs as cartesian coordinates % p1 = [0 1 0]; % p2 = [1 0 0]; % p3 = [0 0 1]; % alpha = sphericalAngle(p1, p2, p3) % alpha = % 1.5708 % % % Use inputs as spherical coordinates % sph1 = [.1 0]; % sph2 = [0 0]; % sph3 = [0 .1]; % alphas = sphericalAngle(sph1, sph2, sph3) % alphas = % 1.5708 % % % See also: % geom3d, angles3d, spheres, sph2cart % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % % HISTORY % 23-05-2006 fix bug for points with angle from center > pi/2 % 05-06-2013 fix bug for points given as spherical coordinates, better % support for multiple inputs % test if points are given as matlab spherical coordinates if size(p1, 2) == 2 [x, y, z] = sph2cart(p1(:,1), p1(:,2), ones(size(p1,1), 1)); p1 = [x y z]; [x, y, z] = sph2cart(p2(:,1), p2(:,2), ones(size(p2,1), 1)); p2 = [x y z]; [x, y, z] = sph2cart(p3(:,1), p3(:,2), ones(size(p3,1), 1)); p3 = [x y z]; end % normalize points p1 = normalizeVector3d(p1); p2 = normalizeVector3d(p2); p3 = normalizeVector3d(p3); % create the plane tangent to the unit sphere and containing central point plane = createPlane(p2, p2); % project the two other points on the plane pp1 = planePosition(projPointOnPlane(p1, plane), plane); pp3 = planePosition(projPointOnPlane(p3, plane), plane); % compute angle on the tangent plane pp2 = zeros(max(size(pp1, 1), size(pp3,1)), 2); alpha = angle3Points(pp1, pp2, pp3); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/sph2cart2.m0000644000000000000000000000013014055375162017046 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/sph2cart2.m0000644000175000017500000000625514055375162020145 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = sph2cart2(theta, phi, rho) %SPH2CART2 Convert spherical coordinates to cartesian coordinates. % % C = SPH2CART2(S) % C = SPH2CART2(THETA, PHI) (assume rho = 1) % C = SPH2CART2(THETA, PHI, RHO) % [X, Y, Z] = SPH2CART2(THETA, PHI, RHO); % % S = [phi theta rho] (spherical coordinate). % C = [X Y Z] (cartesian coordinate) % % The following convention is used: % THETA is the colatitude, in radians, 0 for north pole, +pi for south % pole, pi/2 for points with z=0. % PHI is the azimuth, in radians, defined as matlab cart2sph: angle from % Ox axis, counted counter-clockwise. % RHO is the distance of the point to the origin. % Discussion on choice for convention can be found at: % http://www.physics.oregonstate.edu/bridge/papers/spherical.pdf % % See also: % angles3d, cart2sph2, sph2cart, sph2cart2d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 22/03/2005: make test for 2 args, and add radius if not specified for % 1 arg. % 03/11/2006: change convention for angle: uses order [THETA PHI RHO] % Process input arguments if nargin == 1 phi = theta(:, 2); if size(theta, 2) > 2 rho = theta(:, 3); else rho = ones(size(phi)); end theta = theta(:, 1); elseif nargin == 2 rho = ones(size(theta)); end % conversion rz = rho .* sin(theta); x = rz .* cos(phi); y = rz .* sin(phi); z = rho .* cos(theta); if nargout <= 1 varargout{1} = [x, y, z]; else varargout{1} = x; varargout{2} = y; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotationOx.m0000644000000000000000000000013014055375162020530 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotationOx.m0000644000175000017500000000667314055375162021633 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createRotationOx(varargin) %CREATEROTATIONOX Create the 4x4 matrix of a 3D rotation around x-axis. % % TRANS = createRotationOx(THETA); % Returns the transform matrix corresponding to a rotation by the angle % THETA (in radians) around the Ox axis. A rotation by an angle of PI/2 % would transform the vector [0 1 0] into the vector [0 0 1]. % % The returned matrix has the form: % [1 0 0 0] % [0 cos(THETA) -sin(THETA) 0] % [0 sin(THETA) cos(THETA) 0] % [0 0 0 1] % % TRANS = createRotationOx(ORIGIN, THETA); % TRANS = createRotationOx(X0, Y0, Z0, THETA); % Also specifies origin of rotation. The result is similar as performing % translation(-X0, -Y0, -Z0), rotation, and translation(X0, Y0, Z0). % % See also: % transforms3d, transformPoint3d, createRotationOy, createRotationOz % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 24/11/2008 changed convention for angle % 22/04/2009 rename as createRotationOx % default values dx = 0; dy = 0; dz = 0; theta = 0; % get input values if length(varargin) == 1 % only one argument -> rotation angle theta = varargin{1}; elseif length(varargin) == 2 % origin point (as array) and angle var = varargin{1}; dx = var(1); dy = var(2); dz = var(3); theta = varargin{2}; elseif length(varargin) == 4 % origin (x and y) and angle dx = varargin{1}; dy = varargin{2}; dz = varargin{3}; theta = varargin{4}; end % compute coefs cot = cos(theta); sit = sin(theta); % create transformation trans = [... 1 0 0 0;... 0 cot -sit 0;... 0 sit cot 0;... 0 0 0 1]; % add the translation part t = [1 0 0 dx;0 1 0 dy;0 0 1 dz;0 0 0 1]; trans = t * trans / t; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawVector3d.m0000644000000000000000000000013014055375162017605 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawVector3d.m0000644000175000017500000000517514055375162020704 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawVector3d(pos, vect, varargin) %DRAWVECTOR3D Draw vector at a given position. % % drawVector3d(POS, VECT) % Draws the vector VECT starting at the position POS. Both VECT and POS % are N-by-3 arrays. % % drawVector3d(..., PNAME, PVALUE) % Specifies additional optional parameters that will be given to the % quiver3 function. % % Example % figure; hold on; % drawVector3d([2 3 4], [1 0 0]); % drawVector3d([2 3 4], [0 1 0]); % drawVector3d([2 3 4], [0 0 1]); % view(3); % % See also % vectors3d, quiver3 % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2011-12-19, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. if isAxisHandle(pos) hAx = pos; pos = vect; vect = varargin{1}; varargin(1) = []; else hAx = gca; end h = quiver3(hAx, pos(:, 1), pos(:, 2), pos(:, 3), ... vect(:, 1), vect(:, 2), vect(:, 3), 0, varargin{:}); % format output if nargout > 0 varargout{1} = h; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/midPoint3d.m0000644000000000000000000000013014055375162017250 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/midPoint3d.m0000644000175000017500000000707114055375162020344 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = midPoint3d(varargin) %MIDPOINT3D Middle point of two 3D points or of a 3D edge. % % MID = midPoint3d(P1, P2) % Compute the middle point of the two points P1 and P2. % % MID = midPoint3d(EDGE) % Compute the middle point of the edge given by EDGE. % EDGE has the format: [X1 Y1 Z1 X2 Y2 Z2], and MID has the format % [XMID YMID ZMID], % with XMID = (X1+X2)/2, YMID = (Y1+Y2)/2 and ZMID = (Z1+Z2)/2. % % [MIDX MIDY] = midPoint3d(...) % Return the result as two separate variables or arrays. % % Works also when EDGE is a N-by-6 array, in this case the result is a % N-by-3 array containing the midPoint3d of each edge. % % % Example % P1 = [10 20 30]; % P2 = [30 40 50]; % % edge input % midPoint3d([P1 P2]) % ans = % 20 30 40 % % % two points input % midPoint3d(P1, P2) % ans = % 20 30 40 % % % three outputs % [xm ym zm] = midPoint3d(P1, P2) % xm = % 20 % ym = % 30 % zm = % 40 % % See also % edges3d, points3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-08-08, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. if nargin == 1 % input is a 3D edge edge = varargin{1}; mid = [mean(edge(:, [1 4]), 2) mean(edge(:, [2 5]), 2) mean(edge(:, [3 6]), 2)]; elseif nargin == 2 % input are two points p1 = varargin{1}; p2 = varargin{2}; % assert inputs are equal n1 = size(p1, 1); n2 = size(p2, 1); if n1>1 && n2==1 p2 = repmat(p2, n1, 1); elseif n2>1 && n1==1 p1 = repmat(p1, n2, 1); elseif n1~=n2 error('geom3d:midPoint3d', ... 'Inputs must have same size, or one must have length 1'); end % compute middle point mid = (p1 + p2) / 2; end % process output arguments if nargout<=1 varargout{1} = mid; else varargout = {mid(:,1), mid(:,2), mid(:,3)}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/vectorAngle3d.m0000644000000000000000000000013014055375162017736 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/vectorAngle3d.m0000644000175000017500000000531614055375162021032 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = vectorAngle3d(v1, v2) %VECTORANGLE3D Angle between two 3D vectors. % % THETA = vectorAngle3d(V1, V2) % Computes the angle between the 2 3D vectors V1 and V2. The result THETA % is given in radians, between 0 and PI. % % % Example % % angle between 2 orthogonal vectors % vectorAngle3d([1 0 0], [0 1 0]) % ans = % 1.5708 % % % angle between 2 parallel vectors % v0 = [3 4 5]; % vectorAngle3d(3*v0, 5*v0) % ans = % 0 % % See also % vectors3d, vectorNorm3d, crossProduct3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % 2011-03-10 improve computation precision % compute angle using arc-tangent to get better precision for angles near % zero, see the discussion in: % http://www.mathworks.com/matlabcentral/newsreader/view_thread/151925#381952 theta = atan2(vectorNorm3d(crossProduct3d(v1, v2)), sum(bsxfun(@times, v1, v2),2)); % equivalent to: % v1 = normalizeVector3d(v1); % v2 = normalizeVector3d(v2); % theta = acos(dot(v1, v2, 2)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/projPointOnLine3d.m0000644000000000000000000000013014055375162020556 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/projPointOnLine3d.m0000644000175000017500000000540414055375162021650 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = projPointOnLine3d(point, line) %PROJPOINTONLINE3D Project a 3D point orthogonally onto a 3D line. % % PT2 = projPointOnLine3d(PT, LINE). % Computes the (orthogonal) projection of 3D point PT onto the 3D line % LINE. % % Function works also for multiple points and lines. In this case, it % returns multiple points. % Point PT1 is a N-by-3 array, and LINE is a N-by-6 array. % Result PT2 is a N-by-3 array, containing coordinates of orthogonal % projections of PT1 onto lines LINE. % % % See also: % projPointOnLine, distancePointLine3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 2012-08-23. % % HISTORY % direction vector of the line vx = line(:, 4); vy = line(:, 5); vz = line(:, 6); % difference of point with line origin dx = point(:,1) - line(:,1); dy = point(:,2) - line(:,2); dz = point(:,3) - line(:,3); % Position of projection on line, using dot product delta = vx .* vx + vy .* vy + vz .* vz; tp = (dx .* vx + dy .* vy + dz .* vz) ./ delta; % convert position on line to cartesian coordinates point = [line(:,1) + tp .* vx, line(:,2) + tp .* vy, line(:,3) + tp .* vz]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawAxisCube.m0000644000000000000000000000013014055375162017617 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawAxisCube.m0000644000175000017500000000435714055375162020717 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function p = drawAxisCube(varargin) %DRAWAXISCUBE Draw a colored cube representing axis orientation. % % output = drawAxisCube(input) % % Example % drawAxisCube % % See also % drawAxis3d, createCube, patch % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. [n, e, f] = createCube; %#ok faceColors = [ ... 1 1 0; ... 0 0 1; ... 1 0 0; ... 0 1 1; ... 1 0 1; ... 0 1 0; ... ]; p = patch('vertices', n, 'faces', f, ... 'facecolor', 'flat', 'FaceVertexCData', faceColors); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawSphericalTriangle.m0000644000000000000000000000013014055375162021514 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawSphericalTriangle.m0000644000175000017500000000664714055375162022620 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawSphericalTriangle(sphere, p1, p2, p3, varargin) %DRAWSPHERICALTRIANGLE Draw a triangle on a sphere. % % drawSphericalTriangle(SPHERE, PT1, PT2, PT3); % Draws the spherical triangle defined by the three input 3D points and % the reference sphere. % Points are given as 3D points, and are projected onto the sphere. The % order of the points is not relevant. % % drawSphericalTriangle(SPHERE, PT1, PT2, PT3, OPTIONS); % Allows to specify plot options for spherical edges, in the form of % parameter name-value pairs. % % Example % % Draw a sphere and a spherical triangle on it % s = [0 0 0 2]; % pts = [1 0 0;0 -1 0;0 0 1]; % drawSphere(s); hold on; % drawSphericalTriangle(s, pts(1,:), pts(2,:), pts(3,:), 'linewidth', 2); % view(3); axis equal; % % See also % drawSphere, fillSphericalTriangle, drawSphericalPolygon, % drawSphericalEdge % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 22/02/2005 % % HISTORY % 2007-06-27 manage spheres other than origin % 2008-10-30 replace intersectPlaneLine by intersectLinePlane % 2012-02-09 put drawing code into the 'drawSphericalEdge' function % 2012-10-24 add holding facility, updtate doc % extract data of the sphere ori = sphere(:, 1:3); % extract direction vectors for each point v1 = normalizeVector3d(p1 - ori); v2 = normalizeVector3d(p2 - ori); v3 = normalizeVector3d(p3 - ori); % keep hold state of current axis h = ishold; % draw each spherical edge hold on; h1 = drawSphericalEdge(sphere, [v1 v2], varargin{:}); h2 = drawSphericalEdge(sphere, [v2 v3], varargin{:}); h3 = drawSphericalEdge(sphere, [v3 v1], varargin{:}); % return to previous hold state if needed if ~h hold off; end if nargout > 0 varargout = {h1, h2, h3}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/linePosition3d.m0000644000000000000000000000013014055375162020141 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/linePosition3d.m0000644000175000017500000001006314055375162021230 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pos = linePosition3d(point, line) % Return the position of a 3D point projected on a 3D line. % % T = linePosition3d(POINT, LINE) % Computes position of point POINT on the line LINE, relative to origin % point and direction vector of the line. % LINE has the form [x0 y0 z0 dx dy dy], % POINT has the form [x y z], and is assumed to belong to line. % The result T is the value such that POINT = LINE(1:3) + T * LINE(4:6). % If POINT does not belong to LINE, the position of its orthogonal % projection is computed instead. % % T = linePosition3d(POINT, LINES) % If LINES is an array of NL lines, return NL positions, corresponding to % each line. % % T = linePosition3d(POINTS, LINE) % If POINTS is an array of NP points, return NP positions, corresponding % to each point. % % See also: % lines3d, createLine3d, distancePointLine3d, projPointOnLine3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % % HISTORY % 05/01/2007 update doc % 28/10/2010 change to bsxfun calculation for arbitrary input sizes % (Thanks to Sven Holcombe) % size of input arguments np = size(point, 1); nl = size(line, 1); if np == 1 || nl == 1 || np == nl % standard case where result is either scalar or vector % vector from line origin to point dp = bsxfun(@minus, point, line(:,1:3)); % direction vector of the line vl = line(:, 4:6); % precompute and check validity of denominator denom = sum(vl.^2, 2); invalidLine = denom < eps; denom(invalidLine) = 1; % compute position using dot product normalized with norm of line vector. pos = bsxfun(@rdivide, sum(bsxfun(@times, dp, vl), 2), denom); % position on a degenerated line is set to 0 pos(invalidLine) = 0; else % reshape input point = reshape(point, [np 1 3]); line = reshape(line, [1 nl 6]); % vector from line origin to point dp = bsxfun(@minus, point, line(:,:,1:3)); % direction vector of the line vl = line(:, :, 4:6); % precompute and check validity of denominator denom = sum(vl.^2, 3); invalidLine = denom < eps; denom(invalidLine) = 1; % compute position using dot product normalized with norm of line vector. pos = bsxfun(@rdivide, sum(bsxfun(@times, dp, vl), 3), denom); % position on a degenerated line is set to 0 pos(invalidLine) = 0; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/anglePoints3d.m0000644000000000000000000000013014055375162017750 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/anglePoints3d.m0000644000175000017500000000660714055375162021050 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function alpha = anglePoints3d(varargin) %ANGLEPOINTS3D Compute angle between three 3D points. % % ALPHA = anglePoints3d(P1, P2) % Computes angle (P1, O, P2), in radians, between 0 and PI. % % ALPHA = anglePoints3d(P1, P2, P3) % Computes angle (P1, P2, P3), in radians, between 0 and PI. % % ALPHA = anglePoints3d(PTS) % PTS is a 3x3 or 2x3 array containing coordinate of points. % % See also % points3d, angles3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % % HISTORY % 20/09/2005: add case of single argument for all points % 04/01/2007: check typo % 27/05/2014: adjust known vector sizes n1, n0, n2 once corrected for p2 = [0 0 0]; if length(varargin) == 1 pts = varargin{1}; if size(pts, 1)==2 p1 = pts(1,:); p0 = [0 0 0]; p2 = pts(2,:); else p1 = pts(1,:); p0 = pts(2,:); p2 = pts(3,:); end elseif length(varargin) == 2 p1 = varargin{1}; p0 = [0 0 0]; p2 = varargin{2}; elseif length(varargin) == 3 p1 = varargin{1}; p0 = varargin{2}; p2 = varargin{3}; end % ensure all data have same size n1 = size(p1, 1); n2 = size(p2, 1); n0 = size(p0, 1); if n1 ~= n0 if n1 == 1 p1 = repmat(p1, [n0 1]); n1 = n0; elseif n0==1 p0 = repmat(p0, [n1 1]); else error('Arguments P1 and P0 must have the same size'); end end if n1 ~= n2 if n1 == 1 p1 = repmat(p1, [n2 1]); elseif n2 == 1 p2 = repmat(p2, [n1 1]); else error('Arguments P1 and P2 must have the same size'); end end % normalized vectors p1 = normalizeVector3d(p1 - p0); p2 = normalizeVector3d(p2 - p0); % compute angle alpha = acos(dot(p1, p2, 2)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawEllipseCylinder.m0000644000000000000000000000013014055375162021203 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawEllipseCylinder.m0000644000175000017500000001346714055375162022305 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawEllipseCylinder(cyl, varargin) %DRAWELLIPSECYLINDER Draw a cylinder with ellipse cross-section. % % drawEllipseCylinder(CYL) % draws the cylinder CYL on the current axis. % CYL is a cylinder defined by [x1 y1 z1 x2 y2 z2 r1 r2 roll], with: % * [x1 y2 z1] are coordinates of starting point, % * [x2 y2 z2] are coordinates of ending point, % * R1 and R2 are the lengths of the ellipse semi axes, and % * ROLL is the rotation of the cylinder around its main axis (in % degrees) % % drawEllipseCylinder(CYL, N) % uses N points for discretisation of angle. Default value is 32. % % drawEllipseCylinder(..., OPT) % with OPT = 'open' (default) or 'closed', specify if bases of the % cylinder should be drawn. % % drawEllipseCylinder(..., 'FaceColor', COLOR) % Specifies the color of the cylinder. Any couple of parameters name and % value can be given as argument, and will be transfered to the 'surf' % matlab function % % H = drawEllipseCylinder(...) % returns a handle to the patch representing the cylinder. % % % Example: % figure; drawEllipseCylinder([0 0 0 10 20 30 5 2]); % % figure; drawEllipseCylinder([0 0 0 10 20 30 5 2], 'open'); % % figure; drawEllipseCylinder([0 0 0 10 20 30 5 2], 'FaceColor', 'r'); % % figure; % h = drawEllipseCylinder([0 0 0 10 20 30 5 2]); % set(h, 'facecolor', 'b'); % % % Draw three mutually intersecting elliptic cylinders % p1 = [30 0 0]; % p2 = [0 30 0]; % p3 = [0 0 30]; % radii = [20 10]; % figure; % drawEllipseCylinder([-p1 p1 radii 0], 'FaceColor', 'r'); % hold on % drawEllipseCylinder([-p2 p2 radii 90], 'FaceColor', 'g'); % drawEllipseCylinder([-p3 p3 radii 90], 'FaceColor', 'b'); % axis equal % set(gcf, 'renderer', 'opengl') % view([60 30]); light; % % See Also: % drawCylinder, drawSphere, cylinderMesh, drawLine3d, surf % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 27/02/2014 % HISTORY %% Input argument processing if iscell(cyl) res = zeros(length(cyl), 1); for i = 1:length(cyl) res(i) = drawEllipseCylinder(cyl{i}, varargin{:}); end if nargout > 0 varargout{1} = res; end return; end % default values N = 32; closed = true; % check number of discretization steps if ~isempty(varargin) var = varargin{1}; if isnumeric(var) N = var; varargin = varargin(2:end); end end % check if cylinder must be closed or open if ~isempty(varargin) var = varargin{1}; if ischar(var) if strncmpi(var, 'open', 4) closed = false; varargin = varargin(2:end); elseif strncmpi(var, 'closed', 5) closed = true; varargin = varargin(2:end); end end end %% Computation of mesh coordinates % extreme points of cylinder p1 = cyl(1:3); p2 = cyl(4:6); % radius of cylinder r1 = cyl(7); r2 = cyl(8); roll = 0; if size(cyl, 2) > 8 roll = cyl(9); end % compute orientation angle of cylinder (in degrees) [theta, phi, rho] = cart2sph2d(p2 - p1); dphi = linspace(0, 2*pi, N+1); % generate a cylinder oriented upwards x = repmat(cos(dphi) * r1, [2 1]); y = repmat(sin(dphi) * r2, [2 1]); z = repmat([0 ; rho], [1 length(dphi)]); % transform points trans = localToGlobal3d(p1, theta, phi, roll); pts = transformPoint3d([x(:) y(:) z(:)], trans); % reshape transformed points x2 = reshape(pts(:,1), size(x)); y2 = reshape(pts(:,2), size(x)); z2 = reshape(pts(:,3), size(x)); %% Display cylinder mesh % add default drawing options varargin = [{'FaceColor', 'g', 'edgeColor', 'none'} varargin]; % plot the cylinder as a surface hSurf = surf(x2, y2, z2, varargin{:}); % eventually plot the ends of the cylinder if closed ind = find(strcmpi(varargin, 'facecolor'), 1, 'last'); if isempty(ind) color = 'k'; else color = varargin{ind+1}; end patch(x2(1,:)', y2(1,:)', z2(1,:)', color, 'edgeColor', 'none'); patch(x2(2,:)', y2(2,:)', z2(2,:)', color, 'edgeColor', 'none'); end % format ouptut if nargout == 1 varargout{1} = hSurf; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/distancePoints3d.m0000644000000000000000000000013014055375162020454 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/distancePoints3d.m0000644000175000017500000000555114055375162021551 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dist = distancePoints3d(p1, p2, varargin) %DISTANCEPOINTS3D Compute euclidean distance between pairs of 3D Points. % % D = distancePoints3d(P1, P2) return distance between points P1 and % P2, given as [X Y Z]. % % If P1 and P2 are two arrays of points, result is a N1*N2 array % containing distance between each point of P1 and each point of P2. % % % D = distancePoints3d(P1, P2, NOR) % with NOR being 1, 2, or Inf, corresponfing to the norm used. Default is % 2 (euclidean norm). 1 correspond to manhattan (or taxi driver) distance % and Inf to maximum difference in each coordinate. % % % See also: % points3d, minDistancePoints, distancePoints % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 21/02/2005: add different norms % 28/08/2007: deprecate norm = 2; if length(varargin)==1 norm = varargin{1}; end % compute difference of coordinate for each pair of points ptsDiff = bsxfun(@minus, p2, p1); % Return dist based on the type of measurement requested switch(norm) case 1 dist = sum(abs(ptsDiff),2); case 2 dist = vectorNorm3d(ptsDiff); case Inf dist = max(abs(ptsDiff), [], 2); otherwise dist = power(sum(power(ptsDiff, norm),2), 1/norm); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawGrid3d.m0000644000000000000000000000013014055375162017230 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawGrid3d.m0000644000175000017500000001046614055375162020326 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawGrid3d(varargin) %DRAWGRID3D Draw a 3D grid on the current axis. % % drawGrid3d % draws a 3D square grid, with origin (0,0,0) and spacing 1 in each % direction, with bounds corresponding to the bounds of current axis. % % drawGrid3d(SPACING) % where spacing is either a scalar or a [1x3] matrix, specifies the size % of the unit cell. % % drawGrid3d(ORIGIN, SPACING) % Also specify origin of grid. ORIGIN is a [1x3] array. % % drawGrid3d(..., EDGE) % specifies whether function should draw edges touching edges of axis. % EDGE is a characheter string, which can be : % - 'OPEN' : each line start from one face of window to the opposite % face. This results in a 'spiky' grid. % - 'CLOSED' (default value) : each line stops at the last visible point % of the grid for this line. The result looks like a box (no free spikes % around the grid). % % H = drawGrid3d(...); % return a vector of handles for each LINE object which was crated. % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2005-11-17 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). %% initialize variables ----- % default values closed = true; origin = [0 0 0]; spacing = [1 1 1]; % check if grid is open or not str = ''; if ~isempty(varargin) str = varargin{end}; end if ischar(str) if strncmpi(str, 'open', 4) closed = false; end varargin = varargin(1:end-1); end % check origin and grid spacing if length(varargin)==1 spacing = varargin{1}; elseif length(varargin)==2 origin = varargin{1}; spacing = varargin{2}; end %% Compute internam data ----- % get axis limits ax = axis; x0 = ax(1); x1 = ax(2); y0 = ax(3); y1 = ax(4); z0 = ax(5); z1 = ax(6); % get first and last coordinates of the grid in each direction dx = spacing(1); dy = spacing(2); dz = spacing(3); xe = x0 + mod(origin(1) - x0, dx); xf = x1 - mod(x1 - origin(1), dx); ye = y0 + mod(origin(2) - y0, dy); yf = y1 - mod(y1 - origin(2), dy); ze = z0 + mod(origin(1) - z0, dz); zf = z1 - mod(z1 - origin(1), dz); % update first and last coordinate if grid is 'closed' if closed x0 = xe; x1 = xf; y0 = ye; y1 = yf; z0 = ze; z1 = zf; end %% Draw the grid ----- h = []; %TODO: rewrite code, avoiding loops % draw lines parallel to x axis for y = ye:dy:yf for z = ze:dz:zf h = [h; drawEdge3d([x0 y z x1 y z])]; %#ok end end % draw lines parallel to y axis for x = xe:dx:xf for z = ze:dz:zf h = [h; drawEdge3d([x y0 z x y1 z])]; %#ok end end % draw lines parallel to z axis for x = xe:dx:xf for y = ye:dy:yf h = [h; drawEdge3d([x y z0 x y z1])]; %#ok end end %% Check output arguments ----- if nargout>0 varargout{1} = h; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/projPointOnCylinder.m0000644000000000000000000000013014055375162021211 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/projPointOnCylinder.m0000644000175000017500000001251214055375162022301 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ptProj = projPointOnCylinder(pt, cyl, varargin) %PROJPOINTONCYLINDER Project a 3D point onto a cylinder. % % PTPROJ = projPointOnCircle3d(PT, CYLINDER). % Computes the projection of 3D point PT onto the CYLINDER. % % Point PT is a 1-by-3 array, and CYLINDER is a 1-by-7 array. % Result PTPROJ is a 1-by-3 array, containing the coordinates of the % projection of PT onto the CYLINDER. % % PTPROJ = projPointOnCircle3d(..., OPT) % with OPT = 'open' (0) (default) or 'closed' (1), specify if the bases % of the cylinder should be included. % % Example % demoProjPointOnCylinder % % See also % projPointOnLine3d, projPointOnPlane, projPointOnCircle3d % % --------- % Author: oqilipo % Created: 2021-04-17, using R2020b % Copyright 2021 parser = inputParser; addRequired(parser, 'pt', @(x) validateattributes(x, {'numeric'},... {'size',[1 3],'real','finite','nonnan'})); addRequired(parser, 'cyl', @(x) validateattributes(x, {'numeric'},... {'size',[1 7],'real','finite','nonnan'})); capParValidFunc = @(x) (islogical(x) ... || isequal(x,1) || isequal(x,0) || any(validatestring(x, {'open','closed'}))); addOptional(parser,'cap','open', capParValidFunc); parse(parser,pt,cyl,varargin{:}); pt = parser.Results.pt; cyl = parser.Results.cyl; cap = lower(parser.Results.cap(1)); % Radius of the cylinder cylRadius = cyl(7); % Height of the cylinder cylBottom = -Inf; cylHeight = Inf; if cap == 'c' || cap == 1 cylBottom = 0; cylHeight = distancePoints3d(cyl(1:3),cyl(4:6)); end % Create a transformation for the point into a local cylinder coordinate % system. Align the cylinder axis with the z axis and translate the % starting point of the cylinder to the origin. TFM = createRotationVector3d(cyl(4:6)-cyl(1:3), [0 0 1])*createTranslation3d(-cyl(1:3)); % cylTfm = [transformPoint3d(cyl(1:3), TFM) transformPoint3d(cyl(4:6), TFM) cylRadius]; % cylTfm2 = [0 0 0 0 0 cylHeight, cylRadius]; % assert(ismembertol(cylTfm,cylTfm2,'byRows',1,'DataScale',1e1)) % Transform the point. ptTfm = transformPoint3d(pt,TFM); % Convert the transformed point to cylindrical coordinates. [ptTheta, ptRadius, ptHeight] = cart2cyl(ptTfm); if ptRadius <= cylRadius && (ptHeight <= cylBottom || ptHeight >= cylHeight) % If point is inside the radius of the cylinder but outside its height if ptHeight <= cylBottom ptProj_cyl = [ptTheta, ptRadius, 0]; else ptProj_cyl = [ptTheta, ptRadius, cylHeight]; end elseif ptRadius > cylRadius && (ptHeight <= cylBottom || ptHeight >= cylHeight) % If point is outside the cylinder's radius and height if ptHeight <= cylBottom ptProj_cyl = [ptTheta, cylRadius, 0]; else ptProj_cyl = [ptTheta, cylRadius, cylHeight]; end elseif ptRadius < cylRadius && (ptHeight > cylBottom && ptHeight < cylHeight) % If point is inside the cylinder's radius and height deltaRadius = cylRadius - ptRadius; deltaHeight = cylHeight - ptHeight; if (deltaRadius < ptHeight && deltaRadius < deltaHeight) || isinf(cylBottom) % If the distance to the cylinder's surface is smaller than the % distance to the top and bottom surfaces. ptProj_cyl = [ptTheta, cylRadius, ptHeight]; else if ptHeight < deltaHeight ptProj_cyl = [ptTheta, ptRadius, 0]; else ptProj_cyl = [ptTheta, ptRadius, cylHeight]; end end elseif ptRadius >= cylRadius && (ptHeight > cylBottom && ptHeight < cylHeight) % If point is outside the radius of the cylinder and inside its height ptProj_cyl = [ptTheta, cylRadius, ptHeight]; end % Convert the projected point back to Cartesian coordinates ptProj_cart = cyl2cart(ptProj_cyl); % Transform the projected point back to the global coordinate system ptProj = transformPoint3d(ptProj_cart,inv(TFM)); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/lineToEdge3d.m0000644000000000000000000000013014055375162017504 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/lineToEdge3d.m0000644000175000017500000000450314055375162020575 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = lineToEdge3d(line) %LINETOEDGE3D Convert a 3D straight line to a 3D finite edge. % % EDGE = lineToEdge3d(LINE) % Returns the edge with same origin as the line LINE, and with second % extremity corresponding to the addition of line origin and direction. % LINE is represented as [X0 Y0 Z0 DX DY DZ] % EDGE is represented as [X1 Y1 Z1 X2 Y2 Z2] % % Example % line = [3 4 5 1 2 3]; % edge = lineToEdge3d(line) % edge = % 3 4 5 4 6 8 % % See also % lines3d, edges3d, edgeToLine3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-05-07, using Matlab 9.6.0.1072779 (R2019a) % Copyright 2019 INRA - Cepia Software Platform. edge = [line(:, 1:3) line(:,1:3)+line(:,4:6)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawAxis3d.m0000644000000000000000000000013014055375162017247 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawAxis3d.m0000644000175000017500000000722714055375162020346 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawAxis3d(varargin) %DRAWAXIS3D Draw a coordinate system and an origin. % % drawAxis3d % Adds three 3D arrows to the current axis, corresponding to the % directions of the 3 basis vectors Ox, Oy and Oz. % Ox vector is red, Oy vector is green, and Oz vector is blue. % % drawAxis3d(L, R) % Specifies the length L and the radius of the cylinders representing the % different axes. % % drawAxis3d(..., 'TFM', TRANSFORM) % Transforms the coordinate system before drawing using TRANSFORM. % % H = drawAxis3d(...) returns the group handle of the axis object. % % Example % drawAxis3d % % figure; % drawAxis3d(20, 1); % view([135,15]); lighting('phong'); camlight('head'); axis('equal') % xlabel X; ylabel Y; zlabel Z % % See also % drawAxisCube % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2007-08-14, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % Check if axes handle is specified hAx = gca; if ~isempty(varargin) if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1)=[]; end end % Parsing p = inputParser; addOptional(p,'L',1, @(x)validateattributes(x,{'numeric'},... {'scalar','nonempty','real','finite','positive','nonnan'})); addOptional(p,'R',[], @(x)validateattributes(x,{'numeric'},... {'scalar','nonempty','real','finite','positive','nonnan'})); addParameter(p,'TFM',eye(4), @isTransform3d); parse(p,varargin{:}); L = p.Results.L; R = p.Results.R; if isempty(R) R=L/10; elseif R/L > 0.1 R = (0.1-eps)*L; warning('Value of R is invalid and was ignored!') end TFM = p.Results.TFM; % geometrical data origin = transformPoint3d(zeros(3,3), TFM); vector = transformVector3d(eye(3,3), TFM); color = eye(3,3); % draw three arrows and a ball hold on; sh=drawArrow3d(hAx, origin, vector*L, color, 'arrowRadius', R/L); sh(4)=drawSphere(hAx,[origin(1,:) 2*R], 'faceColor', 'black'); gh = hggroup(hAx); set(sh,'Parent',gh) if nargout > 0 varargout = {gh}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/clipLine3d.m0000644000000000000000000000013014055375162017224 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/clipLine3d.m0000644000175000017500000001101314055375162020307 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = clipLine3d(line, box) %CLIPLINE3D Clip a line with a box and return an edge. % % EDGE = clipLine3d(LINE, BOX); % Clips the line LINE with the bounds given in BOX, and returns the % corresponding edge. % % If the line lies totally outside of the box, returns a 1-by-6 row array % containing only NaN's. % % If LINE is a N-by-6 array, with one line by row, returns the clipped % edge coresponding to each line in a N-by-6 array. % % See also: % lines3d, edges3d, createLine3d, clipRay3d % % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 30/10/2008 from drawLine3d % HISTORY % 30/10/2008 replace intersectPlaneLine by intersectLinePlane % 25/11/2008 improve test for bounds, and use more explicit code % 22/06/2009 fig bug, add support for several lines % 16/11/2010 use middle point for checking edge bounds % get box limits xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); zmin = box(5); zmax = box(6); % extreme corners of the box p000 = [xmin ymin zmin]; p111 = [xmax ymax zmax]; % main vectors ex = [1 0 0]; ey = [0 1 0]; ez = [0 0 1]; % box faces parallel to Oxy planeZ0 = [p000 ex ey]; planeZ1 = [p111 ex ey]; % box faces parallel to Oxz planeY0 = [p000 ex ez]; planeY1 = [p111 ex ez]; % box faces parallel to Oyz planeX0 = [p000 ey ez]; planeX1 = [p111 ey ez]; % number of lines nLines = size(line, 1); % allocate memory for result edge = zeros(nLines, 6); % iterate over lines to clip for i = 1:nLines % compute intersection point with each plane ipZ0 = intersectLinePlane(line(i,:), planeZ0); ipZ1 = intersectLinePlane(line(i,:), planeZ1); ipY0 = intersectLinePlane(line(i,:), planeY0); ipY1 = intersectLinePlane(line(i,:), planeY1); ipX1 = intersectLinePlane(line(i,:), planeX1); ipX0 = intersectLinePlane(line(i,:), planeX0); % concatenate resulting points points = [ipX0;ipX1;ipY0;ipY1;ipZ0;ipZ1]; % compute position of each point on the line pos = linePosition3d(points, line(i,:)); % keep only defined points ind = find(~isnan(pos)); pos = pos(ind); points = points(ind,:); % sort points with respect to their position [pos, ind] = sort(pos); %#ok points = points(ind, :); % keep median points wrt to position. These points define the limit of % the clipped edge. nv = length(ind)/2; % create resulting edge. edge(i,:) = [points(nv, :) points(nv+1, :)]; end % check that middle point of the edge is contained in the box midX = mean(edge(:, [1 4]), 2); xOk = xmin <= midX & midX <= xmax; midY = mean(edge(:, [2 5]), 2); yOk = ymin <= midY & midY <= ymax; midZ = mean(edge(:, [3 6]), 2); zOk = zmin <= midZ & midZ <= zmax; % if one of the bounding condition is not met, set edge to NaN edge (~(xOk & yOk & zOk), :) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectEdgePolygon3d.m0000644000000000000000000000013014055375162021622 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectEdgePolygon3d.m0000644000175000017500000000753114055375162022717 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [inter, valid] = intersectEdgePolygon3d(edge, poly) % Intersection point of a 3D EDGE segment and a 3D polygon. % % INTER = intersectEdgePolygon3d(EDGE, POLY) % Compute coordinates of intersection point between the 3D edge EDGE and % the 3D polygon POLY. EDGE is a 1-by-6 row vector containing source and % target positions of the edge, POLY is a Nv-by-3 array containing % coordinates of 3D polygon vertices. % INTER is a 1-by-3 row vector containing coordinates of intersection % point, or [NaN NaN NaN] if edge and polygon do not intersect. % % INTERS = intersectEdgePolygon3d(EDGES, POLY) % If EDGES is a N-by-6 array representing several edges, the result % INTERS is a N-by-3 array containing coordinates of intersection of each % edge with the polygon. % % [INTER, INSIDE] = intersectEdgePolygon3d(EDGE, POLY) % Also return a N-by-1 boolean array containing TRUE if the corresponding % edge contains the intersection point. % % Example % % Compute intersection between a 3D edge and a 3D triangle % pts3d = [3 0 0; 0 6 0;0 0 9]; % edge1 = [0 0 0 3 6 9]; % inter = intersectEdgePolygon3d(edge1, pts3d) % inter = % 1 2 3 % % % keep only valid intersections with several edges % pts3d = [3 0 0; 0 6 0;0 0 9]; % edges = [0 0 0 3 6 9;10 0 0 10 2 3]; % [inter, inside] = intersectEdgePolygon3d(edges, pts3d); % inter(inside, :) % ans = % 1 2 3 % % See Also % intersectLinePolygon, intersectRayPolygon3d, intersectLinePlane % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % supporting plane of polygon vertices plane = createPlane(poly(1:3, :)); % intersection of edge supporting line with the plane line = edgeToLine3d(edge); inter = intersectLinePlane(line, plane); onEdge = isPointOnEdge3d(inter, edge); % project all points on reference plane pts2d = planePosition(poly, plane); pInt2d = planePosition(inter, plane); % need to check polygon orientation insidePoly = xor(isPointInPolygon(pInt2d, pts2d), polygonArea(pts2d) < 0); % intersection points either outside the polygon on outside the edge bounds % are set to NaN valid = insidePoly & onEdge; inter(~valid, :) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/ellipsoidSurfaceArea.m0000644000000000000000000000013014055375162021324 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/ellipsoidSurfaceArea.m0000644000175000017500000000601514055375162022415 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function s = ellipsoidSurfaceArea(elli) %ELLIPSOIDSURFACEAREA Approximated surface area of an ellipsoid. % % S = ellipsoidSurfaceArea(ELLI) % Computes an approximation of the surface area of an ellipsoid. % ELLI is a 1-by-9 row vector given by [XC YC ZC A B C THETA PHI PSI], % where (XC YC ZC) is the center, (A B C) is the length of each semi axis % and (THETA PHI PSI) representes the orientation. % If ELLI is a 1-by-3 row vector, it is assumed to contain only the % lengths of semi-axes. % % This functions computes an approximation of the surface area, given by: % S = 4 * pi * ( (a^p * b^p + a^p * c^p + b^p * c^p) / 3) ^ (1/p) % with p = 1.6075. The resulting error should be less than 1.061%. % % Example % ellipsoidSurfaceArea % % See also % geom3d, ellipsePerimeter, oblateSurfaceArea, prolateSurfaceArea % % References % * http://en.wikipedia.org/wiki/Ellipsoid % * http://mathworld.wolfram.com/Ellipsoid.html % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. %% Parse input argument if size(elli, 2) == 9 a = elli(:, 4); b = elli(:, 5); c = elli(:, 6); elseif size(elli, 2) == 3 a = elli(:, 1); b = elli(:, 2); c = elli(:, 3); end p = 1.6075; s = 4 * pi * ( (a.^p .* b.^p + a.^p .* c.^p + b.^p .* c.^p) / 3) .^ (1 / p); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fillSphericalTriangle.m0000644000000000000000000000013014055375162021505 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fillSphericalTriangle.m0000644000175000017500000000736514055375162022607 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = fillSphericalTriangle(sphere, p1, p2, p3, varargin) %FILLSPHERICALTRIANGLE Fill a triangle on a sphere. % % fillSphericalTriangle(SPHERE, PT1, PT2, PT3); % % % See also % fillSphericalPolygon, drawSphericalTriangle, drawSphere % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 22/02/2005 % % HISTORY % 27/06/2007 manage spheres other than origin % 30/10/2008 replace intersectPlaneLine by intersectLinePlane % 2012-02-09 rename as fillSphericalTriangle % extract data of the sphere ori = sphere(:, 1:3); r = sphere(4); % extract direction vectors for each point v1 = normalizeVector3d(p1 - ori); v2 = normalizeVector3d(p2 - ori); v3 = normalizeVector3d(p3 - ori); % create a plane tangent to the sphere containing first point plane = createPlane(v1, v1); % position on the plane of the direction vectors pp2 = planePosition(intersectLinePlane([ori v2], plane), plane); pp3 = planePosition(intersectLinePlane([ori v3], plane), plane); % create rough parametrization with 2 variables nTri = 5; s = linspace(0, 1, nTri); t = linspace(0, 1, nTri); ns = length(s); nt = length(t); s = repmat(s, [nt, 1]); t = repmat(t', [1, ns]); % convert to plane coordinates xp = s * pp2(1) + t .* (1-s) * pp3(1); yp = s * pp2(2) + t .* (1-s) * pp3(2); % convert to 3D coordinates (still on the 3D plane) x = plane(1) * ones(size(xp)) + plane(4) * xp + plane(7) * yp - ori(1); y = plane(2) * ones(size(xp)) + plane(5) * xp + plane(8) * yp - ori(2); z = plane(3) * ones(size(xp)) + plane(6) * xp + plane(9) * yp - ori(3); % project on the sphere norm = hypot(hypot(x, y), z); xn = x ./ norm * r + ori(1); yn = y ./ norm * r + ori(2); zn = z ./ norm * r + ori(3); if nargout == 0 % simply display the patch surf(xn, yn, zn, 'FaceColor', 'g', 'EdgeColor', 'none', varargin{:}); elseif nargout == 1 % display the patch and return a handle h = surf(xn, yn, zn, 'FaceColor', 'g', 'EdgeColor', 'none', varargin{:}); varargout = {h}; elseif nargout == 3 % If 3 outputs are required, return patch vertex coordinates varargout = {x, y, z}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawDome.m0000644000000000000000000000013014055375162017000 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawDome.m0000644000175000017500000001621014055375162020067 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawDome(varargin) %DRAWDOME Draw a dome (half-sphere, semi-sphere) as a mesh. % % drawDome(DOME) % Where DOME = [XC YC ZC R], draw the dome centered on the point with % coordinates [XC YC ZC] and with radius R, using a quad mesh. % % drawDome(Dome, V) % Where DOME = [XC YC ZC R] and V is a vector in the direction of the top % % drawDome(CENTER, R, V) % Where CENTER = [XC YC ZC], specifies the center and the radius with two % arguments and vector as third argument. % % drawdrawDome(XC, YC, ZC, R, V) % Specifiy dome center, radius and vector as five arguments. % % drawDome(..., NAME, VALUE); % Specifies one or several options using parameter name-value pairs. % Available options are usual drawing options, as well as: % 'nPhi' the number of arcs used for drawing the meridians % 'nTheta' the number of circles used for drawing the parallels % % H = drawDome(...) % Return a handle to the graphical object created by the function. % % [X Y Z] = drawdrawDome(...) % Return the coordinates of the vertices used by the dome. In this % case, the dome is not drawn. % % Example % % Draw four domes with different centers % figure(1); clf; hold on; % drawDome([0 0 1 1], 'FaceColor', 'b', 'EdgeColor', 'k', 'LineStyle', ':'); % drawDome([0 1 0 1], [0 1 0]); % drawDome([0 -1 0 0.5], [1 0 0]); % drawDome([0 -5 4 10], 'FaceAlpha', 0.5, 'EdgeColor', 'r', 'LineStyle', '-'); % view([-30 20]); axis equal; l = light; % % % Draw dome with different settings % figure(1); clf; % drawDome([10 20 30 10], [0 0 1], 'linestyle', ':', 'facecolor', 'r'); % axis([0 50 0 50 0 50]); axis equal; % l = light; % % % The same, but changes style using graphic handle % figure(1); clf; % h = drawDome([10 20 30 10], [1 0 0]); % set(h, 'linestyle', ':'); % set(h, 'facecolor', 'r'); % axis([0 50 0 50 0 50]); axis equal; % l = light; % % % Draw a dome with high resolution % figure(1); clf; % h = drawDome([10 20 30 10], 'nPhi', 360, 'nTheta', 180); % l = light; view(3); % % % See also % drawSphere % --------- % author: Moritz Schappler % created the 27/07/2013 % % HISTORY % 2013-07-27 initial version as copy of drawSphere with a few changes % 2020-05-18 changes based on current version of geom3d % Check if axes handle is specified if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1)=[]; elseif nargout ~= 3 hAx = gca; end % process input options: when a string is found, assumes this is the % beginning of options options = {'FaceColor', 'g', 'LineStyle', 'none'}; for i = 1:length(varargin) if ischar(varargin{i}) if length(varargin) == 1 options = {'FaceColor', varargin{1}, 'LineStyle', 'none'}; else options = [options(1:end) varargin(i:end)]; end varargin = varargin(1:i-1); break; end end % Parse the input (try to extract center coordinates and radius) if isempty(varargin) % no input: assumes unit dome xc = 0; yc = 0; zc = 0; r = 1; v = [0;0;1]; elseif length(varargin) == 1 % one argument: concatenates center and radius dome = varargin{1}; xc = dome(:,1); yc = dome(:,2); zc = dome(:,3); r = dome(:,4); v = [0;0;1]; elseif length(varargin) == 2 % two arguments: concatenates center and radius with Rotation dome = varargin{1}; xc = dome(:,1); yc = dome(:,2); zc = dome(:,3); r = dome(:,4); v = varargin{2}; elseif length(varargin) == 3 % three arguments, corresponding to center and radius and rotation center = varargin{1}; xc = center(1); yc = center(2); zc = center(3); r = varargin{2}; v = varargin{3}; elseif length(varargin) == 5 % five arguments, corresponding to XC, YX, ZC, R and V xc = varargin{1}; yc = varargin{2}; zc = varargin{3}; r = varargin{4}; v = varargin{5}; else error('drawDome: please specify center and radius'); end % Rotation given by z-Axis. Calculate rotation matrix v = v(:) / norm(v(:)); if all(abs(v(:)-[0;0;1]) < 1e-10) RM = eye(3); elseif all(abs(v(:) - [0;0;-1]) < 1e-10) RM = [[1;0;0], [0; -1; 0], [0; 0; -1]]; else % z-axis given by argument ez = v(:); % x-axis perpendicular ex = cross(ez, [0; 0; 1]); ex = ex/norm(ex); % y-axis to create right-handed coordinate system ey = cross(ez, ex); RM = [ex, ey, ez]; end % number of meridians nPhi = 32; ind = find(strcmpi('nPhi', options(1:2:end))); if ~isempty(ind) ind = ind(1); nPhi = options{2*ind}; options(2*ind-1:2*ind) = []; end % number of parallels nTheta = 8; ind = find(strcmpi('nTheta', options(1:2:end))); if ~isempty(ind) ind = ind(1); nTheta = options{2*ind}; options(2*ind-1:2*ind) = []; end % compute spherical coordinates theta = linspace(0, pi/2, nTheta+1); phi = linspace(0, 2*pi, nPhi+1); % convert to Cartesian coordinates and rotate % Rotate the Dome x = zeros(nPhi+1, nTheta+1); y = x; z = x; sintheta = sin(theta); dx = cos(phi')*sintheta*r; dy = sin(phi')*sintheta*r; dz = ones(length(phi),1)*cos(theta)*r; for i = 1:nPhi+1 for j = 1:nTheta+1 dxyz = RM*[dx(i, j);dy(i, j);dz(i, j)]; x(i, j) = xc + dxyz(1); y(i, j) = yc + dxyz(2); z(i, j) = zc + dxyz(3); end end % Process output if nargout == 0 % no output: draw the dome surf(hAx, x, y, z, options{:}); elseif nargout == 1 % one output: compute varargout{1} = surf(hAx, x, y, z, options{:}); elseif nargout == 3 varargout{1} = x; varargout{2} = y; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createPlane.m0000644000000000000000000000013014055375162017461 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createPlane.m0000644000175000017500000001404314055375162020552 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function plane = createPlane(varargin) %CREATEPLANE Create a plane in parametrized form. % % PLANE = createPlane(P1, P2, P3) % creates a plane containing the 3 points % % PLANE = createPlane(PTS) % The 3 points are packed into a single 3x3 array. % % PLANE = createPlane(P0, N); % Creates a plane from a point and from a normal to the plane. The % parameter N is given either as a 3D vector (1-by-3 row vector), or as % [THETA PHI], where THETA is the colatitute (angle with the vertical % axis) and PHI is angle with Ox axis, counted counter-clockwise (both % given in radians). % % PLANE = createPlane(P0, Dip, DipDir); % Creates a plane from a point and from a dip and dip direction angles % of the plane. Parameters Dip and DipDir angles are given as numbers. % Dip : maximum inclination to the horizontal. % DipDir : direction of the horizontal trace of the line of dip, % measured clockwise from north. % % The created plane data has the following format: % PLANE = [X0 Y0 Z0 DX1 DY1 DZ1 DX2 DY2 DZ2], with % - (X0, Y0, Z0) is a point belonging to the plane % - (DX1, DY1, DZ1) is a first direction vector % - (DX2, DY2, DZ2) is a second direction vector % The 2 direction vectors are normalized and orthogonal. % % See also: % planes3d, medianPlane % % --------- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 24/11/2005 add possibility to pack points for plane creation % 21/08/2006 return normalized planes % 06/11/2006 update doc for planes created from normal if length(varargin) == 1 var = varargin{1}; if iscell(var) plane = zeros([length(var) 9]); for i=1:length(var) plane(i,:) = createPlane(var{i}); end elseif size(var, 1) >= 3 % 3 points in a single array p1 = var(1,:); p2 = var(2,:); p3 = var(3,:); % create direction vectors v1 = p2 - p1; v2 = p3 - p1; % create plane plane = normalizePlane([p1 v1 v2]); return; end elseif length(varargin) == 2 % plane origin p0 = varargin{1}; % second parameter is either a 3D vector or a 3D angle (2 params) var = varargin{2}; if size(var, 2) == 2 % normal is given in spherical coordinates n = sph2cart2([var ones(size(var, 1))]); elseif size(var, 2)==3 % normal is given by a 3D vector n = normalizeVector3d(var); else error ('wrong number of parameters in createPlane'); end % ensure same dimension for parameters if size(p0, 1)==1 p0 = repmat(p0, [size(n, 1) 1]); end if size(n, 1)==1 n = repmat(n, [size(p0, 1) 1]); end % find a vector not colinear to the normal v0 = repmat([1 0 0], [size(p0, 1) 1]); inds = vectorNorm3d(cross(n, v0, 2))<1e-14; v0(inds, :) = repmat([0 1 0], [sum(inds) 1]); % if abs(cross(n, v0, 2))<1e-14 % v0 = repmat([0 1 0], [size(p0, 1) 1]); % end % create direction vectors v1 = normalizeVector3d(cross(n, v0, 2)); v2 = -normalizeVector3d(cross(v1, n, 2)); % concatenate result in the array representing the plane plane = [p0 v1 v2]; return; elseif length(varargin)==3 var1 = varargin{1}; var2 = varargin{2}; var3 = varargin{3}; if size(var1, 2) == 3 && size(var2, 2) == 3 && size(var3, 2) == 3 p1 = var1; p2 = var2; p3 = var3; % create direction vectors v1 = p2 - p1; v2 = p3 - p1; plane = normalizePlane([p1 v1 v2]); return; elseif size(var1, 2) == 3 && size(var2, 2) == 1 && size(var3, 2) == 1 p0 = var1; n = [sin(var2)*sin(var3) sin(var2)*cos(var3) cos(var2)]; % find a vector not colinear to the normal v0 = repmat([1 0 0], [size(p0, 1) 1]); inds = vectorNorm3d(cross(n, v0, 2))<1e-14; v0(inds, :) = repmat([0 1 0], [sum(inds) 1]); % create direction vectors v1 = normalizeVector3d(cross(n, v0, 2)); v2 = -normalizeVector3d(cross(v1, n, 2)); % concatenate result in the array representing the plane plane = [p0 v1 v2]; return; else error('Wrong argument in "createPlane".'); end else error('Wrong number of arguments in "createPlane".'); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isPointInEllipsoid.m0000644000000000000000000000013014055375162021017 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isPointInEllipsoid.m0000644000175000017500000000575514055375162022122 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPointInEllipsoid(point, elli, varargin) % Check if a point is located inside a 3D ellipsoid. % % output = isPointInEllipsoid(input) % % Example % % create an ellipsoid % elli = [10 20 30 50 30 10 5 10 0]; % display it % figure; hold on; % drawEllipsoid(elli, 'FaceColor', 'g', 'FaceAlpha', .5, ... % 'drawEllipses', true, 'EllipseColor', 'b', 'EllipseWidth', 3); % view(3); axis equal; % % check for a point inside the ellipsoid % p1 = [20 30 35]; % b1 = isPointInEllipsoid(p1, elli) % ans = % 1 % % check for a point outside the ellipsoid % p2 = [-20 10 25]; % b2 = isPointInEllipsoid(p2, elli) % ans = % 0 % % % See also % equivalentEllipsoid, drawEllipsoid, isPointInEllipse % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-11-19, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. % extract computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % compute ellipse to unit circle transform rot = eulerAnglesToRotation3d(elli(7:9)); sca = createScaling3d(elli(4:6)); trans = inv(rot * sca); % transform points to unit sphere basis pTrans = bsxfun(@minus, point, elli(1:3)); pTrans = transformPoint3d(pTrans, trans); % test if norm is smaller than 1 b = sqrt(sum(power(pTrans, 2), 2)) - 1 <= tol; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/distancePointTriangle3d.m0000644000000000000000000000013014055375162021757 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/distancePointTriangle3d.m0000644000175000017500000001654014055375162023054 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [dist, proj] = distancePointTriangle3d(point, triangle) %DISTANCEPOINTTRIANGLE3D Minimum distance between a 3D point and a 3D triangle. % % DIST = distancePointTriangle3d(PT, TRI); % Computes the minimum distance between the point PT and the triangle % TRI. The Point PT is given as a row vector of three coordinates. The % triangle TRI is given as a 3-by-3 array containing the coordinates of % each vertex in a row of the array: % TRI = [... % X1 Y1 Z1;... % X2 Y2 Z2;... % X3 Y3 Z3]; % % [DIST, PROJ] = distancePointTriangle3d(PT, TRI); % Also returns the coordinates of the projeced point. % % Example % tri = [1 0 0; 0 1 0;0 0 1]; % pt = [0 0 0]; % dist = distancePointTriangle3d(pt, tri) % dist = % 0.5774 % % See also % meshes3d, distancePointMesh, distancePointEdge3d, distancePointPlane % % Reference % * David Eberly (1999), "Distance Between Point and Triangle in 3D" % https://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf % * see Distance between a point and a triangle in 3d, by Gwendolyn Fischer. % (same algorithm, but different order of input argument) % % * https://fr.mathworks.com/matlabcentral/fileexchange/22857-distance-between-a-point-and-a-triangle-in-3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-03-08, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. % triangle origin and vectors p1 = triangle(1,:); v12 = triangle(2,:) - p1; v13 = triangle(3,:) - p1; % identify coefficients of second order equation a = dot(v12, v12, 2); b = dot(v12, v13, 2); c = dot(v13, v13, 2); diffP = p1 - point; d = dot(v12, diffP, 2); e = dot(v13, diffP, 2); % f = dot(diffP, diffP, 2); % compute position of projected point in the plane of the triangle det = a * c - b * b ; s = b * e - c * d ; t = b * d - a * e ; % switch depending on the region where the projection occur if s + t < det if s < 0 if t < 0 % region 4 % The minimum distance must occur % * on the line t = 0 % * on the line s = 0 with t >= 0 % * at the intersection of the two lines if d < 0 % minimum on edge t = 0 with s > 0. t = 0; if a <= -d s = 1; else s = -d / a; end else % minimum on edge s = 0 s = 0; if e >= 0 t = 0; elseif c <= -e t = 1; else t = -e / c; end end else % region 3 % The minimum distance must occur on the line s = 0 s = 0; if e >= 0 t = 0; else if c <= -e t = 1; else t = -e / c; end end end else if t < 0 % region 5 % The minimum distance must occur on the line t = 0 t = 0; if d >= 0 s = 0; else if a <= -d s = 1; else s = -d / a; end end else % region 0 % the minimum distance occurs inside the triangle s = s / det; t = t / det; end end else if s < 0 % region 2 % The minimum distance must occur: % * on the line s + t = 1 % * on the line s = 0 with t <= 1 % * or at the intersection of the two (s=0; t=1) tmp0 = b + d; tmp1 = c + e; if tmp1 > tmp0 % minimum on edge s+t = 1, with s > 1 numer = tmp1 - tmp0; denom = a - 2 * b + c; if numer >= denom s = 1; else s = numer / denom; end t = 1 - s; else % minimum on edge s = 0, with t <= 1 s = 0; if tmp1 <= 0 t = 1; elseif e >= 0 t = 0; else t = -e / c; end end elseif t < 0 % region 6 % The minimum distance must occur % * on the line s + t = 1 % * on the line t = 0, with s <= 1 % * at the intersection of the two lines tmp0 = b + e; tmp1 = a + d; if tmp1 > tmp0 % minimum on edge s+t=1, with t > 0 numer = tmp1 - tmp0; denom = a - 2 * b + c; if numer > denom t = 1; else t = numer / denom; end s = 1 - t; else % minimum on edge t = 0 with s <= 1 t = 0; if tmp1 <= 0 s = 1; elseif d >= 0 s = 0; else s = -d / a; end end else % region 1 % The minimum distance must occur on the line s + t = 1 numer = (c + e) - (b + d); if numer <= 0 s = 0; else denom = a - 2 * b + c; if numer >= denom s = 1; else s = numer / denom; end end t = 1 - s; end end % compute coordinates of closest point on plane proj = p1 + s * v12 + t * v13; % distance between point and closest point on plane dist = sqrt(sum((point - proj).^2)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/spheres.m0000644000000000000000000000013014055375162016707 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/spheres.m0000644000175000017500000000471014055375162020000 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function spheres(varargin) %SPHERES Description of functions operating on 3D spheres. % % Spheres are represented by their center and their radius: % S = [xc yc zc r]; % % An ellipsoid is defined by: % ELL = [XC YC ZC A B C PHI THETA PSI] % where [XC YC ZY] is the center, [A B C] are length of semi-axes (in % decreasing order), and [PHI THETA PSI] are euler angles representing % the ellipsoid orientation. % % See also % createSphere, equivalentEllipsoid % intersectLineSphere, intersectPlaneSphere, sphericalVoronoiDomain % drawSphere, drawEllipsoid, fillSphericalTriangle, fillSphericalPolygon % drawSphericalEdge, drawSphericalTriangle, drawSphericalPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isParallel3d.m0000644000000000000000000000013014055375162017555 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isParallel3d.m0000644000175000017500000000527714055375162020657 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isParallel3d(v1, v2, varargin) %ISPARALLEL3D Check parallelism of two 3D vectors. % % B = isParallel3d(V1, V2) % where V1 and V2 are 2 [1x3] arrays, returns 1 if the vectors are % parallels, and 0 otherwise. % % Also works when V1 and V2 are two [Nx3] arrays with same number of % rows. In this case, return a [Nx1] array containing 1 at the positions % of parallel vectors. % % Also works when one of V1 or V2 is scalar and the other one is [Nx3] % array, in this case return [Nx1] results. % % B = isPerpendicular3d(V1, V2, TOL) % Specifies the absolute tolerance (default is 1e-14). % % Example % isParallel3d([1 2 1], [2 4 2]) % ans = % 1 % % isParallel3d([1 2 1], [1 3 2]) % ans = % 0 % % See also % vectors3d, isPerpendicular3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-04-25 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % 2011.03.20 fix bug for set of 3 vectors % check if tolerance is specified tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % compute b = vectorNorm3d(crossProduct3d(v1, v2)) < tol; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectBoxes3d.m0000644000000000000000000000013014055375162020466 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectBoxes3d.m0000644000175000017500000000507414055375162021563 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = intersectBoxes3d(box1, box2) %INTERSECTBOXES3D Intersection of two 3D bounding boxes. % % RES = intersectBoxes3d(BOX1, BOX2) % % Example % box1 = [5 20 5 30 10 50]; % box2 = [0 15 0 15 0 20]; % intersectBoxes3d(box1, box2) % ans = % 5 15 5 15 10 20 % % See also % boxes3d, drawBox3d, mergeBoxes3d % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % unify sizes of data if size(box1,1) == 1 box1 = repmat(box1, size(box2,1), 1); elseif size(box2, 1) == 1 box2 = repmat(box2, size(box1,1), 1); elseif size(box1,1) ~= size(box2,1) error('Bad size for inputs'); end % compute extreme coords mini = min(box1(:,2:2:end), box2(:,2:2:end)); maxi = max(box1(:,1:2:end), box2(:,1:2:end)); % concatenate result into a new box structure box = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2) maxi(:,3) mini(:,3)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/parallelLine3d.m0000644000000000000000000000013014055375162020071 xustar0029 mtime=1622538866.03881372 29 atime=1622538866.03881372 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/parallelLine3d.m0000644000175000017500000000410414055375162021157 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = parallelLine3d(line, point) %PARALLELLINE3D Create 3D line parallel to another one. % % L2 = parallelLine3d(L, P) % Creates the 3D line L2, parallel to the line L, and containing the % point P. % % Example % % See also % geom3d, parallelLine, parallelPlane % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-08-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. res = [point line(:, 4:6)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/circles3d.m0000644000000000000000000000013214055375162017113 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/circles3d.m0000644000175000017500000000470514055375162020206 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function circles3d(varargin) % Description of functions operating on 3D circles. % % Circles are represented by a center, a radius and a 3D angle % representing the normal of the plane containing the circle. % C = [xc yc zc R theta phi psi]. % THETA is the colatitude of the normal, in degrees, between 0 and 180 % PHI is the azimut of the normal, in degrees, between 0 and 360 % PSI is the proper rotation of the circle around the normal, between 0 % and 360 degrees % The parameter PSI is used to locate a point on the 3D circle. % % See also % circle3dOrigin, circle3dPosition, circle3dPoint, intersectPlaneSphere % drawCircle3d, drawCircleArc3d, drawEllipse3d % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fillPolygon3d.m0000644000000000000000000000013214055375162017765 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fillPolygon3d.m0000644000175000017500000000741414055375162021060 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = fillPolygon3d(varargin) %FILLPOLYGON3D Fill a 3D polygon specified by a list of vertex coords. % % fillPolygon3d(COORD, COLOR) % packs coordinates in a single [N*3] array. % COORD can also be a cell array of polygon, in this case each polygon is % drawn using the same color. % % fillPolygon3d(PX, PY, PZ, COLOR) % specifies coordinates in separate numeric vectors (either row or % columns) % % fillPolygon3d(..., PARAM, VALUE) % allows to specify some drawing parameter/value pairs as for the plot % function. % % H = fillPolygon3d(...) % also returns a handle to the list of created patch objects. % % Example % t = linspace(0, 2*pi, 100)'; % xt = 10 * cos(t); % yt = 5 * sin(t); % zt = zeros(1,100); % figure; fillPolygon3d(xt, yt, zt, 'c'); % % See Also: % polygons3d, drawPolygon3d, drawPolyline3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-01-05 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % check case we want to draw several curves, stored in a cell array var1 = varargin{1}; if iscell(var1) hold on; h = []; for i = 1:length(var1(:)) h = [h; fillPolygon3d(var1{i}, varargin{2:end})]; %#ok end if nargout>0 varargout{1}=h; end return; end % extract vertex coordinates if min(size(var1)) == 1 % if first argument is a vector (either row or column), then assumes % first argument contains x coords, second argument contains y coords % and third one the z coords px = var1; if length(varargin) < 3 error('geom3d:fillPolygon3d:Wrong number of arguments in fillPolygon3d'); end py = varargin{2}; pz = varargin{3}; varargin = varargin(4:end); else % first argument contains all three coordinates px = var1(:, 1); py = var1(:, 2); pz = var1(:, 3); varargin = varargin(2:end); end % extract color information if isempty(varargin) color = 'c'; else color = varargin{1}; varargin = varargin(2:end); end % fill the polygon h = fill3(px, py, pz, color, varargin{:}); if nargout>0 varargout{1}=h; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/edgeToLine3d.m0000644000000000000000000000013214055375162017506 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/edgeToLine3d.m0000644000175000017500000000437614055375162020605 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = edgeToLine3d(edge) %EDGETOLINE3D Convert a 3D edge to a 3D straight line. % % LINE = edgeToLine3d(EDGE) % Returns the 3D straight line containing the 3D edge EDGE. % EDGE is represented as [X1 Y1 Z1 X2 Y2 Z2] % LINE is represented as [X0 Y0 Z0 DX DY DZ] % % Example % edge = [3 4 5 4 6 8]; % line = edgeToLine3d(edge) % line = % 3 4 5 1 2 3 % % See also % lines3d, edges3d, edgeToLine, lineToEdge3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-04-12, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. line = [edge(:, 1:3) edge(:, 4:6)-edge(:, 1:3)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/clipEdge3d.m0000644000000000000000000000013214055375162017203 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/clipEdge3d.m0000644000175000017500000000600214055375162020266 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function clipped = clipEdge3d(edge, box) %CLIPEDGE3D Clip a 3D edge with a cuboid box. % % CLIPPED = clipEdge3d(EDGE, BOX) % % Example % clipEdge3d % % See also % lines3d, edges3d, clipLine3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-04-12, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. % compute supporting line of edge line = [edge(:, 1:3) edge(:,4:6)-edge(:,1:3)]; % clip supporting line clipped = clipLine3d(line, box); % for each clipped line, check that extremities are contained in edge nEdges = size(edge, 1); for i = 1:nEdges % if supporting line does not intersect the box, the edge is totally % clipped. if isnan(clipped(i,1)) continue; end % position of intersection points on the current supporting line pos1 = linePosition3d(clipped(i,1:3), line(i,:)); pos2 = linePosition3d(clipped(i,4:6), line(i,:)); if pos1 > 1 || pos2 < 0 % case of an edge totally clipped clipped(i,:) = NaN; elseif pos1 > 0 && pos2 < 1 % case of an edge already contained within the bounding box % -> nothin to do... continue; else % otherwise, need to adjust bounds of the clipped edge pos1 = max(pos1, 0); pos2 = min(pos2, 1); p1 = line(i,1:3) + pos1 * line(i,4:6); p2 = line(i,1:3) + pos2 * line(i,4:6); clipped(i,:) = [p1 p2]; end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawAngleBetweenVectors3d.m0000644000000000000000000000013214055375162022253 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawAngleBetweenVectors3d.m0000644000175000017500000000716014055375162023344 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawAngleBetweenVectors3d(o, v1, v2, r, varargin) %DRAWANGLEBETWEENVECTORS3D Draw an arc between 2 vectors. % % drawAngleBetweenVectors3d(ORIGIN, VECTOR1, VECTOR2, RADIUS) % draws the arc between VECTOR1 and VECTOR2. % % drawAngleBetweenVectors3d(...,'ConjugateAngle',1) draws the conjugate % angle instead of the small angle. Default is false. % % H = drawAngleBetweenVectors3d(...) % returns the handle of the created LINE object % % Example % o=-100 + 200*rand(1,3); % v1=normalizeVector3d(-1 + 2*rand(1,3)); % v2=normalizeVector3d(-1 + 2*rand(1,3)); % r = rand; % figure('color','w'); view(3) % hold on; axis equal tight; xlabel X; ylabel Y; zlabel Z; % drawVector3d(o, v1, 'r') % drawVector3d(o, v2, 'g') % drawAngleBetweenVectors3d(o, v1, v2, r,'Color','m','LineWidth', 3) % % See also % drawCircleArc3d % --------- % Author: oqilipo % Created: 2020-02-02 % Copyright 2020 % parse axis handle hAx = gca; if isAxisHandle(o) hAx = o; o = v1; v1 = v2; v2 = r; r = varargin{1}; varargin(1) = []; end p = inputParser; p.KeepUnmatched = true; logParValidFunc=@(x) (islogical(x) || isequal(x,1) || isequal(x,0)); addParameter(p,'ConjugateAngle',false,logParValidFunc); parse(p, varargin{:}); conjugate=p.Results.ConjugateAngle; drawOptions=p.Unmatched; % Normal of the two vectors normal=normalizeVector3d(crossProduct3d(v1, v2)); % Align normal with the z axis. ROT = createRotationVector3d(normal,[0 0 1]); % Align first vector with x axis ROTv1 = createRotationVector3d(transformVector3d(v1,ROT),[1 0 0]); % Get Euler angles of the arc. % The arc is an flat object. Hence, use the 'ZYZ' convention. [PHI, THETA, PSI] = rotation3dToEulerAngles((ROTv1*ROT)','ZYZ'); % Get angle between the vectors angle=rad2deg(vectorAngle3d(v1, v2)); % Draw the arc if ~conjugate h = drawCircleArc3d(hAx, [o r [THETA PHI PSI] 0 angle],drawOptions); else h = drawCircleArc3d(hAx, [o r [THETA PHI PSI] 0 angle-360],drawOptions); end % Format output if nargout > 0 varargout{1} = h; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isPointOnEdge3d.m0000644000000000000000000000013214055375162020176 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isPointOnEdge3d.m0000644000175000017500000001001114055375162021254 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPointOnEdge3d(point, edge, varargin) % Test if a 3D point belongs to an edge. % % Usage % B = isPointOnEdge3d(POINT, EDGE) % B = isPointOnEdge3d(POINT, EDGE, TOL) % % Description % B = isPointOnEdge3d(POINT, EDGE) % with POINT being [xp yp zp], and EDGE being [x1 y1 z1 x2 y2 z2], % returns TRUE if the point is located on the edge, and FALSE otherwise. % % B = isPointOnEdge3d(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 = isPointOnEdge3d(POINTARRAY, EDGE) % B = isPointOnEdge3d(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 = isPointOnEdge3d(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 20;15 10 20; 30 10 20]; % % create an edge array % vertices = [10 10 20;20 10 20;20 20 20;10 20 20]; % edges = [vertices vertices([2:end 1], :)]; % % % Test one point and one edge % isPointOnEdge3d(points(1,:), edges(1,:)) % ans = % 1 % isPointOnEdge3d(points(3,:), edges(1,:)) % ans = % 0 % % % Test one point and several edges % isPointOnEdge3d(points(1,:), edges)' % ans = % 1 0 0 1 % % % Test several points and one edge % isPointOnEdge3d(points, edges(1,:))' % ans = % 1 1 0 % % % Test N points and N edges % isPointOnEdge3d(points, edges(1:3,:))' % ans = % 1 0 0 % % % Test NP points and NE edges % isPointOnEdge3d(points, edges) % ans = % 1 0 0 1 % 1 0 0 0 % 0 0 0 0 % % % See also % edges3d, points3d, isPointOnLine3d % % extract computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % supporting line of the edge line = edgeToLine3d(edge); % check if point belong to supporting line onLine = isPointOnLine3d(point, line, tol); % check if position is within the [0 1] bounds pos = linePosition3d(point, line); withinBounds = pos > -tol & pos < 1+tol; b = onLine & withinBounds; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/distancePointLine3d.m0000644000000000000000000000013214055375162021103 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/distancePointLine3d.m0000644000175000017500000000511114055375162022166 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function d = distancePointLine3d(point, line) %DISTANCEPOINTLINE3D Euclidean distance between 3D point and line. % % D = distancePointLine3d(POINT, LINE); % Returns the distance between point POINT and the line LINE, given as: % POINT : [x0 y0 z0] % LINE : [x0 y0 z0 dx dy dz] % D : (positive) scalar % % See also: % lines3d, isPointOnLine3d, distancePointEdge3d, projPointOnLine3d, % % % References % http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 23/05/2005. % % HISTORY % 15/01/2007 unify size of input data % 31/01/2007 typo in data formatting, and replace norm by vecnorm3d % 12/12/2010 changed to bsxfun implementation - Sven Holcombe % cf. Mathworld (distance point line 3d) for formula d = bsxfun(@rdivide, vectorNorm3d( ... crossProduct3d(line(:,4:6), bsxfun(@minus, line(:,1:3), point)) ), ... vectorNorm3d(line(:,4:6))); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/medianPlane.m0000644000000000000000000000013214055375162017455 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/medianPlane.m0000644000175000017500000000503514055375162020545 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function plane = medianPlane(p1, p2) %MEDIANPLANE Create a plane in the middle of 2 points. % % PLANE = medianPlane(P1, P2) % Creates a plane in the middle of 2 points. % PLANE is perpendicular to line (P1 P2) and contains the midpoint of P1 % and P2. % The direction of the normal of PLANE is the same as the vector from P1 % to P2. % % See also: % planes3d, createPlane % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 28/06/2007: add doc, and manage multiple inputs % unify data dimension if size(p1, 1)==1 p1 = repmat(p1, [size(p2, 1) 1]); elseif size(p2, 1)==1 p2 = repmat(p2, [size(p1, 1) 1]); elseif size(p1, 1)~=size(p2, 1) error('data should have same length, or one data should have length 1'); end % middle point p0 = (p1 + p2)/2; % normal to plane n = p2-p1; % create plane from point and normal plane = createPlane(p0, n); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawEdge3d.m0000644000000000000000000000013214055375162017211 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawEdge3d.m0000644000175000017500000001026214055375162020277 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawEdge3d(varargin) %DRAWEDGE3D Draw 3D edge in the current axes. % % drawEdge3d(EDGE) draws the edge EDGE on the current axis. % EDGE has the form: [x1 y1 z1 x2 y2 z2]. No clipping is performed. % % drawEdge3d(AX,...) plots into AX instead of GCA. % % H = drawEdge3d(...) returns a handle H to the line object. % % Example % figure; axis equal; view(3) % p1 = [10 20 80]; % p2 = [80 10 20]; % p3 = [20 50 10]; % drawEdge3d(gca, [p1;p2],[p2;p3],'b'); % drawEdge3d([p1;p3],'k'); % pause(1) % drawEdge3d(gca, [p1 p2; p2 p3],'g'); % drawEdge3d(p1(1), p1(2), p1(3),p3(1), p3(2), p3(3),'Color','r','Marker','x'); % % See also % drawLine3d, clipLine3d, drawEdge % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 04/01/2007 remove unused variables % 15/12/2009 "reprecate", and add processing of input arguments % Parse and check inputs if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1) = []; else hAx = gca; end % extract edges from input arguments nCol = size(varargin{1}, 2); if nCol == 6 % all parameters in a single array edges = varargin{1}; varargin(1) = []; elseif nCol == 3 if isequal(size(varargin{1}), [2 3]) && length(varargin) == 1 % parameters are two points given as 2x3 edges = [varargin{1}(1,:) varargin{1}(2,:)]; elseif isequal(size(varargin{1}), [2 3]) && ~isnumeric(varargin{2}) % parameters are two points given as 2x3 edges = [varargin{1}(1,:) varargin{1}(2,:)]; varargin(1) = []; else % parameters are two points, or two arrays of points, of size N*3. edges = [varargin{1} varargin{2}]; varargin(1:2) = []; end elseif nargin >= 6 % parameters are 6 parameters of the edge : x1 y1 z1 x2 y2 and z2 edges = [varargin{1} varargin{2} varargin{3} varargin{4} varargin{5} varargin{6}]; varargin(1:6) = []; end % Parse and check inputs isEdge3d = @(x) validateattributes(x,{'numeric'},... {'nonempty','size',[nan,6]}); defOpts.Color = 'b'; [~, edges, varargin] = ... parseDrawInput(hAx, isEdge3d, 'line', defOpts, edges, varargin{:}); % identify indices of valid edge (not containing any NaN's). inds = sum(isnan(edges), 2) == 0; % draw edges h = line(... [edges(inds, 1) edges(inds, 4)]', ... [edges(inds, 2) edges(inds, 5)]', ... [edges(inds, 3) edges(inds, 6)]', varargin{:}, ... 'Parent', hAx); % return handle to created Edges if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/angleSort3d.m0000644000000000000000000000013214055375162017425 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/angleSort3d.m0000644000175000017500000000707614055375162020524 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = angleSort3d(pts, varargin) %ANGLESORT3D Sort 3D coplanar points according to their angles in plane. % % PTS2 = angleSort3d(PTS); % Considers all points are located on the same plane, and sort them % according to the angle on plane. PTS is a [Nx2] array. Note that the % result depends on the plane orientation: points can be in reverse order % compared to expected. The reference plane is computed based on the % first three points. % % PTS2 = angleSort3d(PTS, PTS0); % Computes angles between each point of PTS and PT0. By default, uses % centroid of points. % % PTS2 = angleSort3d(PTS, PTS0, PTS1); % Specifies the point which will be used as a start. % % [PTS2, I] = angleSort3d(...); % Also return in I the indices of PTS, such that PTS2 = PTS(I, :); % % See also: % points3d, angles3d, angleSort % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2005-11-24 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY : % 04/01/2007: remove unused variables % default values pt0 = mean(pts, 1); pt1 = pts(1,:); if length(varargin)==1 pt0 = varargin{1}; elseif length(varargin)==2 pt0 = varargin{1}; pt1 = varargin{2}; end % create support plane plane = createPlane(pts(1:3, :)); % project points onto the plane pts2d = planePosition(pts, plane); pt0 = planePosition(pt0, plane); pt1 = planePosition(pt1, plane); % compute origin angle theta0 = atan2(pt1(2)-pt0(2), pt1(1)-pt0(1)); theta0 = mod(theta0 + 2*pi, 2*pi); % translate to reference point n = size(pts, 1); pts2d = pts2d - repmat(pt0, [n 1]); % compute angles angle = atan2(pts2d(:,2), pts2d(:,1)); angle = mod(angle - theta0 + 4*pi, 2*pi); % sort points according to angles [angle, I] = sort(angle); %#ok % format output if nargout<2 varargout{1} = pts(I, :); elseif nargout==2 varargout{1} = pts(I, :); varargout{2} = I; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawTorus.m0000644000000000000000000000013214055375162017232 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawTorus.m0000644000175000017500000000744514055375162020331 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawTorus(torus, varargin) %DRAWTORUS Draw a torus (3D ring). % % drawTorus(TORUS) % Draws the torus on the current axis. TORUS is given by: % [XC YC ZY R1 R2 THETA PHI] % where (XC YZ ZC) is the center of the torus, R1 is the main radius, R2 % is the radius of the torus section, and (THETA PHI) is the angle of the % torus normal vector (both in degrees). % % drawTorus(..., PNAME, PVALUE) % Specifies a set of parameter name-value pairs. Parameter names include % plitting options ('facecolor', 'linestyle'...), or options specific to % torus: % 'nPhi' number of meridians used to draw the torus (default is 60). % 'nTheta' number of parallels used to draw the torus (default is 60). % % % Example % % draw sample torus % figure; % drawTorus([50 50 50 30 10 30 45]); % axis equal; view([95 10]); light; % % See also % drawEllipsoid, revolutionSurface, torusMesh % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-06-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. %% Default values % number of meridians nPhi = 60; % number of parallels nTheta = 60; %% Extract input arguments center = torus(1:3); r1 = torus(4); r2 = torus(5); normal = [0 0]; if size(torus, 2) >= 7 normal = torus(6:7); end % default set of options for drawing meshes options = {'FaceColor', 'g', 'linestyle', 'none'}; while length(varargin) > 1 switch lower(varargin{1}) case 'nphi' nPhi = varargin{2}; case 'ntheta' nTheta = varargin{2}; otherwise % assumes this is drawing option options = [options varargin(1:2)]; %#ok end varargin(1:2) = []; end %% Draw the torus % create base torus circle = circleToPolygon([r1 0 r2], nTheta); [x, y, z] = revolutionSurface(circle, linspace(0, 2*pi, nPhi)); % transform torus trans = localToGlobal3d([center normal]); [x, y, z] = transformPoint3d(x, y, z, trans); % draw the surface hs = surf(x, y, z, options{:}); %% Process output arguments if nargout > 0 varargout = {hs}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/prolateSurfaceArea.m0000644000000000000000000000013214055375162021010 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/prolateSurfaceArea.m0000644000175000017500000000470714055375162022105 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function S = prolateSurfaceArea(elli, varargin) %PROLATESURFACEAREA Approximated surface area of a prolate ellipsoid. % % S = prolateSurfaceArea(R1,R2) % % Example % prolateSurfaceArea % % See also % geom3d, ellipsoidSurfaceArea, oblateSurfaceArea % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2015-07-03, using Matlab 7.9.0.529 (R2009b) % Copyright 2015 INRA - Cepia Software Platform. %% Parse input argument if size(elli, 2) == 7 R1 = elli(:, 4); R2 = elli(:, 5); elseif size(elli, 2) == 1 && ~isempty(varargin) R1 = elli(:, 1); R2 = varargin{1}; end assert(R1 > R2, 'first radius must be larger than second radius'); % surface theorique d'un ellipsoide prolate % cf http://fr.wikipedia.org/wiki/Ellipso%C3%AFde_de_r%C3%A9volution e = sqrt(R1.^2 - R2.^2) ./ R1; S = 2 * pi * R2.^2 + 2 * pi * R1 .* R2 .* asin(e) ./ e; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fitLine3d.m0000644000000000000000000000013214055375162017061 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fitLine3d.m0000644000175000017500000000613114055375162020147 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = fitLine3d(points) %FITLINE3D Fit a 3D line to a set of points. % % LINE = fitLine3d(PTS) % % Example % pts = randn(300, 3); % pts = transformPoint3d(pts, createScaling3d([6 4 2])); % pts = transformPoint3d(pts, createRotationOx(pi/6)); % pts = transformPoint3d(pts, createRotationOy(pi/4)); % pts = transformPoint3d(pts, createRotationOz(pi/3)); % pts = transformPoint3d(pts, createTranslation3d([5 4 3])); % elli = equivalentEllipsoid(pts); % figure; drawPoint3d(pts); axis equal; % hold on; drawEllipsoid(elli, ... % 'drawEllipses', true, 'EllipseColor', 'b', 'EllipseWidth', 3); % line = fitLine3d(pts); % drawLine3d(line, 'color', 'm', 'LineWidth', 4); % % See also % lines3d, equivalentEllipsoid, fitPlane % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-11-11, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % number of points n = size(points, 1); % compute centroid center = mean(points); % compute the covariance matrix covPts = cov(points)/n; % perform a principal component analysis with 2 variables, % to extract inertia axes [U, S] = svd(covPts); % sort axes from greater to lower [dummy, ind] = sort(diag(S), 'descend'); %#ok % format U to ensure first axis points to positive x direction U = U(ind, :); if U(1,1) < 0 U = -U; % keep matrix determinant positive U(:,3) = -U(:,3); end line = [center U(:,1)']; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/clipPolygon3dHP.m0000644000000000000000000000013214055375162020216 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/clipPolygon3dHP.m0000644000175000017500000001176614055375162021316 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = clipPolygon3dHP(poly, plane) %CLIPPOLYGON3DHP clip a 3D polygon with Half-space. % % usage % POLY2 = clipPolygon3dHP(POLY, PLANE) % POLY is a [Nx3] array of points, and PLANE is given as : % [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2]. % The result POLY2 is also an array of 3d points, sometimes smaller than % poly, and that can be [0x3] (empty polygon). % % POLY2 = clipPolygon3dHP(POLY, PT0, NORMAL) % uses plane with normal NORMAL and containing point PT0. % % TODO: not yet implemented % % There is a problem for non-convex polygons, as they can be clipped in % several polygons. Possible solutions: % * create another function 'clipConvexPolygon3dPlane' or % 'clipConvexPolygon3d', using a simplified algorithm % * returns a list of polygons instead of a single polygon, % * in the case of one polygon as return decide what to return % * and rename this function to 'clipPolygon3d' % % See also: % poygons3d, polyhedra, clipConvexPolygon3dHP % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 02/08/2005. % % HISTORY % 2007-01-04 add todo flag % 2011-08-17 rewrite algo, that works for convex polygons, but is slower % than function clipConvexPolgon3dHP %% Pre-Processing % ensure last point is the same as the first one (makes computation easier) if sum(poly(end, :) == poly(1,:)) ~= 3 poly = [poly; poly(1,:)]; end % compute index of position wrt plane for each vertex below = isBelowPlane(poly, plane); % in the case of a polygon totally over the plane, return empty array if sum(below) == 0 poly2 = zeros(0, 3); return; end % in the case of a polygon totally over the plane, return original polygon if sum(~below) == 0 poly2 = poly; return; end % number of intersections nInter = sum(abs(diff(below))); % number of vertices of new polygon N = size(poly, 1); % N2 = sum(below(1:end-1)) + nInter; N2 = sum(below) + nInter; poly2 = zeros(N2, 3); %% Iteration on polygon vertices % vertex index in current polygon % initialized with first vertex below the plane (vertices before are drop) i = find(below, 1, 'first'); % vertex index in result polygon j = 1; while i <= N if below(i) % keep points located below the plane poly2(j, :) = poly(i,:); i = i + 1; j = j + 1; else % current vertex is above the plane. We know that previous vertex % was below. We compute intersection of supporting line, find the % next vertex below, and find next intersection. % compute intersection of current edge with plane line = createLine3d(poly(i-1, :), poly(i, :)); inter1 = intersectLinePlane(line, plane); poly2(j, :) = inter1; j = j + 1; % find index of next vertex below the plane, possibily re-starting % from the beginning of the polygon while ~below(mod(i - 1, N) + 1) i = i + 1; end % compute intersection of current line with plane i2 = mod(i - 1, N) + 1; line = createLine3d(poly(i2-1, :), poly(i2, :)); inter2 = intersectLinePlane(line, plane); poly2(j, :) = inter2; j = j + 1; % add also the current vertex poly2(j, :) = poly(i2, :); j = j + 1; i = i + 1; end end % remove last point if it is the same as the first one if sum(poly2(end, :) == poly2(1,:)) == 3 poly2(end, :) = []; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotationOy.m0000644000000000000000000000013214055375162020533 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotationOy.m0000644000175000017500000000705014055375162021622 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createRotationOy(varargin) %CREATEROTATIONOY Create the 4x4 matrix of a 3D rotation around y-axis. % % TRANS = createRotationOy(THETA); % Returns the transform matrix corresponding to a rotation by the angle % THETA (in radians) around the Oy axis. A rotation by an angle of PI/2 % would transform the vector [0 0 1] into the vector [1 0 0]. % % The returned matrix has the form: % [ cos(THETA) 0 sin(THETA) 0 ] % [ 0 1 0 0 ] % [-sin(THETA) 0 cos(THETA) 0 ] % [ 0 0 0 1 ] % % TRANS = createRotationOy(ORIGIN, THETA); % TRANS = createRotationOy(X0, Y0, Z0, THETA); % Also specifies origin of rotation. The result is similar as performing % translation(-X0, -Y0, -Z0), rotation, and translation(X0, Y0, Z0). % % % See also: % transforms3d, transformPoint3d, createRotationOx, createRotationOz % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 2008/11/24 changed convention for angle % 22/04/2009 rename as createcreateRotationOy % default values dx = 0; dy = 0; dz = 0; theta = 0; % get input values if length(varargin) == 1 % only one argument -> rotation angle theta = varargin{1}; elseif length(varargin) == 2 % origin point (as array) and angle var = varargin{1}; dx = var(1); dy = var(2); dz = var(3); theta = varargin{2}; elseif length(varargin) == 3 % origin (x and y) and angle dx = varargin{1}; dy = varargin{2}; dz = 0; theta = varargin{3}; elseif length(varargin) == 4 % origin (x and y) and angle dx = varargin{1}; dy = varargin{2}; dz = varargin{3}; theta = varargin{4}; end % compute coefs cot = cos(theta); sit = sin(theta); % create transformation trans = [... cot 0 sit 0;... 0 1 0 0;... -sit 0 cot 0;... 0 0 0 1]; % add the translation part t = [1 0 0 dx;0 1 0 dy;0 0 1 dz;0 0 0 1]; trans = t * trans / t; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectLineTriangle3d.m0000644000000000000000000000013214055375162021765 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectLineTriangle3d.m0000644000175000017500000001211414055375162023051 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [point, pos, isInside] = intersectLineTriangle3d(line, triangle, varargin) %INTERSECTLINETRIANGLE3D Intersection point of a 3D line and a 3D triangle. % % POINT = intersectLineTriangle3d(LINE, TRI) % Compute coordinates of the intersection point between the line LINE and % the triangle TRI. % LINE is a 1-by-6 row vector given as: [X0 Y0 Z0 DX DY DZ] % TRI is given either as a row vector [X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3], or as % a 3-by-3 array, each row containing coordinates of one of the triangle % vertices. % The result is a 1-by-3 array containing coordinates of the intesection % point, or [NaN NaN NaN] if the line and the triangle do not intersect. % % [POINT POS] = intersectLineTriangle3d(LINE, TRI) % Also returns the position of the intersection point on the line, or NaN % if the line and the supporting plane of the triangle are parallel. % % [POINT POS ISINSIDE] = intersectLineTriangle3d(LINE, TRI) % Also returns a boolean value, set to true if the line and the triangle % intersect each other. Can be used for testing validity of result. % % Example % line = [1 1 0 0 0 1]; % tri = [0 0 5;5 0 0;0 5 0]; % intersectLineTriangle3d(line, tri) % ans = % 1 1 3 % % See also % points3d, lines3d, polygons3d, intersectRayPolygon3d, % distancePointTriangle3d % % References % Algorithm adapted from SoftSurfer Ray/Segment-Triangle intersection % http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-04-08, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. %% Default values % default return value point = [NaN NaN NaN]; pos = NaN; isInside = false; tol = 1e-13; if ~isempty(varargin) tol = varargin{1}; end %% Process inputs % triangle edge vectors if size(triangle, 2) > 3 % triangle is given as a 1-by-9 row vector t0 = triangle(1:3); u = triangle(4:6) - t0; v = triangle(7:9) - t0; else % triangle is given as a 3-by-3 array t0 = triangle(1, 1:3); u = triangle(2, 1:3) - t0; v = triangle(3, 1:3) - t0; end %% Compute intersection % triangle normal n = cross(u, v); % test for degenerate case of flat triangle if vectorNorm3d(n) < tol return; end % line direction vector dir = line(4:6); % vector between triangle origin and line origin w0 = line(1:3) - t0; % compute projection of each vector on the plane normal a = -dot(n, w0); b = dot(n, dir); % test case of line parallel to the triangle if abs(b) < tol return; end % compute intersection point of line with supporting plane % If r < 0: point before ray % If r > 1: point after edge pos = a / b; % coordinates of intersection point point = line(1:3) + pos * dir; %% test if intersection point is inside triangle % normalize direction vectors of triangle edges uu = dot(u, u); uv = dot(u, v); vv = dot(v, v); % coordinates of vector v in triangle basis w = point - t0; wu = dot(w, u); wv = dot(w, v); % normalization constant D = uv^2 - uu * vv; % test first coordinate s = (uv * wv - vv * wu) / D; if s < 0.0 || s > 1.0 point = [NaN NaN NaN]; pos = NaN; return; end % test second coordinate, and third triangle edge t = (uv * wu - uu * wv) / D; if t < 0.0 || (s + t) > 1.0 point = [NaN NaN NaN]; pos = NaN; return; end % set the validity flag isInside = true; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/readme.txt0000644000000000000000000000013214055375161017057 xustar0030 mtime=1622538865.994813885 30 atime=1622538865.994813885 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/readme.txt0000644000175000017500000000307614055375161020152 0ustar00juanpijuanpi00000000000000Description of the geom3d library. The aim of geom3d library is to handle and visualize 3D geometric primitives such as points, lines, planes, polyhedra... It provides low-level functions for manipulating 3D geometric primitives, making easier the development of more complex geometric algorithms. Some features of the library are: - creation of various shapes (3D points, 3D lines, planes, polyhedra...) through an intuitive syntax. Ex: createPlane(p1, p2, p3) to create a plane through 3 points. - derivation of new shapes: intersection between 2 planes, intersection between a plane and a line, between a sphere and a line... - functions for 3D polygons and polyhedra. Polyhedra use classical vertex-faces arrays (face array contain indices of vertices), and support faces with any number of vertices. Some basic models are provided (createOctaedron, createCubeoctaedron...), as well as some computation (like faceNormal or centroid) - manipulation of planar transformation. Ex.: ROT = createRotationOx(THETA); P2 = transformPoint3d(P1, ROT); - direct drawing of shapes with specialized functions. Clipping is performed automatically for infinite shapes such as lines or rays. Ex: drawPoint3d([50 50 25; 20 70 10], 'ro'); % draw some points drawLine3d([X0 Y0 Z0 DX DY DZ]); % clip and draw straight line Some functions require the geom2d package. Additional help is provided in geom3d/Contents.m file, as well as summary files like 'points3d.m' or 'lines3d.m'. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createScaling3d.m0000644000000000000000000000013214055375162020233 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createScaling3d.m0000644000175000017500000000740414055375162021325 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createScaling3d(varargin) %CREATESCALING3D Create the 4x4 matrix of a 3D scaling. % % TRANS = createScaling3d(S); % returns the scaling transform corresponding to a scaling factor S in % each direction. S can be a scalar, or a 1-by-3 vector containing the % scaling factor in each direction. % % TRANS = createScaling3d(SX, SY, SZ); % returns the scaling transform corresponding to a different scaling % factor in each direction. % % The returned matrix has the form : % [SX 0 0 0] % [ 0 SY 0 0] % [ 0 0 SZ 0] % [ 0 0 0 0] % % See also: % transforms3d, transformPoint3d, transformVector3d, createTranslation3d, % createRotationOx, createRotationOy, createRotationOz % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 20/04/2006. % % HISTORY % 25/11/2008 rename from scale3d to scaling3d % 30/04/2009 rename to createScaling3d %% default arguments sx = 1; sy = 1; sz = 1; center = [0 0 0]; %% process input parameters if nargin == 1 % only one argument -> scaling factor [sx, sy, sz]= parseScalingFactors(varargin{1}); elseif nargin == 2 % 2 arguments, giving center and uniform scaling center = varargin{1}; [sx, sy, sz]= parseScalingFactors(varargin{2}); elseif nargin == 3 % 3 arguments, giving scaling in each direction sx = varargin{1}; sy = varargin{2}; sz = varargin{3}; elseif nargin == 4 % 4 arguments, giving center and scaling in each direction center = varargin{1}; sx = varargin{2}; sy = varargin{3}; sz = varargin{4}; end %% create the scaling matrix trans = [... sx 0 0 center(1)*(1-sx);... 0 sy 0 center(2)*(1-sy);... 0 0 sz center(3)*(1-sz);... 0 0 0 1]; %% Helper function function [sx, sy, sz] = parseScalingFactors(var) if length(var)==1 % same scaling factor in each direction sx = var; sy = var; sz = var; elseif length(var)==3 % scaling is a vector, giving different scaling in each direction sx = var(1); sy = var(2); sz = var(3); else error('wrong size for first parameter of "createScaling3d"'); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/sphericalVoronoiDomain.m0000644000000000000000000000013214055375162021716 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/sphericalVoronoiDomain.m0000644000175000017500000000614514055375162023011 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly = sphericalVoronoiDomain(refPoint, neighbors) %SPHERICALVORONOIDOMAIN Compute a spherical voronoi domain. % % POLY = sphericalVoronoiDomain(GERM, NEIGHBORS) % GERM is a 1-by-3 row vector representing cartesian coordinates of a % point on the unit sphere (in X, Y Z order) % NEIGHBORS is a N-by-3 array representing cartesian coordinates of the % germ neighbors. It is expected that NEIGHBORS contains only neighbors % that effectively contribute to the voronoi domain. % % Example % sphericalVoronoiDomain % % See also % drawSphericalPolygon % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-11-17, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % reference sphere sphere = [0 0 0 1]; % number of neigbors, and number of sides of the domain nbSides = size(neighbors, 1); % compute planes containing separating circles planes = zeros(nbSides, 9); for i = 1:nbSides planes(i,1:9) = normalizePlane(medianPlane(refPoint, neighbors(i,:))); end % allocate memory lines = zeros(nbSides, 6); intersects = zeros(2 * nbSides, 3); % compute circle-circle intersections for i = 1:nbSides ind2 = mod(i, nbSides) + 1; lines(i,1:6) = intersectPlanes(planes(i,:), planes(ind2,:)); intersects(2*i-1:2*i,1:3) = intersectLineSphere(lines(i,:), sphere); end % keep only points in the same direction than refPoint ind = dot(intersects, repmat(refPoint, [2 * nbSides 1]), 2) > 0; poly = intersects(ind,:); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fitAffineTransform3d.m0000644000000000000000000000013214055375162021256 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fitAffineTransform3d.m0000644000175000017500000000621214055375162022344 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = fitAffineTransform3d(ref, src) % Compute the affine transform that best register two 3D point sets. % % TRANS = fitAffineTransform3d(REF, SRC) % Returns the affine transform matrix that minimizes the distance between % the reference point set REF and the point set SRC after transformation. % Both REF and SRC must by N-by-3 arrays with the same number of rows, % and the points must be in correspondence. % The function minimizes the sum of the squared distances: % CRIT = sum(distancePoints3d(REF, transformPoint3d(PTS, TRANSFO)).^2); % % Example % N = 50; % pts = rand(N, 3)*10; % trans = createRotationOx([5 4 3], pi/4); % pts2 = transformPoint3d(pts, trans); % pts3 = pts2 + randn(N, 3)*2; % fitted = fitAffineTransform3d(pts, pts2); % % % See also % transforms3d, transformPoint3d, transformVector3d, % fitAffineTransform2d, registerPoints3dAffine % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2009-07-31, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRAE - Cepia Software Platform. % number of points N = size(src, 1); if size(ref, 1) ~= N error('Requires the same number of points for both arrays'); end % main matrix of the problem tmp = [src(:,1) src(:,2) src(:,3) ones(N,1)]; A = [... tmp zeros(N, 8) ; ... zeros(N, 4) tmp zeros(N, 4) ; ... zeros(N, 8) tmp ]; % conditions initialisations B = [ref(:,1) ; ref(:,2) ; ref(:,3)]; % compute coefficients using least square coefs = A\B; % format to a matrix trans = [coefs(1:4)' ; coefs(5:8)'; coefs(9:12)'; 0 0 0 1]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/recenterTransform3d.m0000644000000000000000000000013214055375162021172 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/recenterTransform3d.m0000644000175000017500000000546414055375162022270 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = recenterTransform3d(transfo, center) %RECENTERTRANSFORM3D Change the fixed point of an affine 3D transform. % % TRANSFO2 = recenterTransform3d(TRANSFO, CENTER) % where TRANSFO is a 4x4 transformation matrix, and CENTER is a 1x3 row % vector, computes the new transformations that uses the same linear part % (defined by the upper-left 3x3 corner of the transformation matrix) as % the initial transform, and that will leave the point CENTER unchanged. % % % % Example % % creating a re-centered rotation using: % rot1 = createRotationOx(pi/3); % rot2 = recenterTransform3d(rot1, [3 4 5]); % % will give the same result as: % rot3 = createRotationOx([3 4 5], pi/3); % % % See also % transforms3d, createRotationOx, createRotationOy, createRotationOz % createTranslation3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-27, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % remove former translation part res = eye(4); res(1:3, 1:3) = transfo(1:3, 1:3); % create translations t1 = createTranslation3d(-center); t2 = createTranslation3d(center); % compute translated transform res = t2*res*t1; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawPartialPatch.m0000644000000000000000000000013214055375162020472 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawPartialPatch.m0000644000175000017500000000546614055375162021572 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function drawPartialPatch(u, v, z, varargin) %DRAWPARTIALPATCH draw surface patch, with 2 parametrized surfaces. % % usage : % drawSurfPatch(u, v, zuv) % where u, v, and zuv are three matrices the same size, u and % corresponding to each parameter, and zuv being equal to a function of u % and v. % % drawSurfPatch(u, v, zuv, p0) % If p0 is specified, two lines with u(p0(1)) and v(p0(2)) are drawn on % the surface % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 24/05/2005. % % HISTORY % 2005-06-08 add doc. % 2007-01-04 remove unused variables and change function name % 2010-03-08 code cleanup, use drawPolyline3d % prepare figure hold on; % draw the surface interior surf(u, v, z, 'FaceColor', 'g', 'EdgeColor', 'none'); % draw the surface boundaries drawPolyline3d(u(1,:), v(1,:), z(1,:)) drawPolyline3d(u(end,:), v(end,:), z(end,:)) drawPolyline3d(u(:,end), v(:,end), z(:,end)) drawPolyline3d(u(:,1), v(:,1), z(:,1)) % eventually draw two perpendicular lines on the surface if ~isempty(varargin) pos = varargin{1}; drawPolyline3d(u(pos(1),:), v(pos(1),:), z(pos(1),:)); drawPolyline3d(u(:,pos(2)), v(:,pos(2)), z(:,pos(2))); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectEdgePlane.m0000644000000000000000000000013214055375162021005 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectEdgePlane.m0000644000175000017500000001013714055375162022074 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = intersectEdgePlane(edge, plane, varargin) %INTERSECTEDGEPLANE Return intersection point between a plane and a edge. % % PT = intersectEdgePlane(edge, PLANE) return the intersection point of % the given edge and the given plane. % PLANE : [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % edge : [x1 y1 z1 x2 y2 z2] % PT : [xi yi zi] % If EDGE and PLANE are parallel, return [NaN NaN NaN]. % If EDGE (or PLANE) is a matrix with 6 (or 9) columns and N rows, result % is an array of points with N rows and 3 columns. % % Example: % edge = [5 5 -1 5 5 1]; % plane = [0 0 0 1 0 0 0 1 0]; % intersectEdgePlane(edge, plane) % should return [5 5 0]. % ans = % 5 5 0 % % See Also: % planes3d, intersectLinePlane, createLine3d, createPlane % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 24/04/2007 from intersectLinePlane. % % HISTORY % % 17/06/2011 E. J. Payton - fixed indexing error that caused incorrect % points to be returned % extract tolerance for determination of parallel edges and planes tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % number of planes and edges np = size(plane, 1); ne = size(edge, 1); % unify sizes of data if np ~= ne if ne == 1 % one edge and many planes edge = edge(ones(np, 1), :); elseif np == 1 % one plane possible many edges plane = plane(ones(ne, 1), :); else % N planes and M edges, not allowed for now. error('Should have the same number of planes and edges'); end end % initialize empty arrays point = zeros(size(plane, 1), 3); t = zeros(size(plane,1),3); % plane normal n = cross(plane(:,4:6), plane(:,7:9), 2); % create line supporting edge line = createLine3d(edge(:,1:3), edge(:,4:6)); % get indices of edge and plane which are parallel par = abs(dot(n, line(:,4:6), 2)) < tol; point(par,:) = NaN; t(par) = NaN; % difference between origins of plane and edge dp = plane(:, 1:3) - line(:, 1:3); % relative position of intersection on line %t = dot(n(~par,:), dp(~par,:), 2)./dot(n(~par,:), line(~par,4:6), 2); t(~par) = dot(n(~par,:), dp(~par,:), 2) ./ dot(n(~par,:), line(~par,4:6), 2); % compute coord of intersection point %point(~par, :) = line(~par,1:3) + repmat(t,1,3).*line(~par,4:6); point(~par, :) = line(~par,1:3) + repmat(t(~par),1,3) .* line(~par,4:6); % set points outside of edge to [NaN NaN NaN] point(t<0, :) = NaN; point(t>1, :) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRay3d.m0000644000000000000000000000013214055375162017406 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRay3d.m0000644000175000017500000000401614055375162020474 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ray = createRay3d(p1, p2) % Create a 3D ray. % % RAY = createRay3d(P1, P2) % Create a ray starting from point P1 and going in the direction of point % P2. % % Example % createRay3d % % See also % creatLine3d % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-05-25, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. ray = [p1 (p2-p1)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fillSphericalPolygon.m0000644000000000000000000000013214055375162021371 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fillSphericalPolygon.m0000644000175000017500000000437314055375162022465 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = fillSphericalPolygon(sphere, poly, germ) %FILLSPHERICALPOLYGON Fill a spherical polygon. % % fillSphericalPolygon(SPHERE, POLY, GERM) % % % Example % fillSphericalPolygon % % See also % drawSphericalPolygon, fillSphericalTriangle, drawSphere % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-02-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. nv = size(poly, 1); h = zeros(nv, 1); for i = 1:nv v1 = poly(i, :); v2 = poly(mod(i, nv) + 1, :); h(i) = fillSphericalTriangle(sphere, germ, v1, v2); end if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawSphericalPolygon.m0000644000000000000000000000013214055375162021400 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawSphericalPolygon.m0000644000175000017500000000430214055375162022464 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawSphericalPolygon(sphere, poly, varargin) %DRAWSPHERICALPOLYGON Draw a spherical polygon. % % output = drawSphericalPolygon(input) % % Example % drawSphericalPolygon % % See also % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-02-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. nv = size(poly, 1); h = zeros(nv, 1); for i = 1:nv v1 = poly(i, :); v2 = poly(mod(i, nv) + 1, :); h(i) = drawSphericalEdge(sphere, [v1 v2], varargin{:}); end if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/clipPoints3d.m0000644000000000000000000000013214055375162017613 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/clipPoints3d.m0000644000175000017500000000776114055375162020713 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = clipPoints3d(points, shape, varargin) %CLIPPOINTS3D Clip a set of points by a box or other 3d shapes. % % CLIP = clipPoints3d(POINTS, BOX); % Returns the set of points which are located inside of the box BOX. % % [CLIP, IND] = clipPoints3d(POINTS, BOX); % Also returns the indices of clipped points. % % ... = clipPoints3d(..., 'shape', 'sphere') Specify the shape. % Default is 'box'. But it is also possible to use 'sphere' or 'plane'. % % ... = clipPoints3d(..., 'inside', false) returns the set of % points outside the shape instead of inside. % % See also % points3d, boxes3d, spheres % % ------ % Author: David Legland, oqilipo % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA Nantes - MIAJ Jouy-en-Josas. parser = inputParser; validStrings = {'box', 'sphere', 'plane'}; addParameter(parser, 'shape', 'box', @(x) any(validatestring(x, validStrings))); addParameter(parser, 'inside', true, @islogical); parse(parser,varargin{:}); switch parser.Results.shape case 'box' LI = clipPointsByBox(points, shape); case 'plane' LI = clipPointsByPlane(points, shape); case 'sphere' LI = clipPointsBySphere(points, shape); end if parser.Results.inside % keep points inside the shape ind = find(LI); else % keep points outside the shape ind = find(~LI); end points = points(ind, :); % process output arguments varargout{1} = points; if nargout == 2 varargout{2} = ind; end function LI = clipPointsByBox(points, box) % get bounding box limits xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); zmin = box(5); zmax = box(6); % compute indices of points inside visible area xOk = points(:,1) >= xmin & points(:,1) <= xmax; yOk = points(:,2) >= ymin & points(:,2) <= ymax; zOk = points(:,3) >= zmin & points(:,3) <= zmax; LI = xOk & yOk & zOk; end function LI = clipPointsByPlane(points, plane) % points inside and on the surface of the sphere LI = isBelowPlane(points, plane); end function LI = clipPointsBySphere(points, sphere) % points inside and on the surface of the sphere LI = distancePoints3d(points, sphere(1:3)) <= sphere(4); end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectThreePlanes.m0000644000000000000000000000013214055375162021373 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectThreePlanes.m0000644000175000017500000000616314055375162022466 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = intersectThreePlanes(plane1, plane2, plane3) %INTERSECTTHREEPLANES Return intersection point between 3 planes in space. % % LINE = intersectThreePlanes(PLANE1, PLANE2, PLANE3) % Returns the point or straight line belonging to three planes. % PLANE: [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % POINT: [x0 y0 z0] % IF rank of the coefficient matrix r1 = 3 and % Rank of the augmented matrix r2 = 3 return point % Otherwise returns point with NaN values. % % See also: % planes3d, intersectPlanes, intersectLinePlane % % --------- % author : Roozbeh Geraili Mikola % email : roozbehg@berkeley.edu or roozbehg@live.com % created the 09/20/2017. % % HISTORY % plane normal n1 = normalizeVector3d(cross(plane1(:,4:6), plane1(:, 7:9), 2)); n2 = normalizeVector3d(cross(plane2(:,4:6), plane2(:, 7:9), 2)); n3 = normalizeVector3d(cross(plane3(:,4:6), plane3(:, 7:9), 2)); % Uses Hessian form, ie : N.p = d % I this case, d can be found as : -N.p0, when N is normalized d1 = dot(n1, plane1(:,1:3), 2); d2 = dot(n2, plane2(:,1:3), 2); d3 = dot(n3, plane3(:,1:3), 2); % create coefficient and augmented matrices A = [n1;n2;n3]; D = [d1;d2;d3]; AD = [n1,d1;n2,d2;n3,d3]; % calculate rank of the coefficient and augmented matrices r1 = rank(A); r2 = rank(AD); % if rank of the coefficient matrix r1 = 3 and % rank of the augmented matrix r2 = 3 return point % and if r1 = 2 and r2 = 2 return line, % otherwise returns point with NaN values. if r1 == 3 && r2 == 3 % Intersecting at a point point = (A\D)'; else point = [NaN NaN NaN]; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/crossProduct3d.m0000644000000000000000000000013214055375162020161 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/crossProduct3d.m0000644000175000017500000000536214055375162021254 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function c = crossProduct3d(a,b) %CROSSPRODUCT3D Vector cross product faster than inbuilt MATLAB cross. % % C = crossProduct3d(A, B) % returns the cross product of the two 3D vectors A and B, that is: % C = A x B % A and B must be N-by-3 element vectors. If either A or B is a 1-by-3 % row vector, the result C will have the size of the other input and will % be the concatenation of each row's cross product. % % Example % v1 = [2 0 0]; % v2 = [0 3 0]; % crossProduct3d(v1, v2) % ans = % 0 0 6 % % % Class support for inputs A,B: % float: double, single % % See also DOT. % Sven Holcombe % HISTORY % 2017-11-24 rename from vectorCross3d to crossProduct3d % size of inputs sizeA = size(a); sizeB = size(b); % Initialise c to the size of a or b, whichever has more dimensions. If % they have the same dimensions, initialise to the larger of the two switch sign(numel(sizeA) - numel(sizeB)) case 1 c = zeros(sizeA); case -1 c = zeros(sizeB); otherwise c = zeros(max(sizeA, sizeB)); end c(:) = bsxfun(@times, a(:,[2 3 1],:), b(:,[3 1 2],:)) - ... bsxfun(@times, b(:,[2 3 1],:), a(:,[3 1 2],:)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isPlane.m0000644000000000000000000000013214055375162016633 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isPlane.m0000644000175000017500000000430114055375162017716 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function d = isPlane(plane) %ISPLANE Check if input is a plane. % % B = isPlane(PLANE) where PLANE should be a plane or multiple planes % % Example % isPlane([... % 0 0 0 1 0 0 0 1 0;... % 0 0 0 1 0 0 -1 0 0;... % 0 0 0 1i 0 0 -1 0 0;... % 0 0 0 nan 0 0 0 1 0;... % 0 0 0 inf 0 0 0 1 0]) % % See also % createPlane3d % % ------ % Author: oqilipo % Created: 2017-07-09 % Copyright 2017 narginchk(1,1) if size(plane,2)~=9 d=false(size(plane,1),1); return end a = ~any(isnan(plane),2); b = ~any(isinf(plane),2); c = ~isParallel3d(plane(:,4:6), plane(:,7:9)); d = a & b & c; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/equivalentEllipsoid.m0000644000000000000000000000013214055375162021262 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/equivalentEllipsoid.m0000644000175000017500000000710614055375162022353 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ell = equivalentEllipsoid(points) % Equivalent ellipsoid of a set of 3D points. % % ELL = equivalentEllipsoid(PTS) % Compute the equivalent ellipsoid of the set of points PTS. The result % is an ellipsoid defined by: % ELL = [XC YC ZC A B C PHI THETA PSI] % where [XC YC ZY] is the center, [A B C] are the lengths of the % semi-axes (in decreasing order), and [PHI THETA PSI] are Euler angles % representing the ellipsoid orientation, in degrees. % % Example % pts = randn(300, 3); % pts = transformPoint3d(pts, createScaling3d([6 4 2])); % pts = transformPoint3d(pts, createRotationOx(pi/6)); % pts = transformPoint3d(pts, createRotationOy(pi/4)); % pts = transformPoint3d(pts, createRotationOz(pi/3)); % pts = transformPoint3d(pts, createTranslation3d([5 4 3])); % elli = equivalentEllipsoid(pts); % figure; drawPoint3d(pts); axis equal; % hold on; drawEllipsoid(elli, ... % 'drawEllipses', true, 'EllipseColor', 'b', 'EllipseWidth', 3); % % See also % spheres, drawEllipsoid, equivalentEllipse, principalAxes % principalAxesTransform, rotation3dToEulerAngles % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-03-12, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % number of points n = size(points, 1); % compute centroid center = mean(points); % compute the covariance matrix covPts = cov(points)/n; % perform a principal component analysis with 3 variables, % to extract equivalent axes [U, S] = svd(covPts); % extract length of each semi axis radii = sqrt(5) * sqrt(diag(S)*n)'; % sort axes from greater to lower [radii, ind] = sort(radii, 'descend'); % format U to ensure first axis points to positive x direction U = U(ind, :); if U(1,1) < 0 U = -U; % keep matrix determinant positive U(:,3) = -U(:,3); end % convert axes rotation matrix to Euler angles angles = rotation3dToEulerAngles(U); % concatenate result to form an ellipsoid object ell = [center, radii, angles]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/vectorNorm3d.m0000644000000000000000000000013214055375162017625 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/vectorNorm3d.m0000644000175000017500000000425514055375162020720 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function n = vectorNorm3d(v) %VECTORNORM3D Norm of a 3D vector or of set of 3D vectors. % % N = vectorNorm3d(V); % Returns the norm of vector V. % % When V is a N-by-3 array, compute norm for each vector of the array. % Vectors are given as rows. Result is then a N-by-1 array. % % NOTE: Computes only the Euclidean norm. % % See also: % vectors3d, normalizeVector3d, vectorAngle3d, hypot3 % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % HISTORY % 19/06/2009 rename as vectorNorm3d n = sqrt(sum(v.*v, ndims(v))); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/boundingBox3d.m0000644000000000000000000000013214055375162017745 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/boundingBox3d.m0000644000175000017500000000547314055375162021043 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = boundingBox3d(points) %BOUNDINGBOX3D Bounding box of a set of 3D points. % % BOX = boundingBox3d(POINTS) % Returns the bounding box of the set of points POINTS. POINTS is a % N-by-3 array containing points coordinates. The result BOX is a 1-by-6 % array, containing: % [XMIN XMAX YMIN YMAX ZMIN ZMAX] % % Example % % Draw bounding box of a cubeoctehedron % [v e f] = createCubeOctahedron; % box3d = boundingBox3d(v); % figure; hold on; % drawMesh(v, f); % drawBox3d(box3d); % set(gcf, 'renderer', 'opengl') % axis([-2 2 -2 2 -2 2]); % view(3) % % See also % boxes3d, drawBox3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-04-01, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % HISTORY % 2011-04-08 add example % 2011-12-09 rename to boundingBox3d % compute extreme x and y values xmin = min(points(:,1)); xmax = max(points(:,1)); ymin = min(points(:,2)); ymax = max(points(:,2)); box = [xmin xmax ymin ymax]; % process case of 3D points if size(points, 2) > 2 zmin = min(points(:,3)); zmax = max(points(:,3)); box = [xmin xmax ymin ymax zmin zmax]; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/changes.txt0000644000000000000000000000013214055375161017232 xustar0030 mtime=1622538865.990813902 30 atime=1622538865.990813902 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/changes.txt0000644000175000017500000000116514055375161020322 0ustar00juanpijuanpi00000000000000changes in geom3d New features - added createEulerAnglesRotation - added drawPolyline3d - added functions for management of 3D boxes (isothetic cuboids) - added drawAxisCube function - added recenterTransform3d, to change invariant point of 3D transforms. Enhancements - added support for several lines in clipLine3d - added support for multiple inputs in distancePointPlane - updated doc for polyhedra, for function localToGlobal3d - updated several drawing functions Bug fixes - fixed several bugs in 3D rotations - fixed bugs in drawCircle3d, drawCircleArc3d, drawEllipse3d. - fixed bugs in drawCylinder matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/lines3d.m0000644000000000000000000000013214055375162016601 xustar0030 mtime=1622538866.042813703 30 atime=1622538866.042813703 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/lines3d.m0000644000175000017500000000441714055375162017674 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function lines3d(varargin) %LINES3D Description of functions operating on 3D lines. % % A 3D Line is represented by a 1-by-6 row vector containing a 3D point % (its origin) and a 3D vector (its direction): % LINE = [X0 Y0 Z0 DX DY DZ]; % % See also: % createLine3d, distancePointLine3d, isPointOnLine3d, linePosition3d % intersectLinePlane, distanceLines3d, parallelLine3d, projPointOnLine3d % clipLine3d, fitLine3d, drawLine3d, transformLine3d % edgeToLine3d, lineToEdge3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('lines3d'); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawSphere.m0000644000000000000000000000013214055375162017344 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawSphere.m0000644000175000017500000001417714055375162020443 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawSphere(varargin) %DRAWSPHERE Draw a sphere as a mesh. % % drawSphere(SPHERE) % Where SPHERE = [XC YC ZC R], draw the sphere centered on the point with % coordinates [XC YC ZC] and with radius R, using a quad mesh. % % drawSphere(CENTER, R) % Where CENTER = [XC YC ZC], specifies the center and the radius with two % arguments. % % drawSphere(XC, YC, ZC, R) % Specifiy sphere center and radius as four arguments. % % drawSphere(..., NAME, VALUE); % Specifies one or several options using parameter name-value pairs. % Available options are usual drawing options, as well as: % 'nPhi' the number of arcs used for drawing the meridians % 'nTheta' the number of circles used for drawing the parallels % % H = drawSphere(...) % Return a handle to the graphical object created by the function. % % [X Y Z] = drawSphere(...) % Return the coordinates of the vertices used by the sphere. In this % case, the sphere is not drawn. % % Example % % Draw four spheres with different centers % figure(1); clf; hold on; % drawSphere([10 10 30 5]); % drawSphere([20 30 10 5]); % drawSphere([30 30 30 5]); % drawSphere([30 20 10 5]); % view([-30 20]); axis equal; l = light; % % % Draw sphere with different settings % figure(1); clf; % drawSphere([10 20 30 10], 'linestyle', ':', 'facecolor', 'r'); % axis([0 50 0 50 0 50]); axis equal; % l = light; % % % The same, but changes style using graphic handle % figure(1); clf; % h = drawSphere([10 20 30 10]); % set(h, 'linestyle', ':'); % set(h, 'facecolor', 'r'); % axis([0 50 0 50 0 50]); axis equal; % l = light; % % % Draw a sphere with high resolution % figure(1); clf; % h = drawSphere([10 20 30 10], 'nPhi', 360, 'nTheta', 180); % l = light; view(3); % % % See also % spheres, circles3d, sphere, drawEllipsoid % --------- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005 % % HISTORY % 2006-05-19 use centered sphere with radius 1 when no input specified % 2007-01-04 typo % 2010-11-08 code cleanup, add doc % Check if axes handle is specified if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1)=[]; elseif nargout ~= 3 hAx = gca; end % process input options: when a string is found, assumes this is the % beginning of options options = {'FaceColor', 'g', 'LineStyle', 'none'}; for i = 1:length(varargin) if ischar(varargin{i}) if length(varargin) == 1 options = {'FaceColor', varargin{1}, 'LineStyle', 'none'}; else options = [options(1:end) varargin(i:end)]; end varargin = varargin(1:i-1); break; end end % Parse the input (try to extract center coordinates and radius) if isempty(varargin) % no input: assumes unit sphere xc = 0; yc = 0; zc = 0; r = 1; elseif length(varargin) == 1 % one argument: concatenates center and radius sphere = varargin{1}; xc = sphere(:,1); yc = sphere(:,2); zc = sphere(:,3); r = sphere(:,4); elseif length(varargin) == 2 % two arguments, corresponding to center and radius center = varargin{1}; xc = center(1); yc = center(2); zc = center(3); r = varargin{2}; elseif length(varargin) == 4 % four arguments, corresponding to XC, YX, ZC and R xc = varargin{1}; yc = varargin{2}; zc = varargin{3}; r = varargin{4}; else error('drawSphere: please specify center and radius'); end % number of meridians nPhi = 32; ind = find(strcmpi('nPhi', options(1:2:end))); if ~isempty(ind) ind = ind(1); nPhi = options{2*ind}; options(2*ind-1:2*ind) = []; end % number of parallels nTheta = 16; ind = find(strcmpi('nTheta', options(1:2:end))); if ~isempty(ind) ind = ind(1); nTheta = options{2*ind}; options(2*ind-1:2*ind) = []; end % compute spherical coordinates theta = linspace(0, pi, nTheta+1); phi = linspace(0, 2*pi, nPhi+1); % convert to cartesian coordinates sintheta = sin(theta); x = xc + cos(phi')*sintheta*r; y = yc + sin(phi')*sintheta*r; z = zc + ones(length(phi),1)*cos(theta)*r; % Process output if nargout == 0 % no output: draw the sphere surf(hAx, x, y, z, options{:}); elseif nargout == 1 % one output: compute varargout{1} = surf(hAx, x, y, z, options{:}); elseif nargout == 3 varargout{1} = x; varargout{2} = y; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createBasisTransform3d.m0000644000000000000000000000013214055375162021610 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createBasisTransform3d.m0000644000175000017500000001207614055375162022703 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function transfo = createBasisTransform3d(source, target) %CREATEBASISTRANSFORM3D Compute matrix for transforming a basis into another basis. % % TRANSFO = createBasisTransform3d(SOURCE, TARGET) will create a 4-by-4 % transformation matrix representing the transformation from SOURCE basis % to TARGET basis. % SOURCE and TARGET are either standard 1-by-9 geom3d PLANE % representations of the form: [x0 y0 z0 ex1 ey1 ez1 ex2 ey2 ez2] % OR % SOURCE and TARGET may be any string such as 'global' or 'g' in which % case they represent the global plane [0 0 0 1 0 0 0 1 0]. % % The resulting TRANSFO matrix is such that a point expressed with % coordinates of the first basis will be represented by new coordinates % P2 = transformPoint3d(P1, TRANSFO) in the target basis. % % Either (or both) SOURCE or TARGET may be an N-by-9 set of N planes. In % that case, TRANSFO will be a 4-by-4-by-N array of N transformation % matrices. % % Example: % % Calculate local plane coords. of a point given in global coords. % plane = [10 10 10 1 0 0 0 1 0]; % transfo = createBasisTransform3d('global', plane); % PT_IN_PLANE = transformPoint3d([3 8 2], transfo) % PT_IN_PLANE = % 13 18 12 % % See also % transforms3d, transformPoint3d, planePosition, createBasisTransform % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-12-03, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2013-07-03 added support for multiple inputs (Sven Holcombe) % 2017-10-16 rewrite % size of input arguments srcSz = size(source, 1); tgtSz = size(target, 1); maxSz = max(srcSz, tgtSz); % check case of multiple inputs if maxSz > 1 [t1, t2] = deal( bsxfun(@times, eye(4), ones(1,1,maxSz)) ); if srcSz > 1 source = permute(source, [3 2 1]); end if tgtSz > 1 target = permute(target, [3 2 1]); end else [t1, t2] = deal(eye(4)); end % Place source and target planes into t1 and t2 t-form matrices. If either % input is non-numeric it is assumed to mean 'global', or identity t-form. if isnumeric(source) if maxSz > 1 && srcSz == 1 source = bsxfun(@times, source, ones(1,1,maxSz)); end t1(1:3, 1, :) = source(1, 4:6, :); t1(1:3, 2, :) = source(1, 7:9, :); t1(1:3, 3, :) = crossProduct3d(source(1,4:6,:), source(1,7:9,:)); t1(1:3, 4, :) = source(1, 1:3, :); end if isnumeric(target) if maxSz > 1 && tgtSz == 1 target = bsxfun(@times, target, ones(1,1,maxSz)); end t2(1:3, 1, :) = target(1, 4:6, :); t2(1:3, 2, :) = target(1, 7:9, :); t2(1:3, 3, :) = crossProduct3d(target(1,4:6,:), target(1,7:9,:)); t2(1:3, 4, :) = target(1, 1:3, :); end % compute transform matrix transfo = zeros(4, 4, maxSz); for i = 1:maxSz % coordinate of four reference points in source basis po = t1(1:3, 4, i)'; px = po + t1(1:3, 1, i)'; py = po + t1(1:3, 2, i)'; pz = po + t1(1:3, 3, i)'; % express coordinates of reference points in the new basis t2i = inv(t2(:,:,i)); pot = transformPoint3d(po, t2i); pxt = transformPoint3d(px, t2i); pyt = transformPoint3d(py, t2i); pzt = transformPoint3d(pz, t2i); % compute direction vectors in new basis vx = pxt - pot; vy = pyt - pot; vz = pzt - pot; % concatenate result in a 4-by-4 affine transform matrix transfo(:,:,i) = [vx' vy' vz' pot' ; 0 0 0 1]; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/parallelPlane.m0000644000000000000000000000013214055375162020014 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/parallelPlane.m0000644000175000017500000000574214055375162021111 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = parallelPlane(plane, point) %PARALLELPLANE Parallel to a plane through a point or at a given distance. % % PL2 = parallelPlane(PL, PT) % Constructs the plane parallel to plane PL and containing the point PT. % % PL2 = parallelPlane(PL, D) % Constructs the plane parallel to plane PL, and located at the given % signed distance D. % % Example % % Create a plane normal to the 3D vector DIR % dir = [3 4 5]; % plane = createPlane([3 4 5], dir); % % Create plane at a specific distance % plane2 = parallelPlane(plane, 5); % % Create a line perpendicular to both planes % line = [2 4 1 3 4 5]; % pi1 = intersectLinePlane(line, plane); % pi2 = intersectLinePlane(line, plane2); % % check the distance between intersection points % distancePoints3d(pi1, pi2) % ans = % 5 % % See also % geom3d, parallelLine3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-08-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. if size(point, 2) == 1 % use a distance. Compute position of point located at distance DIST on % the line normal to the plane. normal = normalizeVector3d(planeNormal(plane)); point = plane(:, 1:3) + bsxfun(@times, point, normal); end % change origin, and keep direction vectors res = [point plane(:, 4:9)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/edges3d.m0000644000000000000000000000013214055375162016556 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/edges3d.m0000644000175000017500000000433714055375162017652 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges3d(varargin) %EDGES3D Description of functions operating on 3D edges. % % A 3D edge is represented by the coordinates of its extremities: % EDGE = [X1 Y1 Z1 X2 Y2 Z2]; % % A set of 3D edges is represented by a N-by-6 array, each row % representing an edge. % % See also % lines3d, edges2d, createEdge3d, edgeLength3d % intersectEdgePlane, edgeToLine3d, edgeToLine3d, clipEdge3d, midPoint3d % distancePointEdge3d, drawEdge3d, drawSphericalEdge % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-04-12, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. help('edges3d'); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/circle3dPosition.m0000644000000000000000000000013214055375162020455 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/circle3dPosition.m0000644000175000017500000000572014055375162021546 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = circle3dPosition(point, circle) %CIRCLE3DPOSITION Return the angular position of a point on a 3D circle. % % POS = circle3dPosition(POINT, CIRCLE) % Returns angular position of point on the circle, in degrees, between 0 % and 360. % with POINT: [xp yp zp] % and CIRCLE: [X0 Y0 Z0 R THETA PHI] or [X0 Y0 Z0 R THETA PHI PSI] % (THETA being the colatitude, and PHI the azimut) % % See also: % circles3d, circle3dOrigin, circle3dPoint % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005 % % HISTORY % 27/06/2007: change 3D angle convention % 2011-06-21 use degrees for angles % get center and radius xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); % get angle of normal theta = circle(:,5); phi = circle(:,6); % find origin of the circle ori = circle3dOrigin(circle); % normal vector of the supporting plane (cartesian coords) vn = sph2cart2d([theta phi]); % create plane containing the circle plane = createPlane([xc yc zc], vn); % find position of point on the circle plane pp0 = planePosition(ori, plane); pp = planePosition(point, plane); % compute angles in the planes theta0 = mod(atan2(pp0(:,2), pp0(:,1)) + 2*pi, 2*pi); theta = mod(atan2(pp(:,2), pp(:,1)) + 2*pi - theta0, 2*pi); % convert to degrees theta = theta * 180 / pi; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isCoplanar.m0000644000000000000000000000013214055375162017333 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isCoplanar.m0000644000175000017500000000662314055375162020427 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function copl = isCoplanar(x,y,z,tol) %ISCOPLANAR Tests input points for coplanarity in 3-space. % % COPL = isCoplanar(PTS) % Tests the coplanarity of the input points in array PTS. Input array must % be 4-by-3, each row containing coordinate of one point. % % COPL = isCoplanar(PTS, TOLERANCE) % Specifies the tolerance value used for checking coplanarity. Default is % zero. % % % Example: % iscoplanar([1 2 -2; -3 1 -14; -1 2 -6; 1 -2 -8], eps) % % Adapted from a function originally written by Brett Shoelson, Ph.D. % brett.shoelson@joslin.harvard.edu % https://fr.mathworks.com/matlabcentral/fileexchange/46-iscoplanar-m % if nargin == 0 error('Requires at least one input argument.'); elseif nargin == 1 if size(x,2) == 3 % Matrix of all x,y,z is input pts = x; tol = 0; else error('Invalid input.') end elseif nargin == 2 if size(x,2) == 3 % Matrix of all x,y,z is input pts = x; tol = y; else error('Invalid input.') end elseif nargin == 3 % Compile a matrix of all x,y,z pts = [x y z]; tol = 0; else pts = [x y z]; end if size(x, 1) < 4 error('Requires at least four points to compute coplanarity'); end % replace first point at the origin and compute SVD of the matrix sv = svd(bsxfun(@minus, pts(2:end,:), pts(1,:))); copl = sv(3) <= tol * sv(1); % % Alterantive version that computes the rank of the matrix % rnk = rank(bsxfun(@minus, pts(2:end,:), pts(1,:)), tol); % copl = rnk <= size(pts, 2) - 1; % % Old version: % %Compare all 4-tuples of point combinations; {P1:P4} are coplanar iff % %det([x1 y1 z1 1;x2 y2 z2 1;x3 y3 z3 1;x4 y4 z4 1])==0 % tmp = nchoosek(1:size(pts,1),4); % for ii = 1:size(tmp,1) % copl = abs(det([pts(tmp(ii, :), :) ones(4,1)])) <= tolerance; % if ~copl % break % end % end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/projPointOnCircle3d.m0000644000000000000000000000013214055375162021072 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/projPointOnCircle3d.m0000644000175000017500000000626614055375162022171 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point2 = projPointOnCircle3d(point, circle) %PROJPOINTONCIRCLE3D Project a 3D point onto a 3D circle. % % PT2 = projPointOnCircle3d(PT, CIRCLE). % Computes the projection of 3D point PT onto the 3D circle CIRCLE. % % Point PT is a N-by-3 array, and CIRCLE is a 1-by-7 array. % Result PT2 is a N-by-3 array, containing coordinates of projections of % PT onto the circle CIRCLE. % % See also % projPointOnLine3d, projPointOnPlane % % Source % https://www.geometrictools.com/Documentation/DistanceToCircle3.pdf % % --------- % Author: oqilipo % Created: 2020-10-12 % Copyright 2020 % center = circle(1:3); radius = circle(4); % Compute transformation from local basis to world basis TFM = localToGlobal3d(center, circle(5), circle(6), circle(7)); % Create circle plane circlePlaneNormal = transformVector3d([0 0 1], TFM); circlePlane = createPlane(center, circlePlaneNormal); % Project point on circle plane PTonCP = projPointOnPlane(point, circlePlane); % Calculate vector from the projected point to the center of the circle PTtoCenter = normalizeVector3d(circle(1:3) - PTonCP); % Calculate final point point2 = PTonCP + PTtoCenter.*(distancePoints3d(PTonCP, center) - radius); % Take an arbitrary point of the circle if the point is the center of the circle if any(all(isnan(point2),2)) point2(all(isnan(point2),2),:) = center + normalizeVector3d(circlePlane(4:6))*radius; end % Take an arbitrary point of the circle if the point lies on the normal of the circle plane if any(sum(PTtoCenter == 0,2) == 2) point2(sum(PTtoCenter == 0,2) == 2,:) = center + normalizeVector3d(circlePlane(4:6))*radius; end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/planeNormal.m0000644000000000000000000000013214055375162017510 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/planeNormal.m0000644000175000017500000000422414055375162020577 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function n = planeNormal(plane) %PLANENORMAL Compute the normal to a plane. % % N = planeNormal(PLANE) % compute the normal of the given plane % PLANE : [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % N : [dx dy dz] % % See also % geom3d, planes3d, createPlane % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % % HISTORY % 15/04/2013 Extended to N-dim planes by Sven Holcombe % plane normal outSz = size(plane); outSz(2) = 3; n = zeros(outSz); n(:) = crossProduct3d(plane(:,4:6,:), plane(:, 7:9,:)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fitPlane.m0000644000000000000000000000013214055375162017002 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fitPlane.m0000644000175000017500000000612114055375162020067 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function plane = fitPlane(points) %FITPLANE Fit a 3D plane to a set of points. % % PLANE = fitPlane(POINTS) % % Example % pts = randn(300, 3); % pts = transformPoint3d(pts, createScaling3d([6 4 2])); % pts = transformPoint3d(pts, createRotationOx(pi/6)); % pts = transformPoint3d(pts, createRotationOy(pi/4)); % pts = transformPoint3d(pts, createRotationOz(pi/3)); % pts = transformPoint3d(pts, createTranslation3d([5 4 3])); % elli = equivalentEllipsoid(pts); % figure; drawPoint3d(pts); axis equal; % hold on; drawEllipsoid(elli, ... % 'drawEllipses', true, 'EllipseColor', 'b', 'EllipseWidth', 3); % plane = fitPlane(pts); % drawPlane3d(plane, 'm'); % % See also % planes3d, equivalentEllipsoid, fitLine3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-11-11, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % number of points n = size(points, 1); % compute centroid center = mean(points); % compute the covariance matrix covPts = cov(points)/n; % perform a principal component analysis with 2 variables, % to extract inertia axes [U, S] = svd(covPts); % sort axes from greater to lower [dummy, ind] = sort(diag(S), 'descend'); %#ok % format U to ensure first axis points to positive x direction U = U(ind, :); if U(1,1) < 0 U = -U; % keep matrix determinant positive U(:,3) = -U(:,3); end plane = [center U(:,1)' U(:,2)']; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawCube.m0000644000000000000000000000013214055375162016774 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawCube.m0000644000175000017500000001067514055375162020072 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCube(cube, varargin) % Draw a 3D centered cube, eventually rotated. % % drawCube(CUBE) % Displays a 3D cube on current axis. CUBE is given by: % [XC YC ZC SIDE THETA PHI PSI] % where (XC, YC, ZC) is the CUBE center, SIDE is the length of the cube % main sides, and THETA PHI PSI are angles representing the cube % orientation, in degrees. THETA is the colatitude of the cube, between 0 % and 90 degrees, PHI is the azimut, and PSI is the rotation angle % around the axis of the normal. % % CUBE can be axis aligned, in this case it should only contain center % and side information: % CUBE = [XC YC ZC SIDE] % % The function drawCuboid is closely related, but uses a different angle % convention, and allows for different sizes along directions. % % Example % % Draw a cube with small rotations % figure; hold on; % drawCube([10 20 30 50 10 20 30], 'FaceColor', 'g'); % axis equal; % view(3); % % See also % meshes3d, polyhedra, createCube, drawCuboid % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-06-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % Parse and check inputs hAx = gca; if nargin > 0 if isAxisHandle(cube) hAx = cube; if ~isempty(varargin) cube = varargin{1}; varargin(1) = []; end end end % default values xc = 0; yc = 0; zc = 0; a = 1; theta = 0; phi = 0; psi = 0; %% Parses the input if nargin > 0 && ~isAxisHandle(cube) % one argument: parses elements xc = cube(:,1); yc = cube(:,2); zc = cube(:,3); % parses side length if present if size(cube, 2) >= 4 a = cube(:,4); end % parses orientation if present if size(cube, 2) >= 6 theta = deg2rad(cube(:,5)); phi = deg2rad(cube(:,6)); end if size(cube, 2) >= 7 psi = deg2rad(cube(:,7)); end end %% Compute cube coordinates % create unit centered cube [v, f] = createCube; v = bsxfun(@minus, v, mean(v, 1)); % convert unit basis to cube basis sca = createScaling3d(a); rot1 = createRotationOz(psi); rot2 = createRotationOy(theta); rot3 = createRotationOz(phi); tra = createTranslation3d([xc yc zc]); % concatenate transforms trans = tra * rot3 * rot2 * rot1 * sca; % transform mesh vertices v = transformPoint3d(v, trans); %% Process output if nargout == 0 % no output: draw the cube drawMesh(hAx, v, f, varargin{:}); elseif nargout == 1 % one output: draw the cube and return handle varargout{1} = drawMesh(hAx, v, f, varargin{:}); elseif nargout == 3 % 3 outputs: return computed coordinates varargout{1} = v(:,1); varargout{2} = v(:,2); varargout{3} = v(:,3); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawSphericalEdge.m0000644000000000000000000000013214055375162020615 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawSphericalEdge.m0000644000175000017500000000604214055375162021704 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawSphericalEdge(sphere, edge, varargin) %DRAWSPHERICALEDGE Draw an edge on the surface of a sphere. % % drawSphericalEdge(SPHERE, EDGE) % EDGE is given as a couple of 3D coordinates corresponding to edge % extremities. The shortest spherical edge joining the two extremities is % drawn on the current axes. % % Example % drawSphericalEdge % % See also % drawSphericalPolygon % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-02-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % extract data of the sphere origin = sphere(:, 1:3); % extremities of current edge point1 = edge(1:3); point2 = edge(4:6); % compute plane containing current edge plane = createPlane(origin, point1, point2); % intersection of the plane with unit sphere circle = intersectPlaneSphere(plane, sphere); % find the position (in degrees) of the 2 vertices on the circle angle1 = circle3dPosition(point1, circle); angle2 = circle3dPosition(point2, circle); % ensure angles are in right direction if mod(angle2 - angle1 + 360, 360) > 180 tmp = angle1; angle1 = angle2; angle2 = tmp; end % compute angle extent of the circle arc angleExtent = mod(angle2 - angle1 + 360, 360); % create circle arc arc = [circle angle1 angleExtent]; % draw the arc h = drawCircleArc3d(arc, varargin{:}); if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawLabels3d.m0000644000000000000000000000013214055375162017547 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawLabels3d.m0000644000175000017500000000776714055375162020655 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawLabels3d(varargin) %DRAWLABELS3D Draw text labels at specified 3D positions. % % drawLabels3d(X, Y, Z, 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. % % drawLabels3d(POS, LBL) draw labels LBL at position specified by POS, % where POS is a N-by-3 int array. % % drawLabels3d(..., NUMBERS, FORMAT) create labels using sprintf function, % with the mask given by FORMAT (e. g. '%03d' or '5.3f'), and the % corresponding values. % % See also % drawLabels % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/01/2019. % % HISTORY % 2019-01-31 write 3D version from drawLabels %% Parse input arguments % check if enough inputs are given if isempty(varargin) error('wrong number of arguments in drawLabels3d'); end % extract handle of axis to draw on if isAxisHandle(varargin{1}) axH = varargin{1}; varargin(1) = []; else axH = gca; end % process input parameters var = varargin{1}; if size(var, 2) == 1 % coordinates given as separate arguments if length(varargin) < 4 error('wrong number of arguments in drawLabels'); end px = var; py = varargin{2}; pz = varargin{3}; lbl = varargin{4}; varargin(1:4) = []; else % parameters given as a packed array if length(varargin) < 2 error('wrong number of arguments in drawLabels'); end if size(var, 2) < 3 error('Requires coordinates array to have at least three columns'); end px = var(:,1); py = var(:,2); pz = var(:,3); lbl = varargin{2}; varargin(1:2) = []; end % parse format for displaying numeric values format = '%.2f'; if ~isempty(varargin) if varargin{1}(1) == '%' format = varargin{1}; varargin(1)=[]; end end if size(format, 1) == 1 && size(px, 1) > 1 format = repmat(format, size(px, 1), 1); end %% compute the strings that have to be displayed 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); %% display the text h = text(axH, px, py, pz, labels, varargin{:}); %% format output if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/polygonArea3d.m0000644000000000000000000000013214055375162017747 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/polygonArea3d.m0000644000175000017500000000736514055375162021047 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function area = polygonArea3d(poly, varargin) %POLYGONAREA3D Area of a 3D polygon. % % AREA = polygonArea3d(POLY) % POLY is given as a N-by-3 array of vertex coordinates. The resulting % area is positive. % Works also for polygons given as a cell array of polygons. % % Example % % area of a simple 3D square % poly = [10 30 20;20 30 20;20 40 20;10 40 20]; % polygonArea3d(poly) % ans = % 100 % % % Area of a 3D mesh % [v f] = createCubeOctahedron; % polygons = meshFacePolygons(v, f); % areas = polygonArea3d(polygons); % sum(areas) % ans = % 18.9282 % % See also % polygons3d, triangleArea3d, polygonArea, polygonCentroid3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % HISTORY % 2013-08-20 add support for multiple polygons % Check multiple polygons if iscell(poly) || sum(sum(isnan(poly))) > 0 % split the polygons into a cell array polygons = splitPolygons3d(poly); nPolys = length(polygons); % compute area of each polygon area = zeros(nPolys, 1); for i = 1:nPolys area(i) = polygonArea3d(polygons{i}); end return; end % put the first vertex at origin (reducing computation errors for polygons % far from origin) v0 = poly(1, :); poly = bsxfun(@minus, poly, v0); % indices of next vertices N = size(poly, 1); iNext = [2:N 1]; % compute cross-product of each elementary triangle formed by origin and % two consecutive vertices cp = cross(poly, poly(iNext,:), 2); % choose one of the triangles as reference for the normal direction vn = vectorNorm3d(cp); [tmp, ind] = max(vn); %#ok cpRef = cp(ind,:); % compute the sign of the area of each triangle % (need to compute the sign explicitely, as the norm of the cross product % does not keep orientation within supporting plane) sign_i = sign(dot(cp, repmat(cpRef, N, 1), 2)); % compute area of each triangle, using sign correction area_i = vectorNorm3d(cp) .* sign_i; % sum up individual triangles area area = sum(area_i) / 2; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotationVector3d.m0000644000000000000000000000013214055375162021635 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotationVector3d.m0000644000175000017500000000531314055375162022724 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ROT = createRotationVector3d(A,B) %CREATEROTATIONVECTOR3D Calculates the rotation between two vectors. % % ROT = createRotationVector3d(A, B) returns the 4x4 rotation matrix ROT % to transform vector A in the same direction as vector B. % % Example % A=[ .1 .2 .3]; % B=-1+2.*rand(1,3); % ROT = createRotationVector3d(A,B); % C = transformVector3d(A,ROT); % figure('color','w'); hold on; view(3) % O=[0 0 0]; % drawVector3d(O, A,'r'); % drawVector3d(O, B,'g'); % drawVector3d(O, C,'r'); % % See also % transformPoint3d, createRotationOx, createRotationOy, createRotationOz % % Source % https://math.stackexchange.com/a/897677 % % --------- % Author: oqilipo % Created: 2017-08-07 % Copyright 2017 if isParallel3d(A,B) if A*B'>0 ROT = eye(4); else ROT = -1*eye(4); ROT(end)=1; end else a=normalizeVector3d(A); b=normalizeVector3d(B); a=reshape(a,3,1); b=reshape(b,3,1); v = cross(a,b); ssc = [0 -v(3) v(2); v(3) 0 -v(1); -v(2) v(1) 0]; ROT = eye(3) + ssc + ssc^2*(1-dot(a,b))/(norm(v))^2; ROT = [ROT, [0;0;0]; 0 0 0 1]; end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createEdge3d.m0000644000000000000000000000013214055375162017517 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createEdge3d.m0000644000175000017500000000637314055375162020615 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = createEdge3d(varargin) %CREATEEDGE3D Create an edge between two 3D points, or from a 3D line. % % E = createEdge3d(P1, P2) % Creates the 3D edge joining the two points P1 and P2. % % E = createEdge3d(LIN) % Creates the 3D edge with same origin and same direction vector as the % 3D line LIN. % % Example % p1 = [1 1 1]; % p2 = [3 4 5]; % edge = createEdge3d(p1, p2); % edgeLength3d(edge) % ans = % 5.3852 % % See also % edges3d, drawEdge3d, clipEdge3d, edgelength3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-08-29, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. if nargin == 1 % Only one input parameter. Assumes it corresponds to a 3D line with % 6 params. var = varargin{1}; if size(var, 2) ~= 6 error('single input must have 6 columns'); end % converts 3D line into 3D edge edge = zeros(size(var)); edge(:, 1:3) = var(:, 1:3); edge(:, 4:6) = edge(:, 1:3) + var(:,4:6); elseif nargin == 2 % 2 input parameters correspond to two 3D points % extract the two arguments v1 = varargin{1}; v2 = varargin{2}; if size(v1, 2) ~= 3 || size(v2, 2) ~= 3 error('Input points must be arrays with 3 columns'); end % first input parameter is first point, and second input is the % second point. Allows multiple points. n1 = size(v1, 1); n2 = size(v2, 1); if n1 == n2 edge = [v1 v2]; elseif n1 == 1 || n2 == 1 edge = [repmat(v1, n2, 1) repmat(v2, n1, 1)]; end else error('Wrong number of arguments in ''%s''', mfilename); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/surfaceCurvature.m0000644000000000000000000000013214055375162020571 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/surfaceCurvature.m0000644000175000017500000000463214055375162021663 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function kappa = surfaceCurvature(kappa1, kappa2, theta) %SURFACECURVATURE Curvature on a surface from angle and principal curvatures. % % usage: % KAPPA = surfaceCurvature(KAPPA1, KAPPA2, THETA) % return the curvature KAPPA of surface with respect to direction THETA. % KAPPA1 and KAPPA2 are the principal curvatures of the surface at the % considered point. THETA is angle of direction relative to angle of % first principal curvature KAPPA1. % % Examples: % K = surfaceCurvature(KAPPA1, KAPPA2, 0) returns KAPPA1. % K = surfaceCurvature(KAPPA1, KAPPA2, pi/2) returns KAPPA2. % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/04/2004. % % HISTORY % 20/04/2004 change name and add doc. % 14/06/2004 correct creation date kappa = kappa1 * cos(theta).^2 + kappa2 * sin(theta).^2; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/normalizeVector3d.m0000644000000000000000000000013214055375162020652 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/normalizeVector3d.m0000644000175000017500000000466514055375162021752 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vn = normalizeVector3d(v) %NORMALIZEVECTOR3D Normalize a 3D vector to have norm equal to 1. % % V2 = normalizeVector3d(V); % Returns the normalization of vector V, such that ||V|| = 1. Vector V is % given as a row vector. % % If V is a N-by-3 array, normalization is performed for each row of the % input array. % % If V is a M-by-N-by-3 array, normalization is performed along the last % dimension of the array. % % See also: % vectors3d, vectorNorm3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 29/11/2004. % % HISTORY % 2005-11-30 correct a bug % 2009-06-19 rename as normalizeVector3d % 2010-11-16 use bsxfun (Thanks to Sven Holcombe) if ismatrix(v) vn = bsxfun(@rdivide, v, sqrt(sum(v.^2, 2))); else vn = bsxfun(@rdivide, v, sqrt(sum(v.^2, ndims(v)))); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/vectorCross3d.m0000644000000000000000000000013214055375162020003 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/vectorCross3d.m0000644000175000017500000000603414055375162021073 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function c = vectorCross3d(a,b) %VECTORCROSS3D Vector cross product faster than inbuilt MATLAB cross. % % C = vectorCross3d(A, B) % returns the cross product of the 3D vectors A and B, that is: % C = A x B % A and B must be N-by-3 element vectors. If either A or B is a 1-by-3 % row vector, the result C will have the size of the other input and will % be the concatenation of each row's cross product. % % Example % v1 = [2 0 0]; % v2 = [0 3 0]; % vectorCross3d(v1, v2) % ans = % 0 0 6 % % % Class support for inputs A,B: % float: double, single % % See also DOT. % Sven Holcombe % needed_colons = max([3, length(size(a)), length(size(b))]) - 3; % tmp_colon = {':'}; % clnSet = tmp_colon(ones(1, needed_colons)); % % c = bsxfun(@times, a(:,[2 3 1],clnSet{:}), b(:,[3 1 2],clnSet{:})) - ... % bsxfun(@times, b(:,[2 3 1],clnSet{:}), a(:,[3 1 2],clnSet{:})); % deprecation warning warning('geom3d:deprecated', ... [mfilename ' is deprecated, use ''crossProduct3d'' instead']); sza = size(a); szb = size(b); % Initialise c to the size of a or b, whichever has more dimensions. If % they have the same dimensions, initialise to the larger of the two switch sign(numel(sza) - numel(szb)) case 1 c = zeros(sza); case -1 c = zeros(szb); otherwise c = zeros(max(sza, szb)); end c(:) = bsxfun(@times, a(:,[2 3 1],:), b(:,[3 1 2],:)) - ... bsxfun(@times, b(:,[2 3 1],:), a(:,[3 1 2],:)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/composeTransforms3d.m0000644000000000000000000000013214055375162021213 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/composeTransforms3d.m0000644000175000017500000000474414055375162022311 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = composeTransforms3d(varargin) %COMPOSETRANSFORMS3D Concatenate several space transformations. % % TRANS = composeTransforms3d(TRANS1, TRANS2, ...); % Computes the affine transform equivalent to performing successively % TRANS1, TRANS2, ... % % Example: % PTS = rand(20, 3); % ROT1 = createRotationOx(pi/3); % ROT2 = createRotationOy(pi/4); % ROT3 = createRotationOz(pi/5); % ROTS = composeTransforms3d(ROT1, ROT2, ROT3); % Then: % PTS2 = transformPoint3d(PTS, ROTS); % will give the same result as: % PTS3 = transformPoint3d(transformPoint3d(transformPoint3d(PTS, ... % ROT1), ROT2), ROT3); % % See also: % transforms3d, transformPoint3d % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 29/29/2006. % trans = varargin{nargin}; for i=length(varargin)-1:-1:1 trans = trans * varargin{i}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/vectors3d.m0000644000000000000000000000013214055375162017154 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/vectors3d.m0000644000175000017500000000430514055375162020243 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vectors3d(varargin) %VECTORS3D Description of functions operating on 3D vectors. % % Vectors are represented by their 3 Cartesian coordinates: % V = [VX VY VZ]; % % List of vectors are represented by N-by-3 arrays, with the coordinates % of each vector on a row. % % % See also % vectorNorm3d, normalizeVector3d, crossProduct3d, vectorAngle3d % isParallel3d, isPerpendicular3d, createTranslation3d % drawVector3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/dihedralAngle.m0000644000000000000000000000013214055375162017763 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/dihedralAngle.m0000644000175000017500000000571614055375162021061 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = dihedralAngle(plane1, plane2) %DIHEDRALANGLE Compute dihedral angle between 2 planes. % % THETA = dihedralAngle(PLANE1, PLANE2) % PLANE1 and PLANE2 are plane representations given in the following % format: % [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % THETA is the angle between the two vectors given by plane normals, % given between 0 and PI. % % References % http://en.wikipedia.org/wiki/Dihedral_angle % http://mathworld.wolfram.com/DihedralAngle.html % % See also: % planes3d, lines3d, angles3d, planesBisector % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % % HISTORY % 2009-06-19 change convention for dihedral angle % 2011-03-20 improve computation precision % compute plane normals v1 = planeNormal(plane1); v2 = planeNormal(plane2); % number of vectors n1 = size(v1, 1); n2 = size(v2, 1); % ensures vectors have same dimension if n1 ~= n2 if n1 == 1 v1 = repmat(v1, [n2 1]); elseif n2 == 1 v2 = repmat(v2, [n1 1]); else error('Arguments V1 and V2 must have the same size'); end end % compute dihedral angle(s) theta = atan2(vectorNorm3d(cross(v1, v2, 2)), dot(v1, v2, 2)); % % equivalent to following formula, but more precise for small angles: % n1 = normalizeVector3d(planeNormal(plane1)); % n2 = normalizeVector3d(planeNormal(plane2)); % theta = acos(dot(n1, n2, 2)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawCircleArc3d.m0000644000000000000000000000013214055375162020174 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawCircleArc3d.m0000644000175000017500000000745514055375162021274 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCircleArc3d(arc, varargin) % Draw a 3D circle arc. % % drawCircleArc3d([XC YC ZC R THETA PHI PSI START EXTENT]) % [XC YC ZC] : coordinate of arc center % R : arc radius % [THETA PHI] : orientation of arc normal, in degrees (theta: 0->180). % PSI : roll of arc (rotation of circle origin) % START : starting angle of arc, from arc origin, in degrees % EXTENT : extent of circle arc, in degrees (can be negative) % % Drawing options can be specified, as for the plot command. % % See also % angles3d, circles3d, drawCircle3d, drawCircleArc % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005 % % HISTORY % 2007-06-27 change 3D angle convention % 2010-03-08 use drawPolyline3d % 2011-06-21 use angles in degrees % parse axis handle hAx = gca; if isAxisHandle(arc) hAx = arc; arc = varargin{1}; varargin(1) = []; end if iscell(arc) h = []; for i = 1:length(arc) h = [h drawCircleArc3d(hAx, arc{i}, varargin{:})]; %#ok end if nargout > 0 varargout = {h}; end return; end if size(arc, 1) > 1 h = []; for i = 1:size(arc, 1) h = [h drawCircleArc3d(hAx, arc(i,:), varargin{:})]; %#ok end if nargout > 0 varargout = {h}; end return; end % get center and radius xc = arc(:,1); yc = arc(:,2); zc = arc(:,3); r = arc(:,4); % get angle of normal theta = arc(:,5); phi = arc(:,6); psi = arc(:,7); % get starting angle and angle extent of arc start = arc(:,8); extent = arc(:,9); % positions on circle arc N = 60; t = linspace(start, start+extent, N+1) * pi / 180; % compute coordinate of points x = r*cos(t)'; y = r*sin(t)'; z = zeros(length(t), 1); curve = [x y z]; % compute transformation from local basis to world basis trans = localToGlobal3d(xc, yc, zc, theta, phi, psi); % transform circle arc curve = transformPoint3d(curve, trans); % draw the curve with specified options h = drawPolyline3d(hAx, curve, varargin{:}); if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectLinePlane.m0000644000000000000000000000013214055375162021030 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectLinePlane.m0000644000175000017500000001050114055375162022112 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = intersectLinePlane(line, plane, varargin) %INTERSECTLINEPLANE Intersection point between a 3D line and a plane. % % PT = intersectLinePlane(LINE, PLANE) % Returns the intersection point of the given line and the given plane. % LINE: [x0 y0 z0 dx dy dz] % PLANE: [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % PT: [xi yi zi] % If LINE and PLANE are parallel, return [NaN NaN NaN]. % If LINE (or PLANE) is a matrix with 6 (or 9) columns and N rows, result % is an array of points with N rows and 3 columns. % % PT = intersectLinePlane(LINE, PLANE, TOL) % Specifies the tolerance factor to test if a line is parallel to a % plane. Default is 1e-14. % % Example % % define horizontal plane through origin % plane = [0 0 0 1 0 0 0 1 0]; % % intersection with a vertical line % line = [2 3 4 0 0 1]; % intersectLinePlane(line, plane) % ans = % 2 3 0 % % intersection with a line "parallel" to plane % line = [2 3 4 1 2 0]; % intersectLinePlane(line, plane) % ans = % NaN NaN NaN % % See also: % lines3d, planes3d, points3d, clipLine3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % % HISTORY % 24/11/2005 add support for multiple input % 23/06/2006 correction from Songbai Ji allowing different number of % lines or plane if other input has one row % 14/12/2006 correction for parallel lines and plane normals % 05/01/2007 fixup for parallel lines and plane normals % 24/04/2007 rename as 'intersectLinePlane' % 11/19/2010 Added bsxfun functionality for improved speed (Sven Holcombe) % 01/02/2011 code cleanup, add option for tolerance, update doc % extract tolerance if needed tol = 1e-14; if nargin > 2 tol = varargin{1}; end % unify sizes of data nLines = size(line, 1); nPlanes = size(plane, 1); % N planes and M lines not allowed if nLines ~= nPlanes && min(nLines, nPlanes) > 1 error('MatGeom:geom3d:intersectLinePlane', ... 'Input must have same number of rows, or one must be 1'); end % plane normal n = crossProduct3d(plane(:,4:6), plane(:,7:9)); % difference between origins of plane and line dp = bsxfun(@minus, plane(:, 1:3), line(:, 1:3)); % dot product of line direction with plane normal denom = sum(bsxfun(@times, n, line(:,4:6)), 2); % relative position of intersection point on line (can be inf in case of a % line parallel to the plane) t = sum(bsxfun(@times, n, dp),2) ./ denom; % compute coord of intersection point point = bsxfun(@plus, line(:,1:3), bsxfun(@times, [t t t], line(:,4:6))); % set indices of line and plane which are parallel to NaN par = abs(denom) < tol; point(par,:) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/reverseLine3d.m0000644000000000000000000000013214055375162017752 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/reverseLine3d.m0000644000175000017500000000420014055375162021033 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = reverseLine3d(line) %REVERSELINE3D Return same 3D line but with opposite orientation. % % INVLINE = reverseLine(LINE); % Returns the opposite line of LINE. % LINE has the format [x0 y0 z0 dx dy dz], then INVLINE will have % following parameters: [x0 y0 z0 -dx -dy -dz]. % % See also: % reverseLine, reversePlane % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-05-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. line(:, 4:6) = -line(:, 4:6); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/transformLine3d.m0000644000000000000000000000013214055375162020312 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/transformLine3d.m0000644000175000017500000000471014055375162021401 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = transformLine3d(line, trans) %TRANSFORMLINE3D Transform a 3D line with a 3D affine transform. % % LINE2 = transformLine3d(LINE1, TRANS) % % Example % P1 = [10 20 30]; % P2 = [30 40 50]; % L = createLine3d(P1, P2); % T = createRotationOx(P1, pi/6); % L2 = transformLine3d(L, T); % figure; hold on; % axis([0 100 0 100 0 100]); view(3); % drawPoint3d([P1;P2]); % drawLine3d(L, 'b'); % drawLine3d(L2, 'm'); % % See also: % lines3d, transforms3d, transformPoint3d, transformVector3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2008-11-25, using Matlab 7.7.0.471 (R2008b) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. res = [... transformPoint3d(line(:, 1:3), trans) ... % transform origin point transformVector3d(line(:,4:6), trans)]; % transform direction vect. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectPlanes.m0000644000000000000000000000013214055375162020403 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectPlanes.m0000644000175000017500000000607314055375162021476 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = intersectPlanes(plane1, plane2, varargin) %INTERSECTPLANES Return intersection line between 2 planes in space. % % LINE = intersectPlanes(PLANE1, PLANE2) % Returns the straight line belonging to both planes. % PLANE: [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % LINE: [x0 y0 z0 dx dy dz] % In case of parallel planes, returns line with NaN values. % % LINE = intersectPlanes(PLANE1, PLANE2, TOL) % Also specifies the tolerance for detecting parallel planes. % % See also: % planes3d, lines3d, intersectLinePlane % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % % HISTORY tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % plane normal n1 = normalizeVector3d(cross(plane1(:,4:6), plane1(:, 7:9), 2)); n2 = normalizeVector3d(cross(plane2(:,4:6), plane2(:, 7:9), 2)); % test if planes are parallel if abs(cross(n1, n2, 2)) < tol line = [NaN NaN NaN NaN NaN NaN]; return; end % Uses Hessian form, ie : N.p = d % I this case, d can be found as : -N.p0, when N is normalized d1 = dot(n1, plane1(:,1:3), 2); d2 = dot(n2, plane2(:,1:3), 2); % compute dot products dot1 = dot(n1, n1, 2); dot2 = dot(n2, n2, 2); dot12 = dot(n1, n2, 2); % intermediate computations det = dot1*dot2 - dot12*dot12; c1 = (d1*dot2 - d2*dot12)./det; c2 = (d2*dot1 - d1*dot12)./det; % compute line origin and direction p0 = c1*n1 + c2*n2; dp = cross(n1, n2, 2); line = [p0 dp]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/polygons3d.m0000644000000000000000000000013214055375162017341 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/polygons3d.m0000644000175000017500000000455114055375162020433 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polygons3d(varargin) %POLYGONS3D Description of functions operating on 3D polygons. % % A 3D polygon is simply a set of 3D points (called vertices) which are % assumed to be located in the same plane. % Several functions are provided for computing basic geometrical % parameters (centroid, angles), or intersections with lines or planes. % % See also: % polygonArea3d, triangleArea3d, polygonCentroid3d, polygon3dNormalAngle % intersectLinePolygon3d, intersectLineTriangle3d, intersectRayPolygon3d % clipConvexPolygon3dHP % drawPolygon3d, drawPolyline3d, fillPolygon3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/mergeBoxes3d.m0000644000000000000000000000013214055375162017567 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/mergeBoxes3d.m0000644000175000017500000000510014055375162020650 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = mergeBoxes3d(box1, box2) %MERGEBOXES3D Merge 3D boxes, by computing their greatest extent. % % BOX = mergeBoxes3d(BOX1, BOX2); % % Example % box1 = [5 20 5 30 10 50]; % box2 = [0 15 0 15 0 20]; % mergeBoxes3d(box1, box2) % ans = % 0 20 0 30 0 50 % % % See also % boxes3d, drawBox3d, intersectBoxes3d % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % unify sizes of data if size(box1,1) == 1 box1 = repmat(box1, size(box2,1), 1); elseif size(box2, 1) == 1 box2 = repmat(box2, size(box1,1), 1); elseif size(box1,1) ~= size(box2,1) error('Bad size for inputs'); end % compute extreme coords mini = min(box1(:,1:2:end), box2(:,1:2:end)); maxi = max(box1(:,2:2:end), box2(:,2:2:end)); % concatenate result into a new box structure box = [mini(:,1) maxi(:,1) mini(:,2) maxi(:,2) mini(:,3) maxi(:,3)]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/normalizePlane.m0000644000000000000000000000013214055375162020220 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/normalizePlane.m0000644000175000017500000000561214055375162021311 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function plane2 = normalizePlane(plane1) %NORMALIZEPLANE Normalize parametric representation of a plane. % % PLANE2 = normalizePlane(PLANE1); % Transforms the plane PLANE1 in the following format: % [X0 Y0 Z0 DX1 DY1 DZ1 DX2 DY2 DZ2], where: % - (X0, Y0, Z0) is a point belonging to the plane % - (DX1, DY1, DZ1) is a first direction vector % - (DX2, DY2, DZ2) is a second direction vector % into another plane, with the same format, but with: % - (x0 y0 z0) is the closest point of plane to the origin % - (DX1 DY1 DZ1) has norm equal to 1 % - (DX2 DY2 DZ2) has norm equal to 1 and is orthogonal to (DX1 DY1 DZ1) % % See also: % planes3d, createPlane % % --------- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % % HISTORY % 21/08/2009 compute origin after computation of vectors (more precise) % and add support for several planes. % compute first direction vector d1 = normalizeVector3d(plane1(:,4:6)); % compute second direction vector n = normalizeVector3d(planeNormal(plane1)); d2 = -normalizeVector3d(crossProduct3d(d1, n)); % compute origin point of the plane origins = repmat([0 0 0], [size(plane1, 1) 1]); p0 = projPointOnPlane(origins, [plane1(:,1:3) d1 d2]); % create the resulting plane plane2 = [p0 d1 d2]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isBelowPlane.m0000644000000000000000000000013214055375162017624 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isBelowPlane.m0000644000175000017500000000546314055375162020721 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function below = isBelowPlane(point, varargin) %ISBELOWPLANE Test whether a point is below or above a plane. % % BELOW = isBelowPlane(POINT, PLANE) % where POINT is given as coordinate row vector [XP YP ZP], and PLANE is % given as a row containing initial point and 2 direction vectors, % return TRUE if POINT lie below PLANE. % % Example % isBelowPlane([1 1 1], createPlane([1 2 3], [1 1 1])) % ans = % 1 % isBelowPlane([3 3 3], createPlane([1 2 3], [1 1 1])) % ans = % 0 % % See also % planes3d, points3d, linePosition3d, planePosition % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-01-05 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. if length(varargin)==1 plane = varargin{1}; elseif length(varargin)==2 plane = createPlane(varargin{1}, varargin{2}); end % ensure same dimension for parameters if size(point, 1)==1 point = repmat(point, [size(plane, 1) 1]); end if size(plane, 1)==1 plane = repmat(plane, [size(point, 1) 1]); end % compute position of point projected on 3D line corresponding to plane % normal, and returns true for points locatd below the plane (pos<=0). below = linePosition3d(point, [plane(:, 1:3) planeNormal(plane)]) <= 0; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/eulerAnglesToRotation3d.m0000644000000000000000000000013214055375162021760 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/eulerAnglesToRotation3d.m0000644000175000017500000001374714055375162023061 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function mat = eulerAnglesToRotation3d(phi, theta, psi, varargin) %EULERANGLESTOROTATION3D Convert 3D Euler angles to 3D rotation matrix. % % MAT = eulerAnglesToRotation3d(PHI, THETA, PSI) % Creates a rotation matrix from the 3 euler angles PHI THETA and PSI, % given in degrees, using the 'XYZ' convention (local basis), or the % 'ZYX' convention (global basis). The result MAT is a 4-by-4 rotation % matrix in homogeneous coordinates. % % PHI: rotation angle around Z-axis, in degrees, corresponding to the % 'Yaw'. PHI is between -180 and +180. % THETA: rotation angle around Y-axis, in degrees, corresponding to the % 'Pitch'. THETA is between -90 and +90. % PSI: rotation angle around X-axis, in degrees, corresponding to the % 'Roll'. PSI is between -180 and +180. % These angles correspond to the "Yaw-Pitch-Roll" convention, also known % as "Tait-Bryan angles". % % The resulting rotation is equivalent to a rotation around X-axis by an % angle PSI, followed by a rotation around the Y-axis by an angle THETA, % followed by a rotation around the Z-axis by an angle PHI. % That is: % ROT = Rz * Ry * Rx; % % MAT = eulerAnglesToRotation3d(ANGLES) % Concatenates all angles in a single 1-by-3 array. % % ... = eulerAnglesToRotation3d(ANGLES, CONVENTION) % CONVENTION specifies the axis rotation sequence. Default is 'ZYX'. % Supported conventions are: % 'ZYX','ZXY','YXZ','YZX','XYZ','XZY' % 'ZYZ','ZXZ','YZY','YXY','XZX','XYX' % % Example % [n e f] = createCube; % phi = 20; % theta = 30; % psi = 10; % rot = eulerAnglesToRotation3d(phi, theta, psi); % n2 = transformPoint3d(n, rot); % drawPolyhedron(n2, f); % % See also % transforms3d, createRotationOx, createRotationOy, createRotationOz % rotation3dAxisAndAngle % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-07-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2011-06-20 rename and use degrees % Process input arguments if size(phi, 2) == 3 if nargin > 1 varargin{1} = theta; end % manages arguments given as one array psi = phi(:, 3); theta = phi(:, 2); phi = phi(:, 1); end p = inputParser; validStrings = {... 'ZYX','ZXY','YXZ','YZX','XYZ','XZY',... 'ZYZ','ZXZ','YZY','YXY','XZX','XYX'}; addOptional(p,'convention','ZYX',@(x) any(validatestring(x,validStrings))); parse(p,varargin{:}); convention=p.Results.convention; % create individual rotation matrices k = pi / 180; switch convention case 'ZYX' rot1 = createRotationOx(psi * k); rot2 = createRotationOy(theta * k); rot3 = createRotationOz(phi * k); case 'ZXY' rot1 = createRotationOy(psi * k); rot2 = createRotationOx(theta * k); rot3 = createRotationOz(phi * k); case 'YXZ' rot1 = createRotationOz(psi * k); rot2 = createRotationOx(theta * k); rot3 = createRotationOy(phi * k); case 'YZX' rot1 = createRotationOx(psi * k); rot2 = createRotationOz(theta * k); rot3 = createRotationOy(phi * k); case 'XYZ' rot1 = createRotationOz(psi * k); rot2 = createRotationOy(theta * k); rot3 = createRotationOx(phi * k); case 'XZY' rot1 = createRotationOy(psi * k); rot2 = createRotationOz(theta * k); rot3 = createRotationOx(phi * k); case 'ZYZ' rot1 = createRotationOz(psi * k); rot2 = createRotationOy(theta * k); rot3 = createRotationOz(phi * k); case 'ZXZ' rot1 = createRotationOz(psi * k); rot2 = createRotationOx(theta * k); rot3 = createRotationOz(phi * k); case 'YZY' rot1 = createRotationOy(psi * k); rot2 = createRotationOz(theta * k); rot3 = createRotationOy(phi * k); case 'YXY' rot1 = createRotationOy(psi * k); rot2 = createRotationOx(theta * k); rot3 = createRotationOy(phi * k); case 'XZX' rot1 = createRotationOx(psi * k); rot2 = createRotationOz(theta * k); rot3 = createRotationOx(phi * k); case 'XYX' rot1 = createRotationOx(psi * k); rot2 = createRotationOy(theta * k); rot3 = createRotationOx(phi * k); end % concatenate matrices mat = rot3 * rot2 * rot1; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/geodesicCylinder.m0000644000000000000000000000013214055375162020514 xustar0030 mtime=1622538866.046813689 30 atime=1622538866.046813689 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/geodesicCylinder.m0000644000175000017500000001217114055375162021603 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [geo, geoLength, conGeo, conGeoLength] = geodesicCylinder(pts, cyl, varargin) %GEODESICCYLINDER computes the geodesic between two points on a cylinder. % % [GEO, GEOLENGTH] = geodesicCylinder(PTS, CYL) computes the geodesic % between the two points PTS projected onto the infinite cylinder CYL. % PTS is a 2-by-3 array, and CYL is a 1-by-7 array. Result is the % polyline GEO (500-by-3 array) [500 = default] containing the % coordinates of the geodesic between two projected points. GEOLENGTH % contains the analytical length of the geodesic. % % [~, ~, CONGEO, CONGEOLENGTH] = geodesicCylinder(PTS, CYL) provides the % conjugate geodesic and its analytical length. % % ... = geodesicCylinder(PTS, CYL, 'n', N) defines the number of points % representing the geodesic and conjugate geodesic. % % Example % demoGeodesicCylinder % % See also % drawCylinder, projPointOnCylinder % % Source % Based on the script 'geodesic.m' by Lei Wang % https://mathworks.com/matlabcentral/fileexchange/6522 % % --------- % Author: oqilipo % Created: 2021-04-17, using R2020b % Copyright 2021 parser = inputParser; addRequired(parser, 'pts', @(x) validateattributes(x, {'numeric'},... {'size',[2 3],'real','finite','nonnan'})); addRequired(parser, 'cyl', @(x) validateattributes(x, {'numeric'},... {'size',[1 7],'real','finite','nonnan'})); addParameter(parser,'n',500, @(x) validateattributes(x, {'numeric'},... {'scalar','>', 2,'<=', 1e5})); parse(parser,pts,cyl,varargin{:}); pts = parser.Results.pts; cyl = parser.Results.cyl; n = parser.Results.n; % Radius of the cylinder cylRadius = cyl(7); % Project points onto the open (infinite) cylinder ptProj(1,:) = projPointOnCylinder(pts(1,:), cyl, 'open'); ptProj(2,:) = projPointOnCylinder(pts(2,:), cyl, 'open'); % Create a transformation for the points into the local cylinder coordinate % system. Align the cylinder axis with the z axis and translate the % starting point of the cylinder to the origin. TFM = createRotationVector3d(cyl(4:6)-cyl(1:3), [0 0 1])*createTranslation3d(-cyl(1:3)); % Transform the points. ptTfm = transformPoint3d(ptProj, TFM); % Convert the transformed points to cylindrical coordinates. [ptsTheta, ptsRadius, ptsHeight] = cart2cyl(ptTfm); assert(ismembertol(ptsRadius(1),ptsRadius(2))) assert(ismembertol(ptsRadius(1),cylRadius)) % Copy thetas for the conjugate geodesic ptsTheta(:,:,2) = ptsTheta; ptsTheta(1,1,2) = ptsTheta(1,1,2) + 2*pi; geoCyl = nan(n,3,size(ptsTheta,3)); arcLength = nan(1,size(ptsTheta,3)); for t = 1:size(ptsTheta,3) [geoCyl(:,:,t), arcLength(t)] = geoCurve(ptsTheta(:,:,t), cylRadius, ptsHeight, n); end % Select the shortest geodesic if arcLength(1) <= arcLength(2) % Transform the geodesics back to the global coordinate system geo = transformPoint3d(geoCyl(:,:,1), inv(TFM)); conGeo = transformPoint3d(geoCyl(:,:,2), inv(TFM)); geoLength = arcLength(1); conGeoLength = arcLength(2); else % Transform the geodesics back to the global coordinate system geo = transformPoint3d(geoCyl(:,:,2), inv(TFM)); conGeo = transformPoint3d(geoCyl(:,:,1), inv(TFM)); geoLength = arcLength(2); conGeoLength = arcLength(1); end end function [geo, arcLength] = geoCurve(theta, r, z, n) % Parametric expression of the geodesic curve u = linspace(theta(1),theta(2),n)'; geo(:,1) = r*cos(u); geo(:,2) = r*sin(u); geo(:,3) = (z(2)-z(1))/(theta(2)-theta(1))*u + (z(1)*theta(2)-z(2)*theta(1))/(theta(2)-theta(1)); if all(isnan(geo(:,3))) geo(:,3) = linspace(z(1),z(2),n)'; end arcLength = sqrt(r^2*(theta(2)-theta(1))^2+(z(2)-z(1))^2); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawPolyline3d.m0000644000000000000000000000013214055375162020140 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawPolyline3d.m0000644000175000017500000001144614055375162021233 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPolyline3d(varargin) %DRAWPOLYLINE3D Draw a 3D polyline specified by a list of vertex coords. % % drawPolyline3d(POLY); % packs coordinates in a single N-by-3 array. % % drawPolyline3d(PX, PY, PZ); % specifies coordinates in separate numeric vectors (either row or % columns) % % drawPolyline3d(..., CLOSED); % Specifies if the polyline is closed or open. CLOSED can be one of: % - 'closed' % - 'open' (the default) % - a boolean variable with value TRUE for closed polylines. % % drawPolyline3d(..., PARAM, VALUE); % Specifies style options to draw the polyline, see plot for details. % % H = drawPolyline3d(...); % also returns a handle to the list of created line objects. % % Example % t = linspace(0, 2*pi, 100)'; % xt = 10 * cos(t); % yt = 5 * sin(t); % zt = zeros(1,100); % figure; drawPolyline3d(xt, yt, zt, 'b'); % % See Also: % polygons3d, drawPolygon3d, fillPolygon3d % % --------- % Author : David Legland % e-mail: david.legland@inra.fr % Created: 2005-02-15 % Copyright 2005 INRA - TPV URPOI - BIA IMASTE % HISTORY % 2010-03-08 rename to drawPolyline3d %% Process input arguments hAx = gca; if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1) = []; end % check case we want to draw several curves, stored in a cell array var = varargin{1}; if iscell(var) hold on; h = zeros(length(var(:)), 1); for i = 1:length(var(:)) h(i) = drawPolyline3d(hAx, var{i}, varargin{2:end}); end if nargout > 0 varargout = {h}; end return; end % extract curve coordinates if min(size(var)) == 1 % if first argument is a vector (either row or column), then assumes % first argument contains x coords, second argument contains y coords % and third one the z coords px = var; if length(varargin) < 3 error('geom3d:drawPolyline3d:Wrong number of arguments in drawPolyline3d'); end if isnumeric(varargin{2}) && isnumeric(varargin{3}) py = varargin{2}; pz = varargin{3}; varargin(1:3) = []; else px = var(:, 1); py = var(:, 2); pz = var(:, 3); varargin(1) = []; end else % all coordinates are grouped in the first argument px = var(:, 1); py = var(:, 2); pz = var(:, 3); varargin(1) = []; end % check if curve is closed or open (default is open) closed = false; if ~isempty(varargin) var = varargin{1}; if islogical(var) % check boolean flag closed = var; varargin = varargin(2:end); elseif ischar(var) % check string indicating close or open if strncmpi(var, 'close', 5) closed = true; varargin = varargin(2:end); elseif strncmpi(var, 'open', 4) closed = false; varargin = varargin(2:end); end end end %% draw the curve % for closed curve, add the first point at the end to close curve if closed px = [px(:); px(1)]; py = [py(:); py(1)]; pz = [pz(:); pz(1)]; end h = plot3(hAx, px, py, pz, varargin{:}); if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/planePosition.m0000644000000000000000000000013214055375162020064 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/planePosition.m0000644000175000017500000000703014055375162021151 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pos = planePosition(point, plane) %PLANEPOSITION Compute position of a point on a plane. % % PT2 = planePosition(POINT, PLANE) % POINT has format [X Y Z], and plane has format % [X0 Y0 Z0 DX1 DY1 DZ1 DX2 DY2 DZ2], where : % - (X0, Y0, Z0) is a point belonging to the plane % - (DX1, DY1, DZ1) is a first direction vector % - (DX2, DY2, DZ2) is a second direction vector % % Result PT2 has the form [XP YP], with [XP YP] coordinate of the point % in the coordinate system of the plane. % % % CAUTION: % WORKS ONLY FOR PLANES WITH ORTHOGONAL DIRECTION VECTORS % % Example % plane = [10 20 30 1 0 0 0 1 0]; % point = [13 24 35]; % pos = planePosition(point, plane) % pos = % 3 4 % % See also: % geom3d, planes3d, points3d, planePoint % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % % HISTORY % 24/11/2005 add support for multiple inputs % size of input arguments npl = size(plane, 1); npt = size(point, 1); % check inputs have compatible sizes if npl ~= npt && npl > 1 && npt > 1 error('geom3d:planePoint:inputSize', ... 'plane and point should have same size, or one of them must have 1 row'); end % origin and direction vectors of the plane p0 = plane(:, 1:3); d1 = plane(:, 4:6); d2 = plane(:, 7:9); % Compute dot products with direction vectors of the plane if npl > 1 || npt == 1 s = dot(bsxfun(@minus, point, p0), d1, 2) ./ vectorNorm3d(d1); t = dot(bsxfun(@minus, point, p0), d2, 2) ./ vectorNorm3d(d2); else % we have npl == 1 and npt > 1 d1 = d1 / vectorNorm3d(d1); d2 = d2 / vectorNorm3d(d2); inds = ones(npt,1); s = dot(bsxfun(@minus, point, p0), d1(inds, :), 2); t = dot(bsxfun(@minus, point, p0), d2(inds, :), 2); end % % old version: % s = dot(point-p0, d1, 2) ./ vectorNorm3d(d1); % t = dot(point-p0, d2, 2) ./ vectorNorm3d(d2); pos = [s t]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/circle3dOrigin.m0000644000000000000000000000013214055375162020100 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/circle3dOrigin.m0000644000175000017500000000506614055375162021174 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ori = circle3dOrigin(varargin) %CIRCLE3DORIGIN Return the first point of a 3D circle. % % P = circle3dOrigin([XC YC ZC R THETA PHI]) % P = circle3dOrigin([XC YC ZC R THETA PHI PSI]) % Returns the origin point of the circle, i.e. the first point used for % drawing circle. % % See also: % circles3d, points3d, circle3dPosition % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005 % % HISTORY % get center and radius circle = varargin{1}; xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); r = circle(:,4); % get angle of normal theta = circle(:,5); phi = circle(:,6); % get roll if size(circle, 2)==7 psi = circle(:,7); else psi = zeros(size(circle, 1), 1); end % create origin point pt0 = [r 0 0]; % compute transformation from local basis to world basis trans = localToGlobal3d(xc, yc, zc, theta, phi, psi); % transform the point ori = transformPoint3d(pt0, trans); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/oblateSurfaceArea.m0000644000000000000000000000013214055375162020610 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/oblateSurfaceArea.m0000644000175000017500000000471514055375162021704 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function S = oblateSurfaceArea(elli, varargin) %OBLATESURFACEAREA Approximated surface area of an oblate ellipsoid. % % S = oblateSurfaceArea(R1,R2) % % Example % oblateSurfaceArea % % See also % geom3d, ellipsoidSurfaceArea, prolateSurfaceArea % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2015-07-03, using Matlab 7.9.0.529 (R2009b) % Copyright 2015 INRA - Cepia Software Platform. %% Parse input argument if size(elli, 2) == 7 R1 = elli(:, 4); R2 = elli(:, 5); elseif size(elli, 2) == 1 && ~isempty(varargin) R1 = elli(:, 1); R2 = varargin{1}; end assert(R1 < R2, 'First radius must be smaller than second radius'); % surface theorique d'un ellipsoide oblate % cf http://fr.wikipedia.org/wiki/Ellipso%C3%AFde_de_r%C3%A9volution e = sqrt(R2.^2 - R1.^2) ./ R2; S = 2 * pi * R2.^2 + pi * R1.^2 * log((1 + e) ./ (1 - e)) ./ e; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/cart2sph2.m0000644000000000000000000000013214055375162017050 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/cart2sph2.m0000644000175000017500000000624514055375162020144 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cart2sph2(varargin) %CART2SPH2 Convert cartesian coordinates to spherical coordinates. % % [THETA PHI RHO] = cart2sph2([X Y Z]) % [THETA PHI RHO] = cart2sph2(X, Y, Z) % % The following convention is used: % THETA is the colatitude, in radians, 0 for north pole, +pi for south % pole, pi/2 for points with z=0. % PHI is the azimuth, in radians, defined as matlab cart2sph: angle from % Ox axis, counted counter-clockwise. % RHO is the distance of the point to the origin. % Discussion on choice for convention can be found at: % http://www.physics.oregonstate.edu/bridge/papers/spherical.pdf % % Example: % cart2sph2([1 0 0]) returns [pi/2 0 1]; % cart2sph2([1 1 0]) returns [pi/2 pi/4 sqrt(2)]; % cart2sph2([0 0 1]) returns [0 0 1]; % % See also: % angles3d, sph2cart2, cart2sph, cart2sph2d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 02/11/2006: update doc, and manage case RHO is empty % 03/11/2006: change convention for angle : uses order [THETA PHI RHO] % 27/06/2007: manage 2 output arguments if length(varargin)==1 var = varargin{1}; elseif length(varargin)==3 var = [varargin{1} varargin{2} varargin{3}]; end if size(var, 2)==2 var(:,3)=1; end [p, t, r] = cart2sph(var(:,1), var(:,2), var(:,3)); if nargout == 1 || nargout == 0 varargout{1} = [pi/2-t p r]; elseif nargout==2 varargout{1} = pi/2-t; varargout{2} = p; else varargout{1} = pi/2-t; varargout{2} = p; varargout{3} = r; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162017035 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/Contents.m0000644000175000017500000004105314055375162020125 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % GEOM3D Geometry 3D Toolbox % Version 1.22 06-Jun-2018 . % % Creation, transformations, algorithms and visualization of geometrical % 3D primitives, such as points, lines, planes, polyhedra, circles and % spheres. % % Euler Angles are defined as follow: % PHI is the azimut, i.e. the angle of the projection on horizontal plane % with the Ox axis, with value beween 0 and 180 degrees. % THETA is the latitude, i.e. the angle with the Oz axis, with value % between -90 and +90 degrees. % PSI is the 'roll', i.e. the rotation around the (PHI, THETA) direction, % with value in degrees % See also the 'angles3d' page. % % Base format for primitives: % Point: [x0 y0 z0] % Vector: [dx dy dz] % Line: [x0 y0 z0 dx dy dz] % Edge: [x1 y1 z1 x2 y2 z2] % Plane: [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % Sphere: [x0 y0 z0 R] % Circle: [x0 y0 z0 R PHI THETA PSI] (origin+center+normal+'roll'). % Ellipsoid: [x0 y0 z0 A B C PHI THETA PSI] % Cylinder: [X1 Y1 Z1 X2 Y2 Z2 R] % Box: [xmin xmax ymin ymax zmin zmax]. Used for clipping shapes. % % Polygons are represented by N-by-3 array of points, the last point is % not necessarily the same as the first one. Points must be coplanar. % % % 3D Points % points3d - Description of functions operating on 3D points. % midPoint3d - Middle point of two 3D points or of a 3D edge. % isCoplanar - Tests input points for coplanarity in 3-space. % transformPoint3d - Transform a point with a 3D affine transform. % distancePoints3d - Compute euclidean distance between pairs of 3D Points. % clipPoints3d - Clip a set of points by a box or other 3d shapes. % drawPoint3d - Draw 3D point on the current axis. % % 3D Vectors % vectors3d - Description of functions operating on 3D vectors. % transformVector3d - Transform a vector with a 3D affine transform. % normalizeVector3d - Normalize a 3D vector to have norm equal to 1. % vectorNorm3d - Norm of a 3D vector or of set of 3D vectors. % hypot3 - Diagonal length of a cuboidal 3D box . % crossProduct3d - Vector cross product faster than inbuilt MATLAB cross. % vectorAngle3d - Angle between two 3D vectors. % isParallel3d - Check parallelism of two 3D vectors. % isPerpendicular3d - Check orthogonality of two 3D vectors. % drawVector3d - Draw vector at a given position. % % Angles % angles3d - Conventions for manipulating angles in 3D. % anglePoints3d - Compute angle between three 3D points. % sphericalAngle - Compute angle between points on the sphere. % angleSort3d - Sort 3D coplanar points according to their angles in plane. % randomAngle3d - Return a 3D angle uniformly distributed on unit sphere. % % Coordinate transforms % sph2cart2 - Convert spherical coordinates to cartesian coordinates. % cart2sph2 - Convert cartesian coordinates to spherical coordinates. % cart2sph2d - Convert cartesian coordinates to spherical coordinates in degrees. % sph2cart2d - Convert spherical coordinates to cartesian coordinates in degrees. % cart2cyl - Convert cartesian to cylindrical coordinates. % cyl2cart - Convert cylindrical to cartesian coordinates. % % 3D Lines and Edges % lines3d - Description of functions operating on 3D lines. % createLine3d - Create a line with various inputs. % createEdge3d - Create an edge between two 3D points, or from a 3D line. % fitLine3d - Fit a 3D line to a set of points. % parallelLine3d - Create 3D line parallel to another one. % projPointOnLine3d - Project a 3D point orthogonally onto a 3D line. % distancePointLine3d - Euclidean distance between 3D point and line. % isPointOnLine3d - Test if a 3D point belongs to a 3D line. % linePosition3d - Return the position of a 3D point projected on a 3D line. % distanceLines3d - Minimal distance between two 3D lines. % transformLine3d - Transform a 3D line with a 3D affine transform. % reverseLine3d - Return same 3D line but with opposite orientation. % normalizeLine3d - Normalizes the direction vector of a 3D line. % clipLine3d - Clip a line with a box and return an edge. % drawLine3d - Draw a 3D line clipped by the current axes. % % 3D Edges and Rays % edges3d - Description of functions operating on 3D edges. % edgeLength3d - Return the length of a 3D edge. % clipEdge3d - Clip a 3D edge with a cuboid box. % lineToEdge3d - Convert a 3D straight line to a 3D finite edge. % edgeToLine3d - Convert a 3D edge to a 3D straight line. % distancePointEdge3d - Minimum distance between a 3D point and a 3D edge. % drawEdge3d - Draw 3D edge in the current axes. % createRay3d - Create a 3D ray. % clipRay3d - Clip a 3D ray with a box and return a 3D edge. % drawRay3d - Draw a 3D ray on the current axis. % % Planes % planes3d - Description of functions operating on 3D planes. % createPlane - Create a plane in parametrized form. % fitPlane - Fit a 3D plane to a set of points. % normalizePlane - Normalize parametric representation of a plane. % parallelPlane - Parallel to a plane through a point or at a given distance. % reversePlane - Return same 3D plane but with opposite orientation. % isPlane - Check if input is a plane. % transformPlane3d - Transform a 3D plane with a 3D affine transform. % planesBisector - Bisector plane between two other planes. % projPointOnPlane - Return the orthogonal projection of a point on a plane. % intersectPlanes - Return intersection line between 2 planes in space. % intersectThreePlanes - Return intersection point between 3 planes in space. % intersectLinePlane - Intersection point between a 3D line and a plane. % intersectEdgePlane - Return intersection point between a plane and a edge. % distancePointPlane - Signed distance betwen 3D point and plane. % projLineOnPlane - Return the orthogonal projection of a line on a plane. % isBelowPlane - Test whether a point is below or above a plane. % medianPlane - Create a plane in the middle of 2 points. % planeNormal - Compute the normal to a plane. % planePosition - Compute position of a point on a plane. % planePoint - Compute 3D position of a point in a plane. % dihedralAngle - Compute dihedral angle between 2 planes. % drawPlane3d - Draw a plane clipped by the current axes. % % 3D Polygons and curves % polygons3d - Description of functions operating on 3D polygons. % polygonCentroid3d - Centroid (or center of mass) of a polygon. % polygonArea3d - Area of a 3D polygon. % polygon3dNormalAngle - Normal angle at a vertex of the 3D polygon. % intersectLinePolygon3d - Intersection point of a 3D line and a 3D polygon. % intersectRayPolygon3d - Intersection point of a 3D ray and a 3D polygon. % clipConvexPolygon3dHP - Clip a convex 3D polygon with Half-space. % drawPolygon3d - Draw a 3D polygon specified by a list of vertex coords. % drawPolyline3d - Draw a 3D polyline specified by a list of vertex coords. % fillPolygon3d - Fill a 3D polygon specified by a list of vertex coords. % % 3D Triangles % triangleArea3d - Area of a 3D triangle. % distancePointTriangle3d - Minimum distance between a 3D point and a 3D triangle. % intersectLineTriangle3d - Intersection point of a 3D line and a 3D triangle. % % 3D circles and ellipses % circles3d - Description of functions operating on 3D circles. % fitCircle3d - Fit a 3D circle to a set of points. % fitEllipse3d - Fit an ellipse to a set of points. % circle3dPosition - Return the angular position of a point on a 3D circle. % circle3dPoint - Coordinates of a point on a 3D circle from its position. % circle3dOrigin - Return the first point of a 3D circle. % drawCircle3d - Draw a 3D circle. % drawCircleArc3d - Draw a 3D circle arc. % drawEllipse3d - Draw a 3D ellipse. % projPointOnCircle3d - Project a 3D point onto a 3D circle. % % Spheres % spheres - Description of functions operating on 3D spheres. % createSphere - Create a sphere containing 4 points. % fitSphere - Fit a sphere to 3D points using the least squares approach. % intersectLineSphere - Return intersection points between a line and a sphere. % intersectPlaneSphere - Return intersection circle between a plane and a sphere. % drawSphere - Draw a sphere as a mesh. % drawSphericalEdge - Draw an edge on the surface of a sphere. % drawSphericalTriangle - Draw a triangle on a sphere. % fillSphericalTriangle - Fill a triangle on a sphere. % drawSphericalPolygon - Draw a spherical polygon. % fillSphericalPolygon - Fill a spherical polygon. % sphericalVoronoiDomain - Compute a spherical voronoi domain. % % Smooth surfaces % equivalentEllipsoid - Equivalent ellipsoid of a set of 3D points. % isPointInEllipsoid - Check if a point is located inside a 3D ellipsoid. % ellipsoidSurfaceArea - Approximated surface area of an ellipsoid. % oblateSurfaceArea - Approximated surface area of an oblate ellipsoid. % prolateSurfaceArea - Approximated surface area of a prolate ellipsoid. % cylinderSurfaceArea - Surface area of a cylinder. % intersectLineCylinder - Compute intersection points between a line and a cylinder. % revolutionSurface - Create a surface of revolution from a planar curve. % surfaceCurvature - Curvature on a surface from angle and principal curvatures. % drawEllipsoid - Draw a 3D ellipsoid. % drawTorus - Draw a torus (3D ring). % drawCylinder - Draw a cylinder. % drawEllipseCylinder - Draw a cylinder with ellipse cross-section. % drawCapsule - Draw a capsule. % drawDome - Draw a dome (half-sphere, semi-sphere) as a mesh. % drawSurfPatch - Draw a 3D surface patch, with 2 parametrized surfaces. % % Bounding boxes management % boxes3d - Description of functions operating on 3D boxes. % boundingBox3d - Bounding box of a set of 3D points. % orientedBox3d - Object-oriented bounding box of a set of 3D points. % intersectBoxes3d - Intersection of two 3D bounding boxes. % mergeBoxes3d - Merge 3D boxes, by computing their greatest extent. % box3dVolume - Volume of a 3-dimensional box. % randomPointInBox3d - Generate random point(s) within a 3D box. % drawBox3d - Draw a 3D box defined by coordinate extents. % % Geometric transforms % transforms3d - Conventions for manipulating 3D affine transforms. % fitAffineTransform3d - Compute the affine transform that best register two 3D point sets. % registerPoints3dAffine - Fit 3D affine transform using iterative algorithm. % createTranslation3d - Create the 4x4 matrix of a 3D translation. % createScaling3d - Create the 4x4 matrix of a 3D scaling. % createRotationOx - Create the 4x4 matrix of a 3D rotation around x-axis. % createRotationOy - Create the 4x4 matrix of a 3D rotation around y-axis. % createRotationOz - Create the 4x4 matrix of a 3D rotation around z-axis. % createBasisTransform3d - Compute matrix for transforming a basis into another basis. % eulerAnglesToRotation3d - Convert 3D Euler angles to 3D rotation matrix. % isTransform3d - Check if input is a affine transformation matrix. % rotation3dToEulerAngles - Extract Euler angles from a rotation matrix. % createRotation3dLineAngle - Create rotation around a line by an angle theta. % rotation3dAxisAndAngle - Determine axis and angle of a 3D rotation matrix. % createRotationVector3d - Calculates the rotation between two vectors. % createRotationVectorPoint3d - Calculates the rotation between two vectors. % createRotationAboutPoint3d - Rotate about a point using a rotation matrix. % recenterTransform3d - Change the fixed point of an affine 3D transform. % composeTransforms3d - Concatenate several space transformations. % % Various drawing Functions % drawGrid3d - Draw a 3D grid on the current axis. % drawAxis3d - Draw a coordinate system and an origin. % drawAxisCube - Draw a colored cube representing axis orientation. % drawCube - Draw a 3D centered cube, eventually rotated. % drawCuboid - Draw a 3D cuboid, eventually rotated. % drawPlatform - Draw a rectangular platform with a given size. % drawLabels3d - Draw text labels at specified 3D positions. % drawArrow3d - plot a quiver of 3D arrows. % drawAngleBetweenVectors3d - Draw an arc between 2 vectors. % % % Credits: % * Several functions contributed by Sven Holcombe % * function isCoplanar was originally written by Brett Shoelson. % * Songbai Ji enhanced file intersectPlaneLine (6/23/2006). % * several functions contributed by oqilipo % % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2005-11-07 % Homepage: http://github.com/mattools/matGeom % http://www.pfl-cepia.inra.fr/index.php?page=geom3d % Copyright 2005 INRA help(mfilename); % In development: % clipPolygon3dHP - clip a 3D polygon with Half-space. % drawPartialPatch - draw surface patch, with 2 parametrized surfaces. % Deprecated: % vectorCross3d - Vector cross product faster than inbuilt MATLAB cross. % Others matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/cart2sph2d.m0000644000000000000000000000013214055375162017214 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/cart2sph2d.m0000644000175000017500000000650114055375162020303 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cart2sph2d(x, y, z) %CART2SPH2D Convert cartesian coordinates to spherical coordinates in degrees. % % [THETA PHI RHO] = cart2sph2d([X Y Z]) % [THETA PHI RHO] = cart2sph2d(X, Y, Z) % % The following convention is used: % THETA is the colatitude, in degrees, 0 for north pole, 180 degrees for % south pole, 90 degrees for points with z=0. % PHI is the azimuth, in degrees, defined as matlab cart2sph: angle from % Ox axis, counted counter-clockwise. % RHO is the distance of the point to the origin. % Discussion on choice for convention can be found at: % http://www.physics.oregonstate.edu/bridge/papers/spherical.pdf % % Example: % cart2sph2d([1 0 0]) % ans = % 90 0 1 % % cart2sph2d([1 1 0]) % ans = % 90 45 1.4142 % % cart2sph2d([0 0 1]) % ans = % 0 0 1 % % % See also: % angles3d, sph2cart2d, cart2sph, cart2sph2 % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-06-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % if data are grouped, extract each coordinate if nargin == 1 y = x(:, 2); z = x(:, 3); x = x(:, 1); end % cartesian to spherical conversion hxy = hypot(x, y); rho = hypot(hxy, z); theta = 90 - atan2(z, hxy) * 180 / pi; phi = atan2(y, x) * 180 / pi; % % convert to degrees and theta to colatitude % theta = 90 - rad2deg(theta); % phi = rad2deg(phi); % format output if nargout <= 1 varargout{1} = [theta phi rho]; elseif nargout == 2 varargout{1} = theta; varargout{2} = phi; else varargout{1} = theta; varargout{2} = phi; varargout{3} = rho; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/projPointOnPlane.m0000644000000000000000000000013214055375162020501 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/projPointOnPlane.m0000644000175000017500000000707614055375162021600 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = projPointOnPlane(point, plane) %PROJPOINTONPLANE Return the orthogonal projection of a point on a plane. % % PT2 = projPointOnPlane(PT1, PLANE); % Compute the (orthogonal) projection of point PT1 onto the plane PLANE, % given as [X0 Y0 Z0 VX1 VY1 VZ1 VX2 VY2 VZ2] (origin point, first % direction vector, second directionvector). % % The function is fully vectorized, in that multiple points may be % projected onto multiple planes in a single call, returning multiple % points. With the exception of the second dimension (where % SIZE(PT1,2)==3, and SIZE(PLANE,2)==9), each dimension of PT1 and PLANE % must either be equal or one, similar to the requirements of BSXFUN. In % basic usage, point PT1 is a [N*3] array, and PLANE is a [N*9] array % (see createPlane for details). Result PT2 is a [N*3] array, containing % coordinates of orthogonal projections of PT1 onto planes PLANE. In % vectorised usage, PT1 is an [N*3*M*P...] matrix, and PLANE is an % [X*9*Y...] matrix, where (N,X), (M,Y), etc, are either equal pairs, or % one of the two is one. % % See also: % planes3d, points3d, planePosition, intersectLinePlane % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 21/08/2006: debug support for multiple points or planes % 22/04/2013: uses bsxfun for mult. pts/planes in all dimensions (Sven H) % Unpack the planes into origins and normals, keeping original shape plSize = size(plane); plSize(2) = 3; [origins, normals] = deal(zeros(plSize)); origins(:) = plane(:,1:3,:); normals(:) = crossProduct3d(plane(:,4:6,:), plane(:, 7:9,:)); % difference between origins of plane and point dp = bsxfun(@minus, origins, point); % relative position of point on normal's line t = bsxfun(@rdivide, sum(bsxfun(@times,normals,dp),2), sum(normals.^2,2)); % add relative difference to project point back to plane point = bsxfun(@plus, point, bsxfun(@times, t, normals)); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawEllipse3d.m0000644000000000000000000000013214055375162017742 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawEllipse3d.m0000644000175000017500000001673114055375162021037 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawEllipse3d(varargin) %DRAWELLIPSE3D Draw a 3D ellipse. % % Possible calls for the function : % drawEllipse3d([XC YC ZC A B THETA PHI]) % drawEllipse3d([XC YC ZC A B THETA PHI PSI]) % drawEllipse3d([XC YC ZC A B], [THETA PHI]) % drawEllipse3d([XC YC ZC A B], [THETA PHI PSI]) % drawEllipse3d([XC YC ZC A B], THETA, PHI) % drawEllipse3d([XC YC ZC], A, B, THETA, PHI) % drawEllipse3d([XC YC ZC A B], THETA, PHI, PSI) % drawEllipse3d([XC YC ZC], A, B, THETA, PHI, PSI) % drawEllipse3d(XC, YC, ZC, A, B, THETA, PHI) % drawEllipse3d(XC, YC, ZC, A, B, THETA, PHI, PSI) % % where XC, YC, ZY are coordinate of ellipse center, A and B are the % half-lengths of the major and minor axes of the ellipse, % PHI and THETA are 3D angle (in degrees) of the normal to the plane % containing the ellipse (PHI between 0 and 360 corresponding to % longitude, and THETA from 0 to 180, corresponding to angle with % vertical). % % H = drawEllipse3d(...) % return handle on the created LINE object % % Example % figure; axis([-10 10 -10 10 -10 10]); hold on; % ellXY = [0 0 0 8 5 0 0 0]; % drawEllipse3d(ellXY, 'color', [.8 0 0], 'linewidth', 2) % ellXZ = [0 0 0 8 2 90 90 90]; % drawEllipse3d(ellXZ, 'color', [0 .8 0], 'linewidth', 2) % ellYZ = [0 0 0 5 2 90 0 90]; % drawEllipse3d(ellYZ, 'color', [0 0 .8], 'linewidth', 2) % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-05-07 % Copyright 2008 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % Possible calls for the function, with number of arguments : % drawEllipse3d([XC YC ZC A B THETA PHI]) 1 % drawEllipse3d([XC YC ZC A B THETA PHI PSI]) 1 % drawEllipse3d([XC YC ZC A B], [THETA PHI]) 2 % drawEllipse3d([XC YC ZC A B], [THETA PHI PSI]) 2 % drawEllipse3d([XC YC ZC A B], THETA, PHI) 3 % drawEllipse3d([XC YC ZC A B], THETA, PHI, PSI) 4 % drawEllipse3d([XC YC ZC], A, B, THETA, PHI) 5 % drawEllipse3d([XC YC ZC], A, B, THETA, PHI, PSI) 6 % drawEllipse3d(XC, YC, ZC, A, B, THETA, PHI) 7 % drawEllipse3d(XC, YC, ZC, A, B, THETA, PHI, PSI) 8 % extract drawing options ind = find(cellfun(@ischar, varargin), 1, 'first'); options = {}; if ~isempty(ind) options = varargin(ind:end); varargin(ind:end) = []; end if length(varargin)==1 % get center and radius ellipse = varargin{1}; xc = ellipse(:,1); yc = ellipse(:,2); zc = ellipse(:,3); a = ellipse(:,4); b = ellipse(:,5); % get colatitude of normal if size(ellipse, 2)>=6 theta = ellipse(:,6); else theta = zeros(size(ellipse, 1), 1); end % get azimut of normal if size(ellipse, 2)>=7 phi = ellipse(:,7); else phi = zeros(size(ellipse, 1), 1); end % get roll if size(ellipse, 2)==8 psi = ellipse(:,8); else psi = zeros(size(ellipse, 1), 1); end elseif length(varargin)==2 % get center and radius ellipse = varargin{1}; xc = ellipse(:,1); yc = ellipse(:,2); zc = ellipse(:,3); a = ellipse(:,4); b = ellipse(:,5); % get angle of normal angle = varargin{2}; theta = angle(:,1); phi = angle(:,2); % get roll if size(angle, 2)==3 psi = angle(:,3); else psi = zeros(size(angle, 1), 1); end elseif length(varargin)==3 % get center and radius ellipse = varargin{1}; xc = ellipse(:,1); yc = ellipse(:,2); zc = ellipse(:,3); a = ellipse(:,4); b = ellipse(:,5); % get angle of normal and roll theta = varargin{2}; phi = varargin{3}; psi = zeros(size(phi, 1), 1); elseif length(varargin)==4 % get center and radius ellipse = varargin{1}; xc = ellipse(:,1); yc = ellipse(:,2); zc = ellipse(:,3); if size(ellipse, 2)==5 a = ellipse(:,4); b = ellipse(:,5); end theta = varargin{2}; phi = varargin{3}; psi = varargin{4}; elseif length(varargin)==5 % get center and radius ellipse = varargin{1}; xc = ellipse(:,1); yc = ellipse(:,2); zc = ellipse(:,3); a = varargin{2}; b = varargin{3}; theta = varargin{4}; phi = varargin{5}; psi = zeros(size(phi, 1), 1); elseif length(varargin)==6 ellipse = varargin{1}; xc = ellipse(:,1); yc = ellipse(:,2); zc = ellipse(:,3); a = varargin{2}; b = varargin{3}; theta = varargin{4}; phi = varargin{5}; psi = varargin{6}; elseif length(varargin)==7 xc = varargin{1}; yc = varargin{2}; zc = varargin{3}; a = varargin{4}; b = varargin{5}; theta = varargin{6}; phi = varargin{7}; psi = zeros(size(phi, 1), 1); elseif length(varargin)==8 xc = varargin{1}; yc = varargin{2}; zc = varargin{3}; a = varargin{4}; b = varargin{5}; theta = varargin{6}; phi = varargin{7}; psi = varargin{8}; else error('drawEllipse3d: please specify center and radius'); end % uses 60 intervals t = linspace(0, 2*pi, 61)'; % polyline approximation of ellipse, centered and parallel to main axes x = a * cos(t); y = b * sin(t); z = zeros(length(t), 1); base = [x y z]; % compute transformation from local basis to world basis trans = localToGlobal3d(xc, yc, zc, theta, phi, psi); % transform points composing the ellipse ellipse = transformPoint3d(base, trans); % draw the curve h = drawPolyline3d(ellipse, options{:}); if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/distancePointPlane.m0000644000000000000000000000013214055375162021024 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/distancePointPlane.m0000644000175000017500000000454414055375162022120 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function d = distancePointPlane(point, plane) %DISTANCEPOINTPLANE Signed distance betwen 3D point and plane. % % D = distancePointPlane(POINT, PLANE) % Returns the euclidean distance between point POINT and the plane PLANE, % given by: % POINT : [x0 y0 z0] % PLANE : [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % D : scalar % % See also: % planes3d, points3d, intersectLinePlane % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % normalized plane normal n = normalizeVector3d(cross(plane(:,4:6), plane(:, 7:9), 2)); % Uses Hessian form, ie : N.p = d % I this case, d can be found as : -N.p0, when N is normalized d = -sum(bsxfun(@times, n, bsxfun(@minus, plane(:,1:3), point)), 2); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawCircle3d.m0000644000000000000000000000013214055375162017546 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawCircle3d.m0000644000175000017500000002026714055375162020642 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCircle3d(varargin) % Draw a 3D circle. % % Possible calls for the function: % drawCircle3d([XC YC ZC R THETA PHI]) % drawCircle3d([XC YC ZC R], [THETA PHI]) % % where XC, YC, ZY are coordinates of circle center, R is the circle % radius, PHI and THETA are 3D angles in degrees of the normal to the % plane containing the circle: % * THETA between 0 and 180 degrees, corresponding to the colatitude % (angle with Oz axis). % * PHI between 0 and 360 degrees corresponding to the longitude (angle % with Ox axis) % % drawCircle3d([XC YC ZC R THETA PHI PSI]) % drawCircle3d([XC YC ZC R], [THETA PHI PSI]) % drawCircle3d([XC YC ZC R], THETA, PHI) % drawCircle3d([XC YC ZC], R, THETA, PHI) % drawCircle3d([XC YC ZC R], THETA, PHI, PSI) % drawCircle3d([XC YC ZC], R, THETA, PHI, PSI) % drawCircle3d(XC, YC, ZC, R, THETA, PHI) % drawCircle3d(XC, YC, ZC, R, THETA, PHI, PSI) % Are other possible syntaxes for this function. % % H = drawCircle3d(...) % return handle on the created LINE object % % Example % % display 3 mutually orthogonal 3D circles % figure; hold on; % drawCircle3d([10 20 30 50 0 0], 'LineWidth', 2, 'Color', 'b'); % drawCircle3d([10 20 30 50 90 0], 'LineWidth', 2, 'Color', 'r'); % drawCircle3d([10 20 30 50 90 90], 'LineWidth', 2, 'Color', 'g'); % axis equal; % axis([-50 100 -50 100 -50 100]); % view([-10 20]) % % % Draw several circles at once % center = [10 20 30]; % circ1 = [center 50 0 0]; % circ2 = [center 50 90 0]; % circ3 = [center 50 90 90]; % figure; hold on; % drawCircle3d([circ1 ; circ2 ; circ3]); % axis equal; % % See also: % circles3d, drawCircleArc3d, drawEllipse3d, drawSphere % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2005-02-17 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 14/12/2006 allows unspecified PHI and THETA % 04/01/2007 update doc, add todo for angle convention % 19/06/2009 use localToGlobal3d, add drawing options % 08/03/2010 use drawPolyline3d % 2011-06-20 use angles in degrees, support several circles, update doc % Possible calls for the function, with number of arguments : % drawCircle3d([XC YC ZC R THETA PHI]) 1 % drawCircle3d([XC YC ZC R THETA PHI PSI]) 1 % drawCircle3d([XC YC ZC R], [THETA PHI]) 2 % drawCircle3d([XC YC ZC R], [THETA PHI PSI]) 2 % drawCircle3d([XC YC ZC R], THETA, PHI) 3 % drawCircle3d([XC YC ZC], R, THETA, PHI) 4 % drawCircle3d([XC YC ZC R], THETA, PHI, PSI) 4 % drawCircle3d([XC YC ZC], R, THETA, PHI, PSI) 5 % drawCircle3d(XC, YC, ZC, R, THETA, PHI) 6 % drawCircle3d(XC, YC, ZC, R, THETA, PHI, PSI) 7 % parse axis handle hAx = gca; if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1) = []; end % extract drawing options if verLessThan('matlab', '7.8') ind = find(cellfun('isclass', varargin, 'char'), 1, 'first'); else ind = find(cellfun(@ischar, varargin), 1, 'first'); end options = {}; if ~isempty(ind) options = varargin(ind:end); varargin(ind:end) = []; end % Extract circle data if length(varargin) == 1 % get center and radius circle = varargin{1}; xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); r = circle(:,4); % get colatitude of normal if size(circle, 2) >= 5 theta = circle(:,5); else theta = zeros(size(circle, 1), 1); end % get azimut of normal if size(circle, 2)>=6 phi = circle(:,6); else phi = zeros(size(circle, 1), 1); end % get roll if size(circle, 2)==7 psi = circle(:,7); else psi = zeros(size(circle, 1), 1); end elseif length(varargin) == 2 % get center and radius circle = varargin{1}; xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); r = circle(:,4); % get angle of normal angle = varargin{2}; theta = angle(:,1); phi = angle(:,2); % get roll if size(angle, 2)==3 psi = angle(:,3); else psi = zeros(size(angle, 1), 1); end elseif length(varargin) == 3 % get center and radius circle = varargin{1}; xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); r = circle(:,4); % get angle of normal and roll theta = varargin{2}; phi = varargin{3}; psi = zeros(size(phi, 1), 1); elseif length(varargin) == 4 % get center and radius circle = varargin{1}; xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); if size(circle, 2)==4 r = circle(:,4); theta = varargin{2}; phi = varargin{3}; psi = varargin{4}; else r = varargin{2}; theta = varargin{3}; phi = varargin{4}; psi = zeros(size(phi, 1), 1); end elseif length(varargin) == 5 % get center and radius circle = varargin{1}; xc = circle(:,1); yc = circle(:,2); zc = circle(:,3); r = varargin{2}; theta = varargin{3}; phi = varargin{4}; psi = varargin{5}; elseif length(varargin) == 6 xc = varargin{1}; yc = varargin{2}; zc = varargin{3}; r = varargin{4}; theta = varargin{5}; phi = varargin{6}; psi = zeros(size(phi, 1), 1); elseif length(varargin) == 7 xc = varargin{1}; yc = varargin{2}; zc = varargin{3}; r = varargin{4}; theta = varargin{5}; phi = varargin{6}; psi = varargin{7}; else error('drawCircle3d: please specify center and radius'); end % circle parametrisation (by using N=60, some vertices are located at % special angles like 45°, 30°...) Nt = 60; t = linspace(0, 2*pi, Nt+1); nCircles = length(xc); h = zeros(nCircles, 1); for i = 1:nCircles % compute position of circle points x = r(i) * cos(t)'; y = r(i) * sin(t)'; z = zeros(length(t), 1); circle0 = [x y z]; % compute transformation from local basis to world basis trans = localToGlobal3d(xc(i), yc(i), zc(i), theta(i), phi(i), psi(i)); % compute points of transformed circle circle = transformPoint3d(circle0, trans); % draw the curve of circle points h(i) = drawPolyline3d(hAx, circle, options{:}); end if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawPoint3d.m0000644000000000000000000000013214055375162017436 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawPoint3d.m0000644000175000017500000001041614055375162020525 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = drawPoint3d(varargin) %DRAWPOINT3D Draw 3D point on the current axis. % % drawPoint3d(X, Y, Z) % will draw points defined by coordinates X, Y and Z. % X, Y and Z are N*1 array, with N being number of points to be drawn. % % drawPoint3d(COORD) packs coordinates in a single [N*3] array. % % drawPoint3d(..., OPT) will draw each point with given option. OPT is a % string compatible with 'plot' model. % % drawPoint3d(AX,...) plots into AX instead of GCA. % % H = drawPoint3d(...) returns a handle H to the line object % % Example % % generate points on a 3D circle % pts = circleToPolygon([40 30 20], 120); % mat = eulerAnglesToRotation3d([30 20 10]); % pts3d = transformPoint3d([pts zeros(120,1)],mat); % figure; drawPoint3d(pts3d, 'b.'); % view(3); axis equal; % % See also % points3d, clipPoints3d, drawPoint % % --------- % Author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 04/01/2007: remove unused variables, and enhance support for plot % options % 12/02/2010 does not clip points anymore % 12/01/2018 added axes handle input % if isAxisHandle(varargin{1}) hAx = varargin{1}; varargin(1)=[]; else hAx = gca; end if length(varargin) == 1 && size(varargin{1}, 2) == 3 % points are given as one single array with 3 columns px = varargin{1}(:,1); py = varargin{1}(:,2); pz = varargin{1}(:,3); varargin = {}; elseif length(varargin) == 2 && size(varargin{1}, 2) == 3 % points are given as one single array with 3 columns px = varargin{1}(:,1); py = varargin{1}(:,2); pz = varargin{1}(:,3); varargin = varargin(2); elseif length(varargin) >= 3 && size(varargin{1}, 2) == 3 % points are given as one single array with 3 columns px = varargin{1}(:,1); py = varargin{1}(:,2); pz = varargin{1}(:,3); varargin = varargin(2:end); elseif length(varargin) == 3 && numel(varargin{1})==numel(varargin{2}) && numel(varargin{1})==numel(varargin{3}) % points are given as 3 columns with equal lengths px = varargin{1}; py = varargin{2}; pz = varargin{3}; varargin = {}; elseif length(varargin) > 3 % points are given as 3 columns with equal lengths px = varargin{1}; py = varargin{2}; pz = varargin{3}; varargin = varargin(4:end); else error('wrong number of arguments in drawPoint3d'); end % default draw style: no line, marker is 'o' if length(varargin) ~= 1 varargin = ['linestyle', 'none', 'marker', 'o', varargin]; end % plot only points inside the axis. hh = plot3(hAx, px, py, pz, varargin{:}); if nargout > 0 h = hh; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/circle3dPoint.m0000644000000000000000000000013214055375162017742 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/circle3dPoint.m0000644000175000017500000000570614055375162021037 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = circle3dPoint(circle, pos) %CIRCLE3DPOINT Coordinates of a point on a 3D circle from its position. % % output = circle3dPoint(input) % % Example % % Draw some points on a 3D circle % figure('color','w'); hold on; view(130,-10); % circle = [10 20 30 50 90 45 0]; % drawCircle3d(circle) % % origin point % pos1 = 0; % drawPoint3d(circle3dPoint(circle, pos1), 'ro') % % few points regularly spaced % drawPoint3d(circle3dPoint(circle, 10:10:40), '+') % % Draw point opposite to origin % drawPoint3d(circle3dPoint(circle, 180), 'k*') % % % See also % circles3d, circle3dPosition % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-06-21, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. pos=pos(:); % extract circle coordinates xc = circle(1); yc = circle(2); zc = circle(3); r = circle(4); theta = circle(5); phi = circle(6); psi = circle(7); % convert position to angle t = pos * pi / 180; % compute position on base circle x = r * cos(t); y = r * sin(t); z = zeros(length(pos),1); pt0 = [x y z]; % compute transformation from local basis to world basis trans = localToGlobal3d(xc, yc, zc, theta, phi, psi); % compute points of transformed circle point = transformPoint3d(pt0, trans); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotationVectorPoint3d.m0000644000000000000000000000013214055375162022647 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotationVectorPoint3d.m0000644000175000017500000000506714055375162023744 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function TFM = createRotationVectorPoint3d(A,B,P) %CREATEROTATIONVECTORPOINT3D Calculates the rotation between two vectors. % around a point % % TFM = createRotationVectorPoint3d(A,B,P) returns the transformation % to rotate the vector A in the direction of vector B around point P % % Example % A=-5+10.*rand(1,3); % B=-10+20.*rand(1,3); % P=-50+100.*rand(1,3); % ROT = createRotationVectorPoint3d(A,B,P); % C = transformVector3d(A,ROT); % figure('color','w'); hold on; view(3) % drawPoint3d(P,'k') % drawVector3d(P, A,'r') % drawVector3d(P, B,'g') % drawVector3d(P, C,'r') % % See also % transformPoint3d, createRotationVector3d % % --------- % Author: oqilipo % Created: 2017-08-07 % Copyright 2017 P = reshape(P,3,1); % Translation from P to origin invtrans = [eye(3),-P; [0 0 0 1]]; % Rotation from A to B rot = createRotationVector3d(A, B); % Translation from origin to P trans = [eye(3),P; [0 0 0 1]]; % Combine TFM = trans*rot*invtrans; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/rotation3dAxisAndAngle.m0000644000000000000000000000013214055375162021545 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/rotation3dAxisAndAngle.m0000644000175000017500000000704514055375162022640 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [axis, theta] = rotation3dAxisAndAngle(mat) %ROTATION3DAXISANDANGLE Determine axis and angle of a 3D rotation matrix. % % [AXIS, ANGLE] = rotation3dAxisAndAngle(MAT) % Where MAT is a 4-by-4 matrix representing a rotation, computes the % rotation axis (containing the points that remain invariant under the % rotation), and the rotation angle around that axis. % AXIS has the format [DX DY DZ], constrained to unity, and ANGLE is the % rotation angle in radians. % % Note: this method use eigen vector extraction. It would be more precise % to use quaternions, see: % http://www.mathworks.cn/matlabcentral/newsreader/view_thread/160945 % % % Example % origin = [1 2 3]; % direction = [4 5 6]; % line = [origin direction]; % angle = pi/3; % rot = createRotation3dLineAngle(line, angle); % [axis angle2] = rotation3dAxisAndAngle(rot); % angle2 % angle2 = % 1.0472 % % See also % transforms3d, vectors3d, angles3d, eulerAnglesToRotation3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-08-11, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % extract the linear part of the rotation matrix A = mat(1:3, 1:3); % extract eigen values and eigen vectors [V, D] = eig(A - eye(3)); % we need the eigen vector corresponding to eigenvalue==1 [dummy, ind] = min(abs(diag(D)-1)); %#ok % extract corresponding eigen vector vector = V(:, ind)'; % compute rotation angle t = [A(3,2)-A(2,3) , A(1,3)-A(3,1) , A(2,1)-A(1,2)]; theta = atan2(dot(t, vector), trace(A)-1); % If angle is negative, invert both angle and vector direction if theta<0 theta = -theta; vector = -vector; end % try to get a point on the line % seems to work, but not sure about stability [V, D] = eig(mat-eye(4)); %#ok origin = V(1:3,4)'/V(4, 4); % create line corresponding to rotation axis axis = [origin vector]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isTransform3d.m0000644000000000000000000000013214055375162017776 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isTransform3d.m0000644000175000017500000000766614055375162021102 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function a = isTransform3d(trans, varargin) %ISTRANSFORM3D Check if input is a affine transformation matrix. % % A = isTransform3d(TRANS) where TRANS should be a transformation matrix. % The function accepts transformations given using the following formats: % [a b c] , [a b c j] , or [a b c j] % [d e f] [d e f k] [d e f k] % [g h i] [g h i l] [g h i l] % [0 0 0 1] % % If the transformation matrix should only contain rotation and % translation without reflection, scaling, shearing, ... set 'rotation' % to true. Default is false. % % Example % rot = ... % createRotationOx(rand*2*pi)*... % createRotationOy(rand*2*pi)*... % createRotationOx(rand*2*pi); % trans = rot*createTranslation3d(rand(1,3)); % isTransform3d(trans, 'rot', true) % % See also % composeTransforms3d, createBasisTransform3d, recenterTransform3d, % transformPoint3d % % ------ % Author: oqilipo % Created: 2018-07-08 % Copyright 2018 narginchk(1,5) p = inputParser; logParValidFunc = @(x) (islogical(x) || isequal(x,1) || isequal(x,0)); addParameter(p,'rotation', 0, logParValidFunc); valTol = @(x) validateattributes(x,{'numeric'},{'scalar', '>=',eps(class(trans)), '<=',1}); addParameter(p,'tolerance', 1e-8, valTol); parse(p,varargin{:}); rotation = p.Results.rotation; tolerance = p.Results.tolerance; % eventually add null translation if size(trans, 2) == 3 trans = [trans zeros(size(trans, 1), 1)]; elseif size(trans, 2) < 3 || size(trans, 2) > 4 a=false; return end % eventually add normalization if size(trans, 1) == 3 trans = [trans;0 0 0 1]; elseif size(trans, 1) < 3 || size(trans, 1) > 4 a=false; return end a=true; % NaN is invalid if any(isnan(trans(:))) a=false; return end % Infinity is invalid if any(isinf(trans(:))) a=false; return end % trans(4,4) has to be a one if ~isequal(1, trans(4,4)) a = false; return end % trans(4,1:3) have to be zeros if ~isequal(zeros(1,3), trans(4,1:3)) a = false; return end if rotation % transpose(trans(1:3,1:3)) * trans(1:3,1:3) has to be eye(3) if any(abs(eye(3) - (trans(1:3,1:3)'*trans(1:3,1:3))) > tolerance) a = false; return; end % determinant of trans(1:3) has to be one if abs(1-det(trans)) > tolerance a = false; return end end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/randomPointInBox3d.m0000644000000000000000000000013214055375162020721 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/randomPointInBox3d.m0000644000175000017500000000543114055375162022011 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = randomPointInBox3d(box, N, varargin) %RANDOMPOINTINBOX3D Generate random point(s) within a 3D box. % % PTS = randomPointInBox3d(BOX) % Generate a random point within the 3D box BOX. The result is a 1-by-3 % row vector. % % PTS = randomPointInBox3d(BOX, N) % Generates N points within the box. The result is a N-by-3 array. % % BOX has the format: % BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX]. % % Example % % draw points within a box % box = [10 40 20 60 30 50]; % pts = randomPointInBox3d(box, 500); % figure(1); hold on; % drawBox3d(box); % drawPoint3d(pts, '.'); % axis('equal'); % axis([0 100 0 100 0 100]); % view(3); % % See also % points3d, boxes3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-06-27, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. if nargin < 2 N = 1; end % extract box bounds xmin = box(1); ymin = box(3); zmin = box(5); % compute size of box dx = box(2) - xmin; dy = box(4) - ymin; dz = box(6) - zmin; % compute point coordinates points = [rand(N, 1)*dx+xmin , rand(N, 1)*dy+ymin , rand(N, 1)*dz+zmin]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/isPointOnLine3d.m0000644000000000000000000000013214055375162020221 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/isPointOnLine3d.m0000644000175000017500000000622114055375162021307 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPointOnLine3d(point, line, varargin) %ISPOINTONLINE3D Test if a 3D point belongs to a 3D line. % % B = isPointOnLine3d(POINT, LINE) % with POINT being [xp yp zp], and LINE being [x0 y0 z0 dx dy dz]. % Returns 1 if point lies on the line, 0 otherwise. % % If POINT is an N-by-3 array of points, B is a N-by-1 array of booleans. % % If LINE is a N-by-6 array of lines, B is a N-by-1 array of booleans. % % B = isPointOnLine3d(POINT, LINE, TOL) % Specifies the tolerance used for testing location on 3D line. % % See also: % lines3d, distancePointLine3d, linePosition3d, isPointOnLine % % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 17/12/2013 create from isPointOnLine % extract computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % size of inputs np = size(point,1); nl = size(line, 1); if np == 1 || nl == 1 || np == nl % test if lines are colinear, using norm of the cross product b = bsxfun(@rdivide, vectorNorm3d( ... crossProduct3d(bsxfun(@minus, line(:,1:3), point), line(:,4:6))), ... vectorNorm3d(line(:,4:6))) < tol; else % same test, but after reshaping arrays to manage difference of % dimensionality point = reshape(point, [np 1 3]); line = reshape(line, [1 nl 6]); b = bsxfun(@rdivide, vectorNorm3d( ... cross(bsxfun(@minus, line(:,:,1:3), point), line(ones(1,np),:,4:6), 3)), ... vectorNorm3d(line(:,:,4:6))) < tol; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/hypot3.m0000644000000000000000000000013214055375162016466 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/hypot3.m0000644000175000017500000000434514055375162017561 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = hypot3(dx, dy, dz) %HYPOT3 Diagonal length of a cuboidal 3D box . % % h = hypot3(a, b, c) % computes the quantity sqrt(a^2 + b^2 + c^2), by avoiding roundoff % errors. % % Example % % Compute diagonal of unit cube % hypot3(1, 1, 1) % ans = % 1.7321 % % % Compute more complicated diagonal % hypot3(3, 4, 5) % ans = % 7.0711 % % See also % hypot, vectorNorm3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-04-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. h = hypot(hypot(dx, dy), dz); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectPlaneSphere.m0000644000000000000000000000013214055375162021367 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectPlaneSphere.m0000644000175000017500000000754714055375162022471 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function circle = intersectPlaneSphere(plane, sphere) %INTERSECTPLANESPHERE Return intersection circle between a plane and a sphere. % % CIRC = intersectPlaneSphere(PLANE, SPHERE) % Returns the circle which is the intersection of the given plane % and sphere. % PLANE : [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % SPHERE : [XS YS ZS RS] % CIRC : [XC YC ZC RC THETA PHI PSI] % [x0 y0 z0] is the origin of the plane, [dx1 dy1 dz1] and [dx2 dy2 dz2] % are two direction vectors, % [XS YS ZS] are coordinates of the sphere center, RS is the sphere % radius, % [XC YC ZC] are coordinates of the circle center, RC is the radius of % the circle, [THETA PHI] is the normal of the plane containing the % circle (THETA being the colatitude, and PHI the azimut), and PSI is a % rotation angle around the normal (equal to zero in this function, but % kept for compatibility with other functions). All angles are given in % degrees. % % See Also: % planes3d, spheres, circles3d, intersectLinePlane, intersectLineSphere % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 18/02/2005. % % HISTORY % 27/06/2007: change output format of circle, add support for multiple % data % 2011-06-21 use degrees for angles % number of inputs of each type Ns = size(sphere, 1); Np = size(plane, 1); % unify data dimension if Ns ~= Np if Ns == 1 sphere = sphere(ones(Np, 1), :); elseif Np == 1 plane = plane(ones(Ns, 1), :); else error('data should have same length, or one data should have length 1'); end end % center of the spheres center = sphere(:,1:3); % radius of spheres if size(sphere, 2) == 4 Rs = sphere(:,4); else % assume default radius equal to 1 Rs = ones(size(sphere, 1), 1); end % projection of sphere center on plane -> gives circle center circle0 = projPointOnPlane(center, plane); % radius of circles d = distancePoints3d(center, circle0); Rc = sqrt(Rs.*Rs - d.*d); % normal of planes = normal of circles nor = planeNormal(plane); % convert to angles [theta, phi] = cart2sph2(nor(:,1), nor(:,2), nor(:,3)); psi = zeros(Np, 1); % create structure for circle k = 180 / pi; circle = [circle0 Rc [theta phi psi]*k]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/angles3d.m0000644000000000000000000000013214055375162016740 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/angles3d.m0000644000175000017500000000673214055375162020035 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function angles3d(varargin) %ANGLES3D Conventions for manipulating angles in 3D. % % The library uses both radians and degrees angles; % Results of angle computation between shapes usually returns angles in % radians. % Representation of 3D shapes use angles in degrees (easier to manipulate % and to save). % % Contrary to the plane, there are no oriented angles in 3D. Angles % between lines or between planes are comprised between 0 and PI. % % Spherical angles % Spherical angles are defined by 2 angles: % * THETA, the colatitude, representing angle with Oz axis (between 0 and % PI) % * PHI, the azimut, representing angle with Ox axis of horizontal % projection of the direction (between 0 and 2*PI) % % Spherical coordinates can be represented by THETA, PHI, and the % distance RHO to the origin. % % Euler angles % Some functions for creating rotations use Euler angles. They follow the % ZYX convention in the global reference system, that is eqivalent to the % XYZ convention ine a local reference system. % Euler angles are given by a triplet of angles [PHI THETA PSI] that % represents the succession of 3 rotations: % * rotation around X by angle PSI ("roll") % * rotation around Y by angle THETA ("pitch") % * rotation around Z by angle PHI ("yaw") % % In this library, euler angles are given in degrees. The functions that % use euler angles use the keyword 'Euler' in their name. % % % See also % cart2sph2, sph2cart2, cart2sph2d, sph2cart2d % anglePoints3d, angleSort3d, sphericalAngle, randomAngle3d % dihedralAngle, polygon3dNormalAngle, eulerAnglesToRotation3d % rotation3dAxisAndAngle, rotation3dToEulerAngles % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawEllipsoid.m0000644000000000000000000000013214055375162020042 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawEllipsoid.m0000644000175000017500000001673714055375162021145 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawEllipsoid(elli, varargin) %DRAWELLIPSOID Draw a 3D ellipsoid. % % drawEllipsoid(ELLI) % Displays a 3D ellipsoid on current axis. ELLI is given by: % [XC YC ZC A B C PHI THETA PSI], % where (XC, YC, ZC) is the ellipsoid center, A, B and C are the half % lengths of the ellipsoid main axes, and PHI THETA PSI are Euler angles % representing ellipsoid orientation, in degrees. % % drawEllipsoid(..., 'drawEllipses', true) % Also displays the main 3D ellipses corresponding to XY, XZ and YZ % planes. % % % Example % figure; hold on; % drawEllipsoid([10 20 30 50 30 10 5 10 0]); % axis equal; % % figure; hold on; % elli = [10 20 30 50 30 10 5 10 0]; % drawEllipsoid(elli, 'FaceColor', 'r', ... % 'drawEllipses', true, 'EllipseColor', 'b', 'EllipseWidth', 3); % axis equal; % % See also % spheres, drawSphere, equivalentEllipsoid, ellipsoid, drawTorus, % drawCuboid % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-03-12, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. %% Default values % number of meridians nPhi = 32; % number of parallels nTheta = 16; % settings for drawing ellipses drawEllipses = false; ellipseColor = 'k'; ellipseWidth = 1; drawAxes = false; axesColor = 'k'; axesWidth = 2; %% Extract input arguments % Parse the input (try to extract center coordinates and radius) if nargin == 0 % no input: assumes ellipsoid with default shape elli = [0 0 0 5 4 3 0 0 0]; end % default set of options for drawing meshes options = {'FaceColor', 'g', 'linestyle', 'none'}; while length(varargin) > 1 switch lower(varargin{1}) case 'nphi' nPhi = varargin{2}; case 'ntheta' nTheta = varargin{2}; case 'drawellipses' drawEllipses = varargin{2}; case 'ellipsecolor' ellipseColor = varargin{2}; case 'ellipsewidth' ellipseWidth = varargin{2}; case 'drawaxes' drawAxes = varargin{2}; case 'axescolor' axesColor = varargin{2}; case 'axeswidth' axesWidth = varargin{2}; otherwise % assumes this is drawing option options = [options varargin(1:2)]; %#ok end varargin(1:2) = []; end %% Parse numerical inputs % Extract ellipsoid parameters xc = elli(:,1); yc = elli(:,2); zc = elli(:,3); a = elli(:,4); b = elli(:,5); c = elli(:,6); k = pi / 180; ellPhi = elli(:,7) * k; ellTheta = elli(:,8) * k; ellPsi = elli(:,9) * k; %% Coordinates computation % convert unit basis to ellipsoid basis sca = createScaling3d(a, b, c); rotZ = createRotationOz(ellPhi); rotY = createRotationOy(ellTheta); rotX = createRotationOx(ellPsi); tra = createTranslation3d([xc yc zc]); % concatenate transforms trans = tra * rotZ * rotY * rotX * sca; %% parametrisation of ellipsoid % spherical coordinates theta = linspace(0, pi, nTheta+1); phi = linspace(0, 2*pi, nPhi+1); % convert to cartesian coordinates sintheta = sin(theta); x = cos(phi') * sintheta; y = sin(phi') * sintheta; z = ones(length(phi),1) * cos(theta); % transform mesh vertices [x, y, z] = transformPoint3d(x, y, z, trans); %% parametrisation of ellipses if drawEllipses % parametrisation for ellipses nVertices = 120; t = linspace(0, 2*pi, nVertices+1); % XY circle xc1 = cos(t'); yc1 = sin(t'); zc1 = zeros(size(t')); % XZ circle xc2 = cos(t'); yc2 = zeros(size(t')); zc2 = sin(t'); % YZ circle xc3 = zeros(size(t')); yc3 = cos(t'); zc3 = sin(t'); % compute transformed ellipses [xc1, yc1, zc1] = transformPoint3d(xc1, yc1, zc1, trans); [xc2, yc2, zc2] = transformPoint3d(xc2, yc2, zc2, trans); [xc3, yc3, zc3] = transformPoint3d(xc3, yc3, zc3, trans); end %% parametrisation of main axis edges if drawAxes axesEndings = [-1 0 0; +1 0 0; 0 -1 0; 0 +1 0; 0 0 -1; 0 0 +1]; axesEndings = transformPoint3d(axesEndings, trans); end %% Drawing ellipseOptions = {'color', ellipseColor, 'LineWidth', ellipseWidth}; axesOptions = {'color', axesColor, 'LineWidth', axesWidth}; % Process output if nargout == 0 % no output: draw the ellipsoid surf(x, y, z, options{:}); if drawEllipses plot3(xc1, yc1, zc1, ellipseOptions{:}); plot3(xc2, yc2, zc2, ellipseOptions{:}); plot3(xc3, yc3, zc3, ellipseOptions{:}); end if drawAxes drawEdge3d([axesEndings(1,:), axesEndings(2,:)], axesOptions{:}); drawEdge3d([axesEndings(3,:), axesEndings(4,:)], axesOptions{:}); drawEdge3d([axesEndings(5,:), axesEndings(6,:)], axesOptions{:}); end elseif nargout == 1 % one output: draw the ellipsoid and return handle varargout{1} = surf(x, y, z, options{:}); if drawEllipses plot3(xc1, yc1, zc1, ellipseOptions{:}); plot3(xc2, yc2, zc2, ellipseOptions{:}); plot3(xc3, yc3, zc3, ellipseOptions{:}); end elseif nargout == 3 % 3 outputs: return computed coordinates varargout{1} = x; varargout{2} = y; varargout{3} = z; if drawEllipses plot3(xc1, yc1, zc1, ellipseOptions{:}); plot3(xc2, yc2, zc2, ellipseOptions{:}); plot3(xc3, yc3, zc3, ellipseOptions{:}); end elseif nargout == 4 && drawEllipses % Also returns handles to ellipses varargout{1} = surf(x, y, z, options{:}); varargout{2} = plot3(xc1, yc1, zc1, ellipseOptions{:}); varargout{3} = plot3(xc2, yc2, zc2, ellipseOptions{:}); varargout{4} = plot3(xc3, yc3, zc3, ellipseOptions{:}); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/sph2cart2d.m0000644000000000000000000000013214055375162017214 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/sph2cart2d.m0000644000175000017500000000631014055375162020301 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = sph2cart2d(theta, phi, rho) %SPH2CART2D Convert spherical coordinates to cartesian coordinates in degrees. % % C = SPH2CART2(THETA, PHI, RHO) % C = SPH2CART2(THETA, PHI) (assume rho = 1) % C = SPH2CART2(S) % [X, Y, Z] = SPH2CART2(THETA, PHI, RHO); % % S = [phi theta rho] (spherical coordinate). % C = [X Y Z] (cartesian coordinate) % % The following convention is used: % THETA is the colatitude, in degrees, 0 for north pole, +180 degrees for % south pole, +90 degrees for points with z=0. % PHI is the azimuth, in degrees, defined as matlab cart2sph: angle from % Ox axis, counted counter-clockwise. % RHO is the distance of the point to the origin. % Discussion on choice for convention can be found at: % http://www.physics.oregonstate.edu/bridge/papers/spherical.pdf % % See also: % angles3d, cart2sph2d, sph2cart2 % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-06-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % Process input arguments if nargin == 1 phi = theta(:, 2); if size(theta, 2) > 2 rho = theta(:, 3); else rho = ones(size(phi)); end theta = theta(:, 1); elseif nargin == 2 rho = ones(size(theta)); end % conversion rz = rho .* sind(theta); x = rz .* cosd(phi); y = rz .* sind(phi); z = rho .* cosd(theta); % Process output arguments if nargout == 1 || nargout == 0 varargout{1} = [x, y, z]; else varargout{1} = x; varargout{2} = y; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createLine3d.m0000644000000000000000000000013214055375162017542 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createLine3d.m0000644000175000017500000001404414055375162020632 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = createLine3d(varargin) %CREATELINE3D Create a line with various inputs. % % Line is represented in a parametric form : [x0 y0 z0 dx dy dz] % x = x0 + t*dx % y = y0 + t*dy; % z = z0 + t*dz; % % % L = createLine3d(P1, P2); % Returns the line going through the two given points P1 and P2. % % L = createLine3d(X0, Y0, Z0, DX, DY, DZ); % Returns the line going through the point [x0, y0, z0], and with % direction vector given by [DX DY DZ]. % % L = createLine3d(P0, DX, DY, DZ); % Returns the line going through point P0 given by [x0, y0, z0] and with % direction vector given by [DX DY DZ]. % % L = createLine3d(THETA, PHI); % Create a line originated at (0,0) and with angles theta and phi. % % L = createLine3d(P0, THETA, PHI); % Create a line with direction given by theta and phi, and which contains % point P0. % % % Note : in all cases, parameters can be vertical arrays of the same % dimension. The result is then an array of lines, of dimensions [N*6]. % % See also: % lines3d % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % % HISTORY % 30/11/2005 add more cases % 04/01/2007 remove unused variables % NOTE : A 3d line can also be represented with a 1*7 array : % [x0 y0 z0 dx dy dz t]. % whith 't' being one of the following : % - t=0 : line is a singleton (x0,y0) % - t=1 : line is an edge segment, between points (x0,y0) and (x0+dx, % y0+dy). % - t=Inf : line is a Ray, originated from (x0,y0) and going to infinity % in the direction(dx,dy). % - t=-Inf : line is a Ray, originated from (x0,y0) and going to infinity % in the direction(-dx,-dy). % - t=NaN : line is a real straight line, and contains all points % verifying the above equation. % This seems to be a convenient way to represent uniformly all kind of % lines (including edges, rays, and even point). % % NOTE2 : Another form is the 1*8 array : % [x0 y0 z0 dx dy dz t1 t2]. % with t1 and t2 giving first and last position of the edge on the % supporting straight line, and with t2>t1. if length(varargin)==1 error('Wrong number of arguments in ''createLine'' '); elseif length(varargin)==2 % 2 input parameters. They can be : % - 2 points, then 2 arrays of 1*2 double. v1 = varargin{1}; v2 = varargin{2}; if size(v1, 2)==3 % first input parameter is first point, and second input is the % second point. line = [v1(:,1) v1(:,2) v1(:,3) v2(:,1)-v1(:,1) v2(:,2)-v1(:,2) v2(:,3)-v1(:,3)]; elseif size(v1, 2)==1 % first parameter is angle with the vertical % second parameter is horizontal angle with Ox axis theta = varargin{1}; phi = varargin{2}; sit = sin(theta); p0 = zeros([size(theta, 1) 3]); line = [p0 cos(phi)*sit sin(phi)*sit cos(theta)]; end elseif length(varargin)==3 % 3 input parameters : % first parameter is a point of the line % second parameter is angle with the vertical % third parameter is horizontal angle with Ox axis p0 = varargin{1}; theta = varargin{2}; phi = varargin{3}; if size(p0, 2)~=3 error('first argument should be a 3D point'); end sit = sin(theta); line = [p0 cos(phi)*sit sin(phi)*sit cos(theta)]; elseif length(varargin)==4 % 4 input parameters : p0 = varargin{1}; dx = varargin{2}; dy = varargin{3}; dz = varargin{4}; if size(p0, 2)~=3 error('first argument should be a 3D point'); end line = [p0 dx dy dz]; elseif length(varargin)==5 % 5 input parameters : % first parameter is distance of lin to origin % second parameter is angle with the vertical % third parameter is horizontal angle with Ox axis x0 = varargin{1}; y0 = varargin{1}; z0 = varargin{1}; theta = varargin{2}; phi = varargin{3}; sit = sin(theta); line = [x0 y0 z0 cos(phi)*sit sin(phi)*sit cos(theta)]; elseif length(varargin)==6 % 6 input parameters, given as separate arguments for x0, y0, z0 and % dx, dy and dz % (not very useful, but anyway...) x0 = varargin{1}; y0 = varargin{2}; z0 = varargin{3}; dx = varargin{4}; dy = varargin{5}; dz = varargin{6}; line = [x0 y0 z0 dx dy dz]; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/distanceLines3d.m0000644000000000000000000000013214055375162020254 xustar0030 mtime=1622538866.050813674 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/distanceLines3d.m0000644000175000017500000001066714055375162021353 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [d, pt1, pt2] = distanceLines3d(line1, line2) %DISTANCELINES3D Minimal distance between two 3D lines. % % D = distanceLines3d(LINE1, LINE2); % Returns the distance between line LINE1 and the line LINE2, given as: % LINE1 : [x0 y0 z0 dx dy dz] (or M-by-6 array) % LINE2 : [x0 y0 z0 dx dy dz] (or N-by-6 array) % D : (positive) array M-by-N % % [D, PT1, PT2] = distanceLines3d(LINE1, LINE2); % Also returns the points located on LINE1 and LINE2 corresponding to the % shortest distance. % One should get the following: % distancePoints3d(PT1, PT2) - D == 0 % % % Example % line1 = [2 3 4 0 1 0]; % line2 = [8 8 8 0 0 1]; % distanceLines3d(line1, line2) % ans = % 6.0000 % % See also: % lines3d, distancePoints3d % % --------- % authors: Brandon Baker, oqilipo, David Legland % created January 19, 2011 % % number of points of each array n1 = size(line1, 1); n2 = size(line2, 1); if nargout <= 1 % express line coordinate as n1-by-n2 arrays v1x = repmat(line1(:,4), [1 n2]); v1y = repmat(line1(:,5), [1 n2]); v1z = repmat(line1(:,6), [1 n2]); p1x = repmat(line1(:,1), [1 n2]); p1y = repmat(line1(:,2), [1 n2]); p1z = repmat(line1(:,3), [1 n2]); v2x = repmat(line2(:,4)', [n1 1]); v2y = repmat(line2(:,5)', [n1 1]); v2z = repmat(line2(:,6)', [n1 1]); p2x = repmat(line2(:,1)', [n1 1]); p2y = repmat(line2(:,2)', [n1 1]); p2z = repmat(line2(:,3)', [n1 1]); % calculates distance for each set of lines vcross = cross([v1x(:) v1y(:) v1z(:)], [v2x(:) v2y(:) v2z(:)]); num = ([p1x(:) p1y(:) p1z(:)] - [p2x(:) p2y(:) p2z(:)]) .* vcross; t1 = sum(num,2); d = abs(t1) ./ (vectorNorm3d(vcross) + eps); % returns result as n1-by-n2 array d = reshape(d, n1, n2); else % check input dimension, as we need to be able to match each pair of % lines if n1 ~= n2 error('geom3d:distanceLines3d:IllegalInputArgument', ... 'when output points are requested, number of lines should be the same'); end p1 = line1(:, 1:3); p2 = line2(:, 1:3); dp = p2 - p1; v1 = line1(:, 4:6); v2 = line2(:, 4:6); % compute distance vcross = cross(v1, v2, 2); num = dp .* vcross; t1 = sum(num, 2); d = abs(t1) ./ (vectorNorm3d(vcross) + eps); % precomputations a = dot(v1, v1, 2); b = dot(v1, v2, 2); e = dot(v2, v2, 2); den = a.*e - b.*b; % 0, if lines are parallel % vector between origin of both lines r = line1(:,1:3) - line2(:,1:3); % solve linear system c = dot(v1, r, 2); f = dot(v2, r, 2); s = (b .* f - c .* e) ./ den; t = (a .* f - c .* b) ./ den; % convert to coordinates of points on lines pt1 = line1(:,1:3) + v1 .* s; pt2 = line2(:,1:3) + v2 .* t; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/normalizeLine3d.m0000644000000000000000000000013114055375162020276 xustar0029 mtime=1622538866.05481366 30 atime=1622538866.050813674 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/normalizeLine3d.m0000644000175000017500000000430214055375162021363 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line2 = normalizeLine3d(line) %NORMALIZELINE3D Normalizes the direction vector of a 3D line. % % LINE2 = normalizeVector3d(LINE); % Returns the normalization of the direction vector of the line, such % that ||LINE2(4:6)|| = 1. % % See also: % normalizePlane, normalizeVector3d % % ------ % Author: oqilipo % Created: 2020-03-13 % Copyright 2020 isLine3d = @(x) validateattributes(x,{'numeric'},... {'nonempty','nonnan','real','finite','size',[nan,6]}); % Check if the line is valid p=inputParser; addRequired(p,'line',isLine3d) parse(p,line) line2 = line; line2(:,4:6) = normalizeVector3d(line2(:,4:6)); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/revolutionSurface.m0000644000000000000000000000013014055375162020755 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/revolutionSurface.m0000644000175000017500000001263014055375162022046 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = revolutionSurface(varargin) %REVOLUTIONSURFACE Create a surface of revolution from a planar curve. % % usage % [X Y Z] = revolutionSurface(C1, C2, N); % create the surface of revolution of parametrized function (xt, yt), % with N+1 equally spaced slices, around the Oz axis. % It assumed that C1 corresponds to the x coordinate, and that C2 % corresponds to the Oz coordinate. % % [X Y Z] = revolutionSurface(CURVE, N); % is the same, but generating curve is given in a single parameter CURVE, % which is a [Nx2] array of 2D points. % % [X Y Z] = revolutionSurface(..., THETA) % where THETA is a vector, uses values of THETA for computing revolution % angles. % % [X Y Z] = revolutionSurface(..., LINE); % where LINE is a 1x4 array, specifes the revolution axis in the % coordinate system of the curve. LINE is a row vector of 4 parameters, % containing [x0 y0 dx dy], where (x0,y0) is the origin of the line and % (dx,dy) is a direction vector of the line. % The resulting revolution surface still has Oz axis as symmetry axis. It % can be transformed using transformPoint3d function. % Surface can be displayed using : % H = surf(X, Y, Z); % H is a handle to the created patch. % % revolutionSurface(...); % by itself, directly shows the created patch. % % Example % % draws a piece of torus % circle = circleAsPolygon([10 0 3], 50); % [x y z] = revolutionSurface(circle, linspace(0, 4*pi/3, 50)); % surf(x, y, z); % axis equal; % % % % See also % surf, transformPoint3d, drawSphere, drawTorus, drawEllipsoid % surfature (on Matlab File Exchange) % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2004-04-09 % Copyright 2005 INRA - CEPIA Nantes - MIAJ Jouy-en-Josas. % based on function cylinder from matlab % 31/06/2006 fix bug when passing 3 parameters % 20/04/2007 rewrite processing of input parameters, add psb to specify % revolution axis % 24/10/2008 fix angle vector % 29/07/2010 doc update %% Initialisations % default values % use revolution using the full unit circle, decomposed into 24 angular % segments (thus, some vertices correspond to particular angles 30°, % 45°...) theta = linspace(0, 2*pi, 25); % use planar vertical axis as default revolution axis revol = [0 0 0 1]; % extract the generating curve var = varargin{1}; if size(var, 2)==1 xt = var; yt = varargin{2}; varargin(1:2) = []; else xt = var(:,1); yt = var(:,2); varargin(1) = []; end % extract optional parameters: angles, axis of revolution % parameters are identified from their length while ~isempty(varargin) var = varargin{1}; if length(var) == 4 % axis of rotation in the base plane revol = var; elseif length(var) == 1 % number of points -> create row vector of angles theta = linspace(0, 2*pi, var); else % use all specified angle values theta = var(:)'; end varargin(1) = []; end %% Create revolution surface % ensure length is enough m = length(xt); if m==1 xt = [xt xt]; end % ensure x and y are vertical vectors xt = xt(:); yt = yt(:); % transform xt and yt to replace in the reference of the revolution axis tra = createTranslation(-revol(1:2)); rot = createRotation(pi/2 - lineAngle(revol)); [xt, yt] = transformPoint(xt, yt, tra*rot); % compute surface vertices x = xt * cos(theta); y = xt * sin(theta); z = yt * ones(size(theta)); %% Process output arguments % format output depending on how many output parameters are required if nargout == 0 % draw the revolution surface surf(x, y, z); elseif nargout == 1 % draw the surface and return a handle to the shown structure h = surf(x, y, z); varargout{1} = h; elseif nargout == 3 % return computed mesh varargout = {x, y, z}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawPlatform.m0000644000000000000000000000013014055375162017700 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawPlatform.m0000644000175000017500000000766214055375162021002 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPlatform(plane, siz, varargin) %DRAWPLATFORM Draw a rectangular platform with a given size. % % drawPlatform(PLANE, SIZ) draws a rectangular platform with the % dimensions specified by SIZ. If SIZ contains only one value instead of % two the platform will be quadratic. % % drawPlatform(...,'PropertyName',PropertyValue,...) sets the value of % the specified patch property. Multiple property values can be set with % a single statement. See function patch for details. % % drawPlane3d(AX,...) plots into AX instead of GCA. % % H = drawPlatform(...) returns a handle H to the patch object. % % Example % % p0 = [1 2 3]; % v1 = [1 0 1]; % v2 = [0 -1 1]; % plane = [p0 v1 v2]; % axis([-10 10 -10 10 -10 10]); % drawPlatform(plane, [7,3]) % set(gcf, 'renderer', 'zbuffer'); % % See also % planes3d, createPlane, patch % ------ % Author: oqilipo % Created: 2018-08-09 % Copyright 2018 %% Parse inputs % extract axis handle if isAxisHandle(plane) hAx = plane; plane = siz; siz = varargin{1}; varargin(1) = []; else hAx = gca; end % parse optional arguments p = inputParser; addRequired(p, 'plane', @(x) size(x,1)==1 && isPlane(x)) addRequired(p, 'siz', @(x)validateattributes(x,{'numeric'},... {'size',[1, nan],'positive','nonnan','real','finite'})) parse(p, plane, siz) if ~isempty(varargin) if length(varargin) == 1 if isstruct(varargin{1}) % if options are specified as struct, need to convert to % parameter name-value pairs varargin = [fieldnames(varargin{1}) struct2cell(varargin{1})]'; varargin = varargin(:)'; else % if option is a single argument, assume it corresponds to % plane color varargin = {'FaceColor', varargin{1}}; end end else % default face color varargin = {'FaceColor', 'm'}; end if numel(siz) == 1 siz(2) = siz(1); end %% Algorithm % Calculate vertex points of the platform pts(1,:) = planePoint(plane, [1,1]*0.5.*siz); pts(2,:) = planePoint(plane, [1,-1]*0.5.*siz); pts(3,:) = planePoint(plane, [-1,-1]*0.5.*siz); pts(4,:) = planePoint(plane, [-1,1]*0.5.*siz); pf.vertices = pts; pf.faces = [1 2 3 4]; % Draw the patch h = patch(hAx, pf, varargin{:}); %% Parse outputs % Return handle to plane if needed if nargout > 0 varargout{1} = h; end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fitCircle3d.m0000644000000000000000000000013014055375162017371 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fitCircle3d.m0000644000175000017500000001423714055375162020467 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [fittedCircle, circleNormal] = fitCircle3d(pts) %FITCIRCLE3D Fit a 3D circle to a set of points. % % [FITTEDCIRCLE, CIRCLENORMAL] = fitCircle3d(PTS) % % Example % % points on a 2d circle with noise % nop = randi([5 50],1,1); % radius = randi([5 25],1,1); % points2d = circleToPolygon([0 0 radius], nop); % points2d(1,:) = []; % points2d = points2d + rand(size(points2d)); % points2d(:,3)=rand(length(nop),1); % % apply random rotation and translation % [theta, phi] = randomAngle3d; % theta = rad2deg(theta); % phi = rad2deg(phi); % tfm = eulerAnglesToRotation3d(phi, theta, 0); % trans = randi([-250 250],3,1); % tfm(1:3,4)=trans; % points3d = awgn(transformPoint3d(points2d, tfm),1); % % fit 3d circle % [fittedCircle, circleNormal] = fitCircle3d(points3d); % % plot 3d points and 3d circle % figure('Color','w'); hold on; axis equal tight; view(3); % xlabel('X');ylabel('Y');zlabel('Z'); % drawPoint3d(points3d) % drawCircle3d(fittedCircle, 'k') % drawVector3d(fittedCircle(1:3), circleNormal*fittedCircle(4)) % % See also % circle3dOrigin, circle3dPosition, circle3dPoint, intersectPlaneSphere % drawCircle3d, drawCircleArc3d, drawEllipse3d % % ------ % Authors: oqilipo, David Legland % created: 2017-05-09 % Mean of all points meanPoint = mean(pts,1); % Center points by subtracting the meanPoint centeredPoints = pts - repmat(meanPoint,size(pts,1),1); % Project 3D data to a plane [~,~,V]=svd(centeredPoints); tfmPoints = transformPoint3d(centeredPoints, V'); % Fit a circle to the points in the xy-plane circleParamter = CircleFitByTaubin(tfmPoints(:,1:2)); center2d = circleParamter(1:2); radius=circleParamter(3); center3d = transformPoint3d([center2d, 0], [inv(V'), meanPoint']); circleNormal = V(:,3)'; [theta, phi, ~] = cart2sph2(circleNormal); fittedCircle = [center3d radius rad2deg(theta) rad2deg(phi) 0]; end % Circle Fit (Taubin method) % version 1.0 (2.24 KB) by Nikolai Chernov % http://www.mathworks.com/matlabcentral/fileexchange/22678 function Par = CircleFitByTaubin(XY) %-------------------------------------------------------------------------- % % Circle fit by Taubin % G. Taubin, "Estimation Of Planar Curves, Surfaces And Nonplanar % Space Curves Defined By Implicit Equations, With % Applications To Edge And Range Image Segmentation", % IEEE Trans. PAMI, Vol. 13, pages 1115-1138, (1991) % % Input: XY(n,2) is the array of coordinates of n points x(i)=XY(i,1), y(i)=XY(i,2) % % Output: Par = [a b R] is the fitting circle: % center (a,b) and radius R % % Note: this fit does not use built-in matrix functions (except "mean"), % so it can be easily programmed in any programming language % %-------------------------------------------------------------------------- n = size(XY,1); % number of data points centroid = mean(XY); % the centroid of the data set % computing moments (note: all moments will be normed, i.e. divided by n) Mxx = 0; Myy = 0; Mxy = 0; Mxz = 0; Myz = 0; Mzz = 0; for i=1:n Xi = XY(i,1) - centroid(1); % centering data Yi = XY(i,2) - centroid(2); % centering data Zi = Xi*Xi + Yi*Yi; Mxy = Mxy + Xi*Yi; Mxx = Mxx + Xi*Xi; Myy = Myy + Yi*Yi; Mxz = Mxz + Xi*Zi; Myz = Myz + Yi*Zi; Mzz = Mzz + Zi*Zi; end Mxx = Mxx/n; Myy = Myy/n; Mxy = Mxy/n; Mxz = Mxz/n; Myz = Myz/n; Mzz = Mzz/n; % computing the coefficients of the characteristic polynomial Mz = Mxx + Myy; Cov_xy = Mxx*Myy - Mxy*Mxy; A3 = 4*Mz; A2 = -3*Mz*Mz - Mzz; A1 = Mzz*Mz + 4*Cov_xy*Mz - Mxz*Mxz - Myz*Myz - Mz*Mz*Mz; A0 = Mxz*Mxz*Myy + Myz*Myz*Mxx - Mzz*Cov_xy - 2*Mxz*Myz*Mxy + Mz*Mz*Cov_xy; A22 = A2 + A2; A33 = A3 + A3 + A3; xnew = 0; ynew = 1e+20; epsilon = 1e-12; IterMax = 20; % Newton's method starting at x=0 for iter=1:IterMax yold = ynew; ynew = A0 + xnew*(A1 + xnew*(A2 + xnew*A3)); if abs(ynew) > abs(yold) disp('Newton-Taubin goes wrong direction: |ynew| > |yold|'); xnew = 0; break; end Dy = A1 + xnew*(A22 + xnew*A33); xold = xnew; xnew = xold - ynew/Dy; if (abs((xnew-xold)/xnew) < epsilon), break, end if (iter >= IterMax) disp('Newton-Taubin will not converge'); xnew = 0; end if (xnew<0.) fprintf(1,'Newton-Taubin negative root: x=%f\n',xnew); xnew = 0; end end % computing the circle parameters DET = xnew*xnew - xnew*Mz + Cov_xy; Center = [Mxz*(Myy-xnew)-Myz*Mxy , Myz*(Mxx-xnew)-Mxz*Mxy]/DET/2; Par = [Center+centroid , sqrt(Center*Center'+Mz)]; end % CircleFitByTaubin matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/transformPoint3d.m0000644000000000000000000000013014055375162020512 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/transformPoint3d.m0000644000175000017500000001357414055375162021613 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = transformPoint3d(pts, transfo, varargin) %TRANSFORMPOINT3D Transform a point with a 3D affine transform. % % PT2 = transformPoint3d(PT1, TRANS); % PT2 = transformPoint3d(X1, Y1, Z1, TRANS); % where PT1 has the form [xp yp zp], and TRANS is a 3-by-3, 3-by-4, or % 4-by-4 matrix, returns the point transformed according to the affine % transform specified by TRANS. % % The function accepts transforms given using the following formats: % [a b c] , [a b c j] , or [a b c j] % [d e f] [d e f k] [d e f k] % [g h i] [g h i l] [g h i l] % [0 0 0 1] % % PT2 = transformPoint3d(PT1, TRANS) % also work when PT1 is a N-by-3-by-M-by-P-by-ETC array of double. In % this case, PT2 has the same size as PT1. % % PT2 = transformPoint3d(X1, Y1, Z1, TRANS); % also work when X1, Y1 and Z1 are 3 arrays with the same size. In this % case, PT2 will be a 1-by-3 cell containing {X Y Z} outputs of size(X1). % % [X2, Y2, Z2] = transformPoint3d(...); % returns the result in 3 different arrays the same size as the input. % This form can be useful when used with functions like meshgrid or warp. % % MESH2 = transformPoint3d(MESH, TRANS) % transforms the field 'vertices' of the struct MESH and returns the same % struct with the transformed vertices. % (It is recommended to use the function 'transformMesh', within the % "meshes3d" module). % % See also: % points3d, transforms3d, transformMesh, createTranslation3d % createRotationOx, createRotationOy, createRotationOz, createScaling % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % 23/03/2006 add support for non vector point data % 26/10/2006 better support for large data handling: iterate on points % in the case of a memory lack. % 20/04/2007 add link to rotationXX functions % 29/09/2010 fix bug in catch case % 12/03/2011 slightly reduce memory usage %% Parse input arguments % Check special case: if first argument is a struct with a field named % 'vertices', then the output will be the same struct, but with the % transformed vertices. if nargin == 2 && isstruct(pts) && isfield(pts, 'vertices') mesh = pts; mesh.vertices = transformPoint3d(mesh.vertices, transfo); varargout = {mesh}; return; end % Parse x, y, and z coordinates of input points from input arguments if nargin == 2 % Point coordinates are given in a single N-by-3-by-M-by-etc argument. % Preallocate x, y, and z to size N-by-1-by-M-by-etc, then fill them in dim = size(pts); dim(2) = 1; [x, y, z] = deal(zeros(dim, class(pts))); x(:) = pts(:,1,:); y(:) = pts(:,2,:); z(:) = pts(:,3,:); elseif nargin == 4 % Point coordinates are given in 3 different arrays x = pts; y = transfo; z = varargin{1}; transfo = varargin{2}; dim = size(x); else error('MatGeom:geom3d:WrongInputArgumentNumber', ... 'Requires number of input arguments to be either 2 or 4'); end %% Process transformation matrix % extract the linear and the translation parts of the matrix linear = transfo(1:3, 1:3)'; trans = [0 0 0]; if size(transfo, 2) > 3 trans = transfo(1:3, 4)'; end %% Main processing % convert coordinates try % vectorial processing, if there is enough memory. % same as: % res = (transfo * [x(:) y(:) z(:) ones(NP, 1)]')'; res = bsxfun(@plus, [x(:) y(:) z(:)] * linear, trans); % Back-fill x,y,z with new result (saves calling costly reshape()) x(:) = res(:,1); y(:) = res(:,2); z(:) = res(:,3); catch ME disp(ME.message) % process each point one by one, writing in existing array NP = numel(x); for i = 1:NP res = [x(i) y(i) z(i)] * linear + trans; x(i) = res(1); y(i) = res(2); z(i) = res(3); end end % process output arguments if nargout <= 1 % results are stored in a unique array if length(dim) > 2 && dim(2) > 1 warning('geom3d:shapeMismatch',... 'Shape mismatch: Non-vector xyz input should have multiple x,y,z output arguments. Cell {x,y,z} returned instead.') varargout{1} = {x,y,z}; else varargout{1} = [x y z]; end elseif nargout == 3 % results are returned in three array with same size. varargout = {x, y, z}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/changelog.txt0000644000000000000000000000013214055375161017551 xustar0030 mtime=1622538865.990813902 30 atime=1622538865.990813902 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/changelog.txt0000644000175000017500000000723214055375161020642 0ustar00juanpijuanpi00000000000000change log for geom3d geom3d release 2011.10.13 ========================= New Features - added function vectorCross3d (thanks to Sven Holcombe) - added function triangleArea3d - added function trimeshSurfaceArea - added drawPolygon3d (mostly the same as drawPolyline3d) Several bug fixes and improvements in code speed, thanks to Sven Holcombe geom3d release 2011.06.30 ========================= Important changes: - Package has been splitted up into 'geom3d' and 'meshes3d'. - Representation of geometrical shapes (3D circles, ellipsoids...) now uses degrees for angles New features - added function distanceLine3d - added functions inertiaEllipsoid and drawEllipsoid - added functions intersectLinePolygon3d, intersectRayPolygon3d, and intersectLineTriangle3d - added function eulerAngleToRotation3d - added drawing functions: drawTorus, drawCube, drawCuboid - added function randomPointInBox3d - added functions sph2cart2d and cart2sph2d, that work with degrees Bug fixes - fixed bugs in intersectEdgePlanes - fixed bugs in isPerpendicular3d - enhanced createPlane geom3d release 2011.01.10 ========================= New features - new functions for meshes and polyhedra: + meshEdgeLength + meshDihedralAngles + meshEdgeFaces + meshSurfaceArea + polyhedronMeanBreadth + checkMeshAdjacentFaces + drawFaceNormals + meshFace - new function createBasisTransform3d to compute coordinate changes between basis - added vectorAngle3d, to compute angle between 2 3D vectors - added midPoint3d, to compute middle points of either 2 points or a 3D edge - added functions for 3D rotations: + createRotation3dLineAngle + rotation3dAxisAndAngle + rotation3dToEulerAngles Regressions - function 'local2global3d' moved to private directory Bug fixes - most meshes now have their faces oriented with normals pointing outwards of the meshes - fix bug in drawPlane for planes touching current axis at one corner - fix bug in faceNormal for cell array of faces - fix bug in transformPoint3d for large arrays Code - creation of private directory, for utilitary functions geom3d release 2010.07.28 ========================= New features - added createEulerAnglesRotation - added functions for management of 3D boxes (isothetic cuboids) - added drawPolyline3d - added drawAxisCube function - added recenterTransform3d, to change invariant point of 3D transforms. Enhancements - added support for several lines in clipLine3d - added support for multiple inputs in distancePointPlane - updated doc for polyhedra, for function localToGlobal3d - updated several drawing functions Bug fixes - fixed several bugs in 3D rotations - fixed bugs in drawCircle3d, drawCircleArc3d, drawEllipse3d. - fixed bugs in drawCylinder geom3d release 2009-06-17 ========================= * new features - added transform functions: + transformLine3d, transformVector3d - added intersectLineCylinder - added 'localToGlobal3d': transform from local coordinates to global coordinates, using a translation vector and 3 rotation angles * Changes - renamed some functions to avoid name conflicts and ambiguities translation3d -> createTranslation3d rotationOx -> createRotationOx rotationOy -> createRotationOy rotationOz -> createRotationOz scale3d -> createScaling3d vecnorm3d -> vectorNorm3d normalize3d -> normalizeVector3d * Compatibility considerations - changed convention for angle in rotationOx, rotationOy and rotationOz. - changed convention for dihedral angle, to be consistent with other references matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/private0000644000000000000000000000013214055375161016456 xustar0030 mtime=1622538865.994813885 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/private/0000755000175000017500000000000014055375161017620 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/geom3d/private/PaxHeaders.19757/polygonCentroid.m0000644000000000000000000000013014055375162022067 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/private/polygonCentroid.m0000644000175000017500000000577414055375162023173 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [centroid, area] = polygonCentroid(varargin) %POLYGONCENTROID Compute the centroid (center of mass) of a polygon. % % CENTROID = polygonCentroid(POLY) % CENTROID = polygonCentroid(PTX, PTY) % Computes center of mass of a polygon defined by POLY. POLY is a N-by-2 % array of double containing coordinates of vertices. % % [CENTROID AREA] = polygonCentroid(POLY) % Also returns the (signed) area of the polygon. % % Example % % Draws the centroid of a paper hen % x = [0 10 20 0 -10 -20 -10 -10 0]; % y = [0 0 10 10 20 10 10 0 -10]; % poly = [x' y']; % centro = polygonCentroid(poly); % drawPolygon(poly); % hold on; axis equal; % drawPoint(centro, 'bo'); % % References % algo adapted from P. Bourke web page % % See also: % polygons2d, polygonArea, drawPolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 05/05/2004. % % Algorithme P. Bourke, vectorized version % HISTORY % 2012.02.24 vectorize code % parse input arguments if nargin == 1 var = varargin{1}; px = var(:,1); py = var(:,2); elseif nargin == 2 px = varargin{1}; py = varargin{2}; end % vertex indices N = length(px); iNext = [2:N 1]; % compute cross products common = px .* py(iNext) - px(iNext) .* py; sx = sum((px + px(iNext)) .* common); sy = sum((py + py(iNext)) .* common); % area and centroid area = sum(common) / 2; centroid = [sx sy] / 6 / area; matgeom-1.2.3/inst/geom3d/private/PaxHeaders.19757/splitPolygons3d.m0000644000000000000000000000013014055375162022025 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/private/splitPolygons3d.m0000644000175000017500000000510414055375162023114 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polygons = splitPolygons3d(polygon) %SPLITPOLYGONS3D Convert a NaN separated polygon list to a cell array of polygons. % % Same function as splitpolygons for planar case, included in private % directory of geom3d to avoid missing file problems. % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-10-12, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. if iscell(polygon) % case of a cell array polygons = polygon; elseif sum(isnan(polygon(:))) == 0 % single polygon -> no break polygons = {polygon}; else % find indices of NaN couples inds = find(sum(isnan(polygon), 2) > 0); % number of polygons N = length(inds) + 1; polygons = cell(N, 1); % iterate over NaN-separated regions to create new polygon inds = [0; inds; size(polygon, 1)+1]; for i = 1:N polygons{i} = polygon((inds(i)+1):(inds(i+1)-1), :); end end matgeom-1.2.3/inst/geom3d/private/PaxHeaders.19757/localToGlobal3d.m0000644000000000000000000000013014055375162021655 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/private/localToGlobal3d.m0000644000175000017500000001055414055375162022751 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = localToGlobal3d(varargin) %LOCALTOGLOBAL3D Transformation matrix from local to global coordinate system. % % TRANS = localToGlobal3d(CENTER, THETA, PHI, PSI) % Compute the transformation matrix from a local (or modelling) % coordinate system to the global (or world) coordinate system. % This is a low-level function, used by several drawing functions. % % The transform is defined by: % - CENTER: the position of the local origin into the world coordinate % system % - THETA: colatitude, defined as the angle with the Oz axis (between 0 % and 180 degrees), positive in the direction of the of Oy axis. % - PHI: azimut, defined as the angle of the normal with the Ox axis, % between 0 and 360 degrees % - PSI: intrinsic rotation, corresponding to the rotation of the object % around the direction vector, between 0 and 360 degrees % % The resulting transform is obtained by applying (in that order): % - Rotation by PSI around the Z-axis % - Rotation by THETA around the Y-axis % - Rotation by PHI around the Z-axis % - Translation by vector CENTER % This corresponds to Euler ZYZ rotation, using angles PHI, THETA and % PSI. % % The 'eulerAnglesToRotation3d' function may better suit your needs as % it is more 'natural'. % % Example % localToGlobal3d % % See also % transforms3d, eulerAnglesToRotation3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-06-19, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % HISTORY % 19/08/2009 fix bug in parsing center with 4 args % 2011-06-21 use degrees % extract the components of the transform if nargin == 1 % all components are bundled in the first argument var = varargin{1}; center = var(1:3); theta = var(4); phi = var(5); psi = 0; if length(var) > 5 psi = var(6); end elseif nargin == 4 % arguments = center, then the 3 angles center = varargin{1}; theta = varargin{2}; phi = varargin{3}; psi = varargin{4}; elseif nargin > 4 % center is given in 3 arguments, then 3 angles center = [varargin{1} varargin{2} varargin{3}]; theta = varargin{4}; phi = varargin{5}; psi = 0; if nargin > 5 psi = varargin{6}; end end % conversion from degrees to radians k = pi / 180; % rotation around normal vector axis rot1 = createRotationOz(psi * k); % colatitude rot2 = createRotationOy(theta * k); % longitude rot3 = createRotationOz(phi * k); % shift center tr = createTranslation3d(center); % create final transform by concatenating transforms trans = tr * rot3 * rot2 * rot1; matgeom-1.2.3/inst/geom3d/private/PaxHeaders.19757/parseDrawInput.m0000644000000000000000000000013214055375162021662 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/private/parseDrawInput.m0000644000175000017500000000627214055375162022756 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [hAx, prim, varargin] = parseDrawInput(prim, valFun, type, defOpts, varargin) %PARSEDRAWINPUT Parse input arguments for drawing functions: draw*. % % INPUT: % PRIM: The primitive object: line, plane, ... % VALFUN: An anonymous Function to validate PRIM % TYPE: The drawing type of PRIM: 'line', 'patch', ... % DEFOPTS: The default drawing options for PRIM as struct % % OUTPUT: % HAX: The current or specified axes for drawing % PRIM: validated PRIM % % ------ % Author: oqilipo % Created: 2017-10-13, using R2017b % Copyright 2017 % Check if first input argument is an axes handle if isAxisHandle(prim) hAx = prim; prim = varargin{1}; varargin(1) = []; else hAx = gca; end % Check if the primitive is valid p=inputParser; addRequired(p,'prim',valFun) parse(p,prim) % parse input arguments if there are any if ~isempty(varargin) if length(varargin) == 1 if isstruct(varargin{1}) % if options are specified as struct, need to convert to % parameter name-value pairs varargin = [fieldnames(varargin{1}) struct2cell(varargin{1})]'; varargin = varargin(:)'; else % if option is a single argument, assume it is the color switch type case 'line' varargin = {'Color', varargin{1}}; case 'patch' varargin = {'FaceColor', varargin{1}}; end end end else % If no arguments are given, use the default options varargin = [fieldnames(defOpts) struct2cell(defOpts)]'; varargin = varargin(:)'; end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawBox3d.m0000644000000000000000000000013014055375162017073 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawBox3d.m0000644000175000017500000001013714055375162020164 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawBox3d(box, varargin) % Draw a 3D box defined by coordinate extents. % % drawBox3d(BOX); % Draw a box defined by its coordinate extents: % BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX]. % The function draws only the outline edges of the box. % % Example % % Draw bounding box of a cubeoctehedron % [v e f] = createCubeOctahedron; % box3d = boundingBox3d(v); % figure; hold on; % drawMesh(v, f); % drawBox3d(box3d); % set(gcf, 'renderer', 'opengl') % axis([-2 2 -2 2 -2 2]); % view(3) % % See Also: % boxes3d, boundingBox3d % % --------- % Author: David Legland % e-mail: david.legland@inrae.fr % INRA - TPV URPOI - BIA IMASTE % created the 22/02/2010. % % Parse and check inputs isBox3d = @(x) validateattributes(x,{'numeric'},... {'nonempty','nonnan','real','finite','size',[nan,6]}); defOpts.Color = 'b'; [hAx, box, varargin] = ... parseDrawInput(box, isBox3d, 'line', defOpts, varargin{:}); % box limits xmin = box(:,1); xmax = box(:,2); ymin = box(:,3); ymax = box(:,4); zmin = box(:,5); zmax = box(:,6); nBoxes = size(box, 1); gh=zeros(nBoxes,1); for i=1:nBoxes % lower face (z=zmin) sh(1)=drawEdge3d(hAx, [xmin(i) ymin(i) zmin(i) xmax(i) ymin(i) zmin(i)], varargin{:}); sh(2)=drawEdge3d(hAx, [xmin(i) ymin(i) zmin(i) xmin(i) ymax(i) zmin(i)], varargin{:}); sh(3)=drawEdge3d(hAx, [xmax(i) ymin(i) zmin(i) xmax(i) ymax(i) zmin(i)], varargin{:}); sh(4)=drawEdge3d(hAx, [xmin(i) ymax(i) zmin(i) xmax(i) ymax(i) zmin(i)], varargin{:}); % front face (y=ymin) sh(5)=drawEdge3d(hAx, [xmin(i) ymin(i) zmin(i) xmin(i) ymin(i) zmax(i)], varargin{:}); sh(6)=drawEdge3d(hAx, [xmax(i) ymin(i) zmin(i) xmax(i) ymin(i) zmax(i)], varargin{:}); sh(7)=drawEdge3d(hAx, [xmin(i) ymin(i) zmax(i) xmax(i) ymin(i) zmax(i)], varargin{:}); % left face (x=xmin) sh(8)=drawEdge3d(hAx, [xmin(i) ymax(i) zmin(i) xmin(i) ymax(i) zmax(i)], varargin{:}); sh(9)=drawEdge3d(hAx, [xmin(i) ymin(i) zmax(i) xmin(i) ymax(i) zmax(i)], varargin{:}); % the last 3 remaining edges sh(10)=drawEdge3d(hAx, [xmin(i) ymax(i) zmax(i) xmax(i) ymax(i) zmax(i)], varargin{:}); sh(11)=drawEdge3d(hAx, [xmax(i) ymax(i) zmin(i) xmax(i) ymax(i) zmax(i)], varargin{:}); sh(12)=drawEdge3d(hAx, [xmax(i) ymin(i) zmax(i) xmax(i) ymax(i) zmax(i)], varargin{:}); gh(i) = hggroup(hAx); set(sh,'Parent',gh(i)) end if nargout > 0 varargout = {gh}; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/fitEllipse3d.m0000644000000000000000000000013014055375162017565 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/fitEllipse3d.m0000644000175000017500000002674714055375162020674 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [fittedEllipse3d, TFM3D] = fitEllipse3d(points, varargin) %FITELLIPSE3D Fit an ellipse to a set of points. % % FITTEDELLIPSE3D = fitEllipse3d(POINTS) returns the 3D ellipse fitted to % a set of 3D points. % % Example % % Create 2D ellipse % n=randi([10,100]); % a=randi([30,50]); b=randi([5,25]); % [x, y] = ellipseToPolygon([0 0 a b 0 ], n); % % 3D and add some noise % points = [x, y, zeros(n,1)]; % points=points+(-1+2*rand(n,3)); % % Create a random transformation % center=-100+200*rand(1,3); % phi=randi([-180,180]); theta=randi([-180,180]); psi=randi([-180,180]); % TFM=eulerAnglesToRotation3d(phi, theta, psi, 'ZYZ'); TFM(1:3,4)=center'; % points = transformPoint3d(points, TFM); % % Fit ellipse % [fE, fTFM] = fitEllipse3d(points, 'vis', true); % % Plot reconstructed ellipse % [fx, fy] = ellipseToPolygon([0 0 fE(4), fE(5) 0 ], n); % fpoints = transformPoint3d([fx, fy, zeros(n,1)], fTFM); % drawEllipse3d(fE,'k') % % See also % drawEllipse3d, ellipseToPolygon % % Source % Nested functions are part of the quadfit toolbox by Levente Hunyadi % https://mathworks.com/matlabcentral/fileexchange/45356 % % --------- % Author: oqilipo % Created: 2017-08-11 % Copyright 2017 parser = inputParser; addRequired(parser, 'points', @(x) validateattributes(x, {'numeric'},... {'ncols',3,'real','finite','nonnan'})); addOptional(parser,'visualization',false,@islogical); parse(parser,points,varargin{:}); points=parser.Results.points; % Mean of all points meanPoint = mean(points,1); % Center points around origin centeredPoints = bsxfun(@minus, points, meanPoint); % Transformation to x-y plane [~,~,R]=svd(centeredPoints); tfmPoints = transformPoint3d(centeredPoints, R'); % Fit ellipse parEllipse = ellipsefit_direct(tfmPoints(:,1),tfmPoints(:,2)); % Convert to explicit form [X, Y, A, B, phi2D] = ellipse_im2ex(parEllipse); % Transform to fitted 2d ellipse TFM2D = createRotationOz(phi2D); TFM2D(1:3,4)=[X; Y; 0]; % Transformation back to 3d space TFM3D = [inv(R'), meanPoint'; 0 0 0 1]*TFM2D; % Extract translation center = TFM3D(1:3,4)'; % Extract rotation TFM3D_ROT=TFM3D(1:3,1:3); % Convert to euler angles [PHI, THETA, PSI] = rotation3dToEulerAngles(TFM3D_ROT,'ZYZ'); % Test if psi is correct TFM3D_test = eulerAnglesToRotation3d(PHI, THETA, PSI,'ZYZ'); if ~all(all(ismembertol(TFM3D_test(1:3,1:3), TFM3D_ROT))) PSI=-1*PSI; end % matGeom format fittedEllipse3d=[center A B THETA PHI PSI]; %% Visualization if parser.Results.visualization figure('Color','w'); axis equal tight; hold on; view(3) xlabel('x'); ylabel('y'); zlabel('z'); % Input points scatter3(points(:,1),points(:,2),points(:,3), 'r', 'filled') % Centered points scatter3(centeredPoints(:,1),centeredPoints(:,2),centeredPoints(:,3), 'g', 'filled') % SVD points scatter3(tfmPoints(:,1),tfmPoints(:,2),tfmPoints(:,3), 'b', 'filled') % planeProps.FaceAlpha=0.25; % planeProps.FaceColor='b'; % drawPlane3d([0 0 0 1 0 0 0 1 0],planeProps) % Fitted ellipse drawEllipse3d(fittedEllipse3d) end %% Nested functions function p = ellipsefit_direct(x,y) % Direct least squares fitting of ellipses. % % Input arguments: % x,y; % x and y coodinates of 2D points % % Output arguments: % p: % a 6-parameter vector of the algebraic ellipse fit with % p(1)*x^2 + p(2)*x*y + p(3)*y^2 + p(4)*x + p(5)*y + p(6) = 0 % % References: % Andrew W. Fitzgibbon, Maurizio Pilu and Robert B. Fisher, "Direct Least % Squares Fitting of Ellipses", IEEE Trans. PAMI 21, 1999, pp476-480. % Copyright 2011 Levente Hunyadi narginchk(2,2); validateattributes(x, {'numeric'}, {'real','nonempty','vector'}); validateattributes(y, {'numeric'}, {'real','nonempty','vector'}); x = x(:); y = y(:); % normalize data mx = mean(x); my = mean(y); sx = (max(x)-min(x))/2; sy = (max(y)-min(y))/2; smax = max(sx,sy); sx = smax; sy = smax; x = (x-mx)/sx; y = (y-my)/sy; % build design matrix D = [ x.^2 x.*y y.^2 x y ones(size(x)) ]; % build scatter matrix S = D'*D; % build 6x6 constraint matrix C = zeros(6,6); C(1,3) = -2; C(2,2) = 1; C(3,1) = -2; if 1 p = ellipsefit_robust(S,-C); elseif 0 % solve eigensystem [gevec, geval] = eig(S,C); geval = diag(geval); % extract eigenvector corresponding to unique negative (nonpositive) eigenvalue p = gevec(:,geval < 0 & ~isinf(geval)); r = geval(geval < 0 & ~isinf(geval)); elseif 0 % formulation as convex optimization problem gamma = 0; %#ok<*UNRCH> cvx_begin sdp variable('gamma'); variable('lambda'); maximize(gamma); lambda >= 0; %#ok<*VUNUS> %[ S + lambda*C, zeros(size(S,1),1) ... %; zeros(1,size(S,2)), lambda - gamma ... %] >= 0; S + lambda*C >= 0; lambda - gamma >= 0; cvx_end % recover primal optimal values from dual [evec, eval] = eig(S + lambda*C); eval = diag(eval); [~,ix] = min(abs(eval)); p = evec(:,ix); end % unnormalize p(:) = ... [ p(1)*sy*sy ... ; p(2)*sx*sy ... ; p(3)*sx*sx ... ; -2*p(1)*sy*sy*mx - p(2)*sx*sy*my + p(4)*sx*sy*sy ... ; -p(2)*sx*sy*mx - 2*p(3)*sx*sx*my + p(5)*sx*sx*sy ... ; p(1)*sy*sy*mx*mx + p(2)*sx*sy*mx*my + p(3)*sx*sx*my*my - p(4)*sx*sy*sy*mx - p(5)*sx*sx*sy*my + p(6)*sx*sx*sy*sy ... ]; p = p ./ norm(p); end function p = ellipsefit_robust(R, Q) % Constrained ellipse fit by solving a modified eigenvalue problem. % The method is numerically stable. % % Input arguments: % R: % positive semi-definite data covariance matrix % Q: % constraint matrix in parameters x^2, xy, y^2, x, y and 1. % % Output arguments: % p: % estimated parameters (taking constraints into account) % References: % Radim Halir and Jan Flusser, "Numerically stable direct least squares fitting of % ellipses", 1998 % Copyright 2012 Levente Hunyadi validateattributes(R, {'numeric'}, {'real','2d','size',[6,6]}); validateattributes(Q, {'numeric'}, {'real','2d','size',[6,6]}); % check that constraint matrix has all zeros except in upper left block assert( nnz(Q(4:6,:)) == 0 ); assert( nnz(Q(:,4:6)) == 0 ); S1 = R(1:3,1:3); % quadratic part of the scatter matrix S2 = R(1:3,4:6); % combined part of the scatter matrix S3 = R(4:6,4:6); % linear part of the scatter matrix T = -(S3 \ S2'); % for getting a2 from a1 M = S1 + S2 * T; % reduced scatter matrix M = Q(1:3,1:3) \ M; % premultiply by inv(C1), e.g. M = [M(3,:)./2 ; -M(2,:) ; M(1,:)./2] for an ellipse [evec,~] = eig(M); % solve eigensystem % evaluate a'*C*a, e.g. cond = 4 * evec(1,:).*evec(3,:) - evec(2,:).^2 for an ellipse cond = zeros(1,size(evec,2)); for k = 1 : numel(cond) cond(k) = evec(:,k)'*Q(1:3,1:3)*evec(:,k); end % eigenvector for minimum positive eigenvalue evec = evec(:,cond > 0); cond = cond(cond > 0); [~,ix] = min(cond); p1 = evec(:,ix); % eigenvector for minimum positive eigenvalue % ellipse coefficients p = [p1 ; T * p1]; end function varargout = ellipse_im2ex(varargin) % Cast ellipse defined with implicit parameter vector to explicit form. % % See also: ellipse_ex2im % Copyright 2011 Levente Hunyadi if nargin > 1 narginchk(6,6); for k = 1 : 6 validateattributes(varargin{k}, {'numeric'}, {'real','scalar'}); end [c1,c2,a,b,phi] = ellipse_explicit(varargin{:}); else narginchk(1,1); p = varargin{1}; validateattributes(p, {'numeric'}, {'real','vector'}); p = p(:); validateattributes(p, {'numeric'}, {'size',[6 1]}); [c1,c2,a,b,phi] = ellipse_explicit(p(1), 0.5*p(2), p(3), 0.5*p(4), 0.5*p(5), p(6)); end if nargout > 1 varargout = num2cell([c1,c2,a,b,phi]); else varargout{1} = [c1,c2,a,b,phi]; end function [c1,c2,semia,semib,phi] = ellipse_explicit(a,b,c,d,f,g) % Cast ellipse defined with explicit parameter vector to implicit form. % helper quantities N = 2*(a*f^2+c*d^2+g*b^2-2*b*d*f-a*c*g); D = b^2-a*c; S = realsqrt((a-c)^2+4*b^2); % semi-axes ap = realsqrt( N/(D*(S-(a+c))) ); bp = realsqrt( N/(D*(-S-(a+c))) ); semia = max(ap,bp); semib = min(ap,bp); % center c1 = (c*d-b*f)/D; c2 = (a*f-b*d)/D; % angle of tilt if b ~= 0 if abs(a) < abs(c) phi = 0.5*acot((a-c)/(2*b)); else phi = 0.5*pi+0.5*acot((a-c)/(2*b)); end else if abs(a) < abs(c) phi = 0; else % a > c phi = 0.5*pi; end end end end end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotation3dLineAngle.m0000644000000000000000000000013014055375162022227 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotation3dLineAngle.m0000644000175000017500000000553114055375162023322 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function mat = createRotation3dLineAngle(line, theta) %CREATEROTATION3DLINEANGLE Create rotation around a line by an angle theta. % % MAT = createRotation3dLineAngle(LINE, ANGLE) % % Example % origin = [1 2 3]; % direction = [4 5 6]; % line = [origin direction]; % angle = pi/3; % rot = createRotation3dLineAngle(line, angle); % [axis angle2] = rotation3dAxisAndAngle(rot); % angle2 % angle2 = % 1.0472 % % See also % transforms3d, rotation3dAxisAndAngle, rotation3dToEulerAngles, % eulerAnglesToRotation3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-08-11, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % determine rotation center and direction center = [0 0 0]; if size(line, 2)==6 center = line(1:3); vector = line(4:6); else vector = line; end % normalize vector v = normalizeVector3d(vector); % compute projection matrix P and anti-projection matrix P = v'*v; Q = [0 -v(3) v(2) ; v(3) 0 -v(1) ; -v(2) v(1) 0]; I = eye(3); % compute vectorial part of the transform mat = eye(4); mat(1:3, 1:3) = P + (I - P)*cos(theta) + Q*sin(theta); % add translation coefficient mat = recenterTransform3d(mat, center); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/polygonCentroid3d.m0000644000000000000000000000013014055375162020644 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/polygonCentroid3d.m0000644000175000017500000000565414055375162021745 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function centroid = polygonCentroid3d(varargin) %POLYGONCENTROID3D Centroid (or center of mass) of a polygon. % % PTC = polygonCentroid3d(POLY) % Computes center of mass of a polygon defined by POLY. POLY is a N-by-3 % array of double containing coordinates of polygon vertices. % % PTC = polygonCentroid3d(VX, VY, VZ) % Specifies vertex coordinates as three separate arrays. % % Example % % compute centroid of a basic polygon % poly = [0 0 0; 10 0 10;10 10 20;0 10 10]; % centro = polygonCentroid3d(poly) % centro = % 5.0000 5.0000 10.0000 % % See also % polygons3d, polygonArea3d, polygonCentroid % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-09-18 % Copyright 2007 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if nargin == 1 % polygon is given as a single argument pts = varargin{1}; elseif nargin == 3 % polygon is given as 3 coordinate arrays px = varargin{1}; py = varargin{2}; pz = varargin{3}; pts = [px py pz]; end % create supporting plane (assuming first 3 points are not colinear...) plane = createPlane(pts(1:3, :)); % project points onto the plane pts = planePosition(pts, plane); % compute centroid in 2D centro2d = polygonCentroid(pts); % project back in 3D centroid = planePoint(plane, centro2d); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/createRotationOz.m0000644000000000000000000000013014055375162020532 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/createRotationOz.m0000644000175000017500000000670514055375162021631 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createRotationOz(varargin) %CREATEROTATIONOZ Create the 4x4 matrix of a 3D rotation around z-axis. % % TRANS = createRotationOz(THETA); % Returns the transform matrix corresponding to a rotation by the angle % THETA (in radians) around the Oz axis. A rotation by an angle of PI/2 % would transform the vector [1 0 0] into the vector [0 1 0]. % % The returned matrix has the form: % [cos(THETA) -sin(THETA) 0 0] % [sin(THETA) cos(THETA) 0 0] % [ 0 0 1 0] % [ 0 0 0 1] % % TRANS = createRotationOz(ORIGIN, THETA); % TRANS = createRotationOz(X0, Y0, Z0, THETA); % Also specifies origin of rotation. The result is similar as performing % translation(-X0, -Y0, -Z0), rotation, and translation(X0, Y0, Z0). % % % See also: % transforms3d, transformPoint3d, createRotationOx, createRotationOy % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 2008/11/24 changed convention for angle % 22/04/2009 rename as createcreateRotationOz % default values dx = 0; dy = 0; dz = 0; theta = 0; % get input values if length(varargin) == 1 % only one argument -> rotation angle theta = varargin{1}; elseif length(varargin) == 2 % origin point (as array) and angle var = varargin{1}; dx = var(1); dy = var(2); dz = var(3); theta = varargin{2}; elseif length(varargin) == 4 % origin (x and y) and angle dx = varargin{1}; dy = varargin{2}; dz = varargin{3}; theta = varargin{4}; end % compute coefs cot = cos(theta); sit = sin(theta); % create transformation trans = [... cot -sit 0 0;... sit cot 0 0;... 0 0 1 0;... 0 0 0 1]; % add the translation part t = [1 0 0 dx;0 1 0 dy;0 0 1 dz;0 0 0 1]; trans = t * trans / t; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/cart2cyl.m0000644000000000000000000000013014055375162016761 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/cart2cyl.m0000644000175000017500000000604314055375162020053 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cart2cyl(varargin) %CART2CYL Convert cartesian to cylindrical coordinates. % % CYL = cart2cyl(POINT) % convert the 3D cartesian coordinates of points POINT (given by [X Y Z] % where X, Y, Z have the same size) into cylindrical coordinates CYL, % given by [THETA R Z]. % THETA is the arctangent of the ratio Y/X (between 0 and 2*PI) % R can be computed using sqrt(X^2+Y^2) % Z keeps the same value. % The size of THETA, and R is the same as the size of X, Y and Z. % % CYL = cart2cyl(X, Y, Z) % provides coordinates as 3 different parameters % % Example % cart2cyl([-1 0 2]) % gives : 4.7124 1.0000 2.0000 % % See also agles3d, cart2pol, cart2sph2 % % % ------ % Author: David Legland % e-mail: david.legland@jouy.inra.fr % Created: 2006-03-23 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % process input parameters if length(varargin)==1 var = varargin{1}; x = var(:,1); y = var(:,2); z = var(:,3); elseif length(varargin)==3 x = varargin{1}; y = varargin{2}; z = varargin{3}; end % convert coordinates dim = size(x); theta = reshape(mod(atan2(y(:), x(:))+2*pi, 2*pi), dim); r = reshape(sqrt(x(:).*x(:) + y(:).*y(:)), dim); % process output parameters if nargout==0 ||nargout==1 if length(dim)>2 || dim(2)>1 varargout{1} = {theta r z}; else varargout{1} = [theta r z]; end elseif nargout==3 varargout{1} = theta; varargout{2} = r; varargout{3} = z; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawArrow3d.m0000644000000000000000000000013014055375162017435 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawArrow3d.m0000644000175000017500000001741014055375162020527 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawArrow3d(pos, vec, varargin) %DRAWARROW3D plot a quiver of 3D arrows. % % drawArrow3d(pos, vec) % Plots 3D arrows given the (pos)ition array [x1 y1 z1; x2 y2 z2; ...] % and the (vec)tor array [dx1 dy1 dz1; dx2 dy2 dz2; ...]. % % drawArrow3d(pos, vec, color) % Optional positional argument color conforms to 'ColorSpec.' % For example, 'r','red',[1 0 0] will all plot a quiver with all arrows % as red. This can also be in the form of Nx3 where 'N' is the number of % arrows and each column corresponds to the RGB values. Default color is % black. % % drawArrow3d(...,Name,Value) Optional name-value pair arguments: % 'stemRatio': Ratio of the arrow head (cone) to the arrow stem (cylinder) % For example, setting this value to 0.94 will produce arrows with % arrow stems 94% of the length and short, 6% cones as arrow heads. % Values above 0 and below 1 are valid. Default is 0.75. % 'arrowRadius': changes the radius of the arrowstem. Percentage of the % lenght of the arrow. Values between 0.01 and 0.01 are valid. % Default is 0.025. % Uses the 'patch' function to plot the arrows. 'patch' properties can be % used to control the appearance of the arrows. % % drawArrow3d(AX,...) plots into AX instead of GCA. % % H = drawArrow3d(...) returns the handles of the arrows. % % Example: % [X,Y] = meshgrid(1:5, -2:2); % Z = zeros(size(X)); % pos = [X(:),Y(:),Z(:)]; % vec = zeros(size(pos)); % vec(:,1) = 1; % drawArrow3d(pos, vec, 'g', 'stemRatio', 0.6); % view(3); lighting('phong'); camlight('head'); axis('equal') % % ------ % Authors: Shawn Arseneau, oqilipo % History: % Created: 2006-09-14 by Shawn Arseneau % Updated: 2020-02-08 by oqilipo % Check if first argument is an axes handle if numel(pos) == 1 && ishghandle(pos, 'axes') hAx = pos; pos=vec; vec=varargin{1}; varargin(1)=[]; else hAx = gca; end numArrows = size(pos,1); if numArrows ~= size(vec,1) error(['Number of rows of position and magnitude inputs do not agree. ' ... 'Type ''help drawArrow3d'' for details']); end % Parsing p = inputParser; p.KeepUnmatched = true; isPointArray3d = @(x) validateattributes(x,{'numeric'},... {'nonempty','nonnan','real','finite','size',[nan,3]}); addRequired(p,'pos',isPointArray3d) addRequired(p,'vec',isPointArray3d); addOptional(p,'color', 'k', @(x) validateColor(x, numArrows)); isStemRatio = @(x) validateattributes(x,{'numeric'},{'vector','>', 0, '<', 1}); addParameter(p,'stemRatio', 0.75, isStemRatio); isArrowRadius = @(x) validateattributes(x,{'numeric'},{'scalar','>=', 0.01, '<=', 0.1}); addParameter(p,'arrowRadius',0.025, isArrowRadius); parse(p,pos,vec,varargin{:}); pos = p.Results.pos; vec = p.Results.vec; [~, color] = validateColor(p.Results.color, numArrows); stemRatio = p.Results.stemRatio; if numel(stemRatio) == 1; stemRatio = repmat(stemRatio,numArrows,1); end arrowRadius = p.Results.arrowRadius; if numel(arrowRadius) == 1; arrowRadius = repmat(arrowRadius,numArrows,1); end drawOptions=p.Unmatched; %% Loop through all arrows and plot in 3D hold(hAx,'on') qHandle=gobjects(numArrows,1); for i=1:numArrows qHandle(i) = drawSingleVector3d(hAx, pos(i,:), vec(i,:), color(i,:), ... stemRatio(i),arrowRadius(i),drawOptions); end if nargout > 0 varargout = {qHandle}; end end function [valid, color]=validateColor(color,numArrows) valid=true; [arrowRow, arrowCol] = size(color); if arrowRow==1 if ischar(color) %in ShortName or LongName color format color=repmat(color,numArrows,1); else if arrowCol~=3 error('color in RGBvalue must be of the form 1x3.'); end color=repmat(color,numArrows,1); end elseif arrowRow~=numArrows error('color in RGBvalue must be of the form Nx3.'); end end function arrowHandle = drawSingleVector3d(hAx, pos, vec, color, stemRatio, arrowRadius, drawOptions) %ARROW3D Plot a single 3D arrow with a cylindrical stem and cone arrowhead % % See header of drawArrow3d X = pos(1); Y = pos(2); Z = pos(3); [~, ~, srho] = cart2sph(vec(1), vec(2), vec(3)); %% CYLINDER == STEM cylinderRadius = srho*arrowRadius; cylinderLength = srho*stemRatio; [CX,CY,CZ] = cylinder(cylinderRadius); CZ = CZ.*cylinderLength; % lengthen % Rotate Cylinder [row, col] = size(CX); % initial rotation to coincide with x-axis newEll = transformPoint3d([CX(:), CY(:), CZ(:)],createRotationVector3d([1 0 0],[0 0 -1])); CX = reshape(newEll(:,1), row, col); CY = reshape(newEll(:,2), row, col); CZ = reshape(newEll(:,3), row, col); [row, col] = size(CX); newEll = transformPoint3d([CX(:), CY(:), CZ(:)],createRotationVector3d([1 0 0],vec)); stemX = reshape(newEll(:,1), row, col); stemY = reshape(newEll(:,2), row, col); stemZ = reshape(newEll(:,3), row, col); % Translate cylinder stemX = stemX + X; stemY = stemY + Y; stemZ = stemZ + Z; %% CONE == ARROWHEAD RADIUS_RATIO = 1.5; coneLength = srho*(1-stemRatio); coneRadius = cylinderRadius*RADIUS_RATIO; incr = 4; % Steps of cone increments coneincr = coneRadius/incr; [coneX, coneY, coneZ] = cylinder(cylinderRadius*2:-coneincr:0); % Cone coneZ = coneZ.*coneLength; % Rotate cone [row, col] = size(coneX); newEll = transformPoint3d([coneX(:), coneY(:), coneZ(:)],createRotationVector3d([1 0 0],[0 0 -1])); coneX = reshape(newEll(:,1), row, col); coneY = reshape(newEll(:,2), row, col); coneZ = reshape(newEll(:,3), row, col); newEll = transformPoint3d([coneX(:), coneY(:), coneZ(:)],createRotationVector3d([1 0 0],vec)); headX = reshape(newEll(:,1), row, col); headY = reshape(newEll(:,2), row, col); headZ = reshape(newEll(:,3), row, col); % Translate cone % centerline for cylinder: the multiplier is to set the cone 'on the rim' of the cylinder V = [0, 0, srho*stemRatio]; Vp = transformPoint3d(V,createRotationVector3d([1 0 0],[0 0 -1])); Vp = transformPoint3d(Vp,createRotationVector3d([1 0 0],vec)); headX = headX + Vp(1) + X; headY = headY + Vp(2) + Y; headZ = headZ + Vp(3) + Z; % Draw cylinder & cone hStem = patch(hAx, surf2patch(stemX, stemY, stemZ), 'FaceColor', color, 'EdgeColor', 'none', drawOptions); hold(hAx,'on') hHead = patch(hAx, surf2patch(headX, headY, headZ), 'FaceColor', color, 'EdgeColor', 'none', drawOptions); arrowHandle = hggroup(hAx); set([hStem, hHead],'Parent',arrowHandle); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/orientedBox3d.m0000644000000000000000000000013014055375162017747 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/orientedBox3d.m0000644000175000017500000000741014055375162021040 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box3d = orientedBox3d(pts) %ORIENTEDBOX3D Object-oriented bounding box of a set of 3D points. % % OOBB = orientedBox3d(PTS) % % Example % [v, f] = sphereMesh; % rotMat = eulerAnglesToRotation3d(30, 20, 10); % pts = transformPoint3d(bsxfun(@times, v, [5 3 1]), rotMat); % box3d = orientedBox3d(pts); % figure; drawPoint3d(pts, '.'); hold on; % axis equal; axis([-6 6 -6 6 -5 5]); % h = drawCuboid(box3d); % set(h, 'facecolor', 'none'); % % See also % meshes3d, drawCuboid % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2015-12-01, using Matlab 8.6.0.267246 (R2015b) % Copyright 2015 INRA - Cepia Software Platform. tri = convhulln(pts); nFaces = size(tri, 1); %% identify index of face with smallest width indMinBreadth = 0; minBreadth = Inf; for iFace = 1:nFaces faceInds = tri(iFace, :); plane = createPlane(pts(faceInds, :)); breadth = max(abs(distancePointPlane(pts, plane))); if breadth < minBreadth minBreadth = breadth; indMinBreadth = iFace; end end % compute projection on reference plane refPlane = createPlane(pts(tri(indMinBreadth, :), :)); pts2d = planePosition(projPointOnPlane(pts, refPlane), refPlane); % compute 2D OOBB for projected points box2d = orientedBox(pts2d); % extract reference points from planar OOBB: the center, and two direction % vectors center2d = box2d(1:2); L1 = box2d(3); L2 = box2d(4); markers2d = [0 0; L1/2 0; 0 L2/2]; % orient reference points to 2d basis theta2d = box2d(5); rot = createRotation(deg2rad(theta2d)); tra = createTranslation(center2d); transfo = tra * rot; markers2d = transformPoint(markers2d, transfo); % backprojection to 3D space markers3d = planePoint(refPlane, markers2d); % compute 3D vectors and center centerProj = markers3d(1,:); v1n = normalizeVector3d(markers3d(2,:) - centerProj); v2n = normalizeVector3d(markers3d(3,:) - centerProj); % compute rotation matrix and convert to Euler Angles v3n = crossProduct3d(v1n, v2n); rotMat = [v1n' v2n' v3n']; boxAngles = rotation3dToEulerAngles(rotMat); % create 3D object-oriented bounding box boxCenter3d = centerProj + v3n * minBreadth/2; box3d = [boxCenter3d L1 L2 minBreadth boxAngles]; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/planePoint.m0000644000000000000000000000013014055375162017347 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/planePoint.m0000644000175000017500000000556514055375162020451 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function coord = planePoint(plane, point) %PLANEPOINT Compute 3D position of a point in a plane. % % POINT = planePoint(PLANE, POS) % PLANE is a 9 element row vector [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2] % POS is the coordinate of a point in the plane basis, % POINT is the 3D coordinate in global basis. % % Example % plane = [10 20 30 1 0 0 0 1 1]; % pos2d = [3 4]; % pt = planePoint(plane, pos2d) % pt = % 13 24 34 % % See also % geom3d, planes3d, planePosition % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-09-18, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY % 2013-10-09 remove repmat % size of input arguments npl = size(plane, 1); npt = size(point, 1); % check inputs have compatible sizes if npl ~= npt && npl > 1 && npt > 1 error('geom3d:planePoint:inputSize', ... 'plane and point should have same size, or one of them must have 1 row'); end % basis origin, eventually resized origin = plane(:, 1:3); if npl == 1 && npt > 1 origin = origin(ones(npt,1), :); end % compute 3D coordinate coord = origin + ... bsxfun(@times, plane(:,4:6), point(:,1)) + ... bsxfun(@times, plane(:,7:9), point(:,2)) ; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawSurfPatch.m0000644000000000000000000000013014055375162020013 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawSurfPatch.m0000644000175000017500000000554014055375162021106 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function drawSurfPatch(u, v, z, varargin) %DRAWSURFPATCH Draw a 3D surface patch, with 2 parametrized surfaces. % % usage: % drawSurfPatch(u, v, zuv) % where u, v, and zuv are three matrices the same size, u and % corresponding to each parameter, and zuv being equal to a function of u % and v. % % drawSurfPatch(u, v, zuv, p0) % If p0 is specified, two lines with u(p0(1)) and v(p0(2)) are drawn on % the surface, and corresponding tangent are also shown. % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 24/05/2005. % % HISTORY % 2005-06-08 add doc. % 2007-01-04 remove unused variables and change function name % 2010-03-08 code cleanup, use drawPolyline3d % prepare figure hold on; % draw the surface interior surf(u, v, z, 'FaceColor', 'g', 'EdgeColor', 'none'); % draw the surface boundaries drawPolyline3d(u(1,:), v(1,:), z(1,:)) drawPolyline3d(u(end,:), v(end,:), z(end,:)) drawPolyline3d(u(:,end), v(:,end), z(:,end)) drawPolyline3d(u(:,1), v(:,1), z(:,1)) % eventually draw two perpendicular lines on the surface if ~isempty(varargin) pos = varargin{1}; drawPolyline3d(u(pos(1),:), v(pos(1),:), z(pos(1),:)); drawPolyline3d(u(:,pos(2)), v(:,pos(2)), z(:,pos(2))); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawLine3d.m0000644000000000000000000000013014055375162017232 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawLine3d.m0000644000175000017500000000644314055375162020330 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = drawLine3d(lin, varargin) %DRAWLINE3D Draw a 3D line clipped by the current axes. % % drawLine3d(LINE) draws the line LINE on the current axis, by clipping % with the current axis. % % drawLine3d(LINE, PARAM, VALUE) accepts parameter/value pairs, like % for plot function. Color of the line can also be given as a single % parameter. % % drawLine3d(AX,...) plots into AX instead of GCA. % % H = drawLine3d(...) returns a handle to the created line object. % If the line is not clipped by the axis, function returns -1. % % Example % % draw a sphere together with the three main axes % figure; hold on; % drawSphere([40 30 20 30]); % view(3); axis equal; axis([-20 80 -20 80 -20 80]) % drawLine3d([0 0 0 1 0 0], 'k'); % drawLine3d([0 0 0 0 1 0], 'k'); % drawLine3d([0 0 0 0 0 1], 'k'); % light; % % % See also: % lines3d, createLine3d, clipLine3d, drawRay3d, drawEdge3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/02/2005. % Parse and check inputs isLine3d = @(x) validateattributes(x,{'numeric'},... {'nonempty','nonnan','real','finite','size',[nan,6]}); defOpts.Color = 'b'; [hAx, lin, varargin] = ... parseDrawInput(lin, isLine3d, 'line', defOpts, varargin{:}); % extract limits of the bounding box box = [get(hAx, 'xlim') get(hAx, 'ylim') get(hAx, 'zlim')]; % clip the line with the limits of the current axis edge = clipLine3d(lin, box); % draw the clipped line if sum(isnan(edge)) == 0 hh = drawEdge3d(hAx, edge); if ~isempty(varargin) set(hh, varargin{:}); end else hh = []; end % process output if nargout > 0 h = hh; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/points3d.m0000644000000000000000000000013014055375162017001 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/points3d.m0000644000175000017500000000430014055375162020065 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points3d(varargin) %POINTS3D Description of functions operating on 3D points. % % Points are represented by their 3 Cartesian coordinates: % P = [X Y Z]; % % Arrays of points consist in N*3 arrays, each row being a point. % % See also % isCoplanar, distancePoints, boundingBox3d % anglePoints3d, angleSort3d, sphericalAngle % sph2cart2, cart2sph2, cart2cyl, cyl2cart % transformPoint3d, clipPoints3d % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/intersectLinePolygon3d.m0000644000000000000000000000013014055375162021645 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/intersectLinePolygon3d.m0000644000175000017500000000742614055375162022745 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [inter, inside]= intersectLinePolygon3d(line, poly) %INTERSECTLINEPOLYGON3D Intersection point of a 3D line and a 3D polygon. % % INTER = intersectLinePolygon3d(LINE, POLY) % Compute coordinates of intersection point between the 3D line LINE and % the 3D polygon POLY. LINE is a 1-by-6 row vector containing origin and % direction vector of the line, POLY is a Np-by-3 array containing % coordinates of 3D polygon vertices. % INTER is a 1-by-3 row vector containing coordinates of intersection % point, or [NaN NaN NaN] if line and polygon do not intersect. % % INTERS = intersectLinePolygon3d(LINES, POLY) % If LINES is a N-by-6 array representing several lines, the result % INTERS is a N-by-3 array containing coordinates of intersection of each % line with the polygon. % % [INTER INSIDE] = intersectLinePolygon3d(LINE, POLY) % Also return a N-by-1 boolean array containing TRUE if the corresponding % polygon contains the intersection point. % % Example % % Compute intersection between a 3D line and a 3D triangle % pts3d = [3 0 0; 0 6 0;0 0 9]; % line1 = [0 0 0 3 6 9]; % inter = intersectLinePolygon3d(line1, pts3d) % inter = % 1 2 3 % % % keep only valid intersections with several lines % pts3d = [3 0 0; 0 6 0;0 0 9]; % lines = [0 0 0 1 2 3;10 0 0 1 2 3]; % [inter inside] = intersectLinePolygon3d(line1, pts3d); % inter(inside, :) % ans = % 1 2 3 % % See Also % intersectLinePolygon, intersectRayPolygon3d, intersectLinePlane % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % supporting plane of polygon vertices plane = createPlane(poly(1:3, :)); % intersection of 3D line with the plane inter = intersectLinePlane(line, plane); % project all points on reference plane pts2d = planePosition(poly, plane); pInt2d = planePosition(inter, plane); % need to check polygon orientation inside = xor(isPointInPolygon(pInt2d, pts2d), polygonArea(pts2d) < 0); % intersection points outside the polygon are set to NaN inter(~inside, :) = NaN; matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/transformVector3d.m0000644000000000000000000000013014055375162020663 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/transformVector3d.m0000644000175000017500000000600014055375162021746 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = transformVector3d(varargin) %TRANSFORMVECTOR3D Transform a vector with a 3D affine transform. % % V2 = transformVector3d(V1, TRANS); % Computes the vector obtained by transforming vector V1 with affine % transform TRANS. % V1 has the form [x1 y1 z1], and TRANS is a [3x3], [3x4], or [4x4] % matrix, with one of the forms: % [a b c] , [a b c j] , or [a b c j] % [d e f] [d e f k] [d e f k] % [g h i] [g h i l] [g h i l] % [0 0 0 1] % % V2 = transformVector3d(V1, TRANS) also works when V1 is a [Nx3xMxEtc] % array of double. In this case, V2 has the same size as V1. % % V2 = transformVector3d(X1, Y1, Z1, TRANS); % Specifies vectors coordinates in three arrays with same size. % % [X2 Y2 Z2] = transformVector3d(...); % Returns the coordinates of the transformed vector separately. % % % See also: % vectors3d, transforms3d, transformPoint3d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 25/11/2008 from transformPoint3d % if nargin~=2 && nargin~=4 error('Invalid number of input arguments. Type ''help transformVector3d'' for details.'); end % Extract only the linear part of the affine transform trans = varargin{end}; trans(1:4,4) = [0; 0; 0; 1]; % Call transformPoint3d using equivalent output arguments varargout = cell(1, max(1,nargout)); [varargout{:}] = transformPoint3d(varargin{1:end-1}, trans); matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/clipConvexPolygon3dHP.m0000644000000000000000000000013014055375162021377 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/clipConvexPolygon3dHP.m0000644000175000017500000000640514055375162022473 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = clipConvexPolygon3dHP(poly, plane) %CLIPCONVEXPOLYGON3DHP Clip a convex 3D polygon with Half-space. % % POLY2 = clipConvexPolygon3dHP(POLY, PLANE) % POLY is a N-by-3 array of points, and PLANE is given as: % [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2]. % The result POLY2 is also an array of 3d points, sometimes smaller than % poly, and that can be 0-by-3 (empty polygon). % % POLY2 = clipConvexPolygon3dHP(POLY, PT0, NORMAL) % uses plane with normal NORMAL and containing point PT0. % % % See also: % polygons3d, polyhedra % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-01-05 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY % 2007/14/09 fix postprocessing of last point % ensure last point is the same as the first one if sum(poly(end, :) == poly(1,:)) ~= 3 poly = [poly; poly(1,:)]; end % initialize empty polygon poly2 = zeros(0, 2); % compute visible points below = isBelowPlane(poly, plane); % case of empty polygon if sum(below) == 0 return; end % case of totally clipped polygon if sum(below) == length(below) poly2 = poly; return; end % indices of edges intersecting the plane ind = find(below ~= below([2:end 1])); % compute intersection points: they are 2 for a convex polygon lines = createLine3d(poly(ind, :), poly(ind+1, :)); pInt = intersectLinePlane(lines, plane); % insert intersection points and remove invisible points if below(1) poly2 = [poly(1:ind(1), :); pInt; poly(ind(2)+1:end, :)]; else poly2 = [pInt(1, :); poly(ind(1)+1:ind(2), :); pInt(2, :)]; end % remove last point if it is the same as the first one if sum(poly2(end, :) == poly2(1,:)) == 3 poly2(end, :) = []; end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/planesBisector.m0000644000000000000000000000013014055375162020213 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/planesBisector.m0000644000175000017500000000771114055375162021310 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function out = planesBisector(plane1, plane2) % PLANESBISECTOR Bisector plane between two other planes. % % BIS = planesBisector(PL1, PL2); % Returns the planes that contains the intersection line between PL1 and % PL2 and that bisect the dihedral angle of PL1 and PL2. % Note that computing the bisector of PL2 and PL1 (in that order) returns % the same plane but with opposite orientation. % % Example % % Draw two planes together with their bisector % pl1 = createPlane([3 4 5], [1 2 3]); % pl2 = createPlane([3 4 5], [2 -3 4]); % % compute bisector % bis = planesBisector(pl1, pl2); % % setup display % figure; hold on; axis([0 10 0 10 0 10]); % set(gcf, 'renderer', 'opengl') % view(3); % % draw the planes % drawPlane3d(pl1, 'g'); % drawPlane3d(pl2, 'g'); % drawPlane3d(bis, 'b'); % % See also % planes3d, dihedralAngle, intersectPlanes % % Author: Ben X. Kang % Dept. Orthopaedics & Traumatology % Li Ka Shing Faculty of Medicine % The University of Hong Kong % Pok Fu Lam, Hong Kong % % Let the two planes be defined by equations % % a1*x + b1*y + c1*z + d1 = 0 % % and % % a2*x + b2*y + c2*z + d2 = 0 % % in which vectors [a1,b1,c1] and [a2,b2,c2] are normalized to be of unit % length (a^2+b^2+c^2 = 1). Then % % (a1+a2)*x + (b1+b2)*y + (c1+c2)*z + (d1+d2) = 0 % % is the equation of the desired plane which bisects the dihedral angle % between the two planes. These coefficients cannot be all zero because % the two given planes are not parallel. % % Notice that there is a second solution to this problem % % (a1-a2)*x + (b1-b2)*y + (c1-c2)*z + (d1-d2) = 0 % % which also is a valid plane and orthogonal to the first solution. One of % these planes bisects the acute dihedral angle, and the other the % supplementary obtuse dihedral angle, between the two given planes. P1 = plane1(1:3); % a point on the plane n1 = planeNormal(plane1); % the normal of the plane % d1 = -dot(n1, P1); % for line equation P2 = plane2(1:3); n2 = planeNormal(plane2); % d2 = -dot(n2, P2); if ~isequal(P1(1:3), P2(1:3)) L = intersectPlanes(plane1, plane2); % intersection of the given two planes Pt = L(1:3); % a point on the line intersection % v2 = cross(n1-n2, L(4:6)); % another vector lie on the bisect plane % out = [v1, v2]'; else Pt = P1(1:3); end % use column-wise vector out = createPlane(Pt, n1 - n2); %% EOF %% matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/rotation3dToEulerAngles.m0000644000000000000000000000013014055375162021756 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/rotation3dToEulerAngles.m0000644000175000017500000002107614055375162023053 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = rotation3dToEulerAngles(mat, varargin) %ROTATION3DTOEULERANGLES Extract Euler angles from a rotation matrix. % % [PHI, THETA, PSI] = rotation3dToEulerAngles(MAT) % Computes Euler angles PHI, THETA and PSI (in degrees) from a 3D 4-by-4 % or 3-by-3 rotation matrix. % % ANGLES = rotation3dToEulerAngles(MAT) % Concatenates results in a single 1-by-3 row vector. This format is used % for representing some 3D shapes like ellipsoids. % % ... = rotation3dToEulerAngles(MAT, CONVENTION) % CONVENTION specifies the axis rotation sequence. Default is 'ZYX'. % Supported conventions are: % 'ZYX','ZXY','YXZ','YZX','XYZ','XZY' % 'ZYZ','ZXZ','YZY','YXY','XZX','XYX' % % Example % rotation3dToEulerAngles % % References % Code from '1994 - Shoemake - Graphics Gems IV: Euler Angle Conversion: % http://webdocs.cs.ualberta.ca/~graphics/books/GraphicsGems/gemsiv/euler_angle/EulerAngles.c % (see also rotm2eul, that is part of MATLAB's Robotics System Toolbox) % Modified using explanations in: % http://www.gregslabaugh.net/publications/euler.pdf % https://www.geometrictools.com/Documentation/EulerAngles.pdf % % See also % transforms3d, rotation3dAxisAndAngle, createRotation3dLineAngle, % eulerAnglesToRotation3d % % % ------ % Authors: David Legland, oqilipo % e-mail: david.legland@grignon.inra.fr % Created: 2010-08-11, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. p = inputParser; validStrings = {... 'ZYX','ZXY','YXZ','YZX','XYZ','XZY',... 'ZYZ','ZXZ','YZY','YXY','XZX','XYX'}; addOptional(p,'convention','ZYX',@(x) any(validatestring(x,validStrings))); logParValidFunc = @(x) (islogical(x) || isequal(x,1) || isequal(x,0)); addParameter(p,'IsRotation', 1, logParValidFunc); valTol = @(x) validateattributes(x,{'numeric'},{'scalar', '>=',eps(class(mat)), '<=',1}); addParameter(p,'tolerance', 1e-8, valTol); parse(p,varargin{:}); convention=p.Results.convention; isRotation = p.Results.IsRotation; tolerance = p.Results.tolerance; if isRotation if ~isTransform3d(mat(1:3,1:3), 'rotation', 1, 'tolerance', tolerance) warning(['Rotation matrix contains reflection or scaling ' ... 'tested with a tolerance of ' num2str(tolerance) '.' newline ... 'Calculation of euler angles might be incorrect.']) end end switch convention case 'ZYX' % extract |cos(theta)| cy = hypot(mat(1,1), mat(2,1)); % avoid dividing by 0 if cy > 16*eps % normal case: theta <> 0 phi = atan2( mat(2,1), mat(1,1)); theta = atan2(-mat(3,1), cy); psi = atan2( mat(3,2), mat(3,3)); else phi = 0; theta = atan2(-mat(3,1), cy); psi = atan2(-mat(2,3), mat(2,2)); end case 'ZXY' cy = hypot(mat(2,2), mat(1,2)); if cy > 16*eps phi = -atan2( mat(1,2), mat(2,2)); theta = -atan2(-mat(3,2), cy); psi = -atan2( mat(3,1), mat(3,3)); else phi = 0; theta = -atan2(-mat(3,2), cy); psi = -atan2(-mat(1,3), mat(1,1)); end case 'YXZ' cy = hypot(mat(3,3), mat(1,3)); if cy > 16*eps phi = atan2( mat(1,3), mat(3,3)); theta = atan2(-mat(2,3), cy); psi = atan2( mat(2,1), mat(2,2)); else phi = 0; theta = atan2(-mat(2,3), cy); psi = atan2(-mat(1,2), mat(1,1)); end case 'YZX' cy = hypot(mat(1,1), mat(3,1)); if cy > 16*eps phi = -atan2( mat(3,1), mat(1,1)); theta = -atan2(-mat(2,1), cy); psi = -atan2( mat(2,3), mat(2,2)); else phi = 0; theta = -atan2(-mat(2,1), cy); psi = -atan2(-mat(3,2), mat(3,3)); end case 'XYZ' cy = hypot(mat(3,3), mat(2,3)); if cy > 16*eps phi = -atan2( mat(2,3), mat(3,3)); theta = -atan2(-mat(1,3), cy); psi = -atan2( mat(1,2), mat(1,1)); else phi = 0; theta = -atan2(-mat(1,3), cy); psi = -atan2(-mat(2,1), mat(2,2)); end case 'XZY' cy = hypot(mat(2,2), mat(3,2)); if cy > 16*eps phi = atan2( mat(3,2), mat(2,2)); theta = atan2(-mat(1,2), cy); psi = atan2( mat(1,3), mat(1,1)); else phi = 0; theta = atan2(-mat(1,2), cy); psi = atan2(-mat(3,1), mat(3,3)); end case 'ZYZ' cy = hypot(mat(3,2), mat(3,1)); if cy > 16*eps phi = -atan2(mat(2,3), -mat(1,3)); theta = -atan2(cy, mat(3,3)); psi = -atan2(mat(3,2), mat(3,1)); else phi = 0; theta = -atan2(cy, mat(3,3)); psi = -atan2(-mat(2,1), mat(2,2)); end case 'ZXZ' cy = hypot(mat(3,2), mat(3,1)); if cy > 16*eps phi = atan2(mat(1,3), -mat(2,3)); theta = atan2(cy, mat(3,3)); psi = atan2(mat(3,1), mat(3,2)); else phi = 0; theta = atan2(cy, mat(3,3)); psi = atan2(-mat(1,2), mat(1,1)); end case 'YZY' cy = hypot(mat(2,3), mat(2,1)); if cy > 16*eps phi = atan2(mat(3,2), -mat(1,2)); theta = atan2(cy, mat(2,2)); psi = atan2(mat(2,3), mat(2,1)); else phi = 0; theta = atan2(cy, mat(2,2)); psi = atan2(-mat(3,1), mat(3,3)); end case 'YXY' cy = hypot(mat(2,3), mat(2,1)); if cy > 16*eps phi = -atan2(mat(1,2), -mat(3,2)); theta = -atan2(cy, mat(2,2)); psi = -atan2(mat(2,1), mat(2,3)); else phi = 0; theta = -atan2(cy, mat(2,2)); psi = -atan2(-mat(1,3), mat(1,1)); end case 'XZX' cy = hypot(mat(1,3), mat(1,2)); if cy > 16*eps phi = -atan2(mat(3,1), -mat(2,1)); theta = -atan2(cy, mat(1,1)); psi = -atan2(mat(1,3), mat(1,2)); else phi = 0; theta = -atan2(cy, mat(1,1)); psi = -atan2(-mat(3,2), mat(3,3)); end case 'XYX' cy = hypot(mat(1,2), mat(1,3)); if cy > 16*eps phi = atan2(mat(2,1), -mat(3,1)); theta = atan2(cy, mat(1,1)); psi = atan2(mat(1,2), mat(1,3)); else phi = 0; theta = atan2(cy, mat(1,1)); psi = atan2(-mat(2,3), mat(2,2)); end end % format output arguments if nargout <= 1 % one array varargout{1} = rad2deg([phi theta psi]); else % three separate arrays varargout = cellfun(@rad2deg, {phi theta psi},'uni',0); end matgeom-1.2.3/inst/geom3d/PaxHeaders.19757/drawPolygon3d.m0000644000000000000000000000013014055375162017772 xustar0029 mtime=1622538866.05481366 29 atime=1622538866.05481366 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom3d/drawPolygon3d.m0000644000175000017500000000777214055375162021076 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPolygon3d(varargin) %DRAWPOLYGON3D Draw a 3D polygon specified by a list of vertex coords. % % drawPolygon3d(POLY); % packs coordinates in a single N-by-3 array. % % drawPolygon3d(PX, PY, PZ); % specifies coordinates in separate numeric vectors (either row or % columns) % % drawPolygon3d(..., PARAM, VALUE); % Specifies style options to draw the polyline, see plot for details. % % H = drawPolygon3d(...); % also returns a handle to the list of created line objects. % % Example % t = linspace(0, 2*pi, 100)'; % xt = 10 * cos(t); % yt = 5 * sin(t); % zt = zeros(1,100); % figure; drawPolygon3d(xt, yt, zt, 'b'); % % See Also: % polygons3d, fillPolygon3d, drawPolyline3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-08-17 from drawPolyline3d, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % HISTORY % 2019-02-02 add support for multiple polygons %% Process input arguments % extract handle of axis to draw on ax = gca; var1 = varargin{1}; if isAxisHandle (var1) ax = var1; varargin(1) = []; end % check case we want to draw several curves, stored in a cell array var1 = varargin{1}; if iscell(var1) hold on; h = []; for i = 1:length(var1(:)) h = [h; drawPolygon3d(ax, var1{i}, varargin{2:end})]; %#ok end if nargout > 0 varargout{1} = h; end return; end %% extract polygon coordinates if min(size(var1)) == 1 % if first argument is a vector (either row or column), then assumes % first argument contains x coords, second argument contains y coords % and third one the z coords px = var1; if length(varargin) < 3 error('geom3d:drawPolygon3d:Wrong number of arguments in fillPolygon3d'); end py = varargin{2}; pz = varargin{3}; varargin = varargin(4:end); else % first argument contains both coordinate px = var1(:, 1); py = var1(:, 2); pz = var1(:, 3); varargin = varargin(2:end); end %% draw the polygon % check that the polygon is closed if px(1) ~= px(end) || py(1) ~= py(end) || pz(1) ~= pz(end) px = [px(:); px(1)]; py = [py(:); py(1)]; pz = [pz(:); pz(1)]; end % draw the closed curve h = plot3(ax, px, py, pz, varargin{:}); %% Format output if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/PaxHeaders.19757/__matgeom_package_register__.m0000644000000000000000000000013214055375162021666 xustar0030 mtime=1622538866.118813416 30 atime=1622538866.118813416 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/__matgeom_package_register__.m0000644000175000017500000000377614055375162022770 0ustar00juanpijuanpi00000000000000## Copyright (C) 2016 Carnë Draug ## ## 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 ## . ## -*- texinfo -*- ## @deftypefn {} {} __matgeom_package_register__ () ## Undocumented internal function of matgeom package. ## @end deftypefn ## PKG_ADD: __matgeom_package_register__ (1); ## PKG_DEL: __matgeom_package_register__ (-1); function subdir_paths = __matgeom_package_register__ (loading = 0) subdirlist = {"utils", "geom2d", "polygons2d", "graphs",... "geom3d","meshes3d","polynomialCurves2d"}; ## Get full path, with luck we can retreive the package name from here base_pkg_path = fileparts (make_absolute_filename (mfilename ("fullpath"))); subdir_paths = fullfile (base_pkg_path, subdirlist); if (loading > 0) ## Disable dummy verLessThan.m if compare_versions (version, '6.0.0', '>=') ## Check if this package still has varLessThan pkgverchecker = fullfile (base_pkg_path, 'verLessThan.'); if exist ([pkgverchecker, 'm'], 'file') warning ('Octave:deprecated-function', 'Permanently renaming verLessThan.m since it is already present'); ## The change is permanent and done only once ## Means that if testing in older version of Octave, needs re-install rename([pkgverchecker, 'm'], [pkgverchecker, 'deprecated']); endif endif addpath (subdir_paths{:}); elseif (loading < 0) rmpath (subdir_paths{:}); endif endfunction matgeom-1.2.3/inst/PaxHeaders.19757/verLessThan.m0000644000000000000000000000013214055375162016320 xustar0030 mtime=1622538866.118813416 30 atime=1622538866.118813416 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/verLessThan.m0000644000175000017500000000221214055375162017402 0ustar00juanpijuanpi00000000000000## Copyright (C) 2019 Juan Pablo Carbajal ## ## 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 . ## Author: Juan Pablo Carbajal ## Created: 2019-11-20 ## -*- texinfo -*- ## @defun {@var{x} =} verLessThan () ## Dummy function that retunrs true to all Matlab version queries. ## ## This function assumes that octave can cope with code written for the latest ## matlab version. ## ## It will be removed when Octave 6.0.0 is released as verLessThan in shipped ## with it. ## ## @end defun function tf = verLessThan () tf = false; endfunction matgeom-1.2.3/inst/PaxHeaders.19757/geom2d0000644000000000000000000000013214055375161015003 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/0000755000175000017500000000000014055375161016145 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointOnLine.m0000644000000000000000000000013214055375162017771 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointOnLine.m0000644000175000017500000000600314055375162021055 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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-by-2 array of points, B is a N-by-1 array of booleans. % % If LINE is a N-by-4 array of line, B is a 1-by-N array of booleans. % % B = isPointOnLine(POINT, LINE, TOL) % Specifies the tolerance used for testing location on 3D line. Default value is 1e-14. % % See also: % lines2d, points2d, isPointOnEdge, isPointOnRay, isLeftOriented % % --------- % 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 % 17/12/2013 replace repmat by bsxfun (faster) % extract computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % test if lines are colinear, using third coordinate of 3D cross-product % same test as: % b = abs((xp-x0).*dy-(yp-y0).*dx)./hypot(dx, dy).^2 < tol; b = bsxfun(... @rdivide, abs(... bsxfun(@times, bsxfun(@minus, point(:,1), line(:,1)'), line(:,4)') - ... bsxfun(@times, bsxfun(@minus, point(:,2), line(:,2)'), line(:,3)')), ... (line(:,3).^2 + line(:,4).^2)') < tol; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/sedgewick_points.txt0000644000000000000000000000013214055375161021162 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/sedgewick_points.txt0000644000175000017500000000015714055375161022252 0ustar00juanpijuanpi0000000000000013 19 21 11 16 18 14 13 15 25 18 21 11 16 17 14 19 17 24 15 20 23 26 24 25 12 23 26 13 22 22 20 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/mergeBoxes.m0000644000000000000000000000013214055375162017337 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/mergeBoxes.m0000644000175000017500000000500714055375162020426 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = mergeBoxes(box1, box2) %MERGEBOXES Merge two boxes, by computing their greatest extent. % % BOX = mergeBoxes(BOX1, BOX2); % % Example % box1 = [5 20 5 30]; % box2 = [0 15 0 15]; % mergeBoxes(box1, box2) % ans = % 0 20 0 30 % % % See also % boxes2d, drawBox, intersectBoxes % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % unify sizes of data if size(box1,1) == 1 box1 = repmat(box1, size(box2,1), 1); elseif size(box2, 1) == 1 box2 = repmat(box2, size(box1,1), 1); elseif size(box1,1) ~= size(box2,1) error('Bad size for inputs'); end % compute extreme coords mini = min(box1(:,[1 3]), box2(:,[1 3])); maxi = max(box1(:,[2 4]), box2(:,[2 4])); % concatenate result into a new box structure box = [mini(:,1) maxi(:,1) mini(:,2) maxi(:,2)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/rotateVector.m0000644000000000000000000000013214055375162017720 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/rotateVector.m0000644000175000017500000000434114055375162021007 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vr = rotateVector(v, angle) %ROTATEVECTOR Rotate a vector by a given angle. % % VR = rotateVector(V, THETA) % Rotate the vector V by an angle THETA, given in radians. % % Example % rotateVector([1 0], pi/2) % ans = % 0 1 % % See also % vectors2d, transformVector, createRotation % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-04-14, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % precomputes angles cot = cos(angle); sit = sin(angle); % compute rotated coordinates vr = [cot * v(:,1) - sit * v(:,2) , sit * v(:,1) + cot * v(:,2)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointOnRay.m0000644000000000000000000000013214055375162017635 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointOnRay.m0000644000175000017500000000711514055375162020726 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPointOnRay(point, ray, varargin) %ISPOINTONRAY Test if a point belongs to a ray. % % B = isPointOnRay(PT, RAY); % Returns 1 if point PT belongs to the ray RAY. % PT is given by [x y] and RAY by [x0 y0 dx dy]. % % If PT is a N-by-2 array, and RAY is a M-by-4 array, then the result is % a N-by-M array containing the result of each pair-wise test. % % B = isPointOnRay(PT, RAY, TOL); % Specifies the tolerance to use for testing if point is on the ray. % % Example % ray = [10 20 3 4]; % % test for a point on the ray % p1 = [16 28]; % isPointOnRay(p1, ray) % ans = % logical % 0 % % test for a point on the supporting line but "before" the origin % p2 = [7 16]; % isPointOnRay(p1, ray) % ans = % logical % 0 % % See also: % rays2d, points2d, isPointOnLine, isPointOnEdge % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 07/07/2005 normalize condition to test if on the line and add support % of multiple rays or points % 22/05/2009 rename to isPointOnRay, add psb to specify tolerance % 26/01/2010 was drawing a line before making test % extract computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % number of rays and points Nr = size(ray, 1); Np = size(point, 1); % if several rays or several points, adapt sizes of arrays x0 = repmat(ray(:,1)', Np, 1); y0 = repmat(ray(:,2)', Np, 1); dx = repmat(ray(:,3)', Np, 1); dy = repmat(ray(:,4)', Np, 1); xp = repmat(point(:,1), 1, Nr); yp = repmat(point(:,2), 1, Nr); % test if points belongs to the supporting line b1 = abs((xp-x0).*dy - (yp-y0).*dx) ./ (dx.*dx + dy.*dy) < tol; % check if points lie the good direction on the rays ind = abs(dx) > abs(dy); t = zeros(size(b1)); t(ind) = (xp(ind) - x0(ind)) ./ dx(ind); t(~ind) = (yp(~ind) - y0(~ind)) ./ dy(~ind); % combine the two tests b = b1 & (t >= 0); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointInTriangle.m0000644000000000000000000000013214055375162020641 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointInTriangle.m0000644000175000017500000000713014055375162021727 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPointInTriangle(point, p1, p2, p3) %ISPOINTINTRIANGLE Test if a point is located inside a triangle. % % B = isPointInTriangle(POINT, V1, V2, V3) % POINT is a 1-by-2 row vector containing coordinates of the test point, % V1, V2 and V3 are 1-by-2 row vectors containing coordinates of triangle % vertices. The function returns 1 is the point is inside or on the % boundary of the triangle, and 0 otherwise. % % B = isPointInTriangle(POINT, VERTICES) % Specifiy the coordinates of vertices as a 3-by-2 array. % % If POINT contains more than one row, the result B has as many rows as % the input POINT. % % % Example % % vertices of the triangle % p1 = [0 0]; % p2 = [10 0]; % p3 = [5 10]; % tri = [p1;p2;p3]; % % check if points are inside % isPointInTriangle([0 0], tri) % ans = % 1 % isPointInTriangle([5 5], tri) % ans = % 1 % isPointInTriangle([10 5], tri) % ans = % 0 % % check for an array of points % isPointInTriangle([0 0;1 0;0 1], tri) % ans = % 1 % 1 % 0 % % See also % polygons2d, isPointInPolygon, isCounterClockwise % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-05-16, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % if triangle vertices are given as a single array, extract vertices if nargin == 2 p2 = p1(2, :); p3 = p1(3, :); p1 = p1(1, :); end % check triangle orientation isDirect = isCounterClockwise(p1, p2, p3); % check location of point with respect to each side if isDirect b12 = isCounterClockwise(p1, p2, point) >= 0; b23 = isCounterClockwise(p2, p3, point) >= 0; b31 = isCounterClockwise(p3, p1, point) >= 0; else b12 = isCounterClockwise(p1, p2, point) <= 0; b23 = isCounterClockwise(p2, p3, point) <= 0; b31 = isCounterClockwise(p3, p1, point) <= 0; end % combines the 3 results b = b12 & b23 & b31; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/fitPolynomialTransform2d.m0000644000000000000000000000013214055375162022207 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/fitPolynomialTransform2d.m0000644000175000017500000000610214055375162023273 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function coeffs = fitPolynomialTransform2d(pts, ptsRef, degree) %FITPOLYNOMIALTRANSFORM2D Coefficients of polynomial transform between two point sets. % % COEFFS = fitPolynomialTransform2d(PTS, PTSREF, DEGREE) % % Example % % See also % polynomialTransform2d, fitAffineTransform2d % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2013-11-05, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. %% Extract data % ensure degree is valid if nargin < 3 degree = 3; end % polygon coordinates xi = pts(:,1); yi = pts(:,2); nCoords = size(pts, 1); % check inputs have same size if size(ptsRef, 1) ~= nCoords error('fitPolynomialTransform2d:sizeError', ... 'input arrays must have same number of points'); end %% compute coefficient matrix % number of coefficients of polynomial transform nCoeffs = prod(degree + [1 2]) / 2; % initialize matrix A1 = zeros(nCoords, nCoeffs); % iterate over degrees iCoeff = 0; for iDegree = 0:degree % iterate over binomial coefficients of a given degree for k = 0:iDegree iCoeff = iCoeff + 1; A1(:, iCoeff) = ones(nCoords, 1) .* power(xi, iDegree-k) .* power(yi, k); end end % concatenate matrix for both coordinates A = kron(A1, [1 0;0 1]); %% solve linear system that minimizes least squares % create the vector of expected values b = ptsRef'; b = b(:); % solve the system coeffs = (A \ b)'; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/boxToPolygon.m0000644000000000000000000000013214055375162017702 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/boxToPolygon.m0000644000175000017500000000467314055375162021001 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly = boxToPolygon(box) %BOXTOPOLYGON Convert a bounding box to a square polygon. % % poly = boxToPolygon(box) % Utility function that convert box data in [XMIN XMAX YMIN YMAX] format % to polygon data corresponding to the box boundary. The resulting POLY % is a 4-by-2 array. % % % Example % box = [ 10 50 20 40]; % poly = boxToPolygon(box) % poly = % 10 20 % 50 20 % 50 40 % 10 40 % % See also % boxes2d, polygons2d, boxToRect % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2017-09-10, using Matlab 8.6.0.267246 (R2015b) % Copyright 2017 INRA - Cepia Software Platform. % extreme coordinates xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % convert to polygon poly = [... xmin ymin; ... xmax ymin; ... xmax ymax; ... xmin ymax]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawBox.m0000644000000000000000000000013214055375162016645 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawBox.m0000644000175000017500000000637114055375162017741 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawBox(box, varargin) %DRAWBOX Draw a box defined by coordinate extents. % % drawBox(BOX) % Draws a box defined by its extent: BOX = [XMIN XMAX YMIN YMAX]. % % drawBox(..., NAME, VALUE) % Specifies drawing parameters using parameter name and value. See plot % function for syntax. % % drawBox(AX, ...) % Specifies the handle of the axis to draw on. % % Example % % define some points, compute their box, display everything % points = [10 30; 20 50; 20 20; 30 10;40 30;50 20]; % box = pointSetBounds(points); % figure; hold on; % drawPoint(points, 's'); % drawBox(box); % axis([0 60 0 60]); % % See Also: % drawOrientedBox, drawRect % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/12/2003. % % HISTORY % 2010-02-22 creation % 2011-04-01 add support for drawing option, fix bug for several boxes % 2011-10-11 add management of axes handle % extract handle of axis to draw on if isAxisHandle(box) ax = box; box = varargin{1}; varargin(1) = []; else ax = gca; end % default values xmin = box(:,1); xmax = box(:,2); ymin = box(:,3); ymax = box(:,4); nBoxes = size(box, 1); r = zeros(nBoxes, 1); % iterate on boxes for i = 1:nBoxes % exract min and max values tx(1) = xmin(i); ty(1) = ymin(i); tx(2) = xmax(i); ty(2) = ymin(i); tx(3) = xmax(i); ty(3) = ymax(i); tx(4) = xmin(i); ty(4) = ymax(i); tx(5) = xmin(i); ty(5) = ymin(i); % display polygon r(i) = plot(ax, tx, ty, varargin{:}); end % format output if nargout > 0 varargout = {r}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createRotation90.m0000644000000000000000000000013214055375162020373 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createRotation90.m0000644000175000017500000000734014055375162021464 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function mat = createRotation90(varargin) %CREATEROTATION90 Matrix of a rotation for 90 degrees multiples. % % MAT = createRotation90 % Returns the 3-by-3 matrix corresponding to a rotation by 90 degrees. % As trigonometric functions are explicitley converted to +1 or -1, the % resulting matrix obtained with this function is more precise than % the one obtained with createRotation. % % MAT = createRotation90(NUM) % Specifies the number of rotations to performs. NUM should be an integer % (possibly negative). % % Example % poly = [10 0;20 0;10 10]; % rot = createRotation90; % poly2 = transformPoint(poly, rot); % figure; hold on; axis equal; % drawPolygon(poly); % drawPolygon(poly2, 'm'); % legend('original', 'rotated'); % % % specify number of rotations, and center % rot = createRotation90(2, [10 10]); % poly3 = transformPoint(poly, rot); % drawPolygon(poly3, 'g'); % % See also % transforms2d, createRotation % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-06-20, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % default values num = 1; center = [0 0]; % process input arguments while ~isempty(varargin) var = varargin{1}; if isnumeric(var) && isscalar(var) % extract number of rotations num = mod(mod(var, 4) + 4, 4); elseif isnumeric(var) && length(var) == 2 % extract rotation center center = var; else % unknown argument error('MatGeom:createRotation90', ... 'Unable to parse input arguments'); end varargin(1) = []; end % determine rotation parameters switch num case 0 ct = 1; st = 0; case 1 ct = 0; st = 1; case 2 ct = -1; st = 0; case 3 ct = 0; st = -1; end % compute transform matrix mat = [ ... ct -st 0; ... st ct 0; ... 0 0 1]; % change center if needed if sum(center ~= [0 0]) > 0 tra = createTranslation(center); mat = tra * mat / tra; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/lineAngle.m0000644000000000000000000000013214055375162017135 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/lineAngle.m0000644000175000017500000000521514055375162020225 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = lineAngle(varargin) %LINEANGLE Computes angle between two straight lines. % % A = lineAngle(LINE); % Returns the angle between horizontal, right-axis and the given line. % Angle is given in radians, between 0 and 2*pi, in counter-clockwise % direction. % % A = lineAngle(LINE1, LINE2); % Returns the directed angle between the two lines. Angle is given in % radians between 0 and 2*pi, in counter-clockwise direction. % % See also % lines2d, angles2d, createLine, normalizeAngle % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 2004-02-19 added support for multiple lines. % 2011-01-20 use bsxfun nargs = length(varargin); if nargs == 1 % angle of one line with horizontal line = varargin{1}; theta = mod(atan2(line(:,4), line(:,3)) + 2*pi, 2*pi); elseif nargs==2 % angle between two lines theta1 = lineAngle(varargin{1}); theta2 = lineAngle(varargin{2}); theta = mod(bsxfun(@minus, theta2, theta1)+2*pi, 2*pi); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawOrientedBox.m0000644000000000000000000000013214055375162020337 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawOrientedBox.m0000644000175000017500000001053114055375162021424 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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. % % drawOrientedBox(AX, ...) % Specifies the axis to draw to point in. AX should be a handle to a axis % object. By default, display on current axis. % % 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); % % Example % % draw an ellipse together with its oriented box % elli = [30 40 60 30 20]; % figure; % drawEllipse(elli, 'linewidth', 2, 'color', 'g'); % hold on % box = [30 40 120 60 20]; % drawOrientedBox(box, 'color', 'k'); % axis equal; % % See also % orientedBox, drawPolygon, drawRect, drawBox, drawCenteredEdge % % ------ % 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 % 2011-10-11 add management of axes handle %% Parses input arguments % extract handle of axis to draw on if isAxisHandle(box) ax = box; box = varargin{1}; varargin(1) = []; else ax = gca; end if length(varargin) > 4 && sum(cellfun(@isnumeric, varargin(1:4))) == 4 % input given as separate arguments cx = box; cy = varargin{1}; hl = varargin{2} / 2; hw = varargin{3} / 2; theta = varargin{4}; varargin = varargin(5:end); else % input given as packed array 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) = plot(ax, vx, vy, varargin{:}); end %% Format output if nargout > 0 varargout = {hr}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/inertiaEllipse.m0000644000000000000000000000013214055375162020210 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/inertiaEllipse.m0000644000175000017500000000726414055375162021306 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ell = inertiaEllipse(points) %INERTIAELLIPSE Inertia ellipse of a set of points. % % Note: Deprecated! Use equivalentEllipse instead. % % ELL = inertiaEllipse(PTS); % where PTS is a N*2 array containing coordinates of N points, computes % the inertia ellipse 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 principal 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 % equivalentEllipse % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % 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 % deprecation warning warning('geom2d:deprecated', ... [mfilename ' is deprecated, use ''equivalentEllipse'' instead']); % 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/transformVector.m0000644000000000000000000000013214055375162020435 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/transformVector.m0000644000175000017500000000623714055375162021532 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = transformVector(varargin) %TRANSFORMVECTOR Transform a vector with an affine transform. % % VECT2 = transformVector(VECT1, TRANS); % where VECT1 has the form [xv yv], and TRANS is a [2*2], [2*3] or [3*3] % matrix, returns the vector transformed with affine transform TRANS. % % Format of TRANS can be one of : % [a b] , [a b c] , or [a b c] % [d e] [d e f] [d e f] % [0 0 1] % % VECT2 = transformVector(VECT1, TRANS); % Also works when PTA is a [N*2] array of double. In this case, VECT2 has % the same size as VECT1. % % [vx2 vy2] = transformVector(vx1, vy1, TRANS); % Also works when vx1 and vy1 are arrays the same size. The function % transform each couple of (vx1, vy1), and return the result in % (vx2, vy2), which is the same size as (vx1 vy1). % % % See also: % vectors2d, transforms2d, rotateVector, transformPoint % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 12/03/2007. % % HISTORY if length(varargin)==2 var = varargin{1}; vx = var(:,1); vy = var(:,2); trans = varargin{2}; elseif length(varargin)==3 vx = varargin{1}; vy = varargin{2}; trans = varargin{3}; else error('wrong number of arguments in "transformVector"'); end % compute new position of vector vx2 = vx*trans(1,1) + vy*trans(1,2); vy2 = vx*trans(2,1) + vy*trans(2,2); % format output if nargout==0 || nargout==1 varargout{1} = [vx2 vy2]; elseif nargout==2 varargout{1} = vx2; varargout{2} = vy2; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/fitAffineTransform2d.m0000644000000000000000000000013214055375162021254 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/fitAffineTransform2d.m0000644000175000017500000000724514055375162022351 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = fitAffineTransform2d(ref, src) % Compute the affine transform that best register two point sets. % % TRANSFO = fitAffineTransform2d(REF, SRC) % Returns the affine transform matrix that minimizes the distance between % the reference point set REF and the point set SRC after transformation. % Both REF and SRC must by N-by-2 arrays with the same number of rows, % and the points must be in correspondence. % The function minimizes the sum of the squared distances: % CRIT = sum(distancePoints(REF, transformPoint(PTS, TRANSFO)).^2); % % Example % % computes the transform the register two ellipses % % create the reference poitn set % elli = [50 50 40 20 30]; % poly = resamplePolygonByLength(ellipseToPolygon(elli, 200), 5); % figure; axis equal; axis([0 100 0 100]); hold on; % drawPoint(poly, 'kx') % % create the point set to fit on the reference % trans0 = createRotation([20 60], -pi/8); % poly2 = transformPoint(poly, trans0); % poly2 = poly2 + randn(size(poly)) * 2; % drawPoint(poly2, 'b+'); % % compute the transform that project poly2 onto poly. % transfo = fitAffineTransform2d(poly, poly2); % poly2t = transformPoint(poly2, transfo); % drawPoint(poly2t, 'mo') % legend('Reference', 'Initial', 'Transformed'); % % See also % transforms2d, transformPoint, transformVector, % fitPolynomialTransform2d, registerICP, fitAffineTransform3d % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2009-07-31, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRAE - Cepia Software Platform. % check number of points are equal N = size(src, 1); if size(ref, 1) ~= N error('Requires the same number of points for both arrays'); end % main matrix of the problem A = [... src(:,1) src(:,2) ones(N,1) zeros(N, 3) ; ... zeros(N, 3) src(:,1) src(:,2) ones(N,1) ]; % conditions initialisations B = [ref(:,1) ; ref(:,2)]; % compute coefficients using least square coefs = A\B; % format to a matrix trans = [coefs(1:3)' ; coefs(4:6)'; 0 0 1]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/circleToPolygon.m0000644000000000000000000000013214055375162020353 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/circleToPolygon.m0000644000175000017500000000572214055375162021446 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = circleToPolygon(circle, varargin) %CIRCLETOPOLYGON Convert a circle into a series of points. % % PTS = circleToPolygon(CIRC, N); % Converts the circle CIRC into an array of N-by-2 of double, containing % x and y positions of vertices. % CIRC is given as [x0 y0 r], where x0 and y0 are coordinate of center, % and r is the radius. % % P = circleToPolygon(CIRCLE); % uses a default value of N=64 vertices. % % Example % poly = circleToPolygon([30 20 15], 16); % figure; hold on; % axis equal;axis([0 50 0 50]); % drawPolygon(poly, 'b'); % drawPoint(poly, 'bo'); % % See also: % circles2d, polygons2d, circleArcToPolyline, ellipseToPolygon % % --------- % author : David Legland % created the 06/04/2005. % Copyright 2010 INRA - Cepia Software Platform. % % HISTORY % 2007-04-20 return a closed polygon with N+1 vertices, use default N=64 % 2011-12-09 rename to 'circleToPolygon' % 2017-08-31 returns N vertices instead of N+1 % determines number of points N = 64; if ~isempty(varargin) N = varargin{1}; end % create circle t = linspace(0, 2*pi, N+1)'; t(end) = []; % coordinates of circle points x = circle(1) + circle(3) * cos(t); y = circle(2) + circle(3) * sin(t); % foramt output if nargout == 1 varargout{1} = [x y]; elseif nargout == 2 varargout{1} = x; varargout{2} = y; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/orientedBoxToPolygon.m0000644000000000000000000000013214055375162021374 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/orientedBoxToPolygon.m0000644000175000017500000000573314055375162022471 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [tx, ty] = orientedBoxToPolygon(obox) %ORIENTEDBOXTOPOLYGON Convert an oriented box to a polygon (set of vertices). % % POLY = orientedBoxToPolygon(OBOX); % Converts the oriented box OBOX given either as [XC YC W H] or as % [XC YC W H THETA] into a 4-by-2 array of double, containing coordinates % of box vertices. % XC and YC are center of the box. W and H are the width and the height % (dimension in the main directions), and THETA is the orientation, in % degrees between 0 and 360. % % Example % OBOX = [20 10 40 20 0]; % RECT = orientedBoxToPolygon(OBOX) % RECT = % -20 -10 % 20 -10 % 20 10 % -20 10 % % % See also: % polygons2d, orientedBox, drawOrientedBox, rectToPolygon % % --------- % Author: David Legland % e-mail: david.legland@nantes.inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2005. % % HISTORY % 2011-10-09 rewrite from rectAsPolygon to orientedBoxToPolygon % 2016: Simplify by JuanPi Carbajal % extract box parameters theta = 0; x = obox(1); y = obox(2); w = obox(3) / 2; % easier to compute with w and h divided by 2 h = obox(4) / 2; if length(obox) > 4 theta = obox(5); end v = [cosd(theta); sind(theta)]; M = bsxfun (@times, [-1 1; 1 1; 1 -1; -1 -1], [w h]); tx = x + M * v; ty = y + M(4:-1:1,[2 1]) * v; if nargout <= 1 tx = [tx ty]; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/transforms2d.m0000644000000000000000000000013214055375162017663 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/transforms2d.m0000644000175000017500000000556314055375162020761 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function transforms2d(varargin) %TRANSFORMS2D Description of functions operating on transforms. % % By 'transform' we mean an affine transform. A planar affine transform % can be represented by a 3x3 matrix. % % Example % % create a translation by the vector [10 20]: % T = createTranslation([10 20]) % T = % 1 0 10 % 0 1 20 % 0 0 1 % % % apply a rotation on a polygon % poly = [0 0; 30 0;30 10;10 10;10 20;0 20]; % trans = createRotation([10 20], pi/6); % polyT = transformPoint(poly, trans); % % display the original and the rotated polygons % figure; hold on; axis equal; axis([-10 40 -10 40]); % drawPolygon(poly, 'k'); % drawPolygon(polyT, 'b'); % % % See also: % createTranslation, createRotation, createRotation90, createScaling % createHomothecy, createLineReflection, createBasisTransform % transformPoint, transformVector, transformLine, transformEdge % rotateVector, principalAxesTransform, fitAffineTransform2d % polynomialTransform2d, fitPolynomialTransform2d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('transforms2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/cubicBezierToPolyline.m0000644000000000000000000000013214055375162021504 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/cubicBezierToPolyline.m0000644000175000017500000000752614055375162022603 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cubicBezierToPolyline(points, varargin) %CUBICBEZIERTOPOLYLINE Compute equivalent polyline from bezier curve control. % % POLY = cubicBezierToPolyline(POINTS, N) % Creates a polyline with N edges from the coordinates of the 4 control % points stored in POINTS. % POINTS is either a 4-by-2 array (vertical concatenation of point % coordinates), or a 1-by-8 array (horizontal concatenation of point % coordinates). % The result is a (N-1)-by-2 array. % % POLY = cubicBezierToPolyline(POINTS) % Assumes N = 64 edges as default. % % [X Y] = cubicBezierToPolyline(...) % Returns the result in two separate arrays for X and Y coordinates. % % % Example % poly = cubicBezierToPolyline([0 0;5 10;10 5;10 0], 100); % drawPolyline(poly, 'linewidth', 2, 'color', 'g'); % % See also % drawBezierCurve, drawPolyline % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-10-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % default number of discretization steps N = 64; % check if discretization step is specified if ~isempty(varargin) var = varargin{1}; if length(var) == 1 && isnumeric(var) N = round(var); end end % parametrization variable for bezier (use N+1 points to have N edges) t = linspace(0, 1, N+1)'; % rename points if size(points, 2)==2 % case of points given as a 4-by-2 array p1 = points(1,:); c1 = points(2,:); c2 = points(3,:); p2 = points(4,:); else % case of points given as a 1-by-8 array, [X1 Y1 CX1 CX2..] p1 = points(1:2); c1 = points(3:4); c2 = points(5:6); p2 = points(7:8); end % compute coefficients of Bezier Polynomial, using polyval ordering coef(4, 1) = p1(1); coef(4, 2) = p1(2); coef(3, 1) = 3 * c1(1) - 3 * p1(1); coef(3, 2) = 3 * c1(2) - 3 * p1(2); coef(2, 1) = 3 * p1(1) - 6 * c1(1) + 3 * c2(1); coef(2, 2) = 3 * p1(2) - 6 * c1(2) + 3 * c2(2); coef(1, 1) = p2(1) - 3 * c2(1) + 3 * c1(1) - p1(1); coef(1, 2) = p2(2) - 3 * c2(2) + 3 * c1(2) - p1(2); % compute position of vertices x = polyval(coef(:, 1), t); y = polyval(coef(:, 2), t); if nargout <= 1 varargout = {[x y]}; else varargout = {x, y}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/circles2d.m0000644000000000000000000000013214055375162017111 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/circles2d.m0000644000175000017500000000531114055375162020176 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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, % isPointInCircle, isPointOnCircle, enclosingCircle, circumCircle % intersectLineCircle, intersectCircles, radicalAxis % circleToPolygon, circleArcToPolyline % drawCircle, drawCircleArc % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. help('circles2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/centeredEdgeToEdge.m0000644000000000000000000000013214055375162020705 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/centeredEdgeToEdge.m0000644000175000017500000000500714055375162021774 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = centeredEdgeToEdge(cedge) %CENTEREDEDGETOEDGE Convert a centered edge to a two-points edge. % % EDGE = centeredEdgeToEdge(CEDGE) % Converts an edge represented using center, length and orientation to an % edge represented using coordinates of end points. % % Example % % example of conversion on a 'pythagorean' edge % cedge = [30 40 50 atand(3/4)]; % centeredEdgeToEdge(cedge) % ans = % 10 25 50 55 % % % See also % edges2d, drawCenteredEdge, drawOrientedBox % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-07-31, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % length and orientation len = cedge(:,3); ori = cedge(:,4); % x and y shifts around center dx = len * cosd(ori) / 2; dy = len * sind(ori) / 2; % coordinates of extremities edge = [cedge(:,1:2)-[dx dy] cedge(:,1:2)+[dx dy]]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/equivalentEllipse.m0000644000000000000000000000013214055375162020732 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/equivalentEllipse.m0000644000175000017500000000712314055375162022022 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ell = equivalentEllipse(points) % Equivalent ellipse of a set of points. % % ELL = equivalentEllipse(PTS); % Computes the ellips with the same moments up to the second order as the % set of points specified by the N-by-2 array PTS. % % The result has the following form: % ELL = [XC YC A B THETA], % with XC and YC being the center of mass of the point set, A and B being % the lengths of the equivalent ellipse (see below), and THETA being the % angle of the first principal axis with the horizontal (counted in % degrees between 0 and 180 in counter-clockwise direction). % A and B are the standard deviations of the point coordinates when % ellipse is aligned with the principal 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 = equivalentEllipse(pts); % figure(1); clf; hold on; % drawPoint(pts); % drawEllipse(ell, 'linewidth', 2, 'color', 'r'); % % See also % ellipses2d, drawEllipse, equivalentEllipsoid, principalAxes, % principalAxesTransform % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % 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 equivalent 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); % equivalent 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 equivalent ellipse ell = [xc yc ra rb theta]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawCircle.m0000644000000000000000000000013214055375162017316 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawCircle.m0000644000175000017500000001075414055375162020412 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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. % % drawCircle(AX, ...) % Specifies the handle of the axis to draw on. % % H = drawCircle(...); % return handles to each created curve. % % Example % figure; % hold on; % drawCircle([10 20 30]); % drawCircle([15 15 40], 'color', 'r', 'linewidth', 2); % axis equal; % % See also % circles2d, drawCircleArc, drawEllipse, circleToPolygon % % --------- % 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. % 2011-10-11 add support for axis handle % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % 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 isnumeric(var) && isscalar(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(ax, xt, yt, varargin{:}); end if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/parallelLine.m0000644000000000000000000000013214055375162017643 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/parallelLine.m0000644000175000017500000000615014055375162020732 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = parallelLine(line, point) %PARALLELLINE Create a line parallel to another one. % % RES = parallelLine(LINE, POINT); % Returns the line with same direction vector than LINE and going through % the point given by POINT. % LINE is given as [x0 y0 dx dy] and POINT is [xp yp]. % % % RES = parallelLine(LINE, DIST); % Uses relative distance to specify position. The new line will be % located at distance DIST, counted positive in the right side of LINE % and negative in the left side. % % Examples % P1 = [20 30]; P2 = [50 10]; % L1 = createLine([50 10], [20 30]); % figure; hold on; axis equal; axis([0 60 0 50]); % drawPoint([P1; P2], 'ko'); % drawLine(L1, 'k'); % P = [30 40]; % drawPoint(P, 'ko'); % L2 = parallelLine(L1, P); % drawLine(L2, 'Color', 'b'); % % See also: % lines2d, orthogonalLine, distancePointLine, parallelEdge % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 31/07/2005 add usage of distance % 15/06/2009 change convention for distance sign % 31/09/2012 adapt for multiple lines if size(point, 2) == 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(size(line, 1), 4); res(:, 1:2) = point; res(:, 3:4) = line(:, 3:4); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/boxes2d.m0000644000000000000000000000013214055375162016605 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/boxes2d.m0000644000175000017500000000427614055375162017703 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function boxes2d(varargin) %BOXES2D Description of functions operating on bounding boxes. % % A box is represented as a set of limits in each direction: % BOX = [XMIN XMAX YMIN YMAX]. % % Boxes are used as result of computation for bounding boxes, and to clip % shapes. % % See also % boundingBox, clipPoints, clipLine, clipEdge, clipRay % mergeBoxes, intersectBoxes, randomPointInBox, boxToRect, boxToPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. help('boxes2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createTranslation.m0000644000000000000000000000013214055375162020721 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createTranslation.m0000644000175000017500000000502014055375162022003 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createTranslation(varargin) %CREATETRANSLATION Create the 3*3 matrix of a translation. % % TRANS = createTranslation(DX, DY); % Returns the translation corresponding to DX and DY. % The returned matrix has the form : % [1 0 TX] % [0 1 TY] % [0 0 1] % % TRANS = createTranslation(VECTOR); % Returns the matrix corresponding to a translation by the vector [x y]. % % % See also: % transforms2d, transformPoint, createRotation, createScaling % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 22/04/2009: rename as createTranslation % process input arguments if isempty(varargin) tx = 0; ty = 0; elseif length(varargin)==1 var = varargin{1}; tx = var(1); ty = var(2); else tx = varargin{1}; ty = varargin{2}; end % create the matrix representing the translation trans = [1 0 tx ; 0 1 ty ; 0 0 1]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/triangleGrid.m0000644000000000000000000000013214055375162017652 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/triangleGrid.m0000644000175000017500000000475314055375162020750 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/crackPattern2.m0000644000000000000000000000013214055375162017742 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/crackPattern2.m0000644000175000017500000001240614055375162021032 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges = crackPattern2(box, points, alpha, varargin) %CRACKPATTERN2 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); % % See also drawEdge % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 25/05/2004. % % HISTORY : 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)]; %#ok 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 0 varargout = {h}; end function h = drawEdge_2d(ax, edge, options) h = -1 * ones(size(edge, 1), 1); for i = 1:size(edge, 1) if isnan(edge(i,1)) continue; end h(i) = plot(ax, edge(i, [1 3]), edge(i, [2 4]), options{:}); end function h = drawEdge_3d(ax, edge, options) h = -1 * ones(size(edge, 1), 1); for i = 1:size(edge, 1) if isnan(edge(i,1)) continue; end h(i) = plot3(ax, edge(i, [1 4]), edge(i, [2 5]), edge(i, [3 6]), options{:}); end function [ax, edge, options] = parseInputArguments(varargin) % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % find the number of arguments defining edges nbVal = 0; for i = 1:length(varargin) if isnumeric(varargin{i}) nbVal = nbVal+1; else % stop at the first non-numeric value break; end end % extract drawing options options = varargin(nbVal+1:end); % ensure drawing options have correct format if length(options) == 1 options = [{'color'}, options]; end % extract edges characteristics switch nbVal case 1 % all parameters in a single array edge = varargin{1}; case 2 % parameters are two points, or two arrays of points, of size N*2. p1 = varargin{1}; p2 = varargin{2}; edge = [p1 p2]; case 4 % parameters are 4 parameters of the edge : x1 y1 x2 and y2 edge = [varargin{1} varargin{2} varargin{3} varargin{4}]; case 6 % parameters are 6 parameters of the edge : x1 y1 z1 x2 y2 and z2 edge = [varargin{1} varargin{2} varargin{3} varargin{4} varargin{5} varargin{6}]; otherwise error('drawEdge:WrongNumberOfParameters', 'Wrong number of parameters'); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointInCircle.m0000644000000000000000000000013214055375162020275 xustar0030 mtime=1622538866.058813643 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointInCircle.m0000644000175000017500000000503514055375162021365 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawEllipseArc.m0000644000000000000000000000013214055375162020140 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.058813643 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawEllipseArc.m0000644000175000017500000001255714055375162021237 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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... % % drawEllipseArc(..., NAME, VALUE) % Specifies one or more parameters name-value pairs, as in the plot % function. % % drawEllipseArc(AX, ...) % Sepcifies the handle of theaxis to draw on. % % H = drawEllipseArc(...) % Returns handle(s) of the created graphic objects. % % 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 % 2011-10-11 add management of axes handle %% Extract input arguments % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % 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('drawEllipseArc: 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(ax, xt, yt, styles{:}); end %% Process output arguments if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/normalize.m0000644000000000000000000000013214055375162017237 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/normalize.m0000644000175000017500000000431514055375162020327 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vn = normalize(v) %NORMALIZE Normalize a vector. % % V2 = normalize(V); % Returns the normalization of vector V, such that ||V|| = 1. V can be % either a row or a column vector. % % When V is a MxN array, normalization is performed for each row of the % array. % % See Also: % vectors2d, normalizeVector, vectorNorm % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 29/11/2004. % % HISTORY % 14/01/2005 : correct bug dim = size(v); if dim(1)==1 || dim(2)==1 vn = v/sqrt(sum(v.*v)); else vn = v./repmat(sqrt(sum(v.*v, 2)), [1 dim(2)]); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/boundingBox.m0000644000000000000000000000013214055375162017515 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/boundingBox.m0000644000175000017500000000621214055375162020603 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = boundingBox(points) %BOUNDINGBOX Bounding box of a set of points. % % BOX = boundingBox(POINTS) % Returns the bounding box of the set of points POINTS. POINTS can be % either a N-by-2 or N-by-3 array. The result BOX is a 1-by-4 or 1-by-6 % array, containing: % [XMIN XMAX YMIN YMAX] (2D point sets) % [XMIN XMAX YMIN YMAX ZMIN ZMAX] (3D point sets) % % Example % % Draw the bounding box of a set of random points % points = rand(30, 2); % figure; hold on; % drawPoint(points, '.'); % box = boundingBox(points); % drawBox(box, 'r'); % % % Draw bounding box of a cubeoctehedron % [v e f] = createCubeOctahedron; % box3d = boundingBox(v); % figure; hold on; % drawMesh(v, f); % drawBox3d(box3d); % set(gcf, 'renderer', 'opengl') % axis([-2 2 -2 2 -2 2]); % view(3) % % See also % polygonBounds, drawBox % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-04-01, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % HISTORY % 2011-04-08 add example % 2011-12-09 rename to boundingBox % compute extreme x and y values xmin = min(points(:,1)); xmax = max(points(:,1)); ymin = min(points(:,2)); ymax = max(points(:,2)); if size(points, 2) > 2 % process case of 3D points zmin = min(points(:,3)); zmax = max(points(:,3)); % format as box 3D data structure box = [xmin xmax ymin ymax zmin zmax]; else % format as box data structure box = [xmin xmax ymin ymax]; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createRay.m0000644000000000000000000000013214055375162017156 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createRay.m0000644000175000017500000000573214055375162020252 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function ray = createRay(varargin) %CREATERAY Create a ray (half-line), from various inputs. % % RAY = createRay(POINT, ANGLE) % POINT is a N*2 array giving starting point of the ray, and ANGLE is the % orientation of the ray. % % RAY = createRay(X0, Y0, ANGLE) % Specify ray origin with 2 input arguments. % % RAY = createRay(P1, P2) % Create a ray starting from point P1 and going in the direction of point % P2. % % Ray is represented in a parametric form: [x0 y0 dx dy] % x = x0 + t*dx % y = y0 + t*dy; % for all t>0 % % Example % origin = [3 4]; % theta = pi/6; % ray = createRay(origin, theta); % figure(1); clf; hold on; % axis([0 10 0 10]); % drawRay(ray); % % See also: % rays2d, createLine, points2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-10-18 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. if length(varargin)==2 p0 = varargin{1}; arg = varargin{2}; if size(arg, 2)==1 % second input is the ray angle ray = [p0 cos(arg) sin(arg)]; else % second input is another point ray = [p0 arg-p0]; end elseif length(varargin)==3 x = varargin{1}; y = varargin{2}; theta = varargin{3}; ray = [x y cos(theta) sin(theta)]; else error('Wrong number of arguments in ''createRay'' '); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawArrow.m0000644000000000000000000000013214055375162017207 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawArrow.m0000644000175000017500000001244114055375162020276 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawArrow(varargin) %DRAWARROW Draw an arrow on the current axis. % % drawArrow(x1, y1, x2, y2) % draws an arrow between the points (x1 y1) and (x2 y2). % % drawArrow([x1 y1 x2 y2]) % gives argument as a single array. % % drawArrow(..., L, W) % specifies length and width of the arrow. % % drawArrow(..., L, W, TYPE) % also specifies arrow type. 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-by-1. In this case, % the function draws multiple arrows. % % H = drawArrow(...) % return handle(s) to created arrow elements. % The handles are returned in a structure with the fields % 'body', 'wing' and 'head' containing the handles to the different % parts of the arrow(s). % % Example % t = linspace(0, 2*pi, 200); % figure; hold on; % plot(t, sin(t)); % drawArrow([2 -1 pi 0], .1, .05, .5) % % See also % drawEdge % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 11/11/2004 from drawEdge % % HISTORY % 2014-09-17 fix managment of handle values as suggested by Benoit Botton % 2016-05-23 Improve codee and reduce calculations (by JuanPi Carbajal) if isempty (varargin) error ('should specify at least one argument'); end % parse arrow coordinates var = varargin{1}; if size (var, 2) == 4 x1 = var(:,1); y1 = var(:,2); x2 = var(:,3); y2 = var(:,4); varargin = varargin(2:end); elseif length (varargin) > 3 x1 = varargin{1}; y1 = varargin{2}; x2 = varargin{3}; y2 = varargin{4}; varargin = varargin(5:end); else error ('MatGeom:drawArrow:invalidArgumentNumber', ... 'wrong number of arguments, please read the doc'); end N = size (x1, 1); % default values l = 10 * ones (N, 1); % Body length w = 5 * ones (N, 1); % Head width r = 0.1 * ones (N, 1); % Head to body ratio h = zeros (N, 1); % Head type if ~isempty (varargin) % Parse parameters k = length (varargin); vartxt = 'lwrh'; cmd = ['%s = varargin{%d}; %s = %s(:);' ... 'if length (%s) < N; %s = %s(1) * ones (N , 1); end']; for i = 1:k v = vartxt(i); eval (sprintf (cmd, v, i, v, v, v, v, v)); end end hold on; oldHold = ishold (gca); if ~oldHold hold on; end axis equal; % angle of the edge theta = atan2 (y2-y1, x2-x1); rl = r .* l; rh = r .* h; cT = cos (theta); sT = sin (theta); % point on the 'left' xa1 = x2 - rl .* cT - w .* sT / 2; ya1 = y2 - rl .* sT + w .* cT / 2; % point on the 'right' xa2 = x2 - rl .* cT + w .* sT / 2; ya2 = y2 - rl .* sT - w .* cT / 2; % point on the middle of the arrow xa3 = x2 - rh .* cT; ya3 = y2 - rh .* sT; % draw main edge tmp = line ([x1.'; x2.'], [y1.'; y2.'], 'color', [0 0 1]); handle.body = tmp; % draw only 2 wings ind = find (h == 0); if ~isempty (ind) tmp = line ([xa1(ind).'; x2(ind).'], [ya1(ind).'; y2(ind).'], ... 'color', [0 0 1]); handle.wing(:,1) = tmp; tmp = line ([xa2(ind).'; x2(ind).'], [ya2(ind).'; y2(ind).'], ... 'color', [0 0 1]); handle.wing(:,2) = tmp; end % draw a full arrow ind = find (h ~= 0); if ~isempty (ind) tmp = patch ([x2(ind) xa1(ind) xa3(ind) xa2(ind) x2(ind)].', ... [y2(ind) ya1(ind) ya3(ind) ya2(ind) y2(ind)].', [0 0 1]); handle.head = tmp; end % format output arguments if nargout > 0 varargout{1} = handle; end if ~oldHold hold off; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointOnCircle.m0000644000000000000000000000013214055375162020303 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointOnCircle.m0000644000175000017500000000474514055375162021402 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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))1 % arguments are POINTS, and MASS pts = var; mass = varargin{2}; else % arguments are PX and PY pts = [var varargin{2}]; end elseif nargin==3 % arguments are PX, PY, and MASS pts = [varargin{1} varargin{2}]; mass = varargin{3}; end %% compute centroid if isempty(mass) % no weight center = mean(pts); else % format mass to have sum equal to 1, and column format mass = mass(:)/sum(mass(:)); % compute weighted centroid center = sum(bsxfun(@times, pts, mass), 1); % equivalent to: % center = sum(pts .* mass(:, ones(1, size(pts, 2)))); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawBezierCurve.m0000644000000000000000000000013214055375162020342 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawBezierCurve.m0000644000175000017500000000654114055375162021435 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawBezierCurve(points, varargin) %DRAWBEZIERCURVE Draw a cubic bezier curve defined by 4 control points. % % drawBezierCurve(POINTS) % Draw the Bezier curve defined by the 4 control points stored in POINTS. % POINTS is either a 4-by-2 array (vertical concatenation of control % points coordinates), or a 1-by-8 array (horizontal concatenation of % control point coordinates). % % drawBezierCurve(..., PARAM, VALUE) % Specifies additional drawing parameters, see the line function for % details. % % drawBezierCurve(AX, ...); % Spcifies the handle of the axis to draw on. % % H = drawBezierCurve(...); % Return a handle to the created graphic object. % % % Example % drawBezierCurve([0 0;5 10;10 5;10 0]); % drawBezierCurve([0 0;5 10;10 5;10 0], 'linewidth', 2, 'color', 'g'); % % See also % drawPolyline, cubicBezierToPolyline % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-03-16, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % HISTORY % 2011-10-11 add management of axes handle % extract handle of axis to draw on if isAxisHandle(points) ax = points; points = varargin{1}; varargin(1) = []; else ax = gca; end % default number of discretization steps N = 64; % 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 % convert control coordinates to polyline poly = cubicBezierToPolyline(points, N); % draw the curve h = drawPolyline(ax, poly, varargin{:}); % eventually return a handle to the created object if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/distancePointEdge.m0000644000000000000000000000013214055375162020630 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/distancePointEdge.m0000644000175000017500000001044114055375162021715 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [dist, pos] = distancePointEdge(point, edge) %DISTANCEPOINTEDGE 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 1-by-4 array computed for each edge. % If POINT is a N-by-2 array, the result is a N-by-1 array. % If both POINT and EDGE are array, the result is computed for each % point-edge couple, and stored into a NP-by-NE array. % % [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). % % Eaxmple % % Distance between a point and an edge % distancePointEdge([3 4], [0 0 10 0]) % ans = % 4 % % % Distance between several points and one edge % points = [10 15; 15 10; 30 10]; % edge = [10 10 20 10]; % distancePointEdge(points, edge) % ans = % 5 % 0 % 10 % % % Distance between a point a several edges % point = [14 33]; % edges = [10 30 20 30; 20 30 20 40;20 40 10 40;10 40 10 30]; % distancePointEdge(point, edges) % ans = % 3 6 7 4 % % % See also: % edges2d, points2d, distancePoints, distancePointLine % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2004-04-07 % Copyright 2016 INRA - BIA-BIBS. % % HISTORY % 2005-06-24 rename, and change arguments sequence % 2009-04-30 add possibility to return position of closest point % 2011-04-14 add checkup for degenerate edges, improve speed, update doc % direction vector of each edge (row vectors) vx = (edge(:, 3) - edge(:,1))'; vy = (edge(:, 4) - edge(:,2))'; % squared length of edges, with a check of validity delta = vx .* vx + vy .* vy; invalidEdges = delta < eps; delta(invalidEdges) = 1; % difference of coordinates between point and edge first vertex % (NP-by-NE arrays) dx = bsxfun(@minus, point(:, 1), edge(:, 1)'); dy = bsxfun(@minus, point(:, 2), edge(:, 2)'); % compute position of points projected on the supporting line, by using % normalised dot product (NP-by-NE array) pos = bsxfun(@rdivide, bsxfun(@times, dx, vx) + bsxfun(@times, dy, vy), delta); % ensure degenerated edges are correclty processed (consider the first % vertex is the closest) pos(:, invalidEdges) = 0; % change position to ensure projected point is located on the edge pos(pos < 0) = 0; pos(pos > 1) = 1; % compute distance between point and its projection on the edge dist = hypot(bsxfun(@times, pos, vx) - dx, bsxfun(@times, pos, vy) - dy); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/hexagonalGrid.m0000644000000000000000000000013214055375162020013 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/hexagonalGrid.m0000644000175000017500000000763214055375162021110 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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 = zeros(length(ind), 4); tmpEdges(ind, 1) = lx; tmpEdges(ind, 2) = ly(i); tmpEdges(ind, 3) = lx+size; tmpEdges(ind, 4) = ly(i); edges = [edges; tmpEdges]; %#ok end end % process output arguments if nargout > 0 varargout{1} = pts; if nargout > 1 varargout{2} = edges; end end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/triangleArea.m0000644000000000000000000000013214055375162017635 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/triangleArea.m0000644000175000017500000000546214055375162020731 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function area = triangleArea(pt1, pt2, pt3) %TRIANGLEAREA Signed area of a triangle. % % AREA = triangleArea(P1, P2, P3) % Computes area of the triangle whose vertices are given by P1, P2 and % P3. Each vertex is a 1-by-2 row vector. % % AREA = triangleArea(PTS) % Concatenates vertex coordinates in a 3-by-2 array. Each row of the % array contains coordinates of one vertex. % % % Example % % Compute area of a Counter-Clockwise (CCW) oriented triangle % triangleArea([10 10], [30 10], [10 40]) % ans = % 300 % % % Compute area of a Clockwise (CW) oriented triangle % triangleArea([10 40], [30 10], [10 10]) % ans = % -300 % % See also % polygonArea, triangleArea3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-08-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % if data is given as one array, split vertices if nargin == 1 pt2 = pt1(2,:); pt3 = pt1(3,:); pt1 = pt1(1,:); end % compute individual vectors v12 = bsxfun(@minus, pt2, pt1); v13 = bsxfun(@minus, pt3, pt1); % compute area from cross product area = (v13(:,2) .* v12(:,1) - v13(:,1) .* v12(:,2)) / 2; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/rectToBox.m0000644000000000000000000000013214055375162017150 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/rectToBox.m0000644000175000017500000000427114055375162020241 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = rectToBox(rect) %RECTTOBOX Convert rectangle data to box data. % % RECT = rectToBox(BOX) % Converts from rectangle representation to box representation. % BOX is given by [XMIN XMAX YMIN YMAX]. % RECT is given by [X0 Y0 WIDTH HEIGHT], with WIDTH and HEIGHT > 0 % % Example % rectToBox % % See also % boxToRect, drawBox, drawRect % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-08-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. box = [rect(:,1) rect(:,1)+rect(:,3) rect(:,2) rect(:,2)+rect(:,4)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/boxToRect.m0000644000000000000000000000013214055375162017150 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/boxToRect.m0000644000175000017500000000422014055375162020233 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function rect = boxToRect(box) %BOXTORECT Convert box data to rectangle data. % % RECT = boxToRect(BOX) % Converts from boxrepresentation to rectangle representation. % BOX is given by [XMIN XMAX YMIN YMAX]. % RECT is given by [X0 Y0 WIDTH HEIGHT], with WIDTH and HEIGHT > 0 % % See also % boxes2d, boxToPolygon, drawBox % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-08-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. rect = [box(:,1) box(:,3) box(:,2)-box(:,1) box(:,4)-box(:,3)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/midPoint.m0000644000000000000000000000013214055375162017022 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/midPoint.m0000644000175000017500000000622414055375162020113 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = midPoint(varargin) %MIDPOINT Middle point of two points or of an edge. % % MID = midPoint(P1, P2) % Compute the middle point of the two points P1 and P2. % % MID = midPoint(EDGE) % Compute the middle point of the edge given by EDGE. % EDGE has the format: [X1 Y1 X2 Y2], and MID has the format [XMID YMID], % with XMID = (X1+X2)/2, and YMID = (Y1+Y2)/2. % % [MIDX MIDY] = midPoint(...) % Return the result as two separate variables or arrays. % % Works also when EDGE is a N-by-4 array, in this case the result is a % N-by-2 array containing the midpoint of each edge. % % % Example % P1 = [10 20]; % P2 = [30 40]; % midPoint([P1 P2]) % ans = % 20 30 % % See also % edges2d, points2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-08-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. if nargin == 1 % input is an edge edge = varargin{1}; mid = [mean(edge(:, [1 3]), 2) mean(edge(:, [2 4]), 2)]; elseif nargin == 2 % input are two points p1 = varargin{1}; p2 = varargin{2}; % assert inputs are equal n1 = size(p1, 1); n2 = size(p2, 1); if n1~=n2 && min(n1, n2)>1 error('geom2d:midPoint', ... 'Inputs must have same size, or one must have length 1'); end % compute middle point mid = bsxfun(@plus, p1, p2) / 2; end % process output arguments if nargout<=1 varargout{1} = mid; else varargout = {mid(:,1), mid(:,2)}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/circumCircle.m0000644000000000000000000000013214055375162017643 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/circumCircle.m0000644000175000017500000000466614055375162020744 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = circumCircle(varargin) %CIRCUMCIRCLE Circumscribed circle of three points. % % CIRC = circumCircle(TRI) % CIRC = circumCircle(P1, P2, P3) % Compute circumcircle of a triangle given by 3 points. % % Example % T = [10 20; 70 20; 30 70]; % C = circumCircle(T); % figure; drawPolygon(T, 'linewidth', 2); % hold on; drawCircle(C); % axis equal; axis([0 100 0 100]); % % See also % circles2d, enclosingCircle, circumCenter % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-01, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % extract the three points [a, b, c] = parseThreePoints(varargin{:}); % circle center center = circumCenter(a, b, c); % radius r = distancePoints(center, a); % format output varargout = {[center r]}; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/squareGrid.m0000644000000000000000000000013214055375162017345 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/squareGrid.m0000644000175000017500000000545514055375162020443 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/orientedBox.m0000644000000000000000000000013214055375162017521 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/orientedBox.m0000644000175000017500000001307514055375162020614 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function obox = orientedBox(points) %ORIENTEDBOX Minimum-width oriented bounding box of a set of points. % % OBOX = orientedBox(PTS) % Computes the oriented bounding box of a set of points. Oriented box is % defined by a center, two dimensions (the length and the width), and the % orientation of the length axis. Orientation is counted in degrees, % counter-clockwise. % % Example % % Draw oriented bounding box of an ellipse % elli = [30 40 40 20 30]; % pts = ellipseToPolygon(elli, 120); % obox = orientedBox(pts); % figure; hold on; % drawEllipse(elli); % drawOrientedBox(obox, 'm'); % % See also % drawOrientedBox, orientedBoxToPolygon % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2012-03-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. %% initialisations % first, compute convex hull of the polygon inds = convhull(points(:,1), points(:,2)); hull = points(inds, :); % if first and last points are the same, remove the last one if inds(1) == inds(end) hull = hull(1:end-1, :); end % compute convex hull centroid, that corresponds to approximate % location of rectangle center center = mean(hull, 1); hull = bsxfun(@minus, hull, center); % number of hull vertices nV = size(hull, 1); % default values rotatedAngle = 0; minWidth = inf; minAngle = 0; % avoid degenerated cases if nV < 3 return; end % indices of vertices in extreme y directions [tmp, indA] = min(hull(:, 2)); %#ok [tmp, indB] = max(hull(:, 2)); %#ok caliperA = [ 1 0]; % Caliper A points along the positive x-axis caliperB = [-1 0]; % Caliper B points along the negative x-axis %% Find the direction with minimum width (rotating caliper algorithm) while rotatedAngle < pi % compute the direction vectors corresponding to each edge indA2 = mod(indA, nV) + 1; vectorA = hull(indA2, :) - hull(indA, :); indB2 = mod(indB, nV) + 1; vectorB = hull(indB2, :) - hull(indB, :); % Determine the angle between each caliper and the next adjacent edge % in the polygon angleA = vectorAngle(caliperA, vectorA); angleB = vectorAngle(caliperB, vectorB); % Determine the smallest of these angles angleIncrement = min(angleA, angleB); % Rotate the calipers by the smallest angle caliperA = rotateVector(caliperA, angleIncrement); caliperB = rotateVector(caliperB, angleIncrement); rotatedAngle = rotatedAngle + angleIncrement; % compute current width, and update opposite vertex if angleA < angleB line = createLine(hull(indA, :), hull(indA2, :)); width = distancePointLine(hull(indB, :), line); indA = mod(indA, nV) + 1; else line = createLine(hull(indB, :), hull(indB2, :)); width = distancePointLine(hull(indA, :), line); indB = mod(indB, nV) + 1; end % update minimum width and corresponding angle if needed if width < minWidth minWidth = width; minAngle = rotatedAngle; end end %% Compute box dimensions % orientation of the main axis theta = rad2deg(minAngle); % pre-compute trigonometric functions cot = cos(minAngle); sit = sin(minAngle); % elongation in direction of rectangle length x = hull(:,1); y = hull(:,2); x2 = x * cot + y * sit; y2 = - x * sit + y * cot; % compute extension along main directions xmin = min(x2); xmax = max(x2); ymin = min(y2); ymax = max(y2); % position of the center with respect to the centroid compute before dl = (xmax + xmin)/2; dw = (ymax + ymin)/2; % change coordinate from rectangle to user-space dx = dl * cot - dw * sit; dy = dl * sit + dw * cot; % coordinates of oriented box center center = center + [dx dy]; % size of the rectangle rectLength = xmax - xmin; rectWidth = ymax - ymin; % concatenate rectangle data obox = [center rectLength rectWidth theta]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/principalAxes.m0000644000000000000000000000013214055375162020041 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/principalAxes.m0000644000175000017500000000662114055375162021133 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = principalAxes(points) %PRINCIPALAXES Principal axes of a set of ND points. % % [CENTER, ROTMAT] = principalAxes(PTS) % [CENTER, ROTMAT, SCALES] = principalAxes(PTS) % Computes the principal axes of a set of points given in a N-by-ND array % and returns the result in two or three outputs: % CENTER is the centroid of the points, as a 1-by-ND row vector % ROTMAT represents the orientation of the point cloud, as a ND-by-ND % rotation matrix % SCALES is the scaling factor along each dimension, as a 1-by-ND row % vector. % % Example % pts = randn(100, 2); % pts = transformPoint(pts, createScaling(5, 2)); % pts = transformPoint(pts, createRotation(pi/6)); % pts = transformPoint(pts, createTranslation(3, 4)); % [center, rotMat] = principalAxes(pts); % % See also % equivalentEllipse, equivalentEllipsoid, principalAxesTransform % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2019-08-12, using Matlab 9.6.0.1072779 (R2019a) % Copyright 2019 INRAE - Cepia Software Platform. % number and dimension of points n = size(points, 1); nd = size(points, 2); % compute centroid center = mean(points); % compute the covariance matrix covPts = cov(points) / n; % perform a principal component analysis to extract principal axes [rotMat, S] = svd(covPts); % extract length of each semi axis radii = sqrt(diag(S) * n); % sort axes from greater to lower [radii, ind] = sort(radii, 'descend'); radii = radii'; % format U to ensure first axis points to positive x direction rotMat = rotMat(ind, :); if rotMat(1,1) < 0 && nd > 2 rotMat = -rotMat; % keep matrix determinant positive rotMat(:,3) = -rotMat(:,3); end % format output if nargout == 2 varargout = {center, rotMat}; elseif nargout == 3 varargout = {center, rotMat, radii}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/lineFit.m0000644000000000000000000000013214055375162016631 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/lineFit.m0000644000175000017500000000741014055375162017720 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = lineFit(varargin) %LINEFIT Fit a straight line to a set of points. % % L = lineFit(X, Y) % Computes parametric line minimizing square error of all points (X,Y). % Result is a 4*1 array, containing coordinates of a point of the line, % and the direction vector of the line, that is L=[x0 y0 dx dy]; % % L = lineFit(PTS) % Gives coordinats of points in a single array. % % L = lineFit(PT0, PTS); % L = lineFit(PT0, X, Y); % with PT0 = [x0 y0], imposes the line to contain point PT0. % % Requires: % Optimiaztion toolbox % % See also: % lines2d, polyfit, polyfit2, lsqlin % % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 30/04/2004. % % HISTORY % 09/12/2004 : update implementation % --------------------------------------------- % extract input arguments if length(varargin)==1 % argument is an array of points var = varargin{1}; x = var(:,1); y = var(:,2); elseif length(varargin)==2 var = varargin{1}; if size(var, 1)==1 var = varargin{2}; x = var(:,1); y = var(:,2); else % two arguments : x and y x = var; y = varargin{2}; end elseif length(varargin)==3 % three arguments : ref point, x and y x = varargin{2}; y = varargin{3}; end % --------------------------------------------- % Initializations : N = size(x, 1); % --------------------------------------------- % Main algorithm : % main matrix of the problem X = [x y ones(N,1)]; % conditions initialisations A = zeros(0, 3); b = []; Aeq1 = [1 1 0]; beq1 = 1; Aeq2 = [1 -1 0]; beq2 = 1; % disable verbosity of optimisation opt = optimset('lsqlin'); opt.LargeScale = 'off'; opt.Display = 'off'; % compute line coefficients [a;b;c] , in the form a*x + b*y + c = 0 % using linear regression % Not very clean : I could not impose a*a+b*b=1, so I checked for both a=1 % and b=1, and I kept the result with lowest residual error.... [coef1, res1] = lsqlin(X, zeros(N, 1), A, b, Aeq1, beq1, [], [], [], opt); [coef2, res2] = lsqlin(X, zeros(N, 1), A, b, Aeq2, beq2, [], [], [], opt); % choose the best line if res1normalizeAngle for details. % % Example: % rad2deg(vectorAngle([2 2])) % ans = % 45 % rad2deg(vectorAngle([1 sqrt(3)])) % ans = % 60 % rad2deg(vectorAngle([0 -1])) % ans = % 270 % % See also: % vectors2d, angles2d, normalizeAngle % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2007-10-18 % Copyright 2011 INRA - Cepia Software Platform. % HISTORY % 2010-04-16 add psb to specify center interval % 2011-04-10 add support for angle between two vectors %% Initializations % default values v2 = []; midAngle = pi; % normalize angles between 0 and 2*PI % process input arguments while ~isempty(varargin) var = varargin{1}; if isnumeric(var) && isscalar(var) % argument is normalization constant midAngle = varargin{1}; varargin(1) = []; elseif isnumeric(var) && size(var, 2) == 2 % argument is second vector v2 = varargin{1}; varargin(1) = []; elseif ischar(var) && length(varargin) >= 2 % argument is option given as string + value if strcmpi(var, 'cutAngle') || strcmpi(var, 'midAngle') midAngle = varargin{2}; varargin(1:2) = []; else error(['Unknown option: ' var]); end else error('Unable to parse inputs'); end end %% Case of one vector % If only one vector is provided, computes its angle if isempty(v2) % compute angle and format result in a 2*pi interval alpha = atan2(v1(:,2), v1(:,1)); % normalize within a 2*pi interval alpha = normalizeAngle(alpha + 2*pi, midAngle); return; end %% Case of two vectors % compute angle of each vector alpha1 = mod(atan2(v1(:,2), v1(:,1)), 2*pi); alpha2 = mod(atan2(v2(:,2), v2(:,1)), 2*pi); % difference alpha = bsxfun(@minus, alpha2, alpha1); % normalize within a 2*pi interval alpha = normalizeAngle(alpha + 2*pi, midAngle); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawLabels.m0000644000000000000000000000013214055375162017317 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawLabels.m0000644000175000017500000001015314055375162020404 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawLabels(varargin) % Draw labels at specified positions. % % drawLabels(X, Y, LBL) % Draws labels LBL at positions given by X and Y. % LBL can be either a string array, or a number array. In this case, % string are created by using sprintf function, using the '%.2f' format. % % drawLabels(POS, LBL) % Draws labels LBL at position specified by POS, where POS is a N-by-2 % numeric array. % % drawLabels(..., NUMBERS, FORMAT) % Creates labels using sprintf function, with the mask given by FORMAT % (e.g. '%03d' or '5.3f'), and the corresponding values. % % drawLabels(..., PNAME, PVALUE) % Specifies additional parameters to the created labels. See 'text' % properties for available values. % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 15/12/2003. % % HISTORY % 09/03/2007: (re)implement it... % 2011-10-11 add management of axes handle % check if enough inputs are given if isempty(varargin) error('wrong number of arguments in drawLabels'); end % extract handle of axis to draw on if isscalar(varargin{1}) && ishandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % process input parameters var = varargin{1}; if size(var, 2) == 1 % coordinates given as separate arguments if length(varargin) < 3 error('wrong number of arguments in drawLabels'); end px = var; py = varargin{2}; lbl = varargin{3}; varargin(1:3) = []; else % parameters given as a packed array 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 for displaying numeric values format = '%.2f'; if ~isempty(varargin) var1 = varargin{1}; if ischar(var1) && var1(1) == '%' format = varargin{1}; varargin(1) = []; end end if size(format, 1) == 1 && size(px, 1) > 1 format = repmat(format, size(px, 1), 1); end % compute the strings that have to be displayed 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); % display the text h = text(px, py, labels, 'parent', ax, varargin{:}); % format output if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createVector.m0000644000000000000000000000013214055375162017665 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createVector.m0000644000175000017500000000454614055375162020763 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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: david.legland@grignon.inra.fr % Created: 2010-12-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. vect = bsxfun(@minus, p2, p1); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/minDistancePoints.m0000644000000000000000000000013214055375162020672 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/minDistancePoints.m0000644000175000017500000002142114055375162021757 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = minDistancePoints(p1, varargin) % Minimal distance between several points. % % DIST = minDistancePoints(PTS) % Returns the minimum distance between all pairs of points in PTS. PTS % is a N-by-D array of values, N being the number of points and D the % dimension of the points. % % DIST = minDistancePoints(PTS1, PTS2) % Computes for each point in PTS1 the minimal distance to every point of % PTS2. PTS1 and PTS2 are N-by-D arrays, where N is the number of points, % and D is the dimension. Dimension must be the same for both arrays, but % number of points can be different. % The result is an array the same length as PTS1. % % % DIST = minDistancePoints(..., NORM) % Uses a user-specified norm. NORM=2 means euclidean norm (the default), % NORM=1 is the Manhattan (or "taxi-driver") distance. % Increasing NORM growing up reduces the minimal distance, with a limit % to the biggest coordinate difference among dimensions. % % % [DIST, I, J] = minDistancePoints(PTS) % Returns indices I and J of the 2 points which are the closest. DIST % verifies relation: % DIST = distancePoints(PTS(I,:), PTS(J,:)); % % [DIST, J] = minDistancePoints(PTS1, PTS2, ...) % Also returns the indices of points which are the closest. J has the % same size as DIST. It verifies relation: % DIST(I) = distancePoints(PTS1(I,:), PTS2(J,:)); % for I comprised between 1 and the number of rows in PTS1. % % % Examples: % % minimal distance between random planar points % points = rand(20,2)*100; % minDist = minDistancePoints(points); % % % minimal distance between random space points % points = rand(30,3)*100; % [minDist ind1 ind2] = minDistancePoints(points); % minDist % distancePoints(points(ind1, :), points(ind2, :)) % % results should be the same % % % minimal distance between 2 sets of points % points1 = rand(30,2)*100; % points2 = rand(30,2)*100; % [minDists inds] = minDistancePoints(points1, points2); % minDists(10) % distancePoints(points1(10, :), points2(inds(10), :)) % % results should be the same % % % Find the (approximated) orthogonal projection onto an ellipse % elli = [50 50 40 20 30]; % poly = ellipseToPolygon(elli, 200); % figure; axis equal; axis([0 100 0 100]); hold on; % drawPolygon(poly, 'k') % pts = [20 20; 50 20; 80 30]; % [dists, inds] = minDistancePoints(pts, poly); % drawPoint(pts, 'bo'); % drawPoint(poly(inds,:), 'ko'); % drawEdge([pts poly(inds,:)], 'k') % % % See Also % points2d, distancePoints, nndist, findClosestPoint, hausdorffDistance % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Copyright 2009 INRAE - Cepia Software Platform. % created the 15/06/2004. % HISTORY: % 22/06/2005 compute sqrt only at the end (faster), and change behaviour % for 2 inputs: compute min distance for each point in PTS1. % Also add support for different norms. % 15/08/2005 make difference when 1 array or 2 arrays of points % 25/10/2006 also returns indices of closest points % 30/10/2006 generalize to points of any dimension % 28/08/2007 code cleanup, add comments and help % 01/02/2017 complete re-write by JuanPi Carbajal % 01/02/2017 fix bugs, update code, fix MLInt Warning (D. Legland) % 01/02/2017 remove use of vech %% Initialisations % default norm (euclidean) n = 2; % a single array is given one_array = true; % process input variables if nargin == 1 % specify only one array of points, not the norm p2 = p1; elseif nargin == 2 if isscalar (varargin{1}) % specify array of points and the norm n = varargin{1}; p2 = p1; else % specify two arrays of points p2 = varargin{1}; one_array = false; end elseif nargin == 3 % specify two array of points and the norm p2 = varargin{1}; n = varargin{2}; one_array = false; else error ('Wrong number of input arguments'); end % number of points in each array n1 = size (p1, 1); n2 = size (p2, 1); % dimensionality of points d = size (p1, 2); %% Computation of distances % allocate memory dist = zeros (n1, n2); % Compute difference of coordinate for each pair of point (n1-by-n2 array) % and for each dimension. -> dist is a n1-by-n2 array. % in 2D: dist = dx.*dx + dy.*dy; if n == inf % infinite norm corresponds to maximum absolute value of differences % in 2D: dist = max(abs(dx) + max(abs(dy)); for i = 1:d dist = max (dist, abs(bsxfun (@minus, p1(:,i), p2(:,i).'))); end else for i = 1:d dist = dist + abs (bsxfun (@minus, p1(:,i), p2(:,i).')).^n; end end % TODO the previous could be optimized when a single array is given (maybe!) if ~one_array % If two array of points where given [minSqDist, ind] = min (dist, [], 2); minDist = power (minSqDist, 1/n); [ind2, ind1] = ind2sub ([n1 n2], ind); else % A single array was given dist = dist + diag (inf (n1,1)); % remove zeros from diagonal dist = dist (tril(true(n1, n1))); [minSqDist, ind] = min (dist); % index on packed lower triangular matrix minDist = power (minSqDist, 1/n); [ind2, ind1] = ind2sub_tril (n1, ind); ind2 = ind2(1); ind1 = ind1(1); ind = sub2ind ([n1 n1], ind2, ind1); end %% format output parameters % format output depending on number of asked parameters if nargout <= 1 varargout{1} = minDist; elseif nargout == 2 % If two arrays are asked, 'ind' is an array of indices of p2, one for each % point in p1, corresponding to the result in minDist varargout{1} = minDist; varargout{2} = ind; elseif nargout == 3 % If only one array is asked, minDist is a scalar, ind1 and ind2 are 2 % indices corresponding to the closest points. varargout{1} = minDist; varargout{2} = ind1; varargout{3} = ind2; end end function [r, c] = ind2sub_tril (N, idx) % [r, c] = ind2sub_tril (N, idx) % Convert a linear index to subscripts of a trinagular matrix. % % An example of triangular matrix linearly indexed follows % % N = 4; % A = -repmat (1:N,N,1); % A = [A repmat (diagind, N,1) - A.']; % A = tril(A) % => A = % 1 0 0 0 % 2 5 0 0 % 3 6 8 0 % 4 7 9 10 % % The following example shows how to convert the linear index `6' in % the 4-by-4 matrix of the example into a subscript. % % [r, c] = ind2sub_tril (4, 6) % => r = 3 % c = 2 % % when idx is a row or column matrix of linear indeces then r and % c have the same shape as idx. % % See also % ind2sub endofrow = 0.5 * (1:N) .* (2*N:-1:N + 1); c = zeros(size(endofrow)); for i = 1:length(endofrow) ind = find(endofrow <= idx - 1, 1, 'last') + 1; if isempty(ind) ind = 1; end c(i) = ind; % c = lookup (endofrow, idx - 1) + 1; end r = N - endofrow(c) + idx ; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/crackPattern.m0000644000000000000000000000013214055375162017660 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/crackPattern.m0000644000175000017500000001552614055375162020756 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges = crackPattern(box, points, alpha, varargin) %CRACKPATTERN Create a (bounded) crack pattern tessellation. % % E = crackPattern(BOX, POINTS, ALPHA) % create a crack propagation pattern wit following parameters : % - pattern is bounded by area BOX given by [xmin xmax ymin ymax]. % - each crack originates from points given in POINTS % - direction of each crack is given by array ALPHA % - 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 = crackPattern(BOX, POINTS, ALPHA, SPEED) % Also specify speed of propagation of each crack. % % % See the result with : % figure; % drawEdge(E); % % See also % drawEdge % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 25/05/2004. % % HISTORY : 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 pos20 if pos2 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/principalAxesTransform.m0000644000000000000000000000013214055375162021735 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/principalAxesTransform.m0000644000175000017500000000520314055375162023022 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = principalAxesTransform(pts) % Align a set of points along its principal axes. % % TRANSFO = principalAxesTransform(PTS) % Computes the affine transform that will transform the input array PTS % such that its principal axes become aligned with main axes. % % [TRANSFO, PTS2] = principalAxesTransform(PTS) % Also returns the result of the transform applied to the points. % % Example % principalAxesTransform % % See also % principalAxes, equivalentEllipse, equivalentEllipsoid % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2020-03-06, using Matlab 8.6.0.267246 (R2015b) % Copyright 2020 INRAE - Cepia Software Platform. % computes principal axes [center, rotMat] = principalAxes(pts); % concatenate into affine matrix nd = size(pts, 2); transfo = inv([rotMat center'; zeros(1, nd) 1]); % format output if nargout < 2 varargout = transfo; else if nd == 2 pts2 = transformPoint(pts, transfo); else pts2 = transformPoint3d(pts, transfo); end varargout = {transfo, pts2}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/transformEdge.m0000644000000000000000000000013214055375162020037 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/transformEdge.m0000644000175000017500000000532714055375162021133 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dest = transformEdge(edge, trans) %TRANSFORMEDGE Transform an edge with an affine transform. % % EDGE2 = transformEdge(EDGE1, TRANS); % where EDGE1 has the form [x1 y1 x2 y1], and TRANS is a transformation % matrix, return the edge transformed with affine transform TRANS. % % Format of TRANS can be one of : % [a b] , [a b c] , or [a b c] % [d e] [d e f] [d e f] % [0 0 1] % % EDGE2 = transformEdge(EDGES, TRANS); % Also wotk when EDGES is a [N*4] array of double. In this case, EDGE2 % has the same size as EDGE. % % See also: % edges2d, transforms2d, transformPoint, translation, rotation % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % 14/08/2017 Updated by Juanpi Carbajal % allocate memory dest = zeros(size(edge)); % compute position for i=1:2 T = trans(i,1:2).'; dest(:,i) = edge(:,1:2) * T; dest(:,i+2) = edge(:,3:4) * T; end % add translation vector, if exist if size(trans, 2) > 2 dest = bsxfun (@plus, dest, trans([1:2 1:2],3).'); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/circleArcToPolyline.m0000644000000000000000000000013214055375162021145 xustar0030 mtime=1622538866.062813629 30 atime=1622538866.062813629 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/circleArcToPolyline.m0000644000175000017500000000570414055375162022240 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = circleArcToPolyline(arc, N) %CIRCLEARCTOPOLYLINE Convert a circle arc into a series of points. % % P = circleArcToPolyline(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] = circleArcToPolyline(ARC, N); % Return the result in two separate arrays with N lines and 1 column. % % % See also: % circles2d, circleToPolygon, 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 % 2011-12-09 rename to circleArcToPolyline % 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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/polarPoint.m0000644000000000000000000000013214055375162017366 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/polarPoint.m0000644000175000017500000000565114055375162020462 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = polarPoint(varargin) %POLARPOINT Create a point from polar coordinates (rho + theta). % % POINT = polarPoint(RHO, THETA); % Creates a point using polar coordinate. THETA is angle with horizontal % (counted counter-clockwise, and in radians), and RHO is the distance to % origin. % % POINT = polarPoint(THETA) % Specify angle, radius RHO is assumed to be 1. % % POINT = polarPoint(POINT, RHO, THETA) % POINT = polarPoint(X0, Y0, RHO, THETA) % Adds the coordinate of the point to the coordinate of the specified % point. For example, creating a point with : % P = polarPoint([10 20], 30, 2*pi); % will give a result of [40 20]. % % % See Also: % points2d % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 03/05/2004 % % default values x0 = 0; y0=0; rho = 1; theta =0; % process input parameters if length(varargin)==1 theta = varargin{1}; elseif length(varargin)==2 rho = varargin{1}; theta = varargin{2}; elseif length(varargin)==3 var = varargin{1}; x0 = var(:,1); y0 = var(:,2); rho = varargin{2}; theta = varargin{3}; elseif length(varargin)==4 x0 = varargin{1}; y0 = varargin{2}; rho = varargin{3}; theta = varargin{4}; end point = [x0 + rho.*cos(theta) , y0+rho.*sin(theta)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/points2d.m0000644000000000000000000000013214055375162017001 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/points2d.m0000644000175000017500000000460214055375162020070 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points2d %POINTS2D Description of functions operating on points. % % A point is defined by its two cartesian coordinate, put into a row % vector of 2 elements: % P = [x y]; % % Several points are stored in a matrix with two columns, one for the % x-coordinate, one for the y-coordinate. % PTS = [x1 y1 ; x2 y2 ; x3 y3]; % % Example % P = [5 6]; % % See also: % centroid, midPoint, boundingBox, polarPoint % distancePoints, minDistancePoints, nndist, circumCenter % isCounterClockwise, angle2Points, angle3Points, angleSort % transformPoint, clipPoints, drawPoint % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('points2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/parallelEdge.m0000644000000000000000000000013214055375162017620 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/parallelEdge.m0000644000175000017500000000540414055375162020710 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = parallelEdge(edge, dist) %PARALLELEDGE Edge parallel to another edge. % % EDGE2 = parallelEdge(EDGE, DIST) % Computes the edge parallel to the input edge EDGE and located at the % given signed distance DIST. % % Example % obox = [30 40 80 40 30]; % figure; hold on; axis equal; % drawOrientedBox(obox, 'LineWidth', 2); % edge1 = centeredEdgeToEdge(obox([1 2 3 5])); % edge2 = centeredEdgeToEdge(obox([1 2 4 5])+[0 0 0 90]); % drawEdge(edge1, 'LineWidth', 2, 'color', 'g'); % drawEdge(edge2, 'LineWidth', 2, 'color', 'g'); % drawEdge(parallelEdge(edge1, -30), 'LineWidth', 2, 'color', 'k'); % drawEdge(parallelEdge(edge2, -50), 'LineWidth', 2, 'color', 'k'); % % See also % edges2d, parallelLine, drawEdge, centeredEdgeToEdge, edgeToLine % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-07-31, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % compute the line parallel to the supporting line of edge line = parallelLine(edgeToLine(edge), dist); % result edge is given by line positions 0 and 1. res = [line(:, 1:2) line(:, 1:2)+line(:, 3:4)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/circumCenter.m0000644000000000000000000000013214055375162017662 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/circumCenter.m0000644000175000017500000000527714055375162020762 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = circumCenter(a, b, c) %CIRCUMCENTER Circumcenter of three points. % % CC = circumCenter(P1, P2, P3) % % Example % A = [10 10]; B = [30 10]; C = [10 20]; % circumCenter(A, B, C) % ans = % 20 15 % % % works also for multiple input points % circumCenter([A;A;A], [B;B;B], [C;C;C]) % ans = % 20 15 % 20 15 % 20 15 % % % See also % points2d, circles2d, circumCircle, centroid % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % pre-compute some terms ah = sum(a .^ 2, 2); bh = sum(b .^ 2, 2); ch = sum(c .^ 2, 2); dab = a - b; dbc = b - c; dca = c - a; % common denominator D = .5 ./ (a(:,1) .* dbc(:,2) + b(:,1) .* dca(:,2) + c(:,1) .* dab(:,2)); % center coordinates xc = (ah .* dbc(:,2) + bh .* dca(:,2) + ch .* dab(:,2) ) .* D; yc = -(ah .* dbc(:,1) + bh .* dca(:,1) + ch .* dab(:,1) ) .* D; if nargout <= 1 varargout = {[xc yc]}; else varargout = {xc, yc}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointOnEdge.m0000644000000000000000000000013214055375162017746 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointOnEdge.m0000644000175000017500000001433314055375162021037 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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 nPoints = size(point, 1); nEdges = size(edge, 1); % adapt size of inputs if needed, and extract elements for computation if nPoints == nEdges % 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 nPoints == 1 % one point, several edges dx = edge(:, 3) - edge(:, 1); dy = edge(:, 4) - edge(:, 2); lx = point(ones(nEdges, 1), 1) - edge(:, 1); ly = point(ones(nEdges, 1), 2) - edge(:, 2); elseif nEdges == 1 % several points, one edge dx = (edge(3) - edge(1)) * ones(nPoints, 1); dy = (edge(4) - edge(2)) * ones(nPoints, 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)', nPoints, 1); y0 = repmat(edge(:, 2)', nPoints, 1); dx = repmat(edge(:, 3)', nPoints, 1) - x0; dy = repmat(edge(:, 4)', nPoints, 1) - y0; lx = repmat(point(:, 1), 1, nEdges) - x0; ly = repmat(point(:, 2), 1, nEdges) - y0; end % test if point is located on supporting line b1 = abs(lx.*dy - ly.*dx) ./ (dx.*dx + dy.*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; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/registerICP.m0000644000000000000000000000013214055375162017417 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/registerICP.m0000644000175000017500000000577314055375162020520 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [trans, points] = registerICP(points, target, varargin) %REGISTERICP Fit affine transform by Iterative Closest Point algorithm. % % TRANS = registerICP(POINTS, TARGET) % Computes the affine transform that maps the shape defines by POINTS % onto the shape defined by the points TARGET. Both POINTS and TARGET are % N-by-2 array of point coordinates, not necessarily the same size. % The result TRANS is a 3-by-3 affine transform. % % TRANS = registerICP(POINTS, TARGET, NITER) % Specifies the number of iterations for the algorithm. % % [TRANS, POINTS2] = registerICP(...) % Also returns the set of transformed points. % % Example % registerICP % % See also % transforms2d, fitAffineTransform2d, registerPoints3dAffine % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2015-02-24, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. nIter = 10; if ~isempty(varargin) nIter = varargin{1}; end % keep original points to transform them at each trans = [1 0 0;0 1 0;0 0 1]; for i = 1:nIter % identify target points for each source point inds = findClosestPoint(points, target); corrPoints = target(inds, :); % compute transform for current iteration trans_i = fitAffineTransform2d(points, corrPoints); % apply transform, and update cumulated transform points = transformPoint(points, trans_i); trans = trans_i * trans; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawEllipse.m0000644000000000000000000000013214055375162017512 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawEllipse.m0000644000175000017500000001211314055375162020575 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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. % % 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; axis([0 100 10 90]) % % % add another ellipse with different orientation and style % drawEllipse([50 50 40 20 -10], 'linewidth', 2, 'color', 'g'); % % See also: % ellipses2d, drawCircle, drawEllipseArc, ellipseToPolygon % % --------- % author : David Legland % e-mail: david.legland@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 % 2011-10-11 add support for axis handle %% Extract input arguments % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % 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(ax, xt, yt, styles{:}); end % return handles if required if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/polynomialTransform2d.m0000644000000000000000000000013214055375162021544 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/polynomialTransform2d.m0000644000175000017500000000606514055375162022640 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = polynomialTransform2d(pts, coeffs) %POLYNOMIALTRANSFORM2D Apply a polynomial transform to a set of points. % % RES = polynomialTransform2d(PTS, COEFFS) % Transforms the input points PTS given as a N-by-2 array of coordinates % using the polynomial transform defined by PARAMS. % PARAMS given as [a0 b0 a1 b1 ... an bn] % % Example % coeffs = [0 0 1 0 0 1 0.1 0 0 0 0 0.1]; % % cte x y x^2 x*y y^2 % pts = rand(200, 2) * 2 - 1; % pts2 = polynomialTransform2d(pts, coeffs); % figure; hold on; % drawPoint(pts); % drawPoint(pts2, 'g'); % % See also % transformPoint, fitPolynomialTransform2d % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-09-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. x = pts(:,1); y = pts(:,2); nPoints = length(x); xCoeffs = coeffs(1:2:end); yCoeffs = coeffs(2:2:end); nCoeffs = length(xCoeffs); % allocate memory for result x2 = zeros(nPoints, 1); y2 = zeros(nPoints, 1); % degree from coefficient number degree = sqrt(9/4 - 4*(1 - nCoeffs)/2) - 1.5; % iterate over degrees iCoeff = 0; for iDegree = 0:degree % iterate over binomial coefficients of a given degree for k = 0:iDegree iCoeff = iCoeff + 1; tmp = power(x, iDegree-k) .* power(y, k); x2 = x2 + xCoeffs(iCoeff) .* tmp; y2 = y2 + yCoeffs(iCoeff) .* tmp; end end res = [x2 y2]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawVector.m0000644000000000000000000000013214055375162017357 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawVector.m0000644000175000017500000000541414055375162020450 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawVector(pos, vect, varargin) %DRAWVECTOR Draw vector at a given position. % % drawVector(POS, VECT) % POS should be a N-by-2 or N-by-3 array containing position of vector % origins, and VECT should be a N-by-2 or N-by-3 array containing the % direction of the vectors. % % Example % figure; hold on; % drawVector([1 2], [3 2]); % drawVector([1 2], [-2 3]); % axis equal; % % See also % quiver, drawVector3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-03-18, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % check input dimension nd = size(pos, 2); if size(vect, 2) ~= nd error('input vector and position must have same dimension'); end if nd == 2 % Display 2D vectors h = quiver(pos(:, 1), pos(:, 2), vect(:, 1), vect(:, 2), 0, varargin{:}); elseif nd == 3 % Display 3D vectors h = quiver3(pos(:, 1), pos(:, 2), pos(:, 3), ... vect(:, 1), vect(:, 2), vect(:, 3), 0, varargin{:}); else error('Can not display vectors of dimension > 3'); end % format output if nargout > 0 varargout{1} = h; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/distancePoints.m0000644000000000000000000000013214055375162020226 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/distancePoints.m0000644000175000017500000001253414055375162021320 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dist = distancePoints(p1, p2, varargin) %DISTANCEPOINTS Compute distance between two points. % % D = distancePoints(P1, P2) % Return the Euclidean distance between points P1 and P2. % % If P1 and P2 are two arrays of points, result is a N1-by-N2 array % containing distance between each point of P1 and each point of P2. % % D = distancePoints(P1, P2, NORM) % Compute distance using the specified norm. NORM=2 corresponds to usual % euclidean distance, NORM=1 corresponds to Manhattan distance, NORM=inf % is assumed to correspond to maximum difference in coordinate. Other % values (>0) can be specified. % % D = distancePoints(..., 'diag') % compute only distances between P1(i,:) and P2(i,:). % % See also: % points2d, minDistancePoints, nndist, hausdorffDistance % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Copyright 2009 INRA - Cepia Software Platform. % created the 24/02/2004. % % HISTORY : % 25/05/2004: manage 2 array of points % 07/04/2004: add option for computing only diagonal. % 30/10/2006: generalize to any dimension, and manage different norms % 03/01/2007: bug for arbitrary norm, and update doc % 28/08/2007: fix bug for norms 2 and infinite, in diagonal case %% Setup options % default values diag = false; norm = 2; % check first argument: norm or diag if ~isempty(varargin) var = varargin{1}; if isnumeric(var) norm = var; elseif strncmp('diag', var, 4) diag = true; end varargin(1) = []; end % check last argument: diag if ~isempty(varargin) var = varargin{1}; if strncmp('diag', var, 4) diag = true; end end % number of points in each array and their dimension n1 = size(p1, 1); n2 = size(p2, 1); d = size(p1, 2); if diag % compute distance only for apparied couples of pixels dist = zeros(n1, 1); if norm == 2 % Compute euclidian distance. this is the default case % Compute difference of coordinate for each pair of point % and for each dimension. -> dist is a [n1*n2] array. for i = 1:d dist = dist + (p2(:,i)-p1(:,i)).^2; end dist = sqrt(dist); elseif norm == inf % infinite norm corresponds to maximal difference of coordinate for i = 1:d dist = max(dist, abs(p2(:,i)-p1(:,i))); end else % compute distance using the specified norm. for i = 1:d dist = dist + power((abs(p2(:,i)-p1(:,i))), norm); end dist = power(dist, 1/norm); end else % compute distance for all couples of pixels dist = zeros(n1, n2); if norm == 2 % Compute euclidian distance. This is the default case. % Compute difference of coordinate for each pair of point % and for each dimension. -> dist is a [n1*n2] array. for i = 1:d % equivalent to: % dist = dist + ... % (repmat(p1(:,i), [1 n2])-repmat(p2(:,i)', [n1 1])).^2; dist = dist + bsxfun (@minus, p1(:,i), p2(:, i)').^2; end dist = sqrt(dist); elseif norm == inf % infinite norm corresponds to maximal difference of coordinate for i = 1:d dist = max(dist, abs(bsxfun (@minus, p1(:,i), p2(:, i)'))); end else % compute distance using the specified norm. for i = 1:d % equivalent to: % dist = dist + power((abs(repmat(p1(:,i), [1 n2]) - ... % repmat(p2(:,i)', [n1 1]))), norm); dist = dist + power(abs(bsxfun(@minus, p1(:,i), p2(:, i)')), norm); end dist = power(dist, 1/norm); end end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/intersectCircles.m0000644000000000000000000000013214055375162020544 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/intersectCircles.m0000644000175000017500000001074414055375162021637 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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: david.legland@grignon.inra.fr % 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); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createHomothecy.m0000644000000000000000000000013214055375162020362 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createHomothecy.m0000644000175000017500000000536314055375162021456 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function T = createHomothecy(point, ratio) %CREATEHOMOTHECY Create the the 3x3 matrix of an homothetic transform. % % TRANS = createHomothecy(POINT, K); % POINT is the center of the homothecy, K is its factor. % TRANS is a 3-by-3 matrix representing the homothetic transform in % homogeneous coordinates. % % Example: % % p = [0 0; 1 0; 0 1]; % s = [-0.5 0.4]; % T = createHomothecy (s, 1.5); % pT = transformPoint (p, T); % drawPolygon (p,'-b') % hold on; % drawPolygon (pT, '-r'); % % drawEdge (p(:,1), p(:,2), pT(:,1), pT(:,2), ... % 'color', 'k','linestyle','--') % hold off % axis tight equal % % --------- % Author: David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 20/01/2005. % HISTORY % 22/04/2009: rename as createHomothecy % 05/04/2017: improved code by JuanPi Carbajal point = point(:); if length (point) > 2 error('Only one point accepted.'); end if length (ratio) > 1 error('Only one ratio accepted.'); end T = diag ([ratio ratio 1]); T(1:2,3) = point .* (1 - ratio); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/angle2Points.m0000644000000000000000000000013214055375162017604 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/angle2Points.m0000644000175000017500000000526214055375162020676 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = angle2Points(varargin) %ANGLE2POINTS Compute horizontal angle between 2 points. % % ALPHA = angle2Points(P1, P2), % Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a % [N*1] array. The angle computed is the horizontal angle of the line % (P1 P2) % Result is always given in radians, between 0 and 2*pi. % % See Also: % points2d, angles2d, angle3points, normalizeAngle, vectorAngle % % % --------- % Author: David Legland % e-mail: david.legland@grignon.inra.fr % created the 02/03/2007. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY: % 2011-01-11 use bsxfun % process input arguments if length(varargin)==2 p1 = varargin{1}; p2 = varargin{2}; elseif length(varargin)==1 var = varargin{1}; p1 = var(1,:); p2 = var(2,:); end % ensure data have correct size n1 = size(p1, 1); n2 = size(p2, 1); if n1~=n2 && min(n1, n2)>1 error('angle2Points: wrong size for inputs'); end % angle of line (P2 P1), between 0 and 2*pi. dp = bsxfun(@minus, p2, p1); theta = mod(atan2(dp(:,2), dp(:,1)) + 2*pi, 2*pi); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/rays2d.m0000644000000000000000000000013214055375162016443 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/rays2d.m0000644000175000017500000000477114055375162017541 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function rays2d(varargin) %RAYS2D Description of functions operating on planar rays. % % A ray is defined by a point (its origin), and a vector (its % direction). The different parameters are bundled into a row vector: % RAY = [x0 y0 dx dy]; % % The ray contains all the points (x,y) such that: % x = x0 + t*dx % y = y0 + t*dy; % for all t>0 % % Contrary to a (straight) line, the points located before the origin do % not belong to the ray. % However, as rays and lines have the same representation, some functions % working on lines are also working on rays (like 'transformLine'). % % See also: % points2d, vectors2d, lines2d % createRay, bisector, isPointOnRay % clipRay, drawRay % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('rays2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/medianLine.m0000644000000000000000000000013214055375162017304 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/medianLine.m0000644000175000017500000000744714055375162020405 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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); 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/lines2d.m0000644000000000000000000000013214055375162016577 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/lines2d.m0000644000175000017500000000540614055375162017671 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function lines2d(varargin) %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 parameters are bundled into a 1-by-4 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. % % See also: % points2d, vectors2d, edges2d, rays2d % createLine, cartesianLine, medianLine, edgeToLine, lineToEdge % orthogonalLine, parallelLine, bisector, radicalAxis % lineAngle, linePosition, projPointOnLine % isPointOnLine, distancePointLine, isLeftOriented % intersectLines, intersectLineEdge, clipLine % reverseLine, transformLine, drawLine % lineFit % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('lines2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/angles2d.m0000644000000000000000000000013214055375162016736 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/angles2d.m0000644000175000017500000000453614055375162020033 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function angles2d % Description of functions for manipulating angles. % % Angles are normalized in an interval of width 2*PI. Most geom2d % functions return results in the [0 2*pi] interval, but it can be % convenient to consider the [-pi pi] interval as well. See the % normalizeAngle function to switch between conventions. % % Angles are usually oriented. The default orientation is the CCW % (Counter-Clockwise) orientation. % % See also: % normalizeAngle, angleDiff, angleAbsDiff, angleSort % angle2Points, angle3Points, vectorAngle, lineAngle, edgeAngle % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2010-03-31, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. help('angles2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/findClosestPoint.m0000644000000000000000000000013214055375162020526 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/findClosestPoint.m0000644000175000017500000000521214055375162021613 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [index, minDist] = findClosestPoint(coord, points) %FINDCLOSESTPOINT Find index of closest point in an array. % % INDEX = findClosestPoint(POINT, POINTARRAY) % % [INDEX, MINDIST] = findClosestPoint(POINT, POINTARRAY) % Also returns the distance between POINT and closest point in % POINTARRAY. % % Example % pts = rand(10, 2); % findClosestPoint(pts(4, :), pts) % ans = % 4 % % See also % points2d, minDistancePoints, distancePoints % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2015-02-24, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. % number of points % number of point in first input to process np = size(coord, 1); % allocate memory for result index = zeros(np, 1); minDist = zeros(np, 1); for i = 1:np % compute squared distance between current point and all point in array dist = sum(bsxfun(@minus, coord(i,:), points) .^ 2, 2); % keep index of closest point [minDist(i), index(i)] = min(dist); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/enclosingCircle.m0000644000000000000000000000013214055375162020342 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/enclosingCircle.m0000644000175000017500000000677214055375162021443 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function circle = enclosingCircle(pts) %ENCLOSINGCIRCLE Find the minimum circle enclosing a set of points. % % CIRCLE = enclosingCircle(POINTS); % computes the circle CIRCLE=[xc yc r] which encloses all the points POINTS % given as a N-by-2 array. % % % Rewritten from a file from % Yazan Ahed (yash78@gmail.com) % % which was rewritten from a Java applet by Shripad Thite: % http://heyoka.cs.uiuc.edu/~thite/mincircle/ % % See also: % circles2d, points2d, boxes2d, circumCircle % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % created the 07/07/2005. % Copyright 2012 INRA - Cepia Software Platform. % works on convex hull: it is faster pts = pts(convhull(pts(:,1), pts(:,2)), :); % call the recursive function circle = recurseCircle(size(pts, 1), pts, 1, zeros(3, 2)); 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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawParabola.m0000644000000000000000000000013214055375162017636 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawParabola.m0000644000175000017500000001153014055375162020723 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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. % % drawParabola(AX, ...); % Specifies handle of the axis to draw on. % % H = drawParabola(...); % Returns an handle to the created graphical object. % % % Example: % figure(1); clf; hold on; % axis equal; axis([0 100 0 100]) % % draw parabola with default parameterization bounds % drawParabola([50 50 .2 30]); % % draw parabola with more specific bounds and drawing style % drawParabola([50 50 .2 30], [-3 3], 'color', 'r', 'linewidth', 2); % % % 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 % 2011-10-11 add management of axes handle % Extract parabola if nargin < 1 error('geom2d:drawParabola:IllegalArgument', ... 'Please specify parabola representation'); end % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % input parabola is given as a packed array parabola = varargin{1}; varargin(1) = []; x0 = parabola(:,1); y0 = parabola(:,2); a = parabola(:,3); % check if parabola orientation is specified 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 array 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(ax, xt, yt, varargin{:}); end % process output arguments if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/readme.txt0000644000000000000000000000013214055375161017056 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/readme.txt0000644000175000017500000000307414055375161020147 0ustar00juanpijuanpi00000000000000Description 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'. matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/reverseEdge.m0000644000000000000000000000013214055375162017477 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/reverseEdge.m0000644000175000017500000000413714055375162020571 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = reverseEdge(edge) %REVERSEEDGE 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]; % % See also: % edges2d, createEdge, reverseLine % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-05-13, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. res = [edge(:,3:4) edge(:,1:2)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createBasisTransform.m0000644000000000000000000000013214055375162021360 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createBasisTransform.m0000644000175000017500000001111714055375162022446 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function transfo = createBasisTransform(source, target) %CREATEBASISTRANSFORM Compute matrix for transforming a basis into another basis. % % TRANSFO = createBasisTransform(SOURCE, TARGET) % Both SOURCE and TARGET represent basis, in the following form: % [x0 y0 ex1 ey1 ex2 ey2] % [y0 y0] is the origin of the basis, [ex1 ey1] is the first direction % vector, and [ex2 ey2] is the second direction vector. % % The result TRANSFO is a 3-by-3 matrix such that a point expressed with % coordinates of the first basis will be represented by new coordinates % P2 = transformPoint(P1, TRANSFO) in the target basis. % % TRANSFO = createBasisTransform(TARGET) % Assumes the source is the standard (Oij) basis, with origin at (0,0), % first direction vector equal to (1,0) and second direction vector % equal to (0,1). % % % Example % % define source and target bases % src = [ 0 0 1 0 0 1]; % tgt = [20 0 .5 .5 -.5 .5]; % trans = createBasisTransform(src, tgt); % % create a polygon in source basis % poly = [10 10;30 10; 30 20; 20 20;20 40; 10 40]; % figure; % subplot(121); drawPolygon(poly, 'b'); axis equal; axis([-10 50 -10 50]); % hold on; drawLine([0 0 1 0], 'k'); drawLine([0 0 0 1], 'k'); % drawLine([20 0 1 1], 'r'); drawLine([20 0 -1 1], 'r'); % t = -1:5; plot(t*5+20, t*5, 'r.'); plot(-t*5+20, t*5, 'r.'); % % transform the polygon in target basis % poly2 = transformPoint(poly, trans); % subplot(122); drawPolygon(poly2, 'b'); axis equal; axis([-10 50 -10 50]); % hold on; drawLine([0 0 1 0], 'r'); drawLine([0 0 0 1], 'r'); % t = -1:5; plot(t*10, zeros(size(t)), 'r.'); plot(zeros(size(t)), t*10, 'r.'); % % See also % transforms2d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-12-03, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % init basis transform to identity t1 = eye(3); t2 = eye(3); if nargin == 2 % from source to reference basis t1(1:2, 1) = source(3:4); t1(1:2, 2) = source(5:6); t1(1:2, 3) = source(1:2); else % if only one input, use first input as target basis, and leave the % first matrix to identity target = source; end % from reference to target basis t2(1:2, 1) = target(3:4); t2(1:2, 2) = target(5:6); t2(1:2, 3) = target(1:2); % compute transform matrix transfo = zeros(3, 3); maxSz = 1; for i = 1:maxSz % coordinate of three reference points in source basis po = t1(1:2, 3, i)'; px = po + t1(1:2, 1, i)'; py = po + t1(1:2, 2, i)'; % express coordinates of reference points in the new basis t2i = inv(t2(:,:,i)); pot = transformPoint(po, t2i); pxt = transformPoint(px, t2i); pyt = transformPoint(py, t2i); % compute direction vectors in new basis vx = pxt - pot; vy = pyt - pot; % concatenate result in a 3-by-3 affine transform matrix transfo(:,:,i) = [vx' vy' pot' ; 0 0 1]; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createLine.m0000644000000000000000000000013214055375162017312 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createLine.m0000644000175000017500000001446114055375162020405 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = createLine(varargin) %CREATELINE Create a straight line from 2 points, or from other inputs. % % Line is represented in a parametric form : [x0 y0 dx dy] % x = x0 + t*dx % y = y0 + t*dy; % % % L = createLine(p1, p2); % Returns the line going through the two given points. % % L = createLine(x0, y0, dx, dy); % Returns the line going through point (x0, y0) and with direction % vector(dx, dy). % % L = createLine(LINE); % where LINE is an array of 4 values, creates the line going through the % point (LINE(1) LINE(2)), and with direction given by vector (LINE(3) % LINE(4)). % % L = createLine(THETA); % Create a polar line originated at (0,0) and with angle THETA. % % L = createLine(p, THETA); % Create a polar line originated at p and with angle THETA. % % L = createLine(RHO, THETA); % Create a polar line with normal theta, and with min distance to origin % equal to rho. rho can be negative, in this case, the line is the same % as with CREATELINE(-rho, theta+pi), but the orientation is different. % % % Note: in all cases, parameters can be vertical arrays of the same % dimension. The result is then an array of lines, of dimensions [N*4]. % % % See also: % lines2d, createEdge, createRay % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY : % 18/02/2004 : add more possibilities to create lines (4 parameters, % all param in a single tab, and point + dx + dy. % Also add support for creation of arrays of lines. % NOTE : A line can also be represented with a 1*5 array : % [x0 y0 dx dy t]. % whith 't' being one of the following : % - t=0 : line is a singleton (x0,y0) % - t=1 : line is an edge segment, between points (x0,y0) and (x0+dx, % y0+dy). % - t=Inf : line is a Ray, originated from (x0,y0) and going to infinity % in the direction(dx,dy). % - t=-Inf : line is a Ray, originated from (x0,y0) and going to infinity % in the direction(-dx,-dy). % - t=NaN : line is a real straight line, and contains all points % verifying the above equation. % This seems us a convenient way to represent uniformly all kind of lines % (including edges, rays, and even point). % % NOTE2 : Any line object can be represented using a 1x6 array : % [x0 y0 dx dy t0 t1] % the first 4 parameters define the supporting line, % t0 represent the position of the first point on the line, % and t1 the position of the last point. % * for edges : t0 = 0, and t1=1 % * for straight lines : t0 = -inf, t1=inf % * for rays : t0=0, t1=inf (or t0=-inf,t1=0 for inverted ray). % I propose to call these objects 'lineArc' 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. line = var; elseif size(var, 2)==1 % 1 parameter : angle of the line, going through origin. line = [zeros(size(var)) zeros(size(var)) 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 : % - line angle and signed distance to origin. % - 2 points, then 2 arrays of 1*2 double. v1 = varargin{1}; v2 = varargin{2}; if size(v1, 2)==2 && size(v2, 2)==1 % first param is point, and second param is angle of line line = [v1(:,1), v1(:,2) cos(v2) sin(v2)]; elseif size(v1, 2)==1 % first param is angle of line, and second param is signed distance % to origin. line = [v1.*cos(v2) v1.*sin(v2) -sin(v2) cos(v2)]; elseif size(v1, 2)==3 || size(v2, 2)==3 error('The 1st or 2nd input argument has 3 columns. You may want to try createLine3d.'); else % first input parameter is first point, and second input is the % second point. line = [v1(:,1), v1(:,2), v2(:,1)-v1(:,1), v2(:,2)-v1(:,2)]; 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}; line = [p(:,1) p(:,2) varargin{2} varargin{3}]; elseif length(varargin)==4 % 4 input parameters : % they are x0, y0 (point belongng to line) and dx, dy (direction vector % of the line). % All parameters should have the same size. line = [varargin{1} varargin{2} varargin{3} varargin{4}]; else error('Wrong number of arguments in ''createLine'' '); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPointInEllipse.m0000644000000000000000000000013214055375162020471 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPointInEllipse.m0000644000175000017500000000546214055375162021565 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/ellipses2d.m0000644000000000000000000000013214055375162017305 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/ellipses2d.m0000644000175000017500000000424714055375162020401 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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, equivalentEllipse, isPointInEllipse, ellipsePerimeter % ellipseToPolygon, drawEllipse, drawEllipseArc % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. help('ellipses2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawCenteredEdge.m0000644000000000000000000000013214055375162020433 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawCenteredEdge.m0000644000175000017500000001213514055375162021522 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCenteredEdge(varargin) %DRAWCENTEREDEDGE Draw an edge centered on a point. % % Draws a centered edge, defined by a center, a length and an orientation % (in degrees). This function can be used to draw principal axes of an % ellipse or of an oriented box. % % % drawCenteredEdge(EDGE) % Draws an edge centered on a point. EDGE has format [XC YC L THETA], % with (Xc, YC) being edge center, L being the edge length, and THETA % beigng the edge orientation, in degrees (counted Counter-clockwise from % horizontal). % Input argument can also be a N-by-4 array, in that can several edges % are drawn. % % drawCenteredEdge(CENTER, L, THETA) % Specifies argument in seperate inputs. % % drawCenteredEdge(..., NAME, VALUE) % Also specifies drawing options by using one or several parameter name - % value pairs (see doc of plot function for details). % % drawCenteredEdge(AX, ...) % Specifies the axis to draw the edge on. % % 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, drawOrientedBox, drawEllipse, centeredEdgeToEdge, 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 % 2011-10-11 add management of axes handle %% process input variables if nargin < 1 error('Function requires an input argument'); end % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end var = varargin{1}; if size(var, 2) == 4 % manage edge in single parameter len = var(:, 3); theta = var(:, 4); center = var(:, 1:2); N = size(center, 1); varargin(1) = []; elseif length(varargin) >= 3 % parameters given in different arguments % size of data center = varargin{1}; len = varargin{2}; theta = varargin{3}; varargin(1:3) = []; % ensure all data have same size NP = size(center, 1); NL = size(len, 1); ND = size(theta, 1); N = max([NP NL ND]); 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(ax, [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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawLine.m0000644000000000000000000000013214055375162017004 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawLine.m0000644000175000017500000000650214055375162020074 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawLine(lin, varargin) %DRAWLINE Draw a straight line clipped by the current axis. % % drawLine(LINE); % Draws the line LINE on the current axis, by using current axis to clip % the line. % % drawLine(LINE, PARAM, VALUE); % Specifies drawing options. % % H = drawLine(...) % Returns a handle to the created line object. If clipped line is not % contained in the axis, the function returns -1. % % Example % figure; hold on; axis equal; % axis([0 100 0 100]); % drawLine([30 40 10 20]); % drawLine([30 40 20 -10], 'Color', 'm', 'LineWidth', 2); % drawLine([-30 140 10 20]); % % See also: % lines2d, createLine, drawEdge % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 25/05/2004 add support for multiple lines (loop) % 23/05/2005 add support for arguments % 03/08/2010 bug for lines outside box (thanks to Reto Zingg) % 04/08/2010 rewrite using clipLine % 2011-10-11 add management of axes handle % extract handle of axis to draw in if isAxisHandle(lin) ax = lin; lin = varargin{1}; varargin(1) = []; else ax = gca; end % default style for drawing lines if length(varargin) ~= 1 varargin = [{'color', 'b'}, varargin]; end % extract bounding box of the current axis xlim = get(ax, 'xlim'); ylim = get(ax, 'ylim'); % clip lines with current axis box clip = clipLine(lin, [xlim ylim]); ok = isfinite(clip(:,1)); % initialize result array to invalide handles h = -1 * ones(size(lin, 1), 1); % draw valid lines h(ok) = plot(ax, clip(ok, [1 3])', clip(ok, [2 4])', varargin{:}); % return line handle if needed if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/edgeLength.m0000644000000000000000000000013214055375162017305 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/edgeLength.m0000644000175000017500000000505314055375162020375 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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-by-4 array, containing parametric representation of each edge, and % output is a N-by-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]. if nargin == 1 % input is an edge [X1 Y1 X2 Y2] edge = varargin{1}; len = hypot(edge(:,3)-edge(:,1), edge(:,4)-edge(:,2)); elseif nargin == 2 % input are two points [X1 Y1] and [X2 Y2] p1 = varargin{1}; p2 = varargin{2}; len = hypot(p2(:,1)-p1(:,1), p2(:,2)-p1(:,2)); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/clipLine.m0000644000000000000000000000013214055375162016776 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/clipLine.m0000644000175000017500000001146214055375162020067 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = clipLine(line, box, varargin) %CLIPLINE Clip a line with a box. % % EDGE = clipLine(LINE, BOX); % LINE is a straight line given as a 4 element row vector: [x0 y0 dx dy], % with (x0 y0) being a point of the line and (dx dy) a direction vector, % BOX is the clipping box, given by its extreme coordinates: % [xmin xmax ymin ymax]. % The result is given as an edge, defined by the coordinates of its 2 % extreme points: [x1 y1 x2 y2]. % If line does not intersect the box, [NaN NaN NaN NaN] is returned. % % Function works also if LINE is a N-by-4 array, if BOX is a Nx4 array, % or if both LINE and BOX are N-by-4 arrays. In these cases, EDGE is a % N-by-4 array. % % % Example % line = [30 40 10 0]; % box = [0 100 0 100]; % res = clipLine(line, box) % res = % 0 40 100 40 % % See also: % lines2d, boxes2d, edges2d % clipEdge, clipRay, clipLine3d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-08-27, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2010-05-16 rewrite using intersectLines, add precision management % 2010-08-03 fix bugs (thanks to Reto Zingg) % 2010-08-06 remove management of EPS by checking edge midpoint (thanks % again to Reto Zingg) % adjust size of two input arguments nLines = size(line, 1); nBoxes = size(box, 1); if nLines == 1 && nBoxes > 1 line = repmat(line, nBoxes, 1); elseif nBoxes == 1 && nLines > 1 box = repmat(box, nLines, 1); elseif nLines ~= nBoxes error('bad sizes for input'); end % allocate memory nLines = size(line, 1); edge = zeros(nLines, 4); % main loop on lines for i = 1:nLines % extract limits of the box xmin = box(i, 1); xmax = box(i, 2); ymin = box(i, 3); ymax = box(i, 4); % use direction vector for box edges similar to direction vector of the % line in order to reduce computation errors delta = hypot(line(i,3), line(i,4)); % compute intersection with each edge of the box px1 = intersectLines(line(i,:), [xmin ymin delta 0]); % lower edge px2 = intersectLines(line(i,:), [xmax ymin 0 delta]); % right edge py1 = intersectLines(line(i,:), [xmax ymax -delta 0]); % upper edge py2 = intersectLines(line(i,:), [xmin ymax 0 -delta]); % left edge % remove undefined intersections (case of lines parallel to box edges) points = [px1 ; px2 ; py1 ; py2]; points = points(isfinite(points(:,1)), :); % sort points according to their position on the line pos = linePosition(points, line(i,:)); [pos, inds] = sort(pos); %#ok points = points(inds, :); % create clipped edge by using the two points in the middle ind = size(points, 1)/2; inter1 = points(ind,:); inter2 = points(ind+1,:); edge(i, 1:4) = [inter1 inter2]; % check that middle point of the edge is contained in the box midX = mean(edge(i, [1 3])); xOk = xmin <= midX && midX <= xmax; midY = mean(edge(i, [2 4])); yOk = ymin <= midY && midY <= ymax; % if one of the bounding condition is not met, set edge to NaN if ~(xOk && yOk) edge (i,:) = NaN; end end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/transformLine.m0000644000000000000000000000013214055375162020062 xustar0030 mtime=1622538866.066813615 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/transformLine.m0000644000175000017500000000515214055375162021152 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dest = transformLine(line, trans) %TRANSFORMLINE Transform a line with an affine transform. % % LINE2 = transformLine(LINE1, TRANS); % returns the line LINE1 transformed with affine transform TRANS. % LINE1 has the form [x0 y0 dx dy], and TRANS is a transformation % matrix. % % Format of TRANS can be one of : % [a b] , [a b c] , or [a b c] % [d e] [d e f] [d e f] % [0 0 1] % % LINE2 = transformLine(LINES, TRANS); % Also work when LINES is a [N*4] array of double. In this case, LINE2 % has the same size as LINE. % % See also: % lines2d, transforms2d, transformPoint % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 02/03/2007: rewrite function % isolate points points1 = line(:, 1:2); points2 = line(:, 1:2) + line(:, 3:4); % transform points points1 = transformPoint(points1, trans); points2 = transformPoint(points2, trans); dest = createLine(points1, points2); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/hausdorffDistance.m0000644000000000000000000000013214055375162020673 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.066813615 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/hausdorffDistance.m0000644000175000017500000000702714055375162021766 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [hd, ind1, ind2] = hausdorffDistance(pts1, pts2) %HAUSDORFFDISTANCE Hausdorff distance between two point sets. % % HD = hausdorffDistance(PTS1, PTS2) % Computes the Hausdorff distance between the two point sets PTS1 and % PTS2. The Hausdorf distance can be used to compare two shapes. % % The distance between a point x and a set Y is given by: % d(x, Y) = inf { d(x,y) | y in Y } % The distance between two non empty sets X and Y is given by: % d(X, Y) = sup { d(x,Y) | x in X } % The Hausdorff distance between sets X and Y distance is defined as the % maximum of d(X,Y) and d(Y,X): % HD(X,Y) = max { d(X,Y), d(Y,X) } % % % Example % % Compute Hausdorff distance between an ellipse and a rectangle % % first define two shapes % rect = resamplePolygon(orientedBoxToPolygon([20 30 80 40 30]), 60); % poly = ellipseToPolygon([20 30 40 20 30], 500); % % display the shapes % figure; hold on % drawPolygon(poly, 'b'); % drawPolygon(rect, 'g'); % axis equal; % % compute hausdorff distance % [hd ind1 ind2] = hausdorffDistance(poly, rect); % p1h = poly(ind1, :); % p2h = rect(ind2, :); % drawPoint([p1h;p2h], 'mo'); % drawEdge([p1h p2h], 'm') % % See also % points2d, minDistancePoints % % References % http://en.wikipedia.org/wiki/Hausdorff_distance % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2012-05-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRAE - Cepia Software Platform. % distance from pts1 to pts2 [dists1, ind12] = minDistancePoints(pts1, pts2); [max1, ind11] = max(dists1); % distance from pts2 to pts1 [dists2, ind22] = minDistancePoints(pts2, pts1); [max2, ind21] = max(dists2); % keep the max of the two distances hd = max(max1, max2); % keep the rigt indices if max1 > max2 ind1 = ind11; ind2 = ind12(ind11); else ind1 = ind22(ind21); ind2 = ind21; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createDirectedCircle.m0000644000000000000000000000013214055375162021270 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createDirectedCircle.m0000644000175000017500000000623514055375162022363 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/edgeToPolyline.m0000644000000000000000000000013214055375162020162 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/edgeToPolyline.m0000644000175000017500000000514314055375162021252 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly = edgeToPolyline(edge, N) %EDGETOPOLYLINE Convert an edge to a polyline with a given number of segments. % % POLY = edgeToPolyline(EDGE, N) % % Example % edge = [10 20 60 40]; % poly = edgeToPolyline(edge, 10); % drawEdge(edge, 'lineWidth', 2); % hold on % drawPoint(poly); % axis equal; % % See also % edges2d, drawEdge, drawPolyline % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-11-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. if N < 1 error('number of segments must be greater than 1'); end if length(edge) == 4 % case of planar edges p1 = edge(1:2); p2 = edge(3:4); poly = [linspace(p1(1), p2(1), N+1)' linspace(p1(2), p2(2), N+1)']; else % case of 3D edges p1 = edge(1:3); p2 = edge(4:6); poly = [... linspace(p1(1), p2(1), N+1)' ... linspace(p1(2), p2(2), N+1)' ... linspace(p1(3), p2(3), N+1)']; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/edgeAngle.m0000644000000000000000000000013214055375162017112 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/edgeAngle.m0000644000175000017500000000442214055375162020201 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = edgeAngle(edge) %EDGEANGLE Return angle of edge. % % A = edgeAngle(EDGE) % Returns the angle between horizontal, right-axis and the edge EDGE. % Angle is given in radians, between 0 and 2*pi, in counter-clockwise % direction. % Notation for edge is [x1 y1 x2 y2] (coordinates of starting and ending % points). % % Example % p1 = [10 20]; % p2 = [30 40]; % rad2deg(edgeAngle([p1 p2])) % ans = % 45 % % See also % edges2d, angles2d, edgeAngle, lineAngle, edgeLength % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2003. % line = createLine(edge(:,1:2), edge(:,3:4)); theta = lineAngle(line); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/intersectLineCircle.m0000644000000000000000000000013214055375162021171 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/intersectLineCircle.m0000644000175000017500000001026414055375162022261 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = intersectLineCircle(line, circle) % Intersection point(s) of a line and a circle. % % INTERS = intersectLineCircle(LINE, CIRCLE); % Returns a 2-by-2-by-N array, containing on each row the coordinates of % an intersection point for each line-circle pair, i.e. INTERS(:,:,k) % contains the intersections between LINE(k,:) and CIRCLE(k,:). % % If a line-circle pair does not intersect, the corresponding results are % set to 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, david.legland@inrae.fr % Author: JuanPi Carbajal % 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 % 2017-05-05 included some suggestions from code by JuanPi Carbajal % 2017-08-08 update doc % check size of inputs nLines = size(line, 1); nCircles = size(circle, 1); if nLines ~= nCircles error ('matGeom:geom3d:invalidArguments', ... 'Requires same number of lines and circles'); end % center parameters center = circle(:, 1:2); radius = circle(:, 3); % line parameters dp = line(:, 1:2) - center; vl = line(:, 3:4); % coefficients 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; points = nan(2, 2, nCircles); valid = delta >= 0; if any(valid) % compute roots (as a N-by-N-by-2 array) u = bsxfun(@plus, -b(valid), bsxfun(@times, [-1 1], sqrt(delta(valid)))); u = bsxfun(@rdivide, u, a(valid)) / 2; if sum(valid) == 1 points = [... line(1:2) + u(:,1) .* line(3:4); ... line(1:2) + u(:,2) .* line(3:4)]; else tmp = [... line(valid, 1:2) + u(:,1) .* line(valid, 3:4) ... line(valid, 1:2) + u(:,2) .* line(valid, 3:4)].'; points(:, :, valid) = permute(reshape(tmp, [2, 2, nCircles]), [2 1 3]); end end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/reverseLine.m0000644000000000000000000000013214055375162017522 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/reverseLine.m0000644000175000017500000000416114055375162020611 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = reverseLine(line) %REVERSELINE 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]. % % See also: % lines2d, createLine % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 20/01/2004. % % HISTORY % 30/06/2009 rename as reverseLine % 15/03/2011 simplify code line(:, 3:4) = -line(:, 3:4); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/angle3Points.m0000644000000000000000000000013214055375162017605 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/angle3Points.m0000644000175000017500000000507114055375162020675 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = angle3Points(varargin) %ANGLE3POINTS Compute oriented angle made by 3 points. % % ALPHA = angle3Points(P1, P2, P3); % Computes the angle between the points P1, P2 and P3. % Pi are either [1*2] arrays, or [N*2] arrays, in this case ALPHA is a % [N*1] array. The angle computed is the directed angle between line % (P2P1) and line (P2P3). % Result is always given in radians, between 0 and 2*pi. % % See Also: % points2d, angles2d, angle2points % % % --------- % Author: David Legland % e-mail: david.legland@grignon.inra.fr % created the 23/02/2004. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY : % 25/09/2005 : enable single parameter if length(varargin)==3 p1 = varargin{1}; p2 = varargin{2}; p3 = varargin{3}; elseif length(varargin)==1 var = varargin{1}; p1 = var(1,:); p2 = var(2,:); p3 = var(3,:); end % angle line (P2 P1) theta = lineAngle(createLine(p2, p1), createLine(p2, p3)); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/bisector.m0000644000000000000000000000013214055375162017051 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/bisector.m0000644000175000017500000000621614055375162020143 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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, normalized to have unit % norm. % % See also: % lines2d, rays2d % % --------- % Author: David Legland % e-mail: david.legland@grignon.inra.fr % created the 31/10/2003. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2005-07-07 add bisector of 3 points % 2010-11-05 ode cleanup 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)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/clipPoints.m0000644000000000000000000000013214055375162017363 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/clipPoints.m0000644000175000017500000000446314055375162020457 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = clipPoints(points, box) %CLIPPOINTS Clip a set of points by a box. % % CLIP = clipPoints(POINTS, BOX); % Returns the set of points which are located inside of the box BOX. % % % See also % points2d, boxes2d, clipLine, drawPoint % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. % get bounding box limits xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % compute indices of points inside visible area xOk = points(:,1)>=xmin & points(:,1)<=xmax; yOk = points(:,2)>=ymin & points(:,2)<=ymax; % keep only points inside box points = points(xOk & yOk, :); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/projPointOnLine.m0000644000000000000000000000013214055375162020330 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/projPointOnLine.m0000644000175000017500000000557114055375162021425 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = projPointOnLine(point, line) %PROJPOINTONLINE Project of a point orthogonally onto a line. % % PT2 = projPointOnLine(PT, LINE). % Computes the (orthogonal) projection of point PT onto the line LINE. % % Function works also for multiple points and lines. In this case, it % returns multiple points. % Point PT1 is a [N*2] array, and LINE is a [N*4] array (see createLine % for details). Result PT2 is a [N*2] array, containing coordinates of % orthogonal projections of PT1 onto lines LINE. % % Example % line = [0 2 2 1]; % projPointOnLine([3 1], line) % ans = % 2 3 % % See also: % lines2d, points2d, isPointOnLine, linePosition % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/04/2005. % % HISTORY % 2005-08-06 correct bug when several points were passed as param. % 2012-08-23 remove repmats % direction vector of the line vx = line(:, 3); vy = line(:, 4); % difference of point with line origin dx = point(:,1) - line(:,1); dy = point(:,2) - line(:,2); % Position of projection on line, using dot product tp = (dx .* vx + dy .* vy ) ./ (vx .* vx + vy .* vy); % convert position on line to cartesian coordinates point = [line(:,1) + tp .* vx, line(:,2) + tp .* vy]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/randomPointInBox.m0000644000000000000000000000013214055375162020471 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/randomPointInBox.m0000644000175000017500000000537214055375162021565 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = randomPointInBox(box, N, varargin) %RANDOMPOINTINBOX Generate random point within a box. % % PTS = randomPointInBox(BOX) % Generate a random point within the box BOX. The result is a 1-by-2 row % vector. % % PTS = randomPointInBox(BOX, N) % Generates N points within the box. The result is a N-by-2 array. % % BOX has the format: % BOX = [xmin xmax ymin ymax]. % % Example % % draw points within a box % box = [10 80 20 60]; % pts = randomPointInBox(box, 500); % figure(1); clf; hold on; % drawBox(box); % drawPoint(pts, '.'); % axis('equal'); % axis([0 100 0 100]); % % See also % geom2d, points2d, boxes2d, randomPointInBox3d, randomPointInPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-10-10, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. if nargin < 2 N = 1; end % extract box bounds xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % compute size of box dx = xmax - xmin; dy = ymax - ymin; % compute point coordinates points = [rand(N, 1)*dx+xmin , rand(N, 1)*dy+ymin]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/angleSort.m0000644000000000000000000000013214055375162017175 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/angleSort.m0000644000175000017500000000633514055375162020271 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = angleSort(pts, varargin) %ANGLESORT Sort points in the plane according to their angle to origin. % % % PTS2 = angleSort(PTS); % Computes angle of points with origin, and sort points with increasing % angles in Counter-Clockwise direction. % % PTS2 = angleSort(PTS, PTS0); % Computes angles between each point of PTS and PT0, which can be % different from origin. % % PTS2 = angleSort(..., THETA0); % Specifies the starting angle for sorting. % % [PTS2, I] = angleSort(...); % Also returns in I the indices of PTS, such that PTS2 = PTS(I, :); % % [PTS2, I, ANGLES] = angleSort(...); % Also returns the ANGLES in corresponding order to PTS2. % % See Also: % points2d, angles2d, angle2points, normalizeAngle % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2005-11-24 % Copyright 2010 INRA - Cepia Software Platform. % HISTORY : % default values pt0 = [0 0]; theta0 = 0; if length(varargin)==1 var = varargin{1}; if size(var, 2)==1 % specify angle theta0 = var; else pt0 = var; end elseif length(varargin)==2 pt0 = varargin{1}; theta0 = varargin{2}; end n = size(pts, 1); pts2 = pts - repmat(pt0, [n 1]); angle = lineAngle([zeros(n, 2) pts2]); angle = mod(angle - theta0 + 2*pi, 2*pi); [angles, I] = sort(angle); % format output switch nargout case 1 varargout{1} = pts(I, :); case 2 varargout{1} = pts(I, :); varargout{2} = I; case 3 varargout{1} = pts(I, :); varargout{2} = I; varargout{3} = angles; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/edges2d.m0000644000000000000000000000013214055375162016554 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/edges2d.m0000644000175000017500000000521314055375162017642 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges2d(varargin) %EDGES2D Description of functions operating on planar edges. % % An edge is represented by the coordinate of its extremities: % EDGE = [X1 Y1 X2 Y2]; % % Centered edges are sometimes used (for example for representing main % axes of an ellipse or an oriented box). Centered edges are represented % by their center, their length, and their orientation (counted in % degrees and counter-clockwise). % CEDGE = [XC YC LEN THETA]; % % A set of edges is represented by a N-by-4 array, each row representing % an edge. % % % See also: % lines2d, rays2d, points2d, createEdge, parallelEdge, % edgeAngle, edgeLength, midPoint, edgeToLine, lineToEdge % intersectEdges, intersectLineEdge, isPointOnEdge, edgeToPolyline % clipEdge, transformEdge, intersectEdgePolygon, centeredEdgeToEdge % drawEdge, drawCenteredEdge % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('edges2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createScaling.m0000644000000000000000000000013214055375162020003 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createScaling.m0000644000175000017500000000627614055375162021103 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createScaling(varargin) %CREATESCALING Create the 3*3 matrix of a scaling in 2 dimensions. % % TRANS = createScaling(SX, SY); % return the matrix corresponding to scaling by SX and SY in the 2 % main directions. % The returned matrix has the form: % [SX 0 0] % [0 SY 0] % [0 0 1] % % TRANS = createScaling(SX); % Assume SX and SY are equals. % % TRANS = createScaling(CENTER, ...); % Specifies the center of the scaling transform. The argument CENTER % should be a 1-by-2 array representing coordinates of center. % % See also: % transforms2d, transformPoint, createTranslation, createRotation % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/04/2004. % HISTORY % 04/01/2007: rename as scaling % 22/04/2009: rename as createScaling % defined default arguments sx = 1; sy = 1; cx = 0; cy = 0; % process input arguments if nargin == 1 % the argument is either the scaling factor in both direction, % or a 1x2 array containing scaling factor in each direction var = varargin{1}; sx = var(1); sy = var(1); if length(var)>1 sy = var(2); end elseif nargin == 2 % the 2 arguments are the scaling factors in each dimension sx = varargin{1}; sy = varargin{2}; elseif nargin == 3 % first argument is center, 2nd and 3d are scaling factors center = varargin{1}; cx = center(1); cy = center(2); sx = varargin{2}; sy = varargin{3}; end % concatenate results in a 3-by-3 matrix trans = [sx 0 cx*(1-sx); 0 sy cy*(1-sy); 0 0 1]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/intersectEdges.m0000644000000000000000000000013214055375162020207 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/intersectEdges.m0000644000175000017500000001475014055375162021303 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = intersectEdges(edge1, edge2, varargin) %INTERSECTEDGES Return all intersections between two set of edges. % % P = intersectEdges(E1, E2); % returns the intersection point of edges E1 and E2. % 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, the result P contains [Inf Inf]. % In case of parallel but not colinear edges, the result P contains % [NaN NaN]. % % If each input is N-by-4 array, the result is a N-by-2 array containing % the intersection of each couple of edges. % If one of the input has N rows and the other 1 row, the result is a % N-by-2 array. % % P = intersectEdges(E1, E2, TOL); % Specifies a tolerance parameter to determine parallel and colinear % edges, and if a point belongs to an edge or not. The latter test is % performed on the relative position of the intersection point over the % edge, that should lie within [-TOL; 1+TOL]. % % See also: % edges2d, intersectLines % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % INRA - Cepia Software Platform % 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) % 20/02/2013 fix bug for management of parallel edges (thanks to Nicolaj % Kirchhof) % 19/07/2016 add support for tolerance % tolerance for precision tol = 1e-14; if nargin > 2 tol = varargin{1}; end %% 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 % 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) 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 tmp = t1; t1 = t2; t2 = tmp; end % edge totally before first vertex or totally after last vertex resCol(col(t2 < -tol)) = NaN; resCol(col(t1 > 1+tol)) = NaN; % set up result into point coordinate x0(col) = resCol(col); y0(col) = resCol(col); % touches on first point of first edge touch = col(abs(t2) < tol); x0(touch) = edge1(touch, 1); y0(touch) = edge1(touch, 2); % touches on second point of first edge touch = col(abs(t1-1) < tol); x0(touch) = edge1(touch, 3); y0(touch) = edge1(touch, 4); end %% Process non parallel cases % process edges whose supporting 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawCircleArc.m0000644000000000000000000000013214055375162017744 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawCircleArc.m0000644000175000017500000001017714055375162021037 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawCircleArc(varargin) %DRAWCIRCLEARC Draw a circle arc on the current axis. % % drawCircleArc(ARC); % Draws circle arc defined by ARC = [XC YC R START EXTENT], with (XC, YC) % being the circle center, R being the circle radius, starting from angle % START, and with angular extent given by EXTENT. START and EXTENT angles % are given in degrees. % % drawCircleArc(XC, YC, R, START, EXTENT); % Alternative syntax that seperates inputs. % % drawCircleArc(..., PARAM, VALUE); % specifies plot properties by using one or several parameter name-value % pairs. % % drawCircleArc(AX, ...); % Specifies handle of the axis to draw on. % % 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, circleArcToPolyline % % -------- % 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 % 2011-10-11 add management of axes handle if nargin == 0 error('Need to specify circle arc'); end % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; 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(ax, xt, yt, varargin{:}); end if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/ellipsePerimeter.m0000644000000000000000000000013214055375162020551 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/ellipsePerimeter.m0000644000175000017500000000652714055375162021650 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function perim = ellipsePerimeter(ellipse, varargin) %ELLIPSEPERIMETER Perimeter of an ellipse. % % P = ellipsePerimeter(ELLI) % Computes the perimeter of an ellipse, using numerical integration. % ELLI is an ellipse, given using one of the following formats: % * a 1-by-5 row vector containing coordinates of center, length of % semi-axes, and orientation in degrees % * a 1-by-2 row vector containing only the lengths of the semi-axes. % The result % % P = ellipsePerimeter(ELLI, TOL) % Specify the relative tolerance for numerical integration. % % % Example % P = ellipsePerimeter([30 40 30 10 15]) % P = % 133.6489 % % See also % ellipses2d, drawEllipse % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-02-20, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. %% Parse input argument if size(ellipse, 2) == 5 ra = ellipse(:, 3); rb = ellipse(:, 4); elseif size(ellipse, 2) == 2 ra = ellipse(:, 1); rb = ellipse(:, 2); elseif size(ellipse, 2) == 1 ra = ellipse; rb = varargin{1}; varargin(1) = []; end % relative tolerance tol = 1e-10; if ~isempty(varargin) tol = varargin{1}; end %% Numerical integration n = length(ra); perim = zeros(n, 1); for i = 1:n % function to integrate f = @(t) sqrt(ra(i) .^ 2 .* cos(t) .^ 2 + rb(i) .^ 2 .* sin(t) .^ 2) ; % absolute tolerance from relative tolerance eps = tol * max(ra(i), rb(i)); % integrate on first quadrant if verLessThan('matlab', '7.14') perim(i) = 4 * quad(f, 0, pi/2, eps); %#ok else perim(i) = 4 * integral(f, 0, pi/2, 'AbsTol', eps); end end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162017034 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/Contents.m0000644000175000017500000003234614055375162020131 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % GEOM2D Geometry 2D Toolbox % Version 1.24 07-Jun-2018 . % % 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. % midPoint - Middle point of two points or of an edge. % circumCenter - Circumcenter of three points. % isCounterClockwise - Compute the 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. % distancePoints - Compute distance between two points. % transformPoint - Apply an affine transform to a point or a point set. % drawPoint - Draw the point on the axis. % % Point Sets % clipPoints - Clip a set of points by a box. % centroid - Compute centroid (center of mass) of a set of points. % boundingBox - Bounding box of a set of points. % principalAxes - Principal axes of a set of ND points. % angleSort - Sort points in the plane according to their angle to origin. % findClosestPoint - Find index of closest point in an array. % minDistancePoints - Minimal distance between several points. % mergeClosePoints - Merge points that are closer than a given distance. % hausdorffDistance - Hausdorff distance between two point sets. % nndist - Nearest-neighbor distances of each point in a set. % % 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 - Horizontal angle of a vector, or angle 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 through a point. % 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. % lineToEdge - Convert a straight line to a finite edge. % drawLine - Draw a straight line clipped by 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. % edgeAngle - Return angle of edge. % edgeLength - Return length of an edge. % parallelEdge - Edge parallel to another edge. % centeredEdgeToEdge - Convert a centered edge to a two-points 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. % edgeToLine - Convert an edge to a straight line. % edgeToPolyline - Convert an edge to a polyline with a given number of segments. % 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. % circleToPolygon - Convert a circle into a series of points. % circleArcToPolyline - 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. % circumCircle - Circumscribed circle of three 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 and Parabola % ellipses2d - Description of functions operating on ellipses. % equivalentEllipse - Equivalent ellipse of a set of points. % isPointInEllipse - Check if a point is located inside a given ellipse. % ellipsePerimeter - Perimeter of an ellipse. % ellipseToPolygon - 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. % drawParabola - Draw a parabola 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. % createRotation90 - Matrix of a rotation for 90 degrees multiples. % 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. % principalAxesTransform - Align a set of points along its principal axes. % fitAffineTransform2d - Compute the affine transform that best register two point sets. % registerICP - Fit affine transform by Iterative Closest Point algorithm. % polynomialTransform2d - Apply a polynomial transform to a set of points. % fitPolynomialTransform2d - Coefficients of polynomial transform between 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. % % 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. % boxToRect - Convert box data to rectangle data. % boxToPolygon - Convert a bounding box to a square polygon. % drawBox - Draw a box defined by coordinate extents. % % Triangles % isPointInTriangle - Test if a point is located inside a triangle. % triangleArea - Signed area of a triangle. % % Rectangles % rectToPolygon - Convert a rectangle into a polygon (set of vertices). % rectToBox - Convert rectangle data to box data. % drawRect - Draw rectangle on the current axis. % orientedBox - Minimum-width oriented bounding box of a set of points. % orientedBoxToPolygon - Convert an oriented box to a polygon (set of vertices). % drawOrientedBox - Draw centered oriented rectangle. % % Splines % cubicBezierToPolyline - Compute equivalent polyline from bezier curve control. % drawBezierCurve - Draw a cubic bezier curve defined by 4 control points. % % Various drawing functions % drawVector - Draw vector at a given position. % 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 % (yash78@gmail.com), available on Matlab File Exchange % % ----- % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2005-11-07 % Copyright INRA - Cepia Software Platform. % Project homepage: http://github.com/mattools/matGeom % http://www.pfl-cepia.inra.fr/index.php?page=geom2d help(mfilename); %% Deprecated functions % normalize - Normalize a vector. % inertiaEllipse - Inertia ellipse of a set of points. %% Others... matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/normalizeAngle.m0000644000000000000000000000013214055375162020206 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/normalizeAngle.m0000644000175000017500000000522414055375162021276 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function alpha = normalizeAngle(alpha, varargin) %NORMALIZEANGLE Normalize an angle value within a 2*PI interval. % % ALPHA2 = normalizeAngle(ALPHA); % ALPHA2 is the same as ALPHA modulo 2*PI and is positive. % % ALPHA2 = normalizeAngle(ALPHA, CENTER); % Specifies the center of the angle interval. % If CENTER==0, the interval is [-pi ; +pi] % If CENTER==PI, the interval is [0 ; 2*pi] (default). % % Example: % % normalization between 0 and 2*pi (default) % normalizeAngle(5*pi) % ans = % 3.1416 % % % normalization between -pi and +pi % normalizeAngle(7*pi/2, 0) % ans = % -1.5708 % % See also % vectorAngle, lineAngle % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2008-03-10, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY % 2010-03-31 rename as normalizeAngle, and add psb to specify interval % center center = pi; if ~isempty(varargin) center = varargin{1}; end alpha = mod(alpha-center+pi, 2*pi) + center-pi; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/orthogonalLine.m0000644000000000000000000000013214055375162020223 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/orthogonalLine.m0000644000175000017500000000557314055375162021322 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = orthogonalLine(line, point) %ORTHOGONALLINE Create a line orthogonal to another one through a point. % % PERP = orthogonalLine(LINE, POINT); % Returns the line orthogonal to the line LINE and going through the % point given by POINT. Directed angle from LINE to PERP is pi/2. % LINE is given as [x0 y0 dx dy] and POINT is [xp yp]. % % Works also when LINE is a N-by-4 array, or POINT is a N-by-2 array. In % this case, the result is a N-by-4 array. % % % Example % refLine = createLine([10 10], [30 20]); % pt = [20 40]; % figure; hold on; axis equal; axis([0 50 0 50]); % drawLine(refLine, 'lineWidth', 2); % drawPoint(pt); % perp = orthogonalLine(refLine, pt); % drawLine(perp, 'color', 'r'); % % See also: % lines2d, parallelLine, intersectLines % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 19/02/2004 added control for multiple lines and/or points % 31/12/2013 added example 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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/clipEdge.m0000644000000000000000000000013214055375162016753 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/clipEdge.m0000644000175000017500000001237114055375162020044 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge2 = clipEdge(edge, box) %CLIPEDGE Clip an edge with a rectangular box. % % EDGE2 = clipEdge(EDGE, BOX); % EDGE: [x1 y1 x2 y2], % BOX : [xmin xmax ymin ymax], or [xmin xmax ; ymin ymax]. % return : % EDGE2 = [xc1 yc1 xc2 yc2]; % % If clipping is null, return [0 0 0 0]; % % if EDGE is a N-by-4 array, return an N-by-4 array, corresponding to % each clipped edge. % % See also % edges2d, boxes2d, clipLine % % --------- % author : David Legland % e-mail: david.legland@inra.fr % created: the 14/05/2005. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2007-01-08 sort points according to position on edge, not to x coord % -> this allows to return edges with same orientation a source, and % to keep first or end points at the same position if their are not % clipped. % 01/10/2010 fix bug due to precision, thanks to Reto Zingg. % process data input if size(box, 1) == 2 box = box'; end % get limits of window xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % convert window limits into lines lineX0 = [xmin ymin xmax-xmin 0]; lineX1 = [xmin ymax xmax-xmin 0]; lineY0 = [xmin ymin 0 ymax-ymin]; lineY1 = [xmax ymin 0 ymax-ymin]; % compute outcodes of each vertex p11 = edge(:,1) < xmin; p21 = edge(:,3) < xmin; p12 = edge(:,1) > xmax; p22 = edge(:,3) > xmax; p13 = edge(:,2) < ymin; p23 = edge(:,4) < ymin; p14 = edge(:,2) > ymax; p24 = edge(:,4) > ymax; out1 = [p11 p12 p13 p14]; out2 = [p21 p22 p23 p24]; % detect edges totally inside window -> no clip. inside = sum(out1 | out2, 2) == 0; % detect edges totally outside window outside = sum(out1 & out2, 2) > 0; % select edges not totally outside, and process separately edges totally % inside window ind = find(~(inside | outside)); % allocate memroty for all clipped edges edge2 = zeros(size(edge)); % copy result of edges totally inside clipping box edge2(inside, :) = edge(inside, :); % iterate over edges for i = 1:length(ind) % current edge iedge = edge(ind(i), :); % compute intersection points with each line of bounding window px0 = intersectLineEdge(lineX0, iedge); px1 = intersectLineEdge(lineX1, iedge); py0 = intersectLineEdge(lineY0, iedge); py1 = intersectLineEdge(lineY1, iedge); % create array of points points = [px0; px1; py0; py1; iedge(1:2); iedge(3:4)]; % remove infinite points (edges parallel to box edges) points = points(all(isfinite(points), 2), :); % sort points by x then y points = sortrows(points); % get center positions between consecutive points centers = (points(2:end,:) + points(1:end-1,:))/2; % find the centers (if any) inside window inside = find( centers(:,1) >= xmin & centers(:,2) >= ymin & ... centers(:,1) <= xmax & centers(:,2) <= ymax); % if multiple segments are inside box, which can happen due to finite % resolution, only take the longest segment if length(inside) > 1 % compute delta vectors of the segments dv = points(inside+1,:) - points(inside,:); % compute lengths of segments len = hypot(dv(:,1), dv(:,2)); % find index of longest segment [a, I] = max(len); %#ok inside = inside(I); end % if one of the center points is inside box, then the according edge % segment is indide box if length(inside) == 1 % restore same direction of edge if iedge(1) > iedge(3) || (iedge(1) == iedge(3) && iedge(2) > iedge(4)) edge2(ind(i), :) = [points(inside+1,:) points(inside,:)]; else edge2(ind(i), :) = [points(inside,:) points(inside+1,:)]; end end end % end of loop over edges matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/distancePointLine.m0000644000000000000000000000013214055375162020653 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/distancePointLine.m0000644000175000017500000000762214055375162021747 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [dist, pos] = distancePointLine(point, line) %DISTANCEPOINTLINE 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 computed for each couple of % point and line, and is returned in a NP-by-NL array, where NP is the % number of points, and NL is the number of lines. % % % See also: % lines2d, points2d, distancePoints, distancePointEdge % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2005-06-24 % Copyright 2016 INRA - BIA-BIBS. % HISTORY: % 2012-10-24 rewrite using bsxfun % direction vector of each line (row vectors) vx = line(:, 3)'; vy = line(:, 4)'; % squared norm of direction vectors, with a check of validity delta = (vx .* vx + vy .* vy); invalidEdges = delta < eps; delta(invalidEdges) = 1; % difference of coordinates between point and line origins % (NP-by-NE arrays) dx = bsxfun(@minus, point(:, 1), line(:, 1)'); dy = bsxfun(@minus, point(:, 2), line(:, 2)'); % compute position of points projected on the line, by using normalised dot % product % (result is a NP-by-NL array) pos = bsxfun(@rdivide, bsxfun(@times, dx, vx) + bsxfun(@times, dy, vy), delta); % ensure degenerated lines are correclty processed (consider the line % origin as closest point) pos(:, invalidEdges) = 0; % compute distance between point and its projection on the line dist = hypot(bsxfun(@times, pos, vx) - dx, bsxfun(@times, pos, vy) - dy); % 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)); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/cartesianLine.m0000644000000000000000000000013214055375162020020 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/cartesianLine.m0000644000175000017500000000454414055375162021114 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = cartesianLine(varargin) %CARTESIANLINE Create a straight line from cartesian equation coefficients. % % L = cartesianLine(A, B, C); % Create a line verifying the Cartesian equation: % A*x + B*x + C = 0; % % See also: % lines2d, createLine % % --------- % Author: David Legland % e-mail: david.legland@grignon.inra.fr % created the 25/05/2004. % Copyright 2010 INRA - Cepia Software Platform. 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/pointOnLine.m0000644000000000000000000000013214055375162017475 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/pointOnLine.m0000644000175000017500000000441114055375162020562 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = pointOnLine(line, pos) %POINTONLINE Create a point on a line at a given position on the line. % % P = pointOnLine(LINE, POS); % Creates the point belonging to the line LINE, and located at the % distance D from the line origin. % LINE has the form [x0 y0 dx dy]. % LINE and D should have the same number N of rows. The result will have % N rows ans 2 column (x and y positions). % % See also: % lines2d, points2d, onLine, onLine, linePosition % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/04/2004. % angle = lineAngle(line); point = [line(:,1) + pos .* cos(angle), line(:,2) + pos .* sin(angle)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/clipRay.m0000644000000000000000000000013214055375162016642 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/clipRay.m0000644000175000017500000000675514055375162017744 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [edge, isInside] = clipRay(ray, bb) % Clip a ray with a box. % % EDGE = clipRay(RAY, BOX); % RAY is a straight ray given as a 4 element row vector: [x0 y0 dx dy], % with (x0 y0) being the origin of the ray and (dx dy) its direction % vector, BOX is the clipping box, given by its extreme coordinates: % [xmin xmax ymin ymax]. % The result is given as an edge, defined by the coordinates of its 2 % extreme points: [x1 y1 x2 y2]. % If the ray does not intersect the box, [NaN NaN NaN NaN] is returned. % % Function works also if RAY is a N-by-4 array, if BOX is a Nx4 array, or % if both RAY and BOX are N-by-4 arrays. In these cases, EDGE is a N-by-4 % array. % % See also: % rays2d, boxes2d, edges2d, clipLine, drawRay % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2010-05-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2010-05-13 create from clipLine % 2017-09-21 simplify code % adjust size of two input arguments if size(ray, 1) == 1 ray = repmat(ray, size(bb, 1), 1); elseif size(bb, 1) == 1 bb = repmat(bb, size(ray, 1), 1); elseif size(ray, 1) ~= size(bb, 1) error('bad sizes for input'); end % first compute clipping of supporting line edge = clipLine(ray, bb); % detects valid edges (edges outside box are all NaN) inds = find(isfinite(edge(:, 1))); % compute position of edge extremities relative to the ray pos1 = linePosition(edge(inds,1:2), ray(inds,:), 'diag'); pos2 = linePosition(edge(inds,3:4), ray(inds,:), 'diag'); % if first point is before ray origin, replace by origin edge(inds(pos1 < 0), 1:2) = ray(inds(pos1 < 0), 1:2); % if last point of edge is before origin, set all edge to NaN edge(inds(pos2 < 0), :) = NaN; % eventually returns result about inside or outside if nargout > 1 isInside = isfinite(edge(:,1)); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/edgePosition.m0000644000000000000000000000013214055375162017670 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/edgePosition.m0000644000175000017500000000705514055375162020764 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pos = 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 result POS has the following 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 NE 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 NE edges, % return an array of [NP NE] position, corresponding to each couple % point-edge. % % See also: % edges2d, createEdge, isPointOnEdge % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2004-05-25 % Copyright 2009 INRA - Cepia Software Platform. % % HISTORY: % 06/12/2009 created from linePosition % number of points and of edges nEdges = size(edge, 1); nPoints = size(point, 1); if nPoints == nEdges dxe = (edge(:, 3) - edge(:,1))'; dye = (edge(:, 4) - edge(:,2))'; dxp = point(:, 1) - edge(:, 1); dyp = point(:, 2) - edge(:, 2); else % expand one of the arrays to have the same size dxe = (edge(:,3) - edge(:,1))'; dye = (edge(:,4) - edge(:,2))'; dxp = bsxfun(@minus, point(:,1), edge(:,1)'); dyp = bsxfun(@minus, point(:,2), edge(:,2)'); end pos = (dxp .* dxe + dyp .* dye) ./ (dxe .* dxe + dye .* dye); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/intersectBoxes.m0000644000000000000000000000013214055375162020240 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/intersectBoxes.m0000644000175000017500000000477614055375162021343 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = intersectBoxes(box1, box2) %INTERSECTBOXES Intersection of two bounding boxes. % % RES = intersectBoxes(BOX1, BOX2) % % Example % box1 = [5 20 5 30]; % box2 = [0 15 0 15]; % intersectBoxes(box1, box2) % ans = % 5 15 5 15 % % See also % boxes2d, drawBox, mergeBoxes % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % unify sizes of data if size(box1,1) == 1 box1 = repmat(box1, size(box2,1), 1); elseif size(box2, 1) == 1 box2 = repmat(box2, size(box1,1), 1); elseif size(box1,1) ~= size(box2,1) error('Bad size for inputs'); end % compute extreme coords mini = min(box1(:,[2 4]), box2(:,[2 4])); maxi = max(box1(:,[1 3]), box2(:,[1 3])); % concatenate result into a new box structure box = [maxi(:,1) mini(:,1) maxi(:,2) mini(:,2)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createLineReflection.m0000644000000000000000000000013214055375162021325 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createLineReflection.m0000644000175000017500000000512514055375162022415 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createLineReflection(line) %CREATELINEREFLECTION Create the the 3x3 matrix of a line reflection. % % TRANS = createLineReflection(LINE); % where line is given as [x0 y0 dx dy], return the affine tansform % corresponding to the desired line reflection % % % See also: % lines2d, transforms2d, transformPoint, % createTranslation, createHomothecy, createScaling % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 19/01/2005. % % HISTORY % 22/04/2009: rename as createLineReflection % extract line parameters x0 = line(:,1); y0 = line(:,2); dx = line(:,3); dy = line(:,4); % normalisation coefficient of line direction vector delta = dx*dx + dy*dy; % compute coefficients of transform m00 = (dx*dx - dy*dy)/delta; m01 = 2*dx*dy/delta; m02 = 2*dy*(dy*x0 - dx*y0)/delta; m10 = 2*dx*dy/delta; m11 = (dy*dy - dx*dx)/delta; m12 = 2*dx*(dx*y0 - dy*x0)/delta; % create transformation trans = [m00 m01 m02; m10 m11 m12; 0 0 1]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/mergeClosePoints.m0000644000000000000000000000013214055375162020521 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/mergeClosePoints.m0000644000175000017500000000522614055375162021613 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = mergeClosePoints(points, varargin) %MERGECLOSEPOINTS Merge points that are closer than a given distance. % % PTS2 = mergeClosePoints(PTS, DIST) % Remove points in the array PTS such that no points closer than the % distance DIST remain in the array. % % PTS2 = mergeClosePoints(PTS) % If the distance is not specified, the default value 1e-14 is used. % % % Example % pts = rand(200, 2); % pts2 = mergeClosePoints(pts, .1); % figure; drawPoint(pts, '.'); % hold on; drawPoint(pts2, 'mo'); % % See also % points2d, removeMultipleVertices % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % default values minDist = 1e-14; if ~isempty(varargin) minDist = varargin{1}; end i = 1; while i < size(points, 1) dist = distancePoints(points(i,:), points); inds = dist < minDist; inds(i) = 0; points(inds, :) = []; % switch to next point i = i + 1; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createRotation.m0000644000000000000000000000013214055375162020222 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createRotation.m0000644000175000017500000000655714055375162021324 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = createRotation(varargin) %CREATEROTATION Create the 3*3 matrix of a rotation. % % TRANS = createRotation(THETA); % Returns the rotation corresponding to angle THETA (in radians) % The returned matrix has the form : % [cos(theta) -sin(theta) 0] % [sin(theta) cos(theta) 0] % [0 0 1] % % TRANS = createRotation(POINT, THETA); % TRANS = createRotation(X0, Y0, THETA); % Also specifies origin of rotation. The result is similar as performing % translation(-X0, -Y0), rotation(THETA), and translation(X0, Y0). % % Example % % apply a rotation on a polygon % poly = [0 0; 30 0;30 10;10 10;10 20;0 20]; % trans = createRotation([10 20], pi/6); % polyT = transformPoint(poly, trans); % % display the original and the rotated polygons % figure; hold on; axis equal; axis([-10 40 -10 40]); % drawPolygon(poly, 'k'); % drawPolygon(polyT, 'b'); % % See also: % transforms2d, transformPoint, createRotation90, createTranslation % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 22/04/2009: rename as createRotation % default values cx = 0; cy = 0; theta = 0; % get input values if length(varargin)==1 % only angle theta = varargin{1}; elseif length(varargin)==2 % origin point (as array) and angle var = varargin{1}; cx = var(1); cy = var(2); theta = varargin{2}; elseif length(varargin)==3 % origin (x and y) and angle cx = varargin{1}; cy = varargin{2}; theta = varargin{3}; end % compute coefs cot = cos(theta); sit = sin(theta); tx = cy*sit - cx*cot + cx; ty = -cy*cot - cx*sit + cy; % create transformation matrix trans = [cot -sit tx; sit cot ty; 0 0 1]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createCircle.m0000644000000000000000000000013214055375162017624 xustar0030 mtime=1622538866.070813598 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createCircle.m0000644000175000017500000000620514055375162020714 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isPerpendicular.m0000644000000000000000000000013214055375162020370 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.070813598 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isPerpendicular.m0000644000175000017500000000640314055375162021460 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPerpendicular(v1, v2, varargin) %ISPERPENDICULAR Check orthogonality of two vectors. % % B = isPerpendicular(V1, V2) % where V1 and V2 are two 1-by-2 row arrays, returns 1 if the vectors are % perpendicular, and 0 otherwise. % % Also works when V1 and V2 are two N-by-2 arrays with same number of % rows. In this case, return a N-by-1 array containing 1 at the positions % of perpendicular vectors. % % Also works when one of V1 or V2 is 1-by-2 and the other one is a N-by-2 % array. In this case the result has size N-by-1. % % B = isPerpendicular(V1, V2, ACCURACY) % specifies accuracy of numerical tests, default is 1e-14. % % % Example % isPerpendicular([1 2 1], [2 4 2]) % ans = % 1 % % isPerpendicular([1 2 1], [1 3 2]) % ans = % 0 % % See also % vectors2d, isParallel, lines2d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-04-25 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 2007-09-18 copy from isPerpendicular, adapt to any dimension, and add % psb to specify precision % 2009-09-21 fix bug for array of 3 vectors % 2011-01-20 replace repmat by ones-indexing (faster) % 2017-08-31 use normalized vectors % default accuracy acc = 1e-14; if ~isempty(varargin) acc = abs(varargin{1}); end % normalize vectors v1 = normalizeVector(v1); v2 = normalizeVector(v2); % adapt size of inputs n1 = size(v1, 1); n2 = size(v2, 1); if n1 ~= n2 if n1 == 1 v1 = v1(ones(n2, 1), :); elseif n2==1 v2 = v2(ones(n1, 1), :); else error('Inputs must either have same size, or one must be scalar'); end end % performs test b = abs(dot(v1, v2, 2)) < acc; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/radicalAxis.m0000644000000000000000000000013214055375162017463 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/radicalAxis.m0000644000175000017500000000567414055375162020564 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function line = radicalAxis(circle1, circle2) %RADICALAXIS 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); % % See also % lines2d, circles2d, createCircle % % Ref: % http://mathworld.wolfram.com/RadicalLine.html % http://en.wikipedia.org/wiki/Radical_axis % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-05-15, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % % 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]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/intersectLines.m0000644000000000000000000000013214055375162020232 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/intersectLines.m0000644000175000017500000001132014055375162021314 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = intersectLines(line1, line2, varargin) %INTERSECTLINES Return all intersection points of N lines in 2D. % % PT = intersectLines(L1, L2); % returns the intersection point of lines L1 and L2. L1 and L2 are 1-by-4 % row arrays, containing parametric representation of each line (in the % form [x0 y0 dx dy], see 'createLine' for details). % % In case of colinear lines, returns [Inf Inf]. % In case of parallel but not colinear lines, returns [NaN NaN]. % % If each input is [N*4] array, the result is a [N*2] array containing % intersections of each couple of lines. % If one of the input has N rows and the other 1 row, the result is a % [N*2] array. % % PT = intersectLines(L1, L2, EPS); % Specifies the tolerance for detecting parallel lines. Default is 1e-14. % % Example % line1 = createLine([0 0], [10 10]); % line2 = createLine([0 10], [10 0]); % point = intersectLines(line1, line2) % point = % 5 5 % % See also % lines2d, edges2d, intersectEdges, intersectLineEdge % intersectLineCircle % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 2004-02-19 add support for multiple lines. % 2007-03-08 update doc % 2011-10-07 code cleanup %% Process input arguments % extract tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % check size of each input N1 = size(line1, 1); N2 = size(line2, 1); N = max(N1, N2); if N1 ~= N2 && N1*N2 ~= N error('matGeom:IntersectLines:IllegalArgument', ... 'The two input arguments must have same number of lines'); end %% Check parallel and colinear lines % coordinate differences of origin points dx = bsxfun(@minus, line2(:,1), line1(:,1)); dy = bsxfun(@minus, line2(:,2), line1(:,2)); % indices of parallel lines denom = line1(:,3) .* line2(:,4) - line2(:,3) .* line1(:,4); par = abs(denom) < tol; % indices of colinear lines col = abs(dx .* line1(:,4) - dy .* line1(:,3)) < tol & par ; % initialize result array x0 = zeros(N, 1); y0 = zeros(N, 1); % initialize result for parallel lines x0(col) = Inf; y0(col) = Inf; x0(par & ~col) = NaN; y0(par & ~col) = NaN; % in case all line couples are parallel, return if all(par) point = [x0 y0]; return; end %% Extract coordinates of itnersecting lines % indices of intersecting lines inds = ~par; % extract base coordinates of first lines if N1 > 1 line1 = line1(inds,:); end x1 = line1(:,1); y1 = line1(:,2); dx1 = line1(:,3); dy1 = line1(:,4); % extract base coordinates of second lines if N2 > 1 line2 = line2(inds,:); end x2 = line2(:,1); y2 = line2(:,2); dx2 = line2(:,3); dy2 = line2(:,4); % re-compute coordinate differences of origin points dx = bsxfun(@minus, line2(:,1), line1(:,1)); dy = bsxfun(@minus, line2(:,2), line1(:,2)); %% Compute intersection points denom = denom(inds); x0(inds) = (x2 .* dy2 .* dx1 - dy .* dx1 .* dx2 - x1 .* dy1 .* dx2) ./ denom ; y0(inds) = (dx .* dy1 .* dy2 + y1 .* dx1 .* dy2 - y2 .* dx2 .* dy1) ./ denom ; % concatenate result point = [x0 y0]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/vectors2d.m0000644000000000000000000000013214055375162017152 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/vectors2d.m0000644000175000017500000000441314055375162020241 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vectors2d %VECTORS2D Description of functions operating on plane vectors. % % A vector is defined by its two cartesian coordinates, put into a row % vector of 2 elements: % V = [vx vy]; % % Several vectors are stored in a matrix with two columns, one for the % x-coordinate, one for the y-coordinate. % VS = [vx1 vy1 ; vx2 vy2 ; vx3 vy3]; % % See also: % vectorNorm, vectorAngle, isPerpendicular, isParallel % normalizeVector, transformVector, rotateVector % % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. help('vectors2d'); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawRect.m0000644000000000000000000000013214055375162017012 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawRect.m0000644000175000017500000000622314055375162020102 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawRect(rect, varargin) %DRAWRECT Draw rectangle on the current axis. % % drawRect(RECT) % draws the rectangles defined by RECT = [X0 Y0 W H]. % the four corners of rectangle are then : % (X0, Y0), (X0+W, Y0), (X0, Y0+H), (X0+W, Y0+H). % % RECT = [X0 Y0 W H THETA] also specifies orientation for the rectangle. % Theta is given in degrees. % % If RECT is a N-by-4 or N-by-5 array, several rectangles are drawn. % % drawRect(..., PARAM, VALUE) % Specifies one or several parameters name-value pairs, see plot function % for details. % % drawRect(AX, ...) % Specifies the handle of the axis to draw the rectangle on. % % H = drawRect(...) % Returns handle of the created graphic objects. % % See Also: % drawOrientedBox, drawBox, rectToPolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/12/2003. % % HISTORY % 2003-12-12 add support for multiple rectangles % 2011-10-09 rewrite using rectToPolygon, add support for drawing options % 2011-10-11 add management of axes handle % extract handle of axis to draw on if isAxisHandle(rect) ax = rect; rect = varargin{1}; varargin(1) = []; else ax = gca; end % number of rectangles to draw n = size(rect, 1); % display each rectangle r = zeros(n, 1); for i = 1:n % compute vertex corodinates poly = rectToPolygon(rect(i, :)); % display resulting polygon r(i) = drawPolygon(ax, poly, varargin{:}); end % process output if nargout > 0 varargout = {r}; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/ellipseToPolygon.m0000644000000000000000000000013214055375162020547 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/ellipseToPolygon.m0000644000175000017500000000653314055375162021643 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = ellipseToPolygon(ellipse, N) %ELLIPSETOPOLYGON Convert an ellipse into a series of points. % % P = ellipseToPolygon(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 a N-by-2 array containing the coordinates % of the N vertices of the polygon. % % P = ellipseToPolygon(ELL); % Use a default number of edges equal to 72. This results in one point % for each 5 degrees. % % [X, Y] = ellipseToPolygon(...); % Return the coordinates of vertices in two separate arrays. % % Example % poly = ellipseToPolygon([50 50 40 30 20], 60); % figure; hold on; % axis equal; axis([0 100 10 90]); % drawPolygon(poly, 'b'); % drawPoint(poly, 'bo'); % % See also: % ellipses2d, drawEllipse, circleToPolygon, rectToPolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2005. % % HISTORY % 2011-03-30 use angles in degrees, add default value for N % 2011-12-09 rename to ellipseToPolygon % 2017-08-31 returns N vertices instead of N+1 % 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)'; t(end) = []; % 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 matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/angleDiff.m0000644000000000000000000000013214055375162017116 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/angleDiff.m0000644000175000017500000000456014055375162020210 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dif = angleDiff(angle1, angle2) %ANGLEDIFF Difference between two angles. % % Computes the signed angular difference between two angles in radians. % The result is comprised between -PI and +PI. % % Example % A = angleDiff(-pi/4, pi/4) % A = % 1.5708 % equal to pi/2 % A = angleDiff(pi/4, -pi/4) % A = % -1.5708 % equal to -pi/2 % % See also % angles2d, angleAbsDiff % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-07-27, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % first, normalization angle1 = normalizeAngle(angle1); angle2 = normalizeAngle(angle2); % compute difference and normalize in [-pi pi] dif = normalizeAngle(angle2 - angle1, 0); matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawPoint.m0000644000000000000000000000013214055375162017206 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawPoint.m0000644000175000017500000001102514055375162020272 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = drawPoint(varargin) %DRAWPOINT Draw the point on the axis. % % drawPoint(X, Y); % Draws points defined by coordinates X and Y. % X and Y should be array the same size. % % drawPoint(COORD); % Packs coordinates in a single N-by-2 array. % % drawPoint(..., OPT); % Draws each point with given option. OPT is a series of arguments pairs % compatible with 'plot' model. Default drawing option is 'bo', % corresponding to blue circles. % If a format string is used then only the color is effective. % Markers can be set using the 'marker' property. % The property 'linestyle' cannot be set. % % drawPoint(AX, ...); % Specifies the axis to draw the points in. AX should be a handle to a axis % object. By default, display on current axis. % % H = drawPoint(...) also return a handle to each of the drawn points. % % Example % % display a single point % figure; % drawPoint([10 10]); % % % display several points forming a circle % t = linspace(0, 2*pi, 20)'; % drawPoint([5*cos(t)+10 3*sin(t)+10], 'r+'); % axis equal; % % See also % points2d, clipPoints % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 23/02/2004 add more documentation. Manage different kind of inputs. % Does not draw points outside visible area. % 26/02/2007 update processing of input arguments. % 30/04/2009 remove clipping of points (use clipPoints if necessary) % 2011-10-11 add management of axes handle % 2018-31-06 fix the bug reported in https://savannah.gnu.org/bugs/index.php?53659 % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % extract point(s) coordinates if size(varargin{1}, 2) == 2 % points packed in one array var = varargin{1}; px = var(:, 1); py = var(:, 2); varargin(1) = []; elseif isvector(varargin{1}) % points stored in separate arrays if nargin == 1 || ~isnumeric(varargin{2}) error('Missing array of y-coordinates'); end px = varargin{1}; py = varargin{2}; varargin(1:2) = []; px = px(:); py = py(:); else error('Points should be two 1D arrays or one N-by-2 array'); end if length(varargin) > 1 % Check if linestyle is given char_opt = cellfun(@lower, varargin(cellfun(@ischar, varargin)), ... 'UniformOutput', false); tf = ismember('linestyle', char_opt); if tf error('Points cannot be draw with lines, use plot or drawPolygon instead'); end hh = plot(ax, px, py, 'marker', 'o', 'linestyle', 'none', varargin{:}); elseif length(varargin) == 1 % use the specified single option (for example: 'b.', or 'k+') hh = plot(ax, px, py, varargin{1}); else % use a default marker hh = plot(ax, px, py, 'o'); end if nargout == 1 h = hh; end end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/changelog.txt0000644000000000000000000000013214055375161017550 xustar0030 mtime=1622538865.994813885 30 atime=1622538865.994813885 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/changelog.txt0000644000175000017500000000765014055375161020645 0ustar00juanpijuanpi00000000000000change 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. matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/private0000644000000000000000000000013214055375161016455 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/private/0000755000175000017500000000000014055375161017617 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/geom2d/private/PaxHeaders.19757/parseThreePoints.m0000644000000000000000000000013214055375162022210 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/private/parseThreePoints.m0000644000175000017500000000501414055375162023275 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [a b c] = parseThreePoints(varargin) %PARSETHREEPOINTS Parse three points from variable length input array. % % [A B C] = parseThreePoints(PTS); % [A B C] = parseThreePoints(P1, P2, P3); % [A B C] = parseThreePoints(VERTICES, INDS); % % Example % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % extract input args if nargin == 1 % inputs are 3 points packed into a 3-by-2 array var = varargin{1}; a = var(1,:); b = var(2,:); c = var(3,:); elseif nargin == 3 % inputs are 3 separate points a = varargin{1}; b = varargin{2}; c = varargin{3}; elseif nargin == 2 % inputs are a vertex array, and index array pts = varargin{1}; inds = varargin{2}; a = pts(inds(1), :); b = pts(inds(2), :); c = pts(inds(3), :); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isLeftOriented.m0000644000000000000000000000013214055375162020157 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isLeftOriented.m0000644000175000017500000000466514055375162021257 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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. % % If POINT is a NP-by-2 array, and/or LINE is a NL-by-4 array, the result % is a NP-by-NL array containing the result for each point-line % combination. % % See also: % lines2d, points2d, isCounterClockwise, isPointOnLine, distancePointLine % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/07/2005. % HISTORY % 2017-09-04 uses bsxfun % equivalent to: % b = (xp-x0).*dy-(yp-y0).*dx < 0; b = bsxfun(@minus, ... bsxfun(@times, bsxfun(@minus, point(:,1), line(:,1)'), line(:,4)'), ... bsxfun(@times, bsxfun(@minus, point(:,2), line(:,2)'), line(:,3)')) < 0; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/nndist.m0000644000000000000000000000013214055375162016536 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/nndist.m0000644000175000017500000000737414055375162017636 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [dists, neighInds] = nndist(points) %NNDIST Nearest-neighbor distances of each point in a set. % % DISTS = nndist(POINTS) % Returns the distance to the nearest neighbor of each point in an array % of points. % POINTS is an array of points, NP-by-ND. % DISTS is a NP-by-1 array containing the distances to the nearest % neighbor. % % This functions first computes the Delaunay triangulation of the set of % points, then search for nearest distance in the set of each vertex % neighbors. This reduces the overall complexity, but difference was % noticed only for large sets (>10000 points) % % Example % % Display Stienen diagram of a set of random points in unit square % pts = rand(100, 2); % [dists, inds] = nndist(pts); % figure; drawPoint(pts, 'k.'); % hold on; drawCircle([pts dists/2], 'b'); % axis equal; axis([-.1 1.1 -.1 1.1]); % % also display edges % drawEdge([pts pts(inds, :)], 'b'); % % See also % points2d, distancePoints, minDistancePoints, findPoint % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-01, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % number of points n = size(points, 1); % allocate memory dists = zeros(n, 1); neighInds = zeros(n, 1); % in case of few points, use direct computation if n < 3 inds = 1:n; for i = 1:n % compute minimal distance [dists(i), indN] = minDistancePoints(points(i,:), points(inds~=i, :)); if indN >= i neighInds(i) = inds(indN) + 1; else neighInds(i) = inds(indN); end end return; end % use Delaunay Triangulation to facilitate computations DT = delaunay (points); % compute distance to nearest neighbor of each point in the pattern for i = 1:n % find indices of neighbor vertices in Delaunay Triangulation. % this set contains the nearest neighbor inds = unique(DT(sum(DT == i, 2) > 0, :)); inds = inds(inds~=i); % compute minimal distance [dists(i), indN] = min(distancePoints(points(i,:), points(inds, :))); neighInds(i) = inds(indN); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/transformPoint.m0000644000000000000000000000013214055375162020264 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/transformPoint.m0000644000175000017500000000664314055375162021362 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = transformPoint(varargin) % Apply an affine transform to a point or a point set. % % PT2 = transformPoint(PT1, TRANSFO); % Returns the result of the transformation TRANSFO applied to the point % PT1. PT1 has the form [xp yp], and TRANSFO is either a 2-by-2, a % 2-by-3, or a 3-by-3 matrix, % % Format of TRANSFO can be one of : % [a b] , [a b c] , or [a b c] % [d e] [d e f] [d e f] % [0 0 1] % % PT2 = transformPoint(PT1, TRANSFO); % Also works when PTA is a N-by-2 array representing point coordinates. % In this case, the result PT2 has the same size as PT1. % % [X2, Y2] = transformPoint(X1, Y1, TRANS); % Also works when PX1 and PY1 are two arrays the same size. The function % transforms each pair (PX1, PY1), and returns the result in (X2, Y2), % which has the same size as (PX1 PY1). % % % See also: % points2d, transforms2d, translation, rotation % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 25/04/2005 : support for 2D arrays of points (px, py, trans). % parse input arguments if length(varargin) == 2 var = varargin{1}; px = var(:,1); py = var(:,2); trans = varargin{2}; elseif length(varargin) == 3 px = varargin{1}; py = varargin{2}; trans = varargin{3}; else error('wrong number of arguments in "transformPoint"'); end % apply linear part of the transform px2 = px * trans(1,1) + py * trans(1,2); py2 = px * trans(2,1) + py * trans(2,2); % add translation vector, if exist if size(trans, 2) > 2 px2 = px2 + trans(1,3); py2 = py2 + trans(2,3); end % format output arguments if nargout < 2 varargout{1} = [px2 py2]; elseif nargout varargout{1} = px2; varargout{2} = py2; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/lineToEdge.m0000644000000000000000000000013214055375162017256 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/lineToEdge.m0000644000175000017500000000443314055375162020347 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edge = lineToEdge(line) %LINETOEDGE Convert a straight line to a finite edge. % % EDGE = lineToEdge(LINE) % Returns the edge with same origin as the line LINE, and with second % extremity corresponding to the addition of line origin and direction. % LINE is represented as [X0 Y0 DX DY] % EDGE is represented as [X1 Y1 X2 Y2] % % Example % line = [3 4 1 2]; % edge = lineToEdge(line) % edge = % 3 4 4 6 % % See also % lines2d, edges2d, edgeToLine % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-05-07, using Matlab 9.6.0.1072779 (R2019a) % Copyright 2019 INRA - Cepia Software Platform. edge = [line(:, 1:2) line(:,1:2)+line(:,3:4)]; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/intersectLineEdge.m0000644000000000000000000000013214055375162020634 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/intersectLineEdge.m0000644000175000017500000001202314055375162021717 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = intersectLineEdge(line, edge, varargin) %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 1-by-4 array containing parametric representation of the line % (in the form [x0 y0 dx dy], see 'createLine' for details). % EDGE is a 1-by-4 array containing the coordinates of first and second % points (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-by-4 array, the result is a N-by-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-by-2 array. % % P = intersectLineEdge(LINE, EDGE, TOL); % Specifies the tolerance option for determining if a point belongs to an % edge and if lines are parallel. % % 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 % extract tolerance option tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % number of lines and edges nLines = size(line, 1); nEdges = size(edge, 1); % origin and direction vector of lines lx0 = line(:,1); ly0 = line(:,2); ldx = line(:,3); ldy = line(:,4); % origin and direction vector of edges ex1 = edge(:,1); ey1 = edge(:,2); ex2 = edge(:,3); ey2 = edge(:,4); edx = ex2 - ex1; edy = ey2 - ey1; % normalizes direction vectors ldn = hypot(ldx, ldy); ldx = ldx ./ ldn; ldy = ldy ./ ldn; % normalizes direction vectors edgeLength = hypot(edx, edy); edx = edx ./ edgeLength; edy = edy ./ edgeLength; % indices of parallel lines par = abs(ldx .* edy - edx .* ldy) < tol; % indices of colinear lines col = abs((ex1-lx0) .* ldy - (ey1-ly0) .* ldx) < tol & par ; xi(col) = Inf; yi(col) = Inf; xi(par & ~col) = NaN; yi(par & ~col) = NaN; i = ~par; % compute intersection points if nLines == nEdges xi(i) = ((ey1(i)-ly0(i)).*ldx(i).*edx(i) + lx0(i).*ldy(i).*edx(i) - ex1(i).*edy(i).*ldx(i)) ./ ... (edx(i).*ldy(i)-ldx(i).*edy(i)) ; yi(i) = ((ex1(i)-lx0(i)).*ldy(i).*edy(i) + ly0(i).*ldx(i).*edy(i) - ey1(i).*edx(i).*ldy(i)) ./ ... (ldx(i).*edy(i)-edx(i).*ldy(i)) ; elseif nLines == 1 xi(i) = ((ey1(i)-ly0).*ldx.*edx(i) + lx0.*ldy.*edx(i) - ex1(i).*edy(i).*ldx) ./ ... (edx(i).*ldy-ldx.*edy(i)) ; yi(i) = ((ex1(i)-lx0).*ldy.*edy(i) + ly0.*ldx.*edy(i) - ey1(i).*edx(i).*ldy) ./ ... (ldx.*edy(i)-edx(i).*ldy) ; elseif nEdges == 1 xi(i) = ((ey1-ly0(i)).*ldx(i).*edx + lx0(i).*ldy(i).*edx - ex1(i).*edy.*ldx(i)) ./ ... (edx.*ldy(i)-ldx(i).*edy) ; yi(i) = ((ex1-lx0(i)).*ldy(i).*edy + ly0(i).*ldx(i).*edy - ey1(i).*edx.*ldy(i)) ./ ... (ldx(i).*edy-edx.*ldy(i)) ; end % format output arguments point = [xi' yi']; % compute position of points projected on the supporting line, by using % dot product and normalising by edge length pos = bsxfun(@rdivide, ... bsxfun(@times, bsxfun(@minus, xi, ex1), edx) + ... bsxfun(@times, bsxfun(@minus, yi, ey1), edy), edgeLength); % set coordinates of points outside edge to NaN out = pos < -tol | pos > (1+tol); point(out, :) = NaN; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/rectToPolygon.m0000644000000000000000000000013214055375162020047 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/rectToPolygon.m0000644000175000017500000000554214055375162021142 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [tx, ty] = rectToPolygon(rect) %RECTTOPOLYGON Convert a rectangle into a polygon (set of vertices). % % POLY = rectToPolygon(RECT); % Converts rectangle given as [X0 Y0 W H] or [X0 Y0 W H THETA] into a % 4-by-2 array double, containing coordinate of rectangle vertices. % X0 and Y0 are the coordinates of the "lower left" vertex (before % applying rotation), W and H are the width and the height of the % rectangle, and THETA is the rotation angle around the first vertex, in % degrees. % % See also: % orientedBoxToPolygon, ellipseToPolygon, drawRect, drawPolygon % % % --------- % Author: David Legland % e-mail: david.legland@nantes.inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2005. % % HISTORY % extract rectangle parameters theta = 0; x0 = rect(1); y0 = rect(2); w = rect(3); h = rect(4); if length(rect) > 4 theta = rect(5); end % precompute angular quantities cot = cosd(theta); sit = sind(theta); % compute vertex coordinates tx = zeros(4, 1); ty = zeros(4, 1); tx(1) = x0; ty(1) = y0; tx(2) = x0 + w * cot; ty(2) = y0 + w * sit; tx(3) = x0 + w * cot - h * sit; ty(3) = y0 + w * sit + h * cot; tx(4) = x0 - h * sit; ty(4) = y0 + h * cot; % format output if nargout <= 1 tx = [tx ty]; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isParallel.m0000644000000000000000000000013214055375162017327 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isParallel.m0000644000175000017500000000667714055375162020434 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isParallel(v1, v2, varargin) %ISPARALLEL Check parallelism of two vectors. % % B = isParallel(V1, V2) % where V1 and V2 are two row vectors of length ND, ND being the % dimension, returns 1 if the vectors are parallel, and 0 otherwise. % % Also works when V1 and V2 are two N-by-ND arrays with same number of % rows. In this case, return a N-by-1 array containing 1 at the positions % of parallel vectors. % % Also works when one of V1 or V2 is N-by-1 and the other one is N-by-ND % array, in this case return N-by-1 results. % % B = isParallel(V1, V2, ACCURACY) % specifies the accuracy for numerical computation. Default value is % 1e-14. % % % Example % isParallel([1 2], [2 4]) % ans = % 1 % isParallel([1 2], [1 3]) % ans = % 0 % % See also % vectors2d, isPerpendicular, lines2d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-04-25 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 2007-09-18 copy from isParallel3d, adapt to any dimension, and add psb % to specify precision % 2007-01-16 fix bug % 2009-09-21 fix bug for array of 3 vectors % 2011-01-20 replace repmat by ones-indexing (faster) % 2011-06-16 use direct computation (faster) % 2017-08-31 use normalized vectors % default accuracy acc = 1e-14; if ~isempty(varargin) acc = abs(varargin{1}); end % normalize vectors v1 = normalizeVector(v1); v2 = normalizeVector(v2); % adapt size of inputs if needed n1 = size(v1, 1); n2 = size(v2, 1); if n1 ~= n2 if n1 == 1 v1 = v1(ones(n2,1), :); elseif n2 == 1 v2 = v2(ones(n1,1), :); end end % performs computation if size(v1, 2) == 2 % computation for plane vectors b = abs(v1(:, 1) .* v2(:, 2) - v1(:, 2) .* v2(:, 1)) < acc; else % computation in greater dimensions b = vectorNorm(cross(v1, v2, 2)) < acc; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/vectorNorm.m0000644000000000000000000000013214055375162017375 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/vectorNorm.m0000644000175000017500000000611614055375162020466 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function n = vectorNorm(v, varargin) % Compute norm of a vector, or of a set of vectors. % % N = vectorNorm(V); % Returns the euclidean norm of vector V. % % N = vectorNorm(V, N); % Specifies the norm to use. N can be any value greater than 0. % N=1 -> city lock norm % N=2 -> euclidean norm % N=inf -> compute max coord. % % When V is a MxN array, compute norm for each vector of the array. % Vector are given as rows. Result is then a [M*1] array. % % Example % n1 = vectorNorm([3 4]) % n1 = % 5 % % n2 = vectorNorm([1, 10], inf) % n2 = % 10 % % See Also: % vectors2d, vectorAngle % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 21/02/2005. % % HISTORY % 02/05/2006 manage several norms % 18/09/2007 use 'isempty' % 15/10/2008 add comments % 22/05/2009 rename as vectorNorm % 01/03/2010 fix bug for inf norm % 03/01/2020 make it work for more dimensions % extract the type of norm to compute d = 2; if ~isempty(varargin) d = varargin{1}; end if d==2 % euclidean norm: sum of squared coordinates, and take square root n = sqrt(sum(v.*v, ndims(v))); elseif d==1 % absolute norm: sum of absolute coordinates n = sum(abs(v), ndims(v)); elseif d==inf % infinite norm: uses the maximal corodinate n = max(v, [], ndims(v)); else % Other norms, use explicit but slower expression n = power(sum(power(v, d), ndims(v)), 1/d); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/isCounterClockwise.m0000644000000000000000000000013214055375162021056 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/isCounterClockwise.m0000644000175000017500000000755314055375162022155 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = isCounterClockwise(p1, p2, p3, varargin) % Compute the relative orientation of 3 points. % % CCW = isCounterClockwise(P1, P2, P3); % Computes the orientation of the 3 points. The returns is: % +1 if the path P1->P2->P3 turns Counter-Clockwise (i.e., the point P3 % is located "on the left" of the line P1-P2) % -1 if the path turns Clockwise (i.e., the point P3 lies "on the right" % of the line P1-P2) % 0 if the point P3 is located on the line segment [P1 P2]. % % This function can be used in more complicated algorithms: detection of % line segment intersections, convex hulls, point in triangle... % % CCW = isCounterClockwise(P1, P2, P3, EPS); % Specifies the threshold used for detecting colinearity of the 3 points. % Default value is 1e-12 (absolute). % % Example % isCounterClockwise([0 0], [10 0], [10 10]) % ans = % 1 % isCounterClockwise([0 0], [0 10], [10 10]) % ans = % -1 % isCounterClockwise([0 0], [10 0], [5 0]) % ans = % 0 % % See also % points2d, isPointOnLine, isPointInTriangle, polygonArea % % References % Algorithm adapated from Sedgewick's book. % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2010-04-09 % Copyright 2011 INRAE - Cepia Software Platform. % HISTORY % 2011-05-16 change variable names, add support for point arrays % get threshold value eps = 1e-12; if ~isempty(varargin) eps = varargin{1}; end % ensure all data have same size np = max([size(p1, 1) size(p2, 1) size(p3,1)]); if np > 1 if size(p1,1) == 1 p1 = repmat(p1, np, 1); end if size(p2,1) == 1 p2 = repmat(p2, np, 1); end if size(p3,1) == 1 p3 = repmat(p3, np, 1); end end % init with 0 res = zeros(np, 1); % extract vector coordinates x0 = p1(:, 1); y0 = p1(:, 2); dx1 = p2(:, 1) - x0; dy1 = p2(:, 2) - y0; dx2 = p3(:, 1) - x0; dy2 = p3(:, 2) - y0; % check non colinear cases res(dx1 .* dy2 > dy1 .* dx2) = 1; res(dx1 .* dy2 < dy1 .* dx2) = -1; % case of colinear points ind = abs(dx1 .* dy2 - dy1 .* dx2) < eps; res(ind( (dx1(ind) .* dx2(ind) < 0) | (dy1(ind) .* dy2(ind) < 0) )) = -1; res(ind( hypot(dx1(ind), dy1(ind)) < hypot(dx2(ind), dy2(ind)) )) = 1; matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/normalizeVector.m0000644000000000000000000000013214055375162020422 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/normalizeVector.m0000644000175000017500000000503114055375162021506 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vn = normalizeVector(v) %NORMALIZEVECTOR Normalize a vector to have norm equal to 1. % % V2 = normalizeVector(V); % Returns the normalization of vector V, such that ||V|| = 1. V can be % either a row or a column vector. % % When V is a M-by-N array, normalization is performed for each row of % the array. % % When V is a M-by-N-by-2 array, normalization is performed along the % last dimension of the array. % % Example: % vn = normalizeVector([3 4]) % vn = % 0.6000 0.8000 % vectorNorm(vn) % ans = % 1 % % See Also: % vectors2d, vectorNorm % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 29/11/2004. % % HISTORY % 2005-01-14 correct bug % 2009-05-22 rename as normalizeVector % 2011-01-20 use bsxfun if ismatrix(v) vn = bsxfun(@rdivide, v, sqrt(sum(v.^2, 2))); else vn = bsxfun(@rdivide, v, sqrt(sum(v.^2, ndims(v)))); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/createEdge.m0000644000000000000000000000013214055375162017267 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/createEdge.m0000644000175000017500000001150314055375162020354 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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-by-4. % % % See also: % edges2d, lines2d, drawEdge, clipEdge, createLine % % --------- % 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 nargin == 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 nargin == 2 % 2 input parameters. They can be : % - 2 points, then 2 arrays of 1*2 double, % - a line, and a distance. % extract the two arguments 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 nargin == 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 nargin == 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 ''createEdge'' '); end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/linePosition.m0000644000000000000000000000013214055375162017713 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/linePosition.m0000644000175000017500000001130114055375162020774 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pos = linePosition(point, line, varargin) %LINEPOSITION Position of a point on a line. % % POS = linePosition(POINT, LINE); % Computes position of point POINT on the line LINE, relative to origin % point and direction vector of the line. % LINE has the form [x0 y0 dx dy], % POINT has the form [x y], and is assumed to belong to line. % % POS = linePosition(POINT, LINES); % If LINES is an array of NL lines, return NL positions, corresponding to % each line. % % POS = linePosition(POINTS, LINE); % If POINTS is an array of NP points, return NP positions, corresponding % to each point. % % POS = linePosition(POINTS, LINES); % If POINTS is an array of NP points and LINES is an array of NL lines, % return an array of [NP NL] position, corresponding to each couple % point-line. % % POS = linePosition(POINTS, LINES, 'diag'); % When POINTS and LINES have the same number of rows, computes positions % only for couples POINTS(i,:) and LINES(i,:). The result POS is a column % vector with as many rows as the number of points/lines. % % % Example % line = createLine([10 30], [30 90]); % linePosition([20 60], line) % ans = % .5 % % See also: % lines2d, createLine, projPointOnLine, isPointOnLine % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 25/05/2004. % % HISTORY % 2005-07-07 manage multiple input % 2011-06-15 avoid the use of repmat when possible % 2012-10-24 rewrite using bsxfun % 2012-11-22 add support for the diag option % if diag is true, we need only to compute position of i-th point with i-th % line. diag = ~isempty(varargin) && ischar(varargin{1}) && strcmpi(varargin{1}, 'diag'); if diag % In the case of 'diag' option, use direct correspondence between % points and lines % check input have same size np = size(point, 1); nl = size(line, 1); if np ~= nl error('matGeom:linePosition', ... 'Using diag option, number of points and lines should be the same'); end % direction vector of the lines vx = line(:, 3); vy = line(:, 4); % difference of coordinates between point and line origins dx = point(:, 1) - line(:, 1); dy = point(:, 2) - line(:, 2); else % General case -> return NP-by-NL array % direction vector of the lines vx = line(:, 3)'; vy = line(:, 4)'; % difference of coordinates between point and line origins dx = bsxfun(@minus, point(:, 1), line(:, 1)'); dy = bsxfun(@minus, point(:, 2), line(:, 2)'); end % squared norm of direction vector, with a check of validity delta = vx .* vx + vy .* vy; invalidLine = delta < eps; delta(invalidLine) = 1; % compute position of points projected on the line, by using normalised dot % product (NP-by-NL array) pos = bsxfun(@rdivide, bsxfun(@times, dx, vx) + bsxfun(@times, dy, vy), delta); % ensure degenerated edges are correclty processed (consider the first % vertex is the closest one) if diag pos(invalidLine) = 0; else pos(:, invalidLine) = 0; end matgeom-1.2.3/inst/geom2d/PaxHeaders.19757/drawShape.m0000644000000000000000000000013214055375162017155 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/geom2d/drawShape.m0000644000175000017500000000675314055375162020255 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function 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 % compute drawing options 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} = circleToPolygon(param{i}, 128); elseif strcmpi(type{i}, 'rect') shape{i} = rectToPolygon(param{i}); elseif strcmpi(type{i}, 'polygon') shape{i} = param{i}; end end % draw or fill each shape as polygon 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 % foramt output if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/PaxHeaders.19757/polygons2d0000644000000000000000000000013214055375161015726 xustar0030 mtime=1622538865.994813885 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/0000755000175000017500000000000014055375161017070 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonOuterNormal.m0000644000000000000000000000013214055375162022041 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonOuterNormal.m0000644000175000017500000000625714055375162023140 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vect = polygonOuterNormal(poly, iVertex) % Outer normal vector for a given vertex(ices). % % NV = polygonOuterNormal(POLY, VIND) % Where POLY is a polygon and VIND is the index of a vertex, returns the % outer normal vector of the specified vertex. % The normal is computed by averaging the tangent vectors of the two % neighbor edges, i.e. by computing a finite difference of the neighbor % vertices. % % NV = polygonOuterNormal(POLY) % Returns an array with as many vectors as the number of vertices of the % input polygon, containing the outer normal of each vertex. % % % Example % % compute outer normals to an ellipse % elli = [50 50 40 20 30]; % poly = ellipseToPolygon(elli, 200); % figure; hold on; % drawPolygon(poly, 'b'); axis equal; axis([0 100 10 90]); % inds = 1:10:200; pts = poly(inds, :); drawPoint(pts, 'bo') % vect = polygonOuterNormal(poly, inds); % drawVector(pts, vect*10, 'b'); % % See also % polygons2d, polygonPoint, polygonNormalAngle % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2017-11-23, using Matlab 8.6.0.267246 (R2015b) % Copyright 2017 INRA - Cepia Software Platform. % number of vertices nv = size(poly, 1); % if indices not specified, compute for all vertices if nargin == 1 iVertex = 1:nv; end % allocate memory vect = zeros(length(iVertex), 2); % compute normal vector of each result vertex for i = 1:length(iVertex) iNext = mod(iVertex(i), nv) + 1; iPrev = mod(iVertex(i)-2, nv) + 1; tangent = (poly(iNext,:) - poly(iPrev,:)) / 2; vect(i,:) = [tangent(2) -tangent(1)]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/intersectEdgePolygon.m0000644000000000000000000000013214055375162022317 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/intersectEdgePolygon.m0000644000175000017500000000623014055375162023405 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [intersects, inds] = intersectEdgePolygon(edge, poly, varargin) %INTERSECTEDGEPOLYGON Intersection point of an edge with a polygon. % % INTER = intersectEdgePolygon(EDGE, POLY) % Computes intersection(s) point(s) between the edge EDGE and the polygon % POLY. EDGE is given by [x1 y1 x2 y2]. POLY is a N-by-2 array of vertex % coordinates. % INTER is a M-by-2 array containing coordinates of intersection(s). It % can be empty if no intersection is found. % % [INTER, INDS] = intersectEdgePolygon(EDGE, POLY) % Also returns index/indices of edge(s) involved in intersections. % % Example % % Intersection of an edge with a square % poly = [0 0;10 0;10 10;0 10]; % edge = [9 2 9+3*1 2+3*2]; % exp = [10 4]; % inter = intersectEdgePolygon(edge, poly) % ans = % 10 4 % % See also % edges2d, polygons2d, intersectLinePolygon, intersectRayPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % get computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % get supporting line of edge line = edgeToLine(edge); % compute all intersections of supporting line with polygon [intersects, inds] = intersectLinePolygon(line, poly, tol); % keep only intersection points located on the edge if ~isempty(intersects) pos = linePosition(intersects, line); keep = pos >= -tol & pos <= (1+tol); intersects = intersects(keep, :); inds = inds(keep); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/clipPolygon.m0000644000000000000000000000013214055375162020461 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/clipPolygon.m0000644000175000017500000000630614055375162021553 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = clipPolygon(polygon, w) %CLIPPOLYGON Clip a polygon with a rectangular box. % % POLY2 = clipPolygon(POLY, BOX); % POLY is N-by-2 array of points % BOX has the form: [XMIN XMAX YMIN YMAX]. % Returns the polygon created by the intersection of the polygon POLY and % the bounding box BOX. % % Note: Works only for convex polygons at the moment. % % See also: % polygons2d, boxes2d, clipPolygonHP, clipPolyline % % --------- % author : David Legland % created the 14/05/2005. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2007/09/14 fix doc % check case of polygons stored in cell array if iscell(polygon) poly2 = cell(1, length(polygon)); for i = 1:length(polygon) poly2{i} = clipPolygon(polygon{i}, w); end return; end % check case of empty polygon N = size(polygon, 1); if N == 0 poly2 = zeros(0, 2); return end % create edges array of polygon edges = [polygon polygon([2:N 1], :)]; % clip edges edges = clipEdge(edges, w); % select non empty edges, and get their vertices ind = sum(abs(edges), 2) > 1e-14; pts = unique([edges(ind, 1:2); edges(ind, 3:4)], 'rows'); % add vertices of window corner corners = [w(1) w(3); w(1) w(4);w(2) w(3);w(2) w(4)]; ind = inpolygon(corners(:,1), corners(:,2), polygon(:,1), polygon(:,2)); pts = [pts; corners(ind, :)]; % polygon totally outside the window if size(pts, 1)==0 poly2 = pts; return; end % compute centroid of visible polygon pc = centroid(pts); % sort vertices around polygon angle = edgeAngle([repmat(pc, [size(pts, 1) 1]) pts]); [dummy, I] = sort(angle); %#ok % create resulting polygon poly2 = pts(I, :); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/clipPolygonHP.m0000644000000000000000000000013214055375162020711 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/clipPolygonHP.m0000644000175000017500000000721714055375162022005 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = clipPolygonHP(poly, line) %CLIPPOLYGONHP Clip a polygon with a Half-plane defined by a directed line. % % POLY2 = clipPolygonHP(POLY, LINE) % POLY is a [Nx2] array of points, and LINE is given as [x0 y0 dx dy]. % The result POLY2 is also an array of points, sometimes smaller than % poly, and that can be [0x2] (empty polygon). % % See also: % polygons2d, clipPolygon % % --------- % author : David Legland % created the 31/07/2005. % Copyright 2010 INRA - Cepia Software Platform. % % HISTORY % 15/08/2005 add test to avoid empty polygons % 13/06/2007 deprecate % 10/10/2008 'reprecate' % avoid to process empty polygons if size(poly, 1)<3 poly2 = zeros([0 2]); return; end % ensure the last point is the same as the first one if sum(poly(end, :)==poly(1,:))~=2 poly = [poly; poly(1,:)]; end N = size(poly, 1); edges = [poly([N 1:N-1], :) poly]; b = isLeftOriented(poly, line); % case of totally clipped polygon if sum(b)==0 poly2 = zeros(0, 2); return; end poly2 = zeros(0, 2); i=1; while i<=N if isLeftOriented(poly(i,:), line) % keep all points located on the right side of line poly2 = [poly2; poly(i,:)]; %#ok else % compute of preceeding edge with line if i>1 poly2 = [poly2; intersectLineEdge(line, edges(i, :))]; %#ok end % go to the next point on the left side i=i+1; while i<=N % find the next point on the right side if isLeftOriented(poly(i,:), line) % add intersection of previous edge poly2 = [poly2; intersectLineEdge(line, edges(i, :))]; %#ok % add current point poly2 = [poly2; poly(i,:)]; %#ok % exit the second loop break; end i=i+1; end end i=i+1; end % remove last point if it is the same as the first one if sum(poly2(end, :)==poly(1,:))==2 poly2 = poly2(1:end-1, :); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/pointSetsAverage.m0000644000000000000000000000013214055375162021445 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/pointSetsAverage.m0000644000175000017500000000551614055375162022541 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function average = pointSetsAverage(pointSets, varargin) %POINTSETSAVERAGE Compute the average of several point sets. % % AVERAGESET = pointSetsAverage(POINTSETS) % POINTSETS is a cell array containing several liste of points with the % same number of points. The function compute the average coordinate of % each vertex, and return the resulting average point set. % % Example % pointSetsAverage % % See also % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-04-01, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % check input if ~iscell(pointSets) error('First argument must be a cell array'); end % number of sets nSets = length(pointSets); % get reference size of coordinates array set1 = pointSets{1}; refSize = size(set1); % allocate memory for result average = zeros(refSize); % iterate on point sets for i = 1:nSets % get current point set, and check its size set = pointSets{i}; if sum(size(set) ~= refSize) > 0 error('All point sets must have the same size'); end % cumulative sum of coordinates average = average + set; end % normalize by the number of sets average = average / nSets; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/findPoint.m0000644000000000000000000000013214055375162020114 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/findPoint.m0000644000175000017500000000647014055375162021210 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function index = findPoint(coord, points, varargin) %FINDPOINT Find index of a point in an set from its coordinates. % % IND = findPoint(POINT, ARRAY) % Returns the index of point whose coordinates match the 1-by-2 row array % POINT in the N-by-2 array ARRAY. If the point is not found, returns 0. % If several points are found, keep only the first one. % % If POINT is a M-by-2 array, the result is a M-by-1 array, containing % the index in the array of each point given by COORD, or 0 if the point % is not found. % % IND = findPoint(POINT, ARRAY, TOL) % use specified tolerance, to find point within a distance of TOL. % Default tolerance is zero. % % See also % points2d, minDistancePoints, distancePoints, findClosestPoint % ----- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/07/2003. % % HISTORY % 10/02/2004 documentation % 09/08/2004 rewrite faster, and add support for multiple points % number of points np = size(coord, 1); % allocate memory for result index = zeros(np, 1); % specify the tolerance tol = 0; if ~isempty(varargin) tol = varargin{1}; end if tol == 0 for i = 1:np % indices of matches ind = find(points(:,1) == coord(i,1) & points(:,2) == coord(i,2)); % format current result if isempty(ind) index(i) = 0; else index(i) = ind(1); end end else for i = 1:np % indices of matches ind = find(sqrt(sum(bsxfun(@minus, points, coord) .^ 2, 2)) <= tol); % format current result if isempty(ind) index(i) = 0; else index(i) = ind(1); end end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/resamplePolyline.m0000644000000000000000000000013214055375162021506 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/resamplePolyline.m0000644000175000017500000000646214055375162022603 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = resamplePolyline(poly, n) %RESAMPLEPOLYLINE Distribute N points equally spaced on a polyline. % % RES = resamplePolyline(POLY, N) % Resample the input polyline POLY such that the resulting polyline RES % has N points. All points of RES belong to the initial polyline, but are % not necessarily vertices. % % Example % poly = [0 10;0 0;20 0]; % figure; drawPolyline(poly, 'b'); % poly2 = resamplePolyline(poly, 10); % hold on; % drawPolyline(poly2, 'bo'); % axis equal; axis([-10 30 -10 20]); % % See also % polygons2d, drawPolyline, resamplePolygon, resamplePolylineByLength % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b) % Copyrightf 2011 INRA - Cepia Software Platform. % parametrisation of the curve s = parametrize(poly); % distribute N points equally spaced Lmax = s(end); pos = linspace(0, Lmax, n); poly2 = zeros(n, size(poly, 2)); for i = 1:n % index of surrounding vertices before and after ind0 = find(s <= pos(i), 1, 'last'); ind1 = find(s >= pos(i), 1, 'first'); if ind0 == ind1 % get position of a vertex in input polyline poly2(i, :) = poly(ind0, :); continue; end % position of surrounding vertices pt0 = poly(ind0, :); pt1 = poly(ind1, :); % weights associated to each neighbor l0 = pos(i) - s(ind0); l1 = s(ind1) - pos(i); % linear interpolation of neighbor positions if (l0 + l1) > Lmax * 1e-12 poly2(i, :) = (pt0 * l1 + pt1 * l0) / (l0 + l1); else % if neighbors are too close, do not use interpolation poly2(i, :) = pt0; end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/reversePolygon.m0000644000000000000000000000013214055375162021205 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/reversePolygon.m0000644000175000017500000000417114055375162022275 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function rev = reversePolygon(poly) %REVERSEPOLYGON Reverse a polygon, by iterating vertices from the end. % % POLY2 = reversePolygon(POLY) % POLY2 has same vertices as POLY, but in different order. The first % vertex of the polygon is still the same. % % Example % reversePolygon % % See also % polygons2d, reversePolyline % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-06-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. rev = poly([1 end:-1:2], :); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonSubcurve.m0000644000000000000000000000013214055375162021370 xustar0030 mtime=1622538866.074813583 30 atime=1622538866.074813583 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonSubcurve.m0000644000175000017500000000677314055375162022472 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [res, inds] = polygonSubcurve(poly, t0, t1) % Extract a portion of a polygon. % % POLY2 = polygonSubcurve(POLYGON, POS0, POS1) % Create a new polyline, by keeping vertices located between positions % POS0 and POS1, and adding points corresponding to positions POS0 and % POS1 if they are not already vertices. % % [POLY2, INDS] = polygonSubcurve(POLYGON, POS0, POS1) % Also return indices of polygon vertices comprised between POS0 and % POS1. The array INDS may be smaller than the array POLY2. % % Example % Nv = 100; % poly = circleToPolygon([30 20 15], Nv); % arc1 = polygonSubcurve(poly, 15, 45); % arc2 = polygonSubcurve(poly, 90, 10); % contains polygon endpoints % figure; axis equal, hold on; axis([0 50 0 50]); % drawPolyline(arc1, 'linewidth', 4, 'color', 'g'); % drawPolyline(arc2, 'linewidth', 4, 'color', 'r'); % drawPolygon(poly, 'color', 'b'); % % See also % polygons2d, polylineSubcurve, projPointOnPolygon, polygonPoint % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRAE - Cepia Software Platform. % number of vertices Nv = size(poly, 1); if t0 < t1 % format positions t0 = max(t0, 0); t1 = min(t1, Nv); end % indices of extreme vertices inside subcurve ind0 = ceil(t0)+1; ind1 = floor(t1)+1; % get the portion of polyline between 2 extremities if t0 < t1 % The result polyline does not contain the last vertex if ind1 <= Nv inds = ind0:ind1; else inds = 1; end else % polygon contains last vertex inds = [ind0:Nv 1:ind1]; end res = poly(inds, :); % add first point if it is not already a vertex if t0 ~= ind0-1 res = [polygonPoint(poly, t0); res]; end % add last point if it is not already a vertex if t1 ~= ind1-1 res = [res; polygonPoint(poly, t1)]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polylineSubcurve.m0000644000000000000000000000013214055375162021534 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polylineSubcurve.m0000644000175000017500000000621314055375162022623 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [res, inds] = polylineSubcurve(poly, t0, t1) % Extract a portion of a polyline. % % POLY2 = polylineSubcurve(POLYLINE, POS0, POS1) % Create a new polyline, by keeping vertices located between positions % POS0 and POS1, and adding points corresponding to positions POS0 and % POS1 if they are not already vertices. % % [POLY2, INDS] = polylineSubcurve(POLYLINE, POS0, POS1) % Also returns the indices of the original polyline that were selected. % The size of the array INDS may be smaller than the array POLY, due to % the addition of new vertices at the extremities. % % Example % Nv = 100; % poly = circleAsPolygon([10 20 30], Nv); % poly2 = polylineSubcurve(poly, 15, 65); % drawCurve(poly2); % % See also % polygons2d, polygonSubCurve % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRAE - Cepia Software Platform. % number of vertices Nv = size(poly, 1); if t0 < t1 % format positions t0 = max(t0, 0); t1 = min(t1, Nv-1); end % indices of extreme vertices inside subcurve ind0 = ceil(t0)+1; ind1 = floor(t1)+1; % get the portion of polyline between 2 extremities if t0 < t1 inds = ind0:ind1; else inds = [ind0:Nv 1:ind1]; end res = poly(inds, :); % add first point if it is not already a vertex if t0 ~= ind0-1 res = [polylinePoint(poly, t0); res]; end % add last point if it is not already a vertex if t1 ~= ind1-1 res = [res; polylinePoint(poly, t1)]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/curveCMoment.m0000644000000000000000000000013214055375162020571 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/curveCMoment.m0000644000175000017500000000522714055375162021664 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function m = curveCMoment(curve, p, q) %CURVECMOMENT Compute centered inertia moment of a 2D curve. % M = curveCMoment(CURVE, P, Q) % % Example % curveCMoment % % See also % polygons2d, curveMoment, curveCSMoment % % Reference % Based on ideas and references in: % "Affine curve moment invariants for shape recognition" % Dongmin Zhao and Jie Chen % Pattern Recognition, 1997, vol. 30, pp. 865-901 % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-03-25, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % compute curve centroid centroid = polylineCentroid(curve); % coordinate of vertices px = curve(:,1)-centroid(1); py = curve(:,2)-centroid(2); % compute centroids of line segments cx = (px(1:end-1)+px(2:end))/2; cy = (py(1:end-1)+py(2:end))/2; % compute length of each line segment dl = hypot(px(2:end)-px(1:end-1), py(2:end)-py(1:end-1)); % compute moment m = zeros(size(p)); for i=1:length(p(:)) m(i) = sum(cx(:).^p(i) .* cy(:).^q(i) .* dl(:)); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/distancePointPolyline.m0000644000000000000000000000013214055375162022502 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/distancePointPolyline.m0000644000175000017500000001033014055375162023564 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [minDist, pos] = distancePointPolyline(point, poly, varargin) %DISTANCEPOINTPOLYLINE Compute shortest distance between a point and a polyline. % % DIST = distancePointPolyline(POINT, POLYLINE) % Returns the shortest distance between a point given as a 1-by-2 row % vector, and a polyline given as a NV-by-2 array of coordinates. % % If POINT is a NP-by-2 array, the result DIST is a NP-by-1 array, % containig the distance of each point to the polyline. % % [DIST, POS] = distancePointPolyline(POINT, POLYLINE) % Also returns the relative position of the point projected on the % polyline, between 0 and NV, the number of polyline vertices. % % ... = distancePointPolyline(POINT, POLYLINE, CLOSED) % Specifies if the polyline is closed or not. CLOSED can be one of: % * 'closed' -> the polyline is closed % * 'open' -> the polyline is open % a column vector of logical with the same number of elements as the % number of points -> specify individually if each polyline is % closed (true=closed). % % % Example: % pt1 = [30 20]; % pt2 = [30 5]; % poly = [10 10;50 10;50 50;10 50]; % distancePointPolyline([pt1;pt2], poly) % ans = % 10 % 5 % % See also % polygons2d, points2d % distancePointEdge, distancePointPolygon, projPointOnPolyline % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % Author: Juan Pablo Carbajal % e-mail: ajuanpi+dev@gmail.com % HISTORY % 2009-06-23 compute all distances in one call % 2016-02-04 Vectorize % check if input polyline is closed or not closed = false; if ~isempty(varargin) c = varargin{1}; if strcmp('closed', c) closed = true; elseif strcmp('open', c) closed = false; elseif islogical(c) closed = c; end end % closes the polyline if necessary if closed poly = [poly; poly(1,:)]; end % number of points Np = size(point, 1); % construct the set of edges edges = [poly(1:end-1, :) poly(2:end, :)]; % compute distance between current each point and all edges, and also % returns the position of projection on corresponding edge, between 0 and 1 [dist, edgePos] = distancePointEdge(point, edges); % get the minimum distance, and index of edge providing minimum distance [minDist, edgeIndex] = min(dist, [], 2); % if required, compute projections pos = []; if nargout == 2 Ne = size(edgePos, 2); j = sub2ind([Np, Ne], (1:Np)', edgeIndex); pos = edgeIndex - 1 + edgePos(j); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonSymmetryAxis.m0000644000000000000000000000013214055375162022250 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonSymmetryAxis.m0000644000175000017500000000655414055375162023347 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function axis = polygonSymmetryAxis(poly) %POLYGONSYMMETRYAXIS Try to identify symmetry axis of polygon. % % LINE = polygonSymmetryAxis(POLY) % Returns a line that minimize difference between the polygon POLY and % its reflection with the line. % The difference metric between the two polygons is the sum of distances % between each vertex of original polygon to the reflected polygon. % % Example % % identify symmetry axis of an ellipse % elli = [50 50 40 20 30]; % poly = ellipseToPolygon(elli, 100); % line = polygonSymmetryAxis(poly); % figure; hold on; % drawEllipse(elli); % axis equal; axis ([0 100 0 100]); % drawLine(line); % % See also % transforms2d, transformPoint, distancePointPolygon % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2015-04-28, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. % start by centering the polygon center = polygonCentroid(poly); poly = bsxfun(@minus, poly, center); % first performs a rough search with 8 angles initAngles = linspace(0, pi, 9); initAngles(end) = []; initRes = zeros(8, 1); for i = 1:8 line = createLine([0 0 cos(initAngles(i)) sin(initAngles(i))]); rotMat = createLineReflection(line); polyRot = transformPoint(poly, rotMat); initRes(i) = sum(distancePointPolygon(poly, polyRot).^2); end % keep the angle that gives best result [dummy, indMin] = min(initRes); %#ok initAngle = initAngles(indMin); % Compute angle that best fit between polygon and its symmetric along line thetaMin = fminbnd(... @(theta) sum(distancePointPolygon(transformPoint(poly, createLineReflection([0 0 cos(theta) sin(theta)])), poly).^2), ... initAngle-pi/4, initAngle+pi/4); % format as a line axis = [center cos(thetaMin) sin(thetaMin)]; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/triangulatePolygon.m0000644000000000000000000000013214055375162022051 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/triangulatePolygon.m0000644000175000017500000000737514055375162023152 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function tri = triangulatePolygon(poly) %TRIANGULATEPOLYGON Compute a triangulation of the polygon. % % TRI = triangulatePolygon(POLY) % Computes a triangulation TRI of the polygon defined by POLY % POLY contains the polygon vertices, as a Nv-by-2 array of double. % TRI is a Nt-by-3 array containing indices of vertices forming the % triangles. % % Example % % creates a simple polygon and computes its Delaunay triangulation % poly = [0 0 ; 10 0;5 10;15 15;5 20;-5 10]; % figure;drawPolygon(poly); axis equal % tri = triangulatePolygon(poly); % figure; % % patch('Faces', tri, 'Vertices', poly, 'facecolor', 'c'); % drawMesh(poly, tri, 'facecolor', 'c'); % axis equal % % % Another example for which constrains were necessary % poly2 = [10 10;80 10; 140 20;30 20; 80 30; 140 30; 120 40;10 40]; % tri2 = triangulatePolygon(poly2); % figure; drawMesh(poly2, tri2); % hold on, drawPolygon(poly2, 'linewidth', 2); % axis equal % axis([0 150 0 50]) % % See also % delaunayTriangulation, drawMesh, patch % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-11-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % compute constraints nv = size(poly, 1); cons = [(1:nv)' [2:nv 1]']; if verLessThan('matlab', '8.1') % Code for versions before R2013a % delaunay triangulation dt = DelaunayTri(poly(:,1), poly(:, 2), cons); %#ok % find which triangles are contained in polygon centers = incenters(dt); inds = isPointInPolygon(centers, poly); % keep selected triangles tri = dt.Triangulation(inds, :); else % Code for versions R2013a and later % delaunay triangulation % dt = DelaunayTri(poly(:,1), poly(:, 2), cons); dt = delaunayTriangulation(poly(:,1), poly(:, 2), cons); % find which triangles are contained in polygon % centers = incenters(dt); centers = incenter(dt); inds = isPointInPolygon(centers, poly); % keep selected triangles % tri = dt.Triangulation(inds, :); tri = dt.ConnectivityList(inds, :); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/drawVertices.m0000644000000000000000000000013214055375162020624 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/drawVertices.m0000644000175000017500000000760614055375162021722 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawVertices(varargin) %DRAWVERTICES Draw the vertices of a polygon or polyline. % % drawVertices(POLY) % Draws the vertices of the given polygon, using pre-defined style. % Default is to draw vertices as squares, with the first vertex filled. % % Example % poly = circleToPolygon([20 30 40], 16); % drawPolygon(poly); % hold on; axis equal; % drawVertices(poly); % % See also % drawPoint, drawPolygon, drawPolyline % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-12-11, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end var = varargin{1}; %% Manage cell arrays of polygons / polylines % 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) = drawVertices(ax, 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 vertices if size(var, 2) > 1 % first argument is a vertex array px = var(:, 1); py = var(:, 2); varargin(1) = []; elseif length(varargin) >= 2 && isnumeric(varargin{1}) && isnumeric(varargin{2}) % arguments 1 and 2 correspond to x and y coordinate respectively px = varargin{1}; py = varargin{2}; varargin(1:2) = []; else % unknow input format error('Should specify either a N-by-2 array, or 2 N-by-1 vectors'); end % concatenate input argument(s) with default options defaults = {'MarkerSize', 6}; if length(varargin) == 1 varargin = [varargin defaults]; else varargin = [{'ks'} defaults varargin]; end %% Draw the vertices % draw the vertices h = plot(ax, px, py, varargin{:}); % draw the first vertex with a different style plot(ax, px(1), py(1), 'ks', 'MarkerFaceColor', 'k', 'MarkerSize', 8); % format output arg if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/intersectLinePolyline.m0000644000000000000000000000013214055375162022506 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/intersectLinePolyline.m0000644000175000017500000001175714055375162023606 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [intersects, edgeIndices] = intersectLinePolyline(line, poly, varargin) %INTERSECTLINEPOLYLINE Intersection points between a line and a polyline. % % P = intersectLinePolyline(LINE, POLY) % Returns the intersection points of the lines LINE with polyline POLY. % LINE is a 1-by-4 row vector containing parametric representation of the % line (in the format [x0 y0 dx dy], see the function 'createLine' for % details). % POLY is a NV-by-2 array containing coordinates of the polyline vertices % P is a K-by-2 array containing the coordinates of the K intersection % points. % % P = intersectLinePolyline(LINE, POLY, TOL) % Specifies the tolerance for geometric tests. Default is 1e-14. % % [P INDS] = intersectLinePolyline(...) % Also returns the indices of edges involved in intersections. INDS is a % K-by-1 column vector, such that P(i,:) corresponds to intersection of % the line with the i-th edge of the polyline. If the intersection occurs % at a polyline vertex, the index of only one of the two neighbor edges % is returned. % Note that due to numerical approximations, the use of function % 'isPointOnEdge' may give results not consistent with this function. % % % Examples % % compute intersections between a square and an horizontal line % poly = [0 0;10 0;10 10;0 10]; % line = [5 5 1 0]; % intersectLinePolyline(line, poly) % ans = % 10 5 % % also return indices of edges % [inters inds] = intersectLinePolyline(line, poly) % inters = % 10 5 % inds = % 2 % % % compute intersections between a square and a diagonal line % poly = [0 0;10 0;10 10;0 10]; % line = [5 5 1 1]; % intersectLinePolyline(line, poly) % ans = % 0 0 % 10 10 % % See Also % lines2d, polylines2d, intersectLines, intersectLinePolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 31/10/2003. % % HISTORY % 2008-11-24 rename 'pi' as 'intersects', update doc % 2009-07-23 removed forgotten occurence of 'pi' variable (thanks to Bala % Krishnamoorthy) % 2010-01-26 rewrite using vectorisation % 2011-05-20 returns unique results % 2011-07-20 returns intersected edge indices % 2012-11-33 add 'diag' option for linePosition % get computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % create the array of edges N = size(poly, 1); edges = [poly(1:N-1, :) poly(2:N, :)]; % compute intersections with supporting lines of polyline edges supportLines = edgeToLine(edges); intersects = intersectLines(line, supportLines, tol); % find edges that are not parallel to the input line inds = find(isfinite(intersects(:, 1))); % compute position of intersection points on corresponding lines pos = linePosition(intersects(inds, :), supportLines(inds, :), 'diag'); % and keep only intersection points located on edges b = pos > -tol & pos < 1+tol; inds = inds(b); intersects = intersects(inds, :); % remove multiple vertices (can occur for intersections located at polyline % vertices) [intersects, I, J] = unique(intersects, 'rows'); %#ok if nargout > 1 % return indices of edges involved in intersection % (in case of intersection located at a vertex, only one of the % neighbor edges is returned) edgeIndices = inds(I); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/distancePolygonsNoCross.m0000644000000000000000000000013214055375162023016 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/distancePolygonsNoCross.m0000644000175000017500000000551014055375162024104 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dist = distancePolygonsNoCross(poly1, poly2) %DISTANCEPOLYGONSNOCROSS Compute the shortest distance between 2 polygons. % % DIST = distancePolygonsNoCross(POLY1, POLY2) % Computes the shortest distance between the boundaries of the two % polygons, assuming they do not cross. % Each polygon is given by a N-by-2 array containing the vertex % coordinates. % % If the polygons may cross, it is necessary to use the % 'distancePolygons' function, that adds a potentially costly test on the % intersection. % % Example % % Computes the distance between a square and a triangle % poly1 = [10 10;20 10;20 20;10 20]; % poly2 = [30 20;50 20;40 45]; % distancePolygons(poly1, poly2) % ans = % 10 % % See also % polygons2d, distancePolygons, distancePolylines, distancePointPolygon % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-06-17, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % compute distance of each vertex of a polygon to the other polygon dist1 = min(distancePointPolygon(poly1, poly2)); dist2 = min(distancePointPolygon(poly2, poly1)); % keep the minimum of the two distances dist = min(dist1, dist2); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/isPointOnPolyline.m0000644000000000000000000000013214055375162021620 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/isPointOnPolyline.m0000644000175000017500000000513114055375162022705 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = isPointOnPolyline(point, poly, varargin) %ISPOINTONPOLYLINE Test if a point belongs to a polyline. % % B = isPointOnPolyline(POINT, POLY) % Returns TRUE of the point POINT belong to the polyline defined by the % set of points in POLY. % % B = isPointOnPolyline(POINT, POLY, TOL) % Specify the absolute tolerance for testing the distance between the % point and the polyline. % % Example % pt1 = [30 20]; % pt2 = [30 10]; % poly = [10 10;50 10;50 50;10 50]; % isPointOnPolyline([pt1;pt2], poly) % ans = % 0 % 1 % % See also % points2d, polygons2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-06-19, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % extract computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % return true if distance is below a given threshold res = distancePointPolyline(point, poly) < tol; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonVertices.m0000644000000000000000000000013214055375162021356 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonVertices.m0000644000175000017500000000700214055375162022442 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vertices = polygonVertices(poly) %POLYGONVERTICES Extract all vertices of a (multi-)polygon. % % VERTS = polygonVertices(POLY) % Returns the set of verttices from the polygon POLY. POLY can be either: % * a N-by-2 array of vertices. In that case, POLY and VERTS are the % same. % * a N-by-2 array of vertices with pairs of NaN values separating two % rings of the polygon. In that case, the array VERTS corresponds to % the vertices of the polygon, without copying the NaN values. % * a cell array of loops. In that case, the functions recursively % process the polygons and populated the vertex array. % % % Example % % create a polygon with a hole, using NaN for separating rings % ring1 = [0 0 ; 50 0;50 50;0 50]; % ring2 = [20 20;20 30;30 30;30 20]; % poly = [ring1 ; NaN NaN ; ring2]; % figure; drawPolygon(poly, 'b'); % axis([-10 60 -10 60]); axis equal; hold on; % verts = polygonVertices(poly); % drawPoint(verts, 'bo'); % % % create a polygon with a hole, storing rings in cell array % ring1 = [0 0 ; 50 0;50 50;0 50]; % ring2 = [20 20;20 30;30 30;30 20]; % poly = {ring1, ring2}; % figure; drawPolygon(poly, 'b'); % axis([-10 60 -10 60]); axis equal; hold on; % verts = polygonVertices(poly); % drawPoint(verts, 'bo'); % % See also % polygons2d, polygonEdges % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-06-07, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. if isnumeric(poly) % find NaN or infinite values inds = sum(isfinite(poly), 2) == 2; % filter non-finite vertices if necessary if any(~inds) vertices = poly(inds, :); else vertices = poly; end elseif iscell(poly) % process cell array vertices = zeros(0, 2); for i = 1:length(poly) vertices = [vertices ; polygonVertices(poly{i})]; %#ok end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonCentroid.m0000644000000000000000000000013214055375162021341 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonCentroid.m0000644000175000017500000000612314055375162022430 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [centroid, area] = polygonCentroid(varargin) %POLYGONCENTROID Compute the centroid (center of mass) of a polygon. % % CENTROID = polygonCentroid(POLY) % CENTROID = polygonCentroid(PTX, PTY) % Computes center of mass of a polygon defined by POLY. POLY is a N-by-2 % array of double containing coordinates of vertices. % % [CENTROID AREA] = polygonCentroid(POLY) % Also returns the (signed) area of the polygon. % % Example % % Draws the centroid of a paper hen % x = [0 10 20 0 -10 -20 -10 -10 0]; % y = [0 0 10 10 20 10 10 0 -10]; % poly = [x' y']; % centro = polygonCentroid(poly); % drawPolygon(poly); % hold on; axis equal; % drawPoint(centro, 'bo'); % % References % algo adapted from P. Bourke web page % % See also: % polygons2d, polygonArea, polygonSecondAreaMoments, drawPolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 05/05/2004. % % Algorithme P. Bourke, vectorized version % HISTORY % 2012.02.24 vectorize code % parse input arguments if nargin == 1 var = varargin{1}; px = var(:,1); py = var(:,2); elseif nargin == 2 px = varargin{1}; py = varargin{2}; end % vertex indices N = length(px); iNext = [2:N 1]; % compute cross products common = px .* py(iNext) - px(iNext) .* py; sx = sum((px + px(iNext)) .* common); sy = sum((py + py(iNext)) .* common); % area and centroid area = sum(common) / 2; centroid = [sx sy] / 6 / area; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/parametrize.m0000644000000000000000000000013214055375162020505 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/parametrize.m0000644000175000017500000000730414055375162021576 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function par = parametrize(varargin) %PARAMETRIZE Parametrization of a polyline, based on edges lengths. % % PAR = parametrize(POLY); % Returns a parametrization of the curve defined by the serie of points, % based on euclidean distance between two consecutive points. % POLY is a N-by-2 array, representing coordinates of vertices. The % result PAR is N-by-1, and contains the cumulative length of edges until % corresponding vertex. % % PAR = parametrize(PX, PY); % is the same, but specify points coordinates in separate column vectors. % % PAR = parametrize(..., 'normalize', 1); % PAR = parametrize(..., 'normalize', true); % Rescales the result such that the last element of PAR is 1. % % Example % % Parametrize a circle approximation % poly = circleToPolygon([0 0 1], 200); % p = parametrize(poly); % p(end) % ans = % 6.2829 % % See also: % polygons2d, polylineLength % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2003. % %% Process inputs % extract vertex coordinates if size(varargin{1}, 2) > 1 % vertices in a single array pts = varargin{1}; varargin(1) = []; elseif length(varargin) == 2 % points as separate arrays pts = [varargin{1} varargin{2}]; varargin(1:2) = []; end % by default, do not normalize normalize = false; % extract options while length(varargin) > 1 param = varargin{1}; switch lower(param) case 'normalize' normalize = varargin{2}; otherwise error('Unknown parameter name: %s', param); end varargin(1:2) = []; end %% Parametrize polyline % compute cumulative sum of euclidean distances between consecutive % vertices, setting distance of first vertex to 0. if size(pts, 2) == 2 % process points in 2D par = [0 ; cumsum(hypot(diff(pts(:,1)), diff(pts(:,2))))]; else % process points in arbitrary dimension par = [0 ; cumsum(sqrt(sum(diff(pts).^2, 2)))]; end % eventually rescale between 0 and 1 if normalize par = par / par(end); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/distancePointPolygon.m0000644000000000000000000000013214055375162022336 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/distancePointPolygon.m0000644000175000017500000000533514055375162023431 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function minDist = distancePointPolygon(point, poly) %DISTANCEPOINTPOLYGON Shortest distance between a point and a polygon. % % DIST = distancePointPolygon(POINT, POLYGON) % Computes the shortest distance between the point POINT and the polygon % given by POLYGON. POINT is a 1-by-2 row vector, and POLYGON is a N-by-2 % array containing vertex coordinates. % The distance is computed as the minimal distance to the boundary edges. % % Example % % Computes the distance between a point and a square % square = [0 0; 10 0;10 10;0 10]; % p0 = [16 3]; % distancePointPolygon(p0, square) % ans = % 6 % % See also % polygons2d, points2d, distancePointPolyline, distancePointEdge, % projPointOnPolyline % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % eventually copy first point at the end to ensure closed polygon if sum(poly(end, :) == poly(1,:)) ~= 2 poly = [poly; poly(1,:)]; end % call to distancePointPolyline minDist = distancePointPolyline(point, poly); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/geod2cart.m0000644000000000000000000000013214055375162020034 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/geod2cart.m0000644000175000017500000000517314055375162021127 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = geod2cart(src, curve, normal) %GEOD2CART Convert geodesic coordinates to cartesian coord. % % PT2 = geod2cart(PT1, CURVE, NORMAL) % CURVE and NORMAL are both [N*2] array with the same length, and % represent positions of the curve, and normal to each point. % PT1 is the point to transform, in geodesic coordinate (first coord is % distance from the curve start, and second coord is distance between % point and curve). % % The function return the coordinate of PT1 in the same coordinate system % than for the curve. % % TODO : add processing of points not projected on the curve. % -> use the closest end % % See also % polylines2d, cart2geod, curveLength % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 08/04/2004. % t = parametrize(curve); N = size(src, 1); ind = zeros(N, 1); for i=1:N indices = find(t>=src(i,1)); ind(i) = indices(1); end theta = lineAngle([zeros(N,1) zeros(N,1) normal(ind,:)]); d = src(:,2); point = [curve(ind,1)+d.*cos(theta), curve(ind,2)+d.*sin(theta)]; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonNormalAngle.m0000644000000000000000000000013214055375162021771 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonNormalAngle.m0000644000175000017500000000660114055375162023061 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = polygonNormalAngle(poly, inds) % Normal angle at each vertex of a polygon. % % THETA = polygonNormalAngle(POLY); % where POLY is a N-by-2 array representing vertex coordinates, computes % the normal angle at each vertex of the polygon. THETA is a N-by-1 array % containing numeric values between -PI and +PI. The result depends on % the orientation of the polygon (counter-clockwise or clockwise). % % THETA = polygonNormalAngle(POLY, IND); % Computes the normal angle for each vertex specified by IND. If IND is a % vector of vertex indices. % % % Example % % Normal angles at vertices of an isosceles right triangle are pi/2 at % % right angle-vertex and 3*pi/4 for the two remaining vertices. % poly = [0 0 ; 1 0 ; 0 1]; % polygonNormalAngle(poly) % ans = % 1.5708 % 2.3562 % 2.3562 % % % Compute normal angles for a slightly more complicated polygon % poly = [0 0;0 1;-1 1;0 -1;1 0]; % % compute normal angle at each vertex % theta = polygonNormalAngle(poly); % % sum of all normal angle of a non-intersecting polygon equals 2*pi % % (can be -2*pi if polygon is oriented clockwise) % sum(theta) % ans = % 6.2832 % % See also: % polygons2d, polygonOuterNormal, normalizeAngle % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2005-11-30 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % number of polygon vertices np = size(poly, 1); if nargin == 1 inds = 1:np; end % number of angles to compute nv = length(inds); theta = zeros(nv, 1); for i = 1:nv % current vertex curr = poly(inds(i), :); % previous and next vertices prev = poly(mod(inds(i)-2, np)+1, :); next = poly(mod(inds(i), np)+1, :); theta(i) = angle3Points(prev, curr, next) - pi; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonSelfIntersections.m0000644000000000000000000000013214055375162023235 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonSelfIntersections.m0000644000175000017500000000751014055375162024325 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polygonSelfIntersections(poly, varargin) %POLYGONSELFINTERSECTIONS Find self-intersection points of a polygon. % % PTS = polygonSelfIntersections(POLY) % Return the position of self intersection points % % [PTS, POS1, POS2] = polygonSelfIntersections(POLY) % Also return the 2 positions of each intersection point (the position % when meeting point for first time, then position when meeting point % for the second time). % % [...] = polygonSelfIntersections(POLY, 'tolerance', TOL) % Specifies an additional parameter to decide whether two intersection % points should be considered the same, based on their euclidean % distance. % % % Example % % use a '8'-shaped polygon % poly = [10 0;0 0;0 10;20 10;20 20;10 20]; % polygonSelfIntersections(poly) % ans = % 10 10 % % See also % polygons2d, polylineSelfIntersections % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-06-15, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % HISTORY % 2011-06-22 fix bug when removing origin vertex (thanks to Federico % Bonelli) tol = 1e-14; % parse optional arguments while length(varargin) > 1 pname = varargin{1}; if ~ischar(pname) error('Expect optional arguments as name-value pairs'); end if strcmpi(pname, 'tolerance') tol = varargin{2}; else error(['Unknown parameter name: ' pname]); end varargin(1:2) = []; end % ensure the last point equals the first one if sum(abs(poly(end, :)-poly(1,:)) < tol) ~= 2 poly = [poly; poly(1,:)]; end % compute intersections by calling algo for polylines [points, pos1, pos2] = polylineSelfIntersections(poly, 'closed', 'tolerance', tol); % It may append that first vertex of polygon is detected as intersection, % the following tries to detect this. % (pos1 < pos2 by construction) n = size(poly, 1) - 1; inds = abs(pos1) < tol & abs(pos2 - n) < tol; points(inds, :) = []; pos1(inds) = []; pos2(inds) = []; %% Post-processing % process output arguments if nargout <= 1 varargout = {points}; elseif nargout == 3 varargout = {points, pos1, pos2}; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonSignature.m0000644000000000000000000000013214055375162021533 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonSignature.m0000644000175000017500000000630614055375162022625 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [res, thetaList] = polygonSignature(poly, varargin) %POLYGONSIGNATURE Polar signature of a polygon (polar distance to origin). % % DISTS = polygonSignature(POLY, THETALIST) % Computes the polar signature of a polygon, for a set of angles in % degrees. If a ray at a given angle does not intersect the polygon, the % corresponding distance value is set to NaN. % % DISTS = polygonSignature(POLY, N) % When N is a scalar, uses N angles equally distributed between 0 and 360 % degrees. % % [DISTS, THETA] = polygonSignature(...) % Also returns the angle set for which the signature was computed. % % Example % polygonSignature % % See also % polygons2d, signatureToPolygon, intersectRayPolygon % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2013-03-14, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % default angle list thetaList = 0:359; % get user-defined angle list if ~isempty(varargin) var = varargin{1}; if isscalar(var) thetaList = linspace(0, 360, var+1); thetaList(end) = []; else thetaList = var; end end % also extract reference point if needed center = [0 0]; if nargin > 2 center = varargin{2}; end % allocate memory nTheta = length(thetaList); res = NaN * ones(nTheta, 1); % iterate on angles for i = 1:length(thetaList) theta = deg2rad(thetaList(i)); ray = [center cos(theta) sin(theta)]; ptInt = intersectRayPolygon(ray, poly); if ~isempty(ptInt) res(i) = distancePoints(center, ptInt(1,:)); end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/projPointOnPolyline.m0000644000000000000000000000013214055375162022157 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/projPointOnPolyline.m0000644000175000017500000001070114055375162023243 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = projPointOnPolyline(point, poly, varargin) %PROJPOINTONPOLYLINE Compute position of a point projected on a polyline. % % POS = projPointOnPolyline(POINT, POLYLINE) % Compute the position of the orthogonal projection of a point on a % polyline. % POINT is a 1-by-2 row vector containing point coordinates % POLYLINE is a N-by-2 array containing coordinates of polyline vertices % POS is the position of the point on the polyline, between 0 and the % number of vertices of the polyline. POS can be a non-integer value, in % this case, the integer part corresponds to the polyline edge index % (between 0 and Nv-1), and the floating-point part corresponds to the % relative position on i-th edge (between 0 and 1, 0: edge start, 1: edge % end). % % When POINT is an array of points, returns a column vector with as many % rows as the number of points. % % POS = projPointOnPolyline(POINT, POLYLINE, CLOSED) % Specifies if the polyline is closed or not. CLOSED can be one of: % 'closed' -> the polyline is closed % 'open' -> the polyline is open % a column vector of logical with the same number of elements as the % number of points -> specify individually if each polyline is % closed (true=closed). % % [POS, DIST] = projPointOnPolyline(...) % Also returns the distance between POINT and POLYLINE. % % Example % poly = [10 10; 20 10;20 20;10 20]; % projPointOnPolyline([15 0], poly) % ans = % 0.5000 % projPointOnPolyline([0 16], poly) % ans = % 3.0000 % % See also % points2d, polygons2d, polylinePoint, projPointOnPolygon % distancePointPolyline % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % check if input polyline is closed or not closed = false; if ~isempty(varargin) var = varargin{1}; if strcmp('closed', var) closed = true; elseif strcmp('open', var) closed = false; elseif islogical(var) closed = var; end end % closes the polyline if necessary if closed poly = [poly ; poly(1,:)]; end % number of points Np = size(point, 1); % allocate memory results pos = zeros(Np, 1); minDist = inf*ones(Np, 1); % iterate on points for p = 1:Np % build set of edges edges = [poly(1:end-1, :) poly(2:end, :)]; % compute distance between current point and all edges [dist, edgePos] = distancePointEdge(point(p, :), edges); % update distance and position if necessary [minDist(p), edgeIndex] = min(dist); pos(p) = edgeIndex - 1 + edgePos(edgeIndex); end % process output arguments if nargout <= 1 varargout{1} = pos; elseif nargout == 2 varargout{1} = pos; varargout{2} = minDist; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/convexHull.m0000644000000000000000000000013214055375162020311 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/convexHull.m0000644000175000017500000000655314055375162021407 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [hull, inds] = convexHull(points, varargin) %CONVEXHULL Convex hull of a set of points. % % POLY = convexHull(POINTS) % Computes the convex hull of the set of points POINTS. This function is % mainly a wrapper to the convhull function, that format the result to a % polygon. % % [POLY, INDS] = convexHull(POINTS) % Also returns the indices of convex hull vertices within the original % array of points. % % ... = convexHull(POINTS, 'simplify', BOOL) % specifies the 'simplify' option use dfor calling convhull. By default, % the convexHull functions uses simplify equals to TRUE (contrary to the % convhull function), resulting in a more simple convex polygon. % % % Example % % Draws the convex hull of a set of random points % pts = rand(30,2); % drawPoint(pts, '.'); % hull = convexHull(pts); % hold on; % drawPolygon(hull); % % % Draws the convex hull of a paper hen % x = [0 10 20 0 -10 -20 -10 -10 0]; % y = [0 0 10 10 20 10 10 0 -10]; % poly = [x' y']; % hull = convexHull(poly); % figure; drawPolygon(poly); % hold on; axis equal; % drawPolygon(hull, 'm'); % % See also % polygons2d, convhull % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2011-04-08, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % checkup on array size if size(points, 1) < 3 hull = points; inds = 1:size(points, 1); return; end % parse simplify option simplify = true; if nargin > 2 && strcmpi(varargin{1}, 'simplify') simplify = varargin{2}; end % compute convex hull by calling the 'convhull' function inds = convhull(points(:,1), points(:,2), 'simplify', simplify); hull = points(inds, :); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/curveCSMoment.m0000644000000000000000000000013214055375162020714 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/curveCSMoment.m0000644000175000017500000000535314055375162022007 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function m = curveCSMoment(curve, p, q) %CURVECSMOMENT Compute centered scaled moment of a 2D curve. % M = curveCSMoment(CURVE, P, Q) % % Example % curveCSMoment % % See also % polygons2d, curveMoment, curveCMoment % % Reference % Based on ideas and references in: % "Affine curve moment invariants for shape recognition" % Dongmin Zhao and Jie Chen % Pattern Recognition, 1997, vol. 30, pp. 865-901 % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-03-25, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % compute curve centroid centroid = polylineCentroid(curve); % compute perimeter L = polylineLength(curve); % coordinate of vertices px = curve(:,1)-centroid(1); py = curve(:,2)-centroid(2); % compute centroids of line segments cx = (px(1:end-1)+px(2:end))/2; cy = (py(1:end-1)+py(2:end))/2; % compute length of each line segment dl = hypot(px(2:end)-px(1:end-1), py(2:end)-py(1:end-1)); % compute moment m = zeros(size(p)); for i=1:length(p(:)) d = (p(i)+q(i))/2+1; m(i) = sum(cx(:).^p(i) .* cy(:).^q(i) .* dl(:)) / L^d; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/reversePolyline.m0000644000000000000000000000013214055375162021351 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/reversePolyline.m0000644000175000017500000000413514055375162022441 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function rev = reversePolyline(poly) %REVERSEPOLYLINE Reverse a polyline, by iterating vertices from the end. % % POLY2 = reversePolyline(POLY) % POLY2 has same vertices as POLY, but POLY2(i,:) is the same as % POLY(END-i+1,:). % % Example % reversePolyline % % See also % polygons2d, reversePolygon % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-06-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. rev = poly(end:-1:1, :); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/simplifyPolygon.m0000644000000000000000000000013214055375162021366 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/simplifyPolygon.m0000644000175000017500000000514614055375162022461 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [poly, keepInds] = simplifyPolygon(poly, varargin) %SIMPLIFYPOLYGON Douglas-Peucker simplification of a polygon. % % POLY2 = simplifyPolygon(POLY, TOL) % Simplifies the input polygon using the Douglas-Peucker algorithm. % % Example % elli = [20 30 40 20 30]; % poly = ellipseToPolygon(elli, 500); % poly2 = simplifyPolygon(poly, 1); % use a tolerance equal to 1. % figure; hold on; % drawEllipse(elli); % drawPoint(poly2, 'mo'); % % See also % polygons2d, smoothPolygon, simplifyPolyline, resamplePolygon % % References % http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2013-03-14, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % call the simplifyPolyline function by ensuring the last vertex is present poly = poly([1:end 1], :); [poly, keepInds] = simplifyPolyline(poly, varargin{:}); % remove last vertex poly(end, :) = []; keepInds(end) = []; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonContains.m0000644000000000000000000000013214055375162021350 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonContains.m0000644000175000017500000000575614055375162022452 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polygonContains(poly, point) %POLYGONCONTAINS Test if a point is contained in a multiply connected polygon. % % B = polygonContains(POLYGON, POINT); % Returns TRUE if the (possibly multi-connected) polygon POLYGON contains % the point(s) given by POINT. % This is an extension of the Matlab function inpolygon for the case of % polygons with holes. % % Example % POLY = [0 0; 10 0;10 10;0 10;NaN NaN;3 3;3 7;7 7;7 3]; % PT = [5 1;5 4]; % polygonContains(POLY, PT); % ans = % 1 % 0 % % See also % polygons2d, inpolygon, isPointInPolygon % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-10-11, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % transform as a cell array of simple polygons polygons = splitPolygons(poly); N = length(polygons); Np = size(point, 1); % compute orientation of polygon, and format to have Np*N matrix areas = zeros(N, 1); for i = 1:N areas(i) = polygonArea(polygons{i}); end ccw = areas > 0; ccw = repmat(ccw', Np, 1); % test if point inside each polygon in = false(size(point, 1), N); for i = 1:N poly = polygons{i}; in(:, i) = inpolygon(point(:,1), point(:,2), poly(:,1), poly(:,2)); end % count polygons containing point, weighted by polygon orientation res = sum(in.*(ccw==1) - in.*(ccw==0), 2); varargout{1} = res; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/expandPolygon.m0000644000000000000000000000013214055375162021011 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/expandPolygon.m0000644000175000017500000001064714055375162022106 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function loops = expandPolygon(poly, dist, varargin) %EXPANDPOLYGON Expand a polygon by a given (signed) distance. % % POLY2 = expandPolygon(POLY, DIST); % Associates to each edge of the polygon POLY the parallel line located % at distance DIST from the current edge, and compute intersections with % neighbor parallel lines. The input polygon POLY must be oriented % counter-clockwise. Otherwise, distance is computed inside the polygon. % The resulting polygon is simplified to remove inner "loops", and can % eventually be disconnected. % The result POLY2 is a cell array, each cell containing a simple linear % ring. % % This is a kind of dilation, but behaviour on corners is different. % This function keeps angles of polygons, but there is no direct relation % between the lengths of each polygon. % % It is also possible to specify negative distance, and get all points % inside the polygon. If the polygon is convex, the result equals % morphological erosion of polygon by a ball with radius equal to the % given distance. % % Example: % % Computes the negative offset of a non-convex polygon % poly = [10 10;30 10;30 30;20 20;10 30]; % poly2 = expandPolygon(poly, -3); % figure; % drawPolygon(poly, 'linewidth', 2); % hold on; drawPolygon(poly2, 'm') % axis equal; axis([0 40 0 40]); % % See also: % polygons2d, polygonLoops, polygonSelfIntersections % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 14/05/2005. % % HISTORY: % 31-07-2005 change algo for negative distance: use clipping of polygon % by half-planes % default options cleanupLoops = false; % process input argument while length(varargin) > 1 paramName = varargin{1}; switch lower(paramName) case 'cleanuploops' cleanupLoops = varargin{2}; otherwise error(['Unknown parameter name: ' paramName]); end varargin(1:2) = []; end % eventually copy first point at the end to ensure closed polygon if sum(poly(end, :) == poly(1,:)) ~= 2 poly = [poly; poly(1,:)]; end % number of vertices of the polygon N = size(poly, 1)-1; % find lines parallel to polygon edges located at distance DIST lines = zeros(N, 4); for i = 1:N side = createLine(poly(i,:), poly(i+1,:)); lines(i, 1:4) = parallelLine(side, dist); end % compute intersection points of consecutive lines lines = [lines;lines(1,:)]; poly2 = zeros(N, 2); for i = 1:N poly2(i,1:2) = intersectLines(lines(i,:), lines(i+1,:)); end % split result polygon into set of loops (simple polygons) loops = polygonLoops(poly2); % keep only loops whose distance to original polygon is correct if cleanupLoops distLoop = zeros(length(loops), 1); for i = 1:length(loops) distLoop(i) = distancePolygons(loops{i}, poly); end loops = loops(abs(distLoop-abs(dist)) < abs(dist)/1000); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/smoothPolyline.m0000644000000000000000000000013214055375162021207 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/smoothPolyline.m0000644000175000017500000000621314055375162022276 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = smoothPolyline(poly, M) %SMOOTHPOLYLINE Smooth a polyline using local averaging. % % RES = smoothPolygon(POLY, M) % POLY contains the polyline vertices, and M is the size of smoothing % (given as the length of the convolution window). % Extremities of the polyline are smoothed with reduced window (last and % first vertices are kept identical, second and penultimate vertices are % smoothed with 3 values, etc.). % % Example % img = imread('circles.png'); % img = imfill(img, 'holes'); % contours = bwboundaries(img'); % poly = contours{1}(201:500,:); % figure; drawPolyline(poly, 'b'); hold on; % poly2 = smoothPolyline(poly, 21); % drawPolygon(poly2, 'm'); % % See also % polygons2d, smoothPolygon, simplifyPolyline, resamplePolyline % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2015-02-17, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. % compute the number of elements before and after M1 = floor((M - 1) / 2); M2 = ceil((M - 1) / 2); % create convolution vector v2 = ones(M, 1) / M; % apply filtering on central part of the polyline res(:,1) = conv(poly(:,1), v2, 'same'); res(:,2) = conv(poly(:,2), v2, 'same'); % need to recompute the extremities for i = 1:M1 i2 = 2 * i - 1; res(i, 1) = mean(poly(1:i2, 1)); res(i, 2) = mean(poly(1:i2, 2)); end for i = 1:M2 i2 = 2 * i - 1; res(end - i + 1, 1) = mean(poly(end-i2+1:end, 1)); res(end - i + 1, 2) = mean(poly(end-i2+1:end, 2)); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonLength.m0000644000000000000000000000013214055375162021013 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonLength.m0000644000175000017500000000573014055375162022105 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function len = polygonLength(poly, varargin) %POLYGONLENGTH Perimeter of a polygon. % % L = polygonLength(POLYGON); % Computes the boundary length of a polygon. POLYGON is given by a N-by-2 % array of vertices. % % Example % % Perimeter of a circle approximation % poly = circleToPolygon([0 0 1], 200); % polygonLength(poly) % ans = % 6.2829 % % See also: % polygons2d, polygonCentroid, polygonArea, drawPolygon, polylineLength % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 11/05/2005. % % HISTORY % 2011-03-31 add control for empty polygons, code cleanup % 2011-05-27 fix bugs % If first argument is a cell array, this is a multi-polygon, and we simply % add the lengths of individual polygons if iscell(poly) len = 0; for i = 1:length(poly) len = len + polygonLength(poly{i}); end return; end % case of a polygon given as two coordinate arrays if nargin == 2 poly = [poly varargin{1}]; end % check there are enough points if size(poly, 1) < 2 len = 0; return; end % compute length if size(poly, 2) == 2 % polygon in dimension 2 (classical case) dp = diff(poly([1:end 1], :), 1, 1); len = sum(hypot(dp(:, 1), dp(:, 2))); else % polygon of larger dimension len = sum(sqrt(sum(diff(poly([2:end 1], :), 1, 1).^2, 2))); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/distancePolylines.m0000644000000000000000000000013214055375162021653 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/distancePolylines.m0000644000175000017500000000450414055375162022743 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dist = distancePolylines(poly1, poly2) %DISTANCEPOLYLINES Compute the shortest distance between 2 polylines. % % DIST = distancePolylines(POLY1, POLY2) % POLY1 and POLY2 should be two polylines represented by their list of % vertices. % % % See also % polygons2d, distancePolygons, distancePointPolyline % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-06-17, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % compute distance of each vertex of a polyline to the other polyline dist1 = min(distancePointPolyline(poly1, poly2)); dist2 = min(distancePointPolyline(poly2, poly1)); % keep the minimum of the two distances dist = min(dist1, dist2); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/drawPolyline.m0000644000000000000000000000013214055375162020633 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/drawPolyline.m0000644000175000017500000001061714055375162021725 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPolyline(varargin) %DRAWPOLYLINE Draw a polyline specified by a list of points. % % drawPolyline(COORD); % packs coordinates in a single [N*2] array. % % drawPolyline(PX, PY); % specifies coordinates in separate arrays. PX and PY must be column % vectors with the same length. % % drawPolyline(..., TYPE); % where TYPE is either 'closed' or 'open', specifies if last point must % be connected to the first one ('closed') or not ('open'). % Default is 'open'. % % drawPolyline(..., PARAM, VALUE); % specify plot options as described for plot command. % % H = drawPolyline(...) also return a handle to the list of line objects. % % Example: % % Draw a curve representing an ellipse % t = linspace(0, 2*pi, 100)'; % px = 10*cos(t); py = 5*sin(t); % drawPolyline([px py], 'closed'); % axis equal; % % % The same, with different drawing options % drawPolyline([px py], 'closed', 'lineWidth', 2, 'lineStyle', '--'); % % See Also: % polygons2d, drawPolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 06/04/2004. % % HISTORY % 03/01/2007: better processing of input, and update doc (drawing % options and CLOSE option) % 30/04/2009 rename as drawPolyline. % 2011-10-11 add management of axes handle % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % If first argument is a cell array, draw each curve individually, % and eventually returns handle of each plot. var = varargin{1}; if iscell(var) h = []; for i = 1:length(var(:)) h = [h ; drawPolyline(ax, var{i}, varargin{2:end})]; %#ok end if nargout > 0 varargout = {h}; end return; end % extract curve coordinate if size(var, 2) == 1 % first argument contains x coord, second argument contains y coord px = var; if length(varargin) == 1 error('Wrong number of arguments in drawPolyline'); end py = varargin{2}; varargin = varargin(3:end); else % first argument contains both coordinate px = var(:, 1); py = var(:, 2); varargin = varargin(2:end); end % check if curve is closed or open closed = false; if ~isempty(varargin) var = varargin{1}; if strncmpi(var, 'close', 5) closed = true; varargin = varargin(2:end); elseif strncmpi(var, 'open', 4) closed = false; varargin = varargin(2:end); end end % if curve is closed, add first point at the end of the list if closed px = [px; px(1)]; py = [py; py(1)]; end % plot the curve, with eventually optional parameters h = plot(ax, px, py, varargin{:}); % format output arguments if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/steinerPoint.m0000644000000000000000000000013214055375162020645 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/steinerPoint.m0000644000175000017500000000524314055375162021736 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pt = steinerPoint(varargin) %STEINERPOINT Compute steiner point (weighted centroid) of a polygon. % % PT = steinerPoint(POINTS); % PT = steinerPoint(PTX, PTY); % Computes steiner point of a polygon defined by POINTS. POINTS is a % [N*2] array of double. % % The steiner point is computed the same way as the polygon centroid, % except that a weight depending on the angle is given to each vertex. % % See also: % polygons2d, polygonArea, polygonCentroid, drawPolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 11/11/2004. % if nargin==1 var = varargin{1}; px = var(:,1); py = var(:,2); elseif nargin==2 px = varargin{1}; py = varargin{2}; end % Algorithme P. Bourke sx = 0; sy = 0; N = length(px); for i=1:N-1 sx = sx + (px(i)+px(i+1))*(px(i)*py(i+1) - px(i+1)*py(i)); sy = sy + (py(i)+py(i+1))*(px(i)*py(i+1) - px(i+1)*py(i)); end sx = sx + (px(N)+px(1))*(px(N)*py(1) - px(1)*py(N)); sy = sy + (py(N)+py(1))*(px(N)*py(1) - px(1)*py(N)); pt = [sx sy]/6/polygonArea(px, py); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/clipPolyline.m0000644000000000000000000000013214055375162020625 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/clipPolyline.m0000644000175000017500000000664014055375162021720 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = clipPolyline(poly, box) %CLIPPOLYLINE Clip an open polyline with a rectangular box. % % POLY2 = clipPolyline(POLY, BOX); % POLY is N-by-2 array of vertex coordinates. % BOX has the form: [XMIN XMAX YMIN YMAX]. % Returns the set of polylines created by the intersection of the % polyline POLY and the bounding box BOX. The result is a cell array with % as many cells as the number of curve clips. % % % Example % circle = [5 5 6]; % poly = circleToPolygon(circle, 200); % box = [0 10 0 10]; % res = clipPolyline(poly, box); % figure; % hold on; axis equal; axis([-2 12 -2 12]); % drawCircle(circle, 'b:') % drawBox(box, 'k') % drawPolyline(res, 'linewidth', 2, 'color', 'b') % % See also: % polygons2d, boxes2d, clipPolygon, clipEdge % % --------- % author : David Legland % created the 14/05/2005. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2007/09/14 fix doc % check case of polylines stored in cell array if iscell(poly) res = cell(1, length(poly)); for i = 1:length(poly) res{i} = clipPolyline(poly{i}, box); end return; end % check case of empty polylines N = size(poly, 1); if N == 0 res = cell(0, 0); return end % create edges array of polyline edges = [poly(1:N-1, :) poly(2:N, :)]; % clip edges edges = clipEdge(edges, box); % select non empty edges, and get their vertices % find clipped edges within box inds = sum(abs(edges), 2) > 1e-14; % find list of adjacent edges within box dinds = diff(inds); inds0 = find(dinds == 1) + 1; if inds(1) == 1 inds0 = [1 inds0]; end inds1 = find(dinds == -1); if inds(end) == 1 inds1 = [inds1 N-1]; end nClips = length(inds0); res = cell(1, nClips); for iClip = 1:nClips range = inds0(iClip):inds1(iClip); poly2 = [edges(range, 1:2) ; edges(range(end), 3:4)]; res{iClip} = poly2; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/readPolygonSet.m0000644000000000000000000000013214055375162021121 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/readPolygonSet.m0000644000175000017500000000570414055375162022214 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polys = readPolygonSet(filename) %READPOLYGONSET Read a set of simple polygons stored in a file. % % POLY = readPolygonSet(FILENAME); % Returns the polygon stored in the file FILENAME. % Polygons are assumed to be stored in text files, without headers, with % x and y coordinates packed in two separate lines: % X11 X12 X13 ... X1N % Y11 Y12 Y13 ... Y1N % X21 X22 X23 ... X2N % Y21 Y22 Y23 ... Y2N % % Each polygon may have a different number of vertices. The result is a % cell array of polygon, each cell containing a N-by-2 array representing % the vertex coordinates. % % See also: % polygons2d % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 11/04/2004. % % the set of polygons (no pre-allocation, as we do not know how many % polygons are stored) polys = {}; % index of polygon p = 0; % open file for reading fid = fopen(filename, 'rt'); % use an infinite loop, terminated in case of EOF while true % set of X, and Y coordinates line1 = fgetl(fid); line2 = fgetl(fid); % break loop if end of file is reached if line1 == -1 break; end % create a new polygon by concatenating vertex coordinates p = p + 1; polys{p} = [str2num(line1)' str2num(line2)']; %#ok end % close file fclose(fid); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/resamplePolygon.m0000644000000000000000000000013214055375162021342 xustar0030 mtime=1622538866.078813569 30 atime=1622538866.078813569 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/resamplePolygon.m0000644000175000017500000000520614055375162022432 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = resamplePolygon(poly, n) %RESAMPLEPOLYGON Distribute N points equally spaced on a polygon. % % POLY2 = resamplePolygon(POLY, N) % Resample the input polygon POLY such that the resulting polygon POLY2 % has N vertices. All points of POLY2 belong to the initial polygon, but % are not necessarily vertices of the original polygon. % % % Example % % creates a polygon from an ellipse % elli = [20 30 40 20 30]; % poly = ellipseToPolygon(elli, 500); % figure; drawPolygon(poly, 'b'); % % resample the polygon with a fixed number of vertices % poly2 = resamplePolygon(poly, 20); % drawPolygon(poly2, 'm'); % drawPoint(poly2, 'mo'); % axis equal; axis([-20 60 0 60]); % % See also % polygons2d, resamplePolygonByLength, smoothPolygon, resamplePolyline % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. poly2 = resamplePolyline(poly([1:end 1],:), n+1); poly2(end, :) = []; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/densifyPolygon.m0000644000000000000000000000013214055375162021173 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/densifyPolygon.m0000644000175000017500000000572514055375162022271 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = densifyPolygon(poly, N) %DENSIFYPOLYGON Add several points on each edge of the polygon. % % POLY2 = densifyPolygon(POLY, N) % POLY is a NV-by-2 array containing polygon coordinates. The function % iterates on polygon edges, divides it into N subedges (by inserting N-1 % new vertices on each edges), and return the resulting polygon. % The new polygon POLY has therefore N*NV vertices. % % Example % % Densifies a simple polygon % poly = [0 0 ; 10 0;5 10;15 15;5 20;-5 10]; % poly2 = densifyPolygon(poly, 10); % figure; drawPolygon(poly); axis equal % hold on; drawPoint(poly2); % % See also % drawPolygon, edgeToPolyline % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-11-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % number of vertices, and of edges Nv = size(poly, 1); % number of vertices in new polygon N2 = N * Nv; poly2 = zeros(N2, 2); % iterate on polygon edges for i = 1:Nv % extract current edge v1 = poly(i, :); v2 = poly(mod(i, Nv) + 1, :); % convert current edge to polyline newVertices = edgeToPolyline([v1 v2], N); % indices of current polyline to resulting polygon i1 = (i-1)*N + 1; i2 = i * N; % fill up polygon poly2(i1:i2, :) = newVertices(1:end-1, :); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonArea.m0000644000000000000000000000013214055375162020442 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonArea.m0000644000175000017500000001003214055375162021523 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function area = polygonArea(poly, varargin) % Compute the signed area of a polygon. % % A = polygonArea(POINTS); % Compute area of a polygon defined by POINTS. POINTS is a N-by-2 array % of double containing coordinates of vertices. % % Vertices of the polygon are supposed to be oriented Counter-Clockwise % (CCW). In this case, the signed area is positive. % If vertices are oriented Clockwise (CW), the signed area is negative. % % If polygon is self-crossing, the result is undefined. % % Examples % % compute area of a simple shape % poly = [10 10;30 10;30 20;10 20]; % area = polygonArea(poly) % area = % 200 % % % compute area of CW polygon % area2 = polygonArea(poly(end:-1:1, :)) % area2 = % -200 % % % Computes area of a paper hen % x = [0 10 20 0 -10 -20 -10 -10 0]; % y = [0 0 10 10 20 10 10 0 -10]; % poly = [x' y']; % area = polygonArea(poly) % area = % 400 % % % Area of unit square with 25% hole % pccw = [0 0; 1 0; 1 1; 0 1]; % pcw = pccw([1 4 3 2], :) * .5 + .25; % polygonArea ([pccw; nan(1,2); pcw]) % ans = % 0.75 % % References % algo adapted from P. Bourke web page % http://paulbourke.net/geometry/polygonmesh/ % % See also: % polygons2d, polygonCentroid, polygonSecondAreaMoments, triangleArea % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 05/05/2004. % % HISTORY % 25/04/2005: add support for multiple polygons % 12/10/2007: update doc %% Process special cases % in case of polygon sets, computes the sum of polygon areas if iscell(poly) area = 0; for i = 1:length(poly) area = area + polygonArea(poly{i}); end return; end % check there are enough points if size(poly, 1) < 2 area = 0; return; end % case of polygons with holes -> computes the sum of areas if any(isnan(poly)) area = sum(polygonArea(splitPolygons(poly))); return; end %% Process single polygons or single rings % extract coordinates if nargin == 1 % polygon given as N-by-2 array px = poly(:, 1); py = poly(:, 2); elseif nargin == 2 % poylgon given as two N-by-1 arrays px = poly; py = varargin{1}; end % indices of next vertices N = length(px); iNext = [2:N 1]; % compute area (vectorized version) area = sum(px .* py(iNext) - px(iNext) .* py) / 2; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/writePolygonSet.m0000644000000000000000000000013214055375162021340 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/writePolygonSet.m0000644000175000017500000000475714055375162022442 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function writePolygonSet(polys, filename) %WRITEPOLYGONSET Write a set of simple polygons into a file. % % writePolygonSet(POLYS, FILENAME); % Writes the set of polygons in the file FILENAME. % Following format is used: % X11 X12 X13 ... X1N % Y11 Y12 Y13 ... Y1N % X21 X22 X23 ... X2N % Y21 Y22 Y23 ... Y2N % Each polygon may have a different number of vertices. % % See also: % polygons2d, readPolygonSet % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 14/01/2013. % % open file for reading fid = fopen(filename, 'wt'); for i = 1:length(polys) poly = polys{i}; n = size(poly, 1); % precompute format format = [repmat('%g ', 1, n) '\n']; % write one line for x, then one line for y fprintf(fid, format, poly(:,1)'); fprintf(fid, format, poly(:,2)'); end % close file fclose(fid); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/contourMatrixToPolylines.m0000644000000000000000000000013214055375162023242 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/contourMatrixToPolylines.m0000644000175000017500000000536514055375162024340 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polys = contourMatrixToPolylines(C) %CONTOURMATRIXTOPOLYLINES Converts a contour matrix array into a polyline set. % % POLYS = contourMatrixToPolylines(C) % Converts the contour matrix array, as given as the result of the % contourc function, into a set of polylines. % % Example % img = imread('circles.png'); % C = contourc(img, 1); % polys = contourMatrixToPolylines(C); % imshow(img); hold on; % drawPolyline(polys, 'Color', 'r', 'LineWidth', 2); % % See also % polygons2d, contour, contourc % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-08-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % size of the contour matrix array nCoords = size(C, 2); % first, compute the number of contours nContours = 0; offset = 1; while offset < nCoords nContours = nContours + 1; offset = offset + C(2, offset) + 1; end % extract each contour as a polygon or polyline polys = cell(nContours, 1); offset = 1; for iContour = 1:nContours nv = C(2, offset); polys{iContour} = C(:, offset + (1:nv))'; offset = offset + nv + 1; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/splitPolygons.m0000644000000000000000000000013214055375162021050 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/splitPolygons.m0000644000175000017500000000527514055375162022146 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polygons = splitPolygons(polygon) %SPLITPOLYGONS Convert a NaN separated polygon list to a cell array of polygons. % % POLYGONS = splitPolygons(POLYGON); % POLYGON is a N-by-2 array of points, possibly with pairs of NaN values. % The functions separates each component separated by NaN values, and % returns a cell array of polygons. % % See also: % polygons2d % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-10-12, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. if iscell(polygon) % case of a cell array polygons = polygon; elseif sum(isnan(polygon(:))) == 0 % single polygon -> no break polygons = {polygon}; else % find indices of NaN couples inds = find(sum(isnan(polygon), 2) > 0); % number of polygons N = length(inds) + 1; polygons = cell(N, 1); % iterate over NaN-separated regions to create new polygon inds = [0; inds; size(polygon, 1)+1]; for i = 1:N polygons{i} = polygon((inds(i)+1):(inds(i+1)-1), :); end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/intersectLinePolygon.m0000644000000000000000000000013214055375162022342 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/intersectLinePolygon.m0000644000175000017500000001274514055375162023440 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [intersects, edgeIndices] = intersectLinePolygon(line, poly, varargin) %INTERSECTLINEPOLYGON Intersection points between a line and a polygon. % % P = intersectLinePolygon(LINE, POLY) % Returns the intersection points of the lines LINE with polygon POLY. % LINE is a 1-by-4 row vector containing parametric representation of the % line (in the format [x0 y0 dx dy], see the function 'createLine' for % details). % POLY is a NV-by-2 array containing coordinates of the polygon vertices % P is a K-by-2 array containing the coordinates of the K intersection % points. % % P = intersectLinePolygon(LINE, POLY, TOL) % Specifies the tolerance for geometric tests. Default is 1e-14. % % [P, INDS] = intersectLinePolygon(...) % Also returns the indices of edges involved in intersections. INDS is a % K-by-1 column vector, such that P(i,:) corresponds to intersection of % the line with the i-th edge of the polygon. If the intersection occurs % at a polygon vertex, the index of only one of the two neighbor edges is % returned. % Note that due to numerical approximations, the use of function % 'isPointOnEdge' may give results not consistent with this function. % % % Examples % % compute intersections between a square and an horizontal line % poly = [0 0;10 0;10 10;0 10]; % line = [5 5 1 0]; % intersectLinePolygon(line, poly) % ans = % 10 5 % 0 5 % % also return indices of edges % [inters, inds] = intersectLinePolygon(line, poly) % inters = % 10 5 % 0 5 % inds = % 4 % 2 % % % compute intersections between a square and a diagonal line % poly = [0 0;10 0;10 10;0 10]; % line = [5 5 1 1]; % intersectLinePolygon(line, poly) % ans = % 0 0 % 10 10 % % See Also % lines2d, polygons2d, intersectLines, intersectRayPolygon, polygonEdges % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2003-10-31, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % HISTORY % 2008-11-24 rename 'pi' as 'intersects', update doc % 2009-07-23 removed forgotten occurence of 'pi' variable (thanks to Bala % Krishnamoorthy) % 2010-01-26 rewrite using vectorisation % 2011-05-20 returns unique results % 2011-07-20 returns intersected edge indices % 2012-11-22 add 'diag' option for linePosition % get computation tolerance tol = 1e-14; if ~isempty(varargin) tol = varargin{1}; end % test presence of NaN values if isnumeric(poly) && any(isnan(poly(:))) poly = splitPolygons(poly); end % create the array of polygon edges if iscell(poly) edges = zeros(0, 4); for i = 1:length(poly) pol = poly{i}; N = size(pol, 1); edges = [edges; pol(1:N, :) pol([2:N 1], :)]; %#ok end else % get edges of a simple polygon N = size(poly, 1); edges = [poly(1:N, :) poly([2:N 1], :)]; end % compute intersections with supporting lines of polygon edges supportLines = edgeToLine(edges); intersects = intersectLines(line, supportLines, tol); % find edges that are not parallel to the input line inds = find(isfinite(intersects(:, 1))); % compute position of intersection points on corresponding lines pos = linePosition(intersects(inds, :), supportLines(inds, :), 'diag'); % and keep only intersection points located on edges b = pos > -tol & pos < 1+tol; inds = inds(b); intersects = intersects(inds, :); % remove multiple vertices (can occur for intersections located at polygon % vertices) [intersects, I, J] = unique(intersects, 'rows'); %#ok if nargout > 1 % return indices of edges involved in intersection % (in case of intersection located at a vertex, only one of the % neighbor edges is returned) edgeIndices = inds(I); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/resamplePolylineByLength.m0000644000000000000000000000013214055375162023143 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/resamplePolylineByLength.m0000644000175000017500000000676014055375162024241 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = resamplePolylineByLength(poly, step) %RESAMPLEPOLYLINEBYLENGTH Resample a polyline with a fixed sampling step. % % RES = resamplePolyline(POLY, STEP) % Resample the input polyline POLY by distributing new vertices on the % original polyline such that the (curvilinear) distance between the new % vertices is approximately equal to STEP. % % Example % poly = [0 10;0 0;10 0; 10 10; 20 10;20 0]; % figure; drawPolyline(poly, 'k'); % poly2 = resamplePolylineByLength(poly, 4); % hold on; % drawPolyline(poly2, 'm'); % drawPoint(poly2, 'mo'); % axis equal; axis([-10 30 -10 20]); % legend('Original polyline', 'Resampled polyline'); % % See also % polygons2d, drawPolyline, resamplePolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b) % Copyrightf 2011 INRA - Cepia Software Platform. % parametrisation of the curve s = parametrize(poly); % compute the number of points for sampling the polygon % (equal to the number of segments plus one) Lmax = s(end); n = round(Lmax / step) + 1; % distribute N points equally spaced pos = linspace(0, Lmax, n); poly2 = zeros(n, size(poly, 2)); for i = 1:n % index of surrounding vertices before and after ind0 = find(s <= pos(i), 1, 'last'); ind1 = find(s >= pos(i), 1, 'first'); if ind0 == ind1 % get position of a vertex in input polyline poly2(i, :) = poly(ind0, :); continue; end % position of surrounding vertices pt0 = poly(ind0, :); pt1 = poly(ind1, :); % weights associated to each neighbor l0 = pos(i) - s(ind0); l1 = s(ind1) - pos(i); % linear interpolation of neighbor positions if (l0 + l1) > Lmax * 1e-12 poly2(i, :) = (pt0 * l1 + pt1 * l0) / (l0 + l1); else % if neighbors are too close, do not use interpolation poly2(i, :) = pt0; end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/projPointOnPolygon.m0000644000000000000000000000013214055375162022013 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/projPointOnPolygon.m0000644000175000017500000000632514055375162023106 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = projPointOnPolygon(point, poly, varargin) %PROJPOINTONPOLYGON Compute position of a point projected on a polygon. % % POS = projPointOnPolygon(POINT, POLYGON) % Compute the position of the orthogonal projection of a point on a % polygon. % POINT is a 1-by-2 row vector containing point coordinates % POLYGON is a N-by-2 array containing coordinates of polygon vertices % % When POINT is an array of points, returns a column vector with as many % rows as the number of points. % % [POS, DIST] = projPointOnPolygon(...) % Also returns the distance between POINT and POLYGON. The distance is % negative if the point is located inside of the polygon. % % Example % poly = [10 10; 20 10;20 20;10 20]; % projPointOnPolygon([15 0], poly) % ans = % 0.5000 % projPointOnPolygon([0 16], poly) % ans = % 3.4000 % % See also % points2d, polygons2d, polygonPoint, projPointOnPolyline % distancePointpolygon % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % eventually copy first point at the end to ensure closed polygon if sum(poly(end, :) == poly(1,:)) ~= 2 poly = [poly; poly(1,:)]; end % compute position wrt outline [pos, minDist] = projPointOnPolyline(point, poly); % process output arguments if nargout <= 1 varargout{1} = pos; elseif nargout == 2 varargout{1} = pos; if inpolygon(point(:,1), point(:,2), poly(:,1), poly(:,2)) minDist = -minDist; end varargout{2} = minDist; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/removeMultipleVertices.m0000644000000000000000000000013214055375162022700 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/removeMultipleVertices.m0000644000175000017500000000623014055375162023766 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly = removeMultipleVertices(poly, varargin) %REMOVEMULTIPLEVERTICES Remove multiple vertices of a polygon or polyline. % % POLY2 = removeMultipleVertices(POLY, EPS) % Remove adjacent vertices that are closer than the distance EPS to each % other and merge them to a unique vertex. % % POLY2 = removeMultipleVertices(POLY, EPS, CLOSED) % If CLOSED is true, also check if first and last vertices need to be % merged. If not specified, CLOSED is false. % % Example % poly = [10 10; 20 10;20 10;20 20;10 20; 10 10]; % poly2 = removeMultipleVertices(poly, true); % size(poly2, 1) % ans = % 4 % % See also % polygons2d, mergeClosePoints % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % default values eps = 1e-14; closed = false; % process input options while ~isempty(varargin) var = varargin{1}; if islogical(var) closed = var; elseif isnumeric(var) eps = var; else error('MatGeom:removeMultipleVertices:IllegalArgument',... 'Can not interpret optional argument'); end varargin(1) = []; end % distance between adjacent vertices dist = sqrt(sum((poly(2:end,:) - poly(1:end-1,:)).^2, 2)); multi = dist < eps; % process extremities if closed dist = sqrt(sum((poly(end,:) - poly(1,:)).^2, 2)); multi = [multi ; dist < eps]; else multi = [multi ; false]; end % remove multiple vertices poly(multi, :) = []; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/intersectRayPolygon.m0000644000000000000000000000013214055375162022206 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/intersectRayPolygon.m0000644000175000017500000000565214055375162023303 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [intersects, edgeIndices] = intersectRayPolygon(ray, poly, varargin) %INTERSECTRAYPOLYGON Intersection points between a ray and a polygon. % % P = intersectRayPolygon(RAY, POLY) % Returns the intersection points of the ray RAY with polygon POLY. % RAY is a 1x4 array containing parametric representation of the ray % (in the form [x0 y0 dx dy], see createRay for details). % POLY is a Nx2 array containing coordinate of polygon vertices % % P = intersectRayPolygon(RAY, POLY, TOL) % Specifies the tolerance for geometric tests. Default is 1e-14. % % [P IND] = intersectRayPolygon(...) % Also returns index of polygon intersected edge(s). See % intersectLinePolygon for details. % % See also % rays2d, polygons2d, intersectLinePolygon % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 26/01/2010 % HISTORY % 2010/01/26 creation from intersectLinePolygon % 2013-02-11 also returns edgeIndices % compute intersections with supporting line [intersects, edgeIndices] = intersectLinePolygon(ray, poly, varargin{:}); % compute position of intersects on the supporting line pos = linePosition(intersects, ray); % keep only intersects with non-negative position on line indPos = pos >= 0; intersects = intersects(indPos, :); edgeIndices = edgeIndices(indPos); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonCurvature.m0000644000000000000000000000013214055375162021552 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonCurvature.m0000644000175000017500000000700114055375162022635 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function curv = polygonCurvature(poly, M) %POLYGONCURVATURE Estimate curvature on polygon vertices using polynomial fit. % % CURV = polygonCurvature(POLY, M) % Estimate the curvature for each vertex of a polygon, using polynomial % fit from the M verties located around current vertex. M is usually an % odd value, resulting in a symmetric neighborhood. % % Polynomial fitting is of degree 2 by default. % % % Example % img = imread('circles.png'); % img = imfill(img, 'holes'); % imgf = imfilter(double(img), fspecial('gaussian', 7, 2)); % figure(1), imshow(imgf); % contours = imContours(imgf, .5); poly = contours{1}; % poly2 = smoothPolygon(poly, 7); % hold on; drawPolygon(poly2); % curv = polygonCurvature(poly2, 11); % figure; plot(curv); % minima = bwlabel(imextendedmin(curv, .05)); % centroids = imCentroid(minima); % inds = round(centroids(:,2)); % figure(1); hold on; drawPoint(poly2(inds, :), 'g*') % % See also % polygons2d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-03-02, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. % number of vertices of polygon n = size(poly, 1); % allocate memory for result curv = zeros(n, 1); % number of vertices before and after current vertex s1 = floor((M - 1) / 2); s2 = ceil((M - 1) / 2); % parametrisation basis % As we recenter the points, the constant factor is omitted ti = (-s1:s2)'; X = [ti ti.^2]; % Iteration on vertex indices for i = 1:n % coordinate of current vertex, for recentring neighbor vertices x0 = poly(i,1); y0 = poly(i,2); % indices of neighbors inds = i-s1:i+s2; inds = mod(inds-1, n) + 1; % Least square estimation using mrdivide xc = X \ (poly(inds,1) - x0); yc = X \ (poly(inds,2) - y0); % compute curvature curv(i) = 2 * (xc(1)*yc(2) - xc(2)*yc(1) ) / power(xc(1)^2 + yc(1)^2, 3/2); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/smoothPolygon.m0000644000000000000000000000013214055375162021043 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/smoothPolygon.m0000644000175000017500000000544714055375162022142 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = smoothPolygon(poly, M) %SMOOTHPOLYGON Smooth a polygon using local averaging. % % RES = smoothPolygon(POLY, M) % POLY contains the polygon vertices, and M is the size of smoothing % (given as the length of the convolution window). % % % Example % img = imread('circles.png'); % img = imfill(img, 'holes'); % contours = bwboundaries(img'); % contour = contours{1}; % imshow(img); hold on; drawPolygon(contour, 'b'); % contourf = smoothPolygon(contour, 11); % drawPolygon(contourf, 'm'); % % See also % polygons2d, smoothPolyline, simplifyPolygon, resamplePolygon % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2015-02-17, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. % compute the number of elements before and after M1 = floor((M - 1) / 2); M2 = ceil((M - 1) / 2); % repeat beginning and end of contour poly2 = [poly(end-M1+1:end, :) ; poly ; poly(1:M2,:)]; % create convolution vector v2 = ones(M, 1) / M; % apply contour filtering res(:,1) = conv(poly2(:,1), v2, 'same'); res(:,2) = conv(poly2(:,2), v2, 'same'); % keep the interesting part res = res(M1+1:end-M2, :); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/curveMoment.m0000644000000000000000000000013214055375162020466 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/curveMoment.m0000644000175000017500000000506214055375162021556 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function m = curveMoment(curve, p, q) %CURVEMOMENT Compute inertia moment of a 2D curve. % M = curveMoment(CURVE, P, Q) % % Example % curveMoment % % See also % polygons2d, curveCMoment, curveCSMoment % % Reference % Based on ideas and references in: % "Affine curve moment invariants for shape recognition" % Dongmin Zhao and Jie Chen % Pattern Recognition, 1997, vol. 30, pp. 865-901 % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-03-25, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % coordinate of vertices px = curve(:,1); py = curve(:,2); % compute centroids of line segments cx = (px(1:end-1)+px(2:end))/2; cy = (py(1:end-1)+py(2:end))/2; % compute length of each line segment dl = hypot(px(2:end)-px(1:end-1), py(2:end)-py(1:end-1)); % compute moment m = zeros(size(p)); for i=1:length(p(:)) m(i) = sum(cx(:).^p(i) .* cy(:).^q(i) .* dl(:)); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonSecondAreaMoments.m0000644000000000000000000000013214055375162023141 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonSecondAreaMoments.m0000644000175000017500000000554614055375162024240 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [Ixx, Iyy, Ixy] = polygonSecondAreaMoments(poly) %POLYGONSECONDAREAMOMENTS Compute second-order area moments of a polygon. % % [IXX, IYY, IXY] = polygonSecondAreaMoments(POLY) % Compute the second-order inertia moments of a polygon. The polygon is % specified by the N-by-2 list of vertex coordinates. % % Example % polygonSecondAreaMoments % % References % * http://paulbourke.net/geometry/polygonmesh/ % * https://en.wikipedia.org/wiki/Second_moment_of_area % % See also % polygons2d, polygonEquivalentEllipse, polygonArea, polygonCentroid % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-09-08, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. % get vertex coordinates, and recenter polygon centroid = polygonCentroid(poly); px = poly(:,1) - centroid(1); py = poly(:,2) - centroid(2); % vertex indices N = length(px); iNext = [2:N 1]; % compute twice signed area of each triangle common = px .* py(iNext) - px(iNext) .* py; % compute each term Ixx = sum( (py.^2 + py .* py(iNext) + py(iNext).^2) .* common) / 12; Iyy = sum( (px.^2 + px .* px(iNext) + px(iNext).^2) .* common) / 12; Ixy = sum( ... (px .* py(iNext) + 2 * px .* py + 2 * px(iNext) .* py(iNext) ... + px(iNext) .* py ) .* common) / 24; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polylineSelfIntersections.m0000644000000000000000000000013214055375162023401 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polylineSelfIntersections.m0000644000175000017500000001644214055375162024475 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polylineSelfIntersections(poly, varargin) %POLYLINESELFINTERSECTIONS Find self-intersection points of a polyline. % % Computes self-intersections of a polyline, eventually specifying if % polyline is closed or open, and eventually returning position of % intersection points on polyline. % For common use cases, the intersectPolylines function may return the % desired result in a faster way. % % % PTS = polylineSelfIntersections(POLY); % Returns the position of self intersections of the given polyline. % % PTS = polylineSelfIntersections(POLY, CLOSED); % Adds an options to specify if the polyline is closed (i.e., is a % polygon), or open (the default). CLOSED can be a boolean, or one of % 'closed' or 'open'. % % [PTS, POS1, POS2] = polylineSelfIntersections(POLY); % Also return the 2 positions of each intersection point (the position % when meeting point for first time, then position when meeting point % for the second time). % % [...] = polylineSelfIntersections(POLY, 'tolerance', TOL) % Specifies an additional parameter to decide whether two intersection % points should be considered the same, based on their Euclidean % distance. % % % Example % % use a gamma-shaped polyline % poly = [0 0;0 10;20 10;20 20;10 20;10 0]; % polylineSelfIntersections(poly) % ans = % 10 10 % % % use a 'S'-shaped polyline % poly = [10 0;0 0;0 10;20 10;20 20;10 20]; % polylineSelfIntersections(poly) % ans = % Empty matrix: 0-by-2 % polylineSelfIntersections(poly, 'closed') % ans = % 10 10 % % See also % polygons2d, intersectPolylines, polygonSelfIntersections % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2009-06-15, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % HISTORY % 2009/06/18 check bounding boxes before computing intersections %% Initialisations % flag indicating whether the polyline is closed (polygon) or not closed = false; % the tolerance for comparing positions based on distances tol = 1e-14; % determine whether the polyline is open or closed if ~isempty(varargin) closed = varargin{1}; if ischar(closed) if strcmp(closed, 'closed') closed = true; varargin(1) = []; elseif strcmp(closed, 'open') closed = false; varargin(1) = []; end end end % parse optional arguments while length(varargin) > 1 pname = varargin{1}; if ~ischar(pname) error('Expect optional arguments as name-value pairs'); end if strcmpi(pname, 'tolerance') tol = varargin{2}; else error(['Unknown parameter name: ' pname]); end varargin(1:2) = []; end % if polyline is closed, ensure the last point equals the first one if closed if sum(abs(poly(end, :) - poly(1,:)) < tol) ~= 2 poly = [poly; poly(1,:)]; end end % arrays for storing results points = zeros(0, 2); pos1 = zeros(0, 1); pos2 = zeros(0, 1); % number of edges nEdges = size(poly, 1) - 1; %% Main processing % index of current intersection ip = 0; % iterate over each couple of edge ( (N-1)*(N-2)/2 iterations) for iEdge1 = 1:nEdges-1 % create first edge edge1 = [poly(iEdge1, :) poly(iEdge1+1, :)]; for iEdge2 = iEdge1+2:nEdges % create second edge edge2 = [poly(iEdge2, :) poly(iEdge2+1, :)]; % check conditions on bounding boxes, to avoid computing the % intersections if min(edge1([1 3])) > max(edge2([1 3])) continue; end if max(edge1([1 3])) < min(edge2([1 3])) continue; end if min(edge1([2 4])) > max(edge2([2 4])) continue; end if max(edge1([2 4])) < min(edge2([2 4])) continue; end % compute intersection point inter = intersectEdges(edge1, edge2, tol); if sum(isfinite(inter)) == 2 % add point to the list ip = ip + 1; points(ip, :) = inter; % also compute positions on the polyline pos1(ip, 1) = iEdge1 - 1 + edgePosition(inter, edge1); pos2(ip, 1) = iEdge2 - 1 + edgePosition(inter, edge2); end end end %% Post-processing % if polyline is closed, the first vertex was found as an intersection, so % we need to remove it if closed % identify the intersection between first and last edges using position % indices (pos1 < pos2 by construction) ind = pos1 == 0 & pos2 == size(poly,1)-1; points(ind,:) = []; pos1(ind) = []; pos2(ind) = []; end % remove multiple intersections [points, I, J] = unique(points, 'rows', 'first'); %#ok pos1 = pos1(I); pos2 = pos2(I); % remove multiple intersections, using tolerance on distance iInter = 0; while iInter < size(points, 1) - 1 iInter = iInter + 1; % for iInter = 1:size(points, 1)-1 % determine distance between current point and remaining points inds = iInter+1:size(points, 1); dists = distancePoints(points(iInter,:), points(inds, :)); % identify index of other points located in a close neighborhood inds = inds(dists < tol); % remove redundant intersection points if ~isempty(inds) points(inds, :) = []; pos1(inds) = []; pos2(inds) = []; end end %% process output arguments if nargout <= 1 varargout{1} = points; elseif nargout == 3 varargout{1} = points; varargout{2} = pos1; varargout{3} = pos2; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/signatureToPolygon.m0000644000000000000000000000013214055375162022036 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/signatureToPolygon.m0000644000175000017500000000505614055375162023131 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly = signatureToPolygon(signature, varargin) %SIGNATURETOPOLYGON Reconstruct a polygon from its polar signature. % % POLY = signatureToPolygon(SIGNATURE) % POLY = signatureToPolygon(SIGNATURE, ANGLES) % % Example % signatureToPolygon % % See also % polygonSignature % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2015-04-28, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. nAngles = length(signature); % compute default signature angleList = linspace(0, 360, nAngles+1); angleList(end) = []; if ~isempty(varargin) angleList = varargin{1}; if length(angleList) ~= nAngles msg = 'signature and angle list must have same length (here %d and %d)'; error(sprintf(msg, nAngles, length(angleList))); %#ok end end poly = zeros(nAngles, 2); for iAngle = 1:nAngles angle = angleList(iAngle); poly(iAngle, :) = signature(iAngle) * [cosd(angle) sind(angle)]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/convexification.m0000644000000000000000000000013214055375162021352 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/convexification.m0000644000175000017500000000671414055375162022447 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function co = convexification(varargin) %CONVEXIFICATION Compute the convexification of a polygon. % % CO = convexification(H) % Creates convexification from support function. Support function is % supposed to be uniformly distributed over [0 2pi]. % % CO = convexification(POLYGON) % Computes support function of the polygon, then the corresponding % convexification. % % CO = convexification(POLYGON, N) % Uses N points for convexification computation. Note that the number of % points of CO can be lower than N. % % CAUTION: The result will be valid only for convex polygons. % % See also % polygons2d, supportFunction % % --------- % author: David Legland % created the 12/01/2005. % Copyright 2010 INRA - Cepia Software Platform. % % HISTORY % 13/06/2007: clean up code if ~isempty(varargin)>0 var = varargin{1}; if size(var, 2)==1 h = var; else poly = var; N = 128; if length(varargin)>1 N = varargin{2}; end h = supportFunction(poly, N); end else error('not enough input arguments'); end N = length(h); u = (0:2*pi/N:2*pi*(1-1/N))'; v = [cos(u) sin(u)].*[h h]; i1 = 1:N; i2 = [2:N 1]; i3 = [3:N 1 2]; circ = zeros(N, 4); for i=1:N circ(i, 1:4) = createDirectedCircle(v(i1(i),:), v(i2(i),:), v(i3(i), :)); end % remove non direct-oriented circles circ = circ(circ(:,4)==0, :); % keep only circles seen several times dp = diff(circ(:,1:2)); dp = sum(dp.*dp, 2); ind1 = [1; find(dp<1e-10)+1]; circ = circ(ind1, :); % keep only one instance of each circle dp = diff(circ(:,1:2)); dp = sum(dp.*dp, 2); ind = [1; find(dp>1e-10)+1]; co = 2*circ(ind, 1:2); % eventually remove the last point if it is the same as the first one if distancePoints(co(1,:), co(end, :))<1e-10 && size(co, 1)>1 co = co(1:end-1,:); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonBounds.m0000644000000000000000000000013214055375162021024 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonBounds.m0000644000175000017500000000542014055375162022112 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function box = polygonBounds(polygon) %POLYGONBOUNDS Compute the bounding box of a polygon. % % BOX = polygonBounds(POLY); % Returns the bounding box of the polygon. % BOX has the format: [XMIN XMAX YMIN YMAX]. % % Input polygon POLY is as a N-by-2 array containing coordinates of each % vertex. % Multiple polygons can be specified either by inserting NaN rows between % vertex coordinates, or by using a cell array, each cell containing the % vertex coordinates of a polygon loop. % % See also % polygons2d, boxes2d, boundingBox % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2007-10-12, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - Cepia software platform % transform as a cell array of simple polygons polygons = splitPolygons(polygon); % init extreme values xmin = inf; xmax = -inf; ymin = inf; ymax = -inf; % iterate over loops for i = 1:length(polygons) polygon = polygons{i}; xmin = min(xmin, min(polygon(:,1))); xmax = max(xmax, max(polygon(:,1))); ymin = min(ymin, min(polygon(:,2))); ymax = max(ymax, max(polygon(:,2))); end % format output box = [xmin xmax ymin ymax]; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polylineLength.m0000644000000000000000000000013214055375162021157 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polylineLength.m0000644000175000017500000000735414055375162022255 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function len = polylineLength(poly, varargin) %POLYLINELENGTH Return length of a polyline given as a list of points. % % L = polylineLength(POLY); % POLY should be a N-by-D array, where N is the number of points and D is % the dimension of the points. % % L = polylineLength(..., TYPE); % Specifies if the last point is connected to the first one. TYPE can be % either 'closed' or 'open'. % % L = polylineLength(POLY, POS); % Compute the length of the polyline between its origin and the position % given by POS. POS should be between 0 and N-1, where N is the number of % points of the polyline. % % % Example: % % Compute the perimeter of a circle with radius 1 % polylineLength(circleAsPolygon([0 0 1], 500), 'closed') % ans = % 6.2831 % % See also: % polygons2d, polylineCentroid, polygonLength % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % HISTORY % 2006-05-22 manage any dimension for points, closed and open curves, % and update doc accordingly. % 2009-04-30 rename as polylineLength % 2011-03-31 add control for empty polylines % check there are enough points if size(poly, 1) < 2 len = 0; return; end % check whether the curve is closed or not (default is open) closed = false; if ~isempty(varargin) var = varargin{end}; if ischar(var) if strcmpi(var, 'closed') closed = true; end varargin = varargin(1:end-1); end end % if the length is computed between 2 positions, compute only for a % subcurve if ~isempty(varargin) % values for 1 input argument t0 = 0; t1 = varargin{1}; % values for 2 input arguments if length(varargin)>1 t0 = varargin{1}; t1 = varargin{2}; end % extract a portion of the polyline poly = polylineSubcurve(poly, t0, t1); end % compute lengths of each line segment, and sum up if closed len = sum(sqrt(sum(diff(poly([1:end 1],:)).^2, 2))); else len = sum(sqrt(sum(diff(poly).^2, 2))); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/cart2geod.m0000644000000000000000000000013214055375162020034 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/cart2geod.m0000644000175000017500000000555614055375162021134 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = cart2geod(src, curve) %CART2GEOD Convert cartesian coordinates to geodesic coord. % % PT2 = cart2geod(PT1, CURVE) % PT1 is the point to transform, in Cartesian coordinates (same system % used for the curve). % CURVE is a N-by-2 array which represents coordinates of curve vertices. % % The function first compute the projection of PT1 on the curve. Then, % the first geodesic coordinate is the length of the curve to the % projected point, and the second geodesic coordinate is the % distance between PT1 and it projection. % % % TODO : add processing of points not projected on the curve. % -> use the closest end % % See also % polylines2d, geod2cart, curveLength % % --------- % Author: David Legland % e-mail: david.legland@grignon.inra.fr % created the 08/04/2004. % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 15/02/2007 replace minDistance by minDistancePoints % parametrization approximation t = parametrize(curve); % compute distance between each src point and the curve [dist, ind] = minDistancePoints(src, curve); % convert to 'geodesic' coordinate point = [t(ind) dist]; % Old version: % for i=1:size(pt1, 1) % [dist, ind] = minDistance(src(i,:), curve); % point(i,:) = [t(ind) dist]; % end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/fillPolygon.m0000644000000000000000000000013214055375162020460 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/fillPolygon.m0000644000175000017500000000736414055375162021557 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = fillPolygon(varargin) %FILLPOLYGON Fill a polygon specified by a list of points. % % fillPolygon(POLY); % Fills the interior of the polygon specified by POLY. The boundary of % the polygon is not drawn, see 'drawPolygon' to do it. % POLY is a single [N*2] array. % If POLY contains NaN-couples, each portion between the [NaN;NaN] will % be filled separately. % % fillPolygon(PX, PY); % Specifies coordinates of the polygon in separate arrays. % % % H = fillPolygon(...); % Also returns a handle to the created patch % % % See also: % polygons2d, drawCurve, drawPolygon % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/04/2005. % % HISTORY % 2008-05-07 add psb to specify drawing options % 2008/10/15 add psb to draw polygons with holes % check input if isempty(varargin) error('need to specify a polygon'); end % case of a set of polygons stored in a cell array var = varargin{1}; if iscell(var) N = length(var); h = zeros(N, 1); for i = 1:N % check for empty polygons if ~isempty(var{i}) h(i) = fillPolygon(var{i}, varargin{2:end}); end end % setup output values if nargout > 0 varargout{1} = h; end return; end % 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*2 array, or 2 N*1 vectors'); end px = varargin{1}; py = varargin{2}; varargin(1:2) = []; end % Find position of breaks, and copies first point of each loop at the end inds = find(isnan(px(:))); i1 = [inds ; length(px)+1]; i0 = [1 ; inds+1]; px(i1, :) = px(i0, :); py(i1, :) = py(i0, :); % set default line format if isempty(varargin) varargin = {'b'}; end % fill the polygon with desired style h = fill(px, py, varargin{:}, 'lineStyle', 'none'); % output if nargout > 0 varargout{1} = h; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polylineCentroid.m0000644000000000000000000000013214055375162021505 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polylineCentroid.m0000644000175000017500000000646414055375162022604 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function center = polylineCentroid(varargin) %POLYLINECENTROID Compute centroid of a curve defined by a series of points. % % PT = polylineCentroid(POINTS); % Computes center of mass of a polyline defined by POINTS. POINTS is a % [NxD] array of double, representing a set of N points in a % D-dimensional space. % % PT = polylineCentroid(PTX, PTY); % PT = polylineCentroid(PTX, PTY, PTZ); % Specifies points as separate column vectors % % PT = polylineCentroid(..., TYPE); % Specifies if the last point is connected to the first one. TYPE can be % either 'closed' or 'open'. % % Example % poly = [0 0;10 0;10 10;20 10]; % polylineCentroid(poly) % ans = % [10 5] % % See also: % polygons2d, centroid, polygonCentroid, polylineLength % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 22/05/2006. % %% process input arguments % check whether the curve is closed closed = false; var = varargin{end}; if ischar(var) if strcmpi(var, 'closed') closed = true; end varargin = varargin(1:end-1); end % extract point coordinates if length(varargin)==1 points = varargin{1}; elseif length(varargin)==2 points = [varargin{1} varargin{2}]; end % compute centers and lengths composing the curve if closed centers = (points + points([2:end 1],:))/2; lengths = sqrt(sum(diff(points([1:end 1],:)).^2, 2)); else centers = (points(1:end-1,:) + points(2:end,:))/2; lengths = sqrt(sum(diff(points).^2, 2)); end % centroid of edge centers weighted by edge length %weigths = repmat(lengths/sum(lengths), [1 size(points, 2)]); center = sum(centers.*repmat(lengths, [1 size(points, 2)]), 1)/sum(lengths); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonPoint.m0000644000000000000000000000013214055375162020663 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonPoint.m0000644000175000017500000000564014055375162021755 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = polygonPoint(poly, pos) %POLYGONPOINT Extract a point from a polygon. % % POINT = polygonPoint(POLYGON, POS) % % % Example % polygonPoint % % See also % polygons2d, polylinePoint % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % eventually copy first point at the end to ensure closed polygon if sum(poly(end, :) == poly(1,:))~=2 poly = [poly; poly(1,:)]; end % number of points to compute nPoints = length(pos(:)); % number of vertices in polygon Nv = size(poly, 1)-1; % allocate memory results point = zeros(nPoints, 2); % iterate on points for i = 1:nPoints % compute index of edge (between 0 and Nv) ind = floor(pos(i)); % special case of last point of polyline if ind==Nv point(i,:) = poly(end,:); continue; end % format index to ensure being on polygon ind = min(max(ind, 0), Nv-1); % position on current edge t = min(max(pos(i)-ind, 0), 1); % parameters of current edge x0 = poly(ind+1, 1); y0 = poly(ind+1, 2); dx = poly(ind+2,1)-x0; dy = poly(ind+2,2)-y0; % compute position of current point point(i, :) = [x0+t*dx, y0+t*dy]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/drawPolygon.m0000644000000000000000000000013214055375162020467 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/drawPolygon.m0000644000175000017500000001257214055375162021563 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPolygon (px, varargin) %DRAWPOLYGON Draw a polygon specified by a list of points. % % drawPolygon(POLY); % Packs coordinates in a single N-by-2 array, with N the vertex number. % % drawPolygon(PX, PY); % Specifies coordinates in separate arrays. Both array must be N-by-1, % with N the number of vertices. % % drawPolygon(POLYS) % Packs coordinate of several polygons in a cell array. Each element of % the array is a Ni-by-2 double array. % % drawPolygon(..., NAME, VALUE); % Specifies drawing options by using one or several parameter name-value % pairs, see the doc of plot function for details. % % drawPolygon(AX, ...) % Specifies the axis to draw the polygon on. % % H = drawPolygon(...); % Also return a handle to the list of line objects. % % Example % % draw a red rectangle % poly = [10 10;40 10;40 30;10 30]; % figure; drawPolygon(poly, 'r'); % axis equal; axis([0 50 0 50]); % % % Draw two squares % px = [10 20 20 10 NaN 30 40 40 30]'; % py = [10 10 20 20 NaN 10 10 20 20]'; % figure; % drawPolygon([px py], 'lineWidth', 2); % axis equal; axis([0 50 0 50]); % % See also: % polygons2d, drawPolyline % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 05/05/2004. % % HISTORY % 2008/10/15 manage polygons with holes % 2011-10-11 add management of axes handle % 2016-05-26 Juanpi Carbajal reorganized the function for readability and % removed unnecessary variable arguemnts % Store hold state state = ishold(gca); hold on; %% Check input if nargin < 1 error ('should specify at least one argument'); end % check for empty polygons if isempty (px) return end % extract handle of axis to draw on ax = gca; if isAxisHandle(px) ax = px; px = varargin{1}; varargin(1) = []; end %% Manage cell arrays of polygons % case of a set of polygons stored in a cell array if iscell(px) h = cellfun(@(x) drawPolygon(ax, x, varargin{:}), px, 'UniformOutput', 0); h = horzcat(h{:}); else % Check size vs number of arguments if size(px, 2) == 2 % Case of polygon specified as a N-by-2 array (most standard case) py = px(:, 2); px = px(:, 1); elseif size(px, 2) == 1 % Case of polygon specified as two N-by-1 arrays with same length if nargin < 2 || nargin == 2 && ~isnumeric(varargin{1}) error('Matgeom:invalid_input_arg', ... 'Should specify either a N-by-2 array, or 2 N-by-1 vectors'); end % Extract coordinates of polygon vertices py = varargin{1}; varargin(1) = []; if length(py) ~= length(px) error('Matgeom:invalid_input_arg', ... 'X and Y coordinate arrays should have same lengths (%d,%d)', ... length(px), length(py)) end else error('Matgeom:invalid_input_arg', 'Should specify a N-by-2 array'); end % set default line format if isempty (varargin) varargin = {'b-'}; end % Check case of polygons with holes if any (isnan (px(:)) ) polygons = splitPolygons ([px py]); h = drawPolygon (ax, polygons, varargin{:}); else % ensure last point is the same as the first one px(end+1, :) = px(1,:); py(end+1, :) = py(1,:); % draw the polygon outline h = plot(ax, px, py, varargin{:}); end % whether there where holes end % whether input arg was a cell if ~state hold off end % avoid returning argument if not required if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162017757 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/Contents.m0000644000175000017500000002641414055375162021053 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % POLYGONS Manipulation of planar polygons and polylines % Version 1.24 07-Jun-2018 . % % 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]); % % % 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. % resamplePolyline - Distribute N points equally spaced on a polyline. % resamplePolylineByLength - Resample a polyline with a fixed sampling step. % 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. % intersectLinePolyline - Intersection points between a line and a polyline. % intersectPolylines - Find the common points between 2 polylines. % clipPolyline - Clip an open polyline with a rectangular box. % polylineSelfIntersections - Find self-intersection points of a polyline. % simplifyPolyline - Douglas-Peucker simplification of a polyline. % smoothPolyline - Smooth a polyline using local averaging. % removeMultipleVertices - Remove multiple vertices of a polygon or polyline. % % Polygon basic manipulation % reversePolygon - Reverse a polygon, by iterating vertices from the end. % smoothPolygon - Smooth a polygon using local averaging. % simplifyPolygon - Douglas-Peucker simplification of a polygon. % projPointOnPolygon - Compute position of a point projected on a polygon. % splitPolygons - Convert a NaN separated polygon list to a cell array of polygons. % polygonLoops - Divide a possibly self-intersecting polygon into a set of simple loops. % polygonPoint - Extract a point from a polygon. % polygonSubcurve - Extract a portion of a polygon. % polygonEdges - Return the edges of a simple or multiple polygon. % polygonVertices - Extract all vertices of a (multi-)polygon. % % Polygon clipping and intersections % intersectLinePolygon - Intersection points between a line and a polygon. % intersectRayPolygon - Intersection points between a ray and a polygon. % intersectEdgePolygon - Intersection point of an edge with a polygon. % polygonSelfIntersections - Find self-intersection points of a polygon. % clipPolygon - Clip a polygon with a rectangular box. % clipPolygonHP - Clip a polygon with a Half-plane defined by a directed line. % % Point Sets % 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. % convexHull - Convex hull of a set of points. % randomPointInPolygon - Generate random point(s) in a 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. % polygonEquivalentEllipse - Compute equivalent ellipse with same second order moments as polygon. % polygonSecondAreaMoments - Compute second-order area moments of a polygon. % polygonLength - Perimeter of a polygon. % polygonNormalAngle - Normal angle at each vertex of a polygon. % polygonBounds - Compute the bounding box of a polygon. % polygonOuterNormal - Outer normal vector for a given vertex(ices). % distancePointPolygon - Shortest distance between a point and a polygon. % distancePolygons - Compute the shortest distance between 2 polygons. % distancePolygonsNoCross - Compute the shortest distance between 2 polygons. % polygonSignature - Polar signature of a polygon (polar distance to origin). % signatureToPolygon - Reconstruct a polygon from its polar signature. % polygonCurvature - Estimate curvature on polygon vertices using polynomial fit. % % More complex operations on polygons % resamplePolygon - Distribute N points equally spaced on a polygon. % resamplePolygonByLength - Resample a polygon with a fixed sampling step. % densifyPolygon - Add several points on each edge of the polygon. % expandPolygon - Expand a polygon by a given (signed) distance. % triangulatePolygon - Compute a triangulation of the polygon. % polygonSymmetryAxis - Try to identify symmetry axis of polygon. % polygonSkeleton - Skeletonization of a polygon with a dense distribution of vertices. % medialAxisConvex - Compute medial axis of a convex polygon. % % Curves (polylines with lot of vertices) % parametrize - Parametrization of a polyline, based on edges lengths. % 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. % % 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 % polygonToRow - Convert polygon coordinates to a row vector. % rowToPolygon - Create a polygon from a row vector. % contourMatrixToPolylines - Converts a contour matrix array into a polyline set. % readPolygonSet - Read a set of simple polygons stored in a file. % writePolygonSet - Write a set of simple polygons into a file. % % 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. % drawVertices - Draw the vertices of a polygon or polyline. % % % Credits: % * function intersectPolylines uses the 'interX' contribution from "NS" % (file exchange 22441, called 'curve-intersections') % % ----- % Author: David Legland % e-mail: david.legland@inra.fr % created the 07/11/2005. % Project homepage: http://github.com/mattools/matGeom % http://www.pfl-cepia.inra.fr/index.php?page=geom2d % Copyright INRA - Cepia Software Platform. help(mfilename); %% Deprecated % polygonInertiaEllipse - Compute ellipse with same inertia moments as polygon. %% Requires further development %% Others... matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/steinerPolygon.m0000644000000000000000000000013214055375162021203 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/steinerPolygon.m0000644000175000017500000000440714055375162022275 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function nodes = steinerPolygon(points) %STEINERPOLYGON Create a Steiner polygon from a set of vectors. % % NODES = steinerPolygon(VECTORS); % Builds the (convex) polygon which contains an edge for each one of the % vectors given by VECTORS. % % Example % n = steinerPolygon([1 0;0 1;1 1]); % drawPolygon(n); % % See also % polygons2d, drawPolygon % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-04-28 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). nodes = [0 0]; for i=1:length(points) nodes = [nodes; nodes+repmat(points(i,:), [size(nodes, 1) 1])]; %#ok end K = convhull(nodes(:,1), nodes(:,2)); nodes = nodes(K, :); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/simplifyPolyline.m0000644000000000000000000000013214055375162021532 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/simplifyPolyline.m0000644000175000017500000000762114055375162022625 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [poly2, keepInds] = simplifyPolyline(poly, tol) %SIMPLIFYPOLYLINE Douglas-Peucker simplification of a polyline. % % POLY2 = simplifyPolyline(POLY, TOL) % Simplifies the input polyline using the Douglas-Peucker algorithm. % % Example % elli = [20 30 40 20 30]; % poly = ellipseToPolygon(elli, 500); % poly2 = simplifyPolyline(poly, 1); % use a tolerance equal to 1 % figure; hold on; % drawEllipse(elli); % drawPoint(poly2, 'mo'); % % See also % polygons2d, simplifyPolygon, resamplePolyline, smoothPolyline % % References % http://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-05-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % number of vertices n = size(poly, 1); % initial call to the recursive function keepInds = recurseSimplify(1, n); % keep first and last vertices keepInds = [1 keepInds n]; % create the resulting polyline poly2 = poly(keepInds, :); %% Inner function that is called recursively on polyline portions function innerInds = recurseSimplify(i0, i1) % find the furthest vertex mid = furthestPointIndex(i0, i1); % case of no further simplification if isempty(mid) innerInds = mid; return; end % recursively subdivide each portion mid1 = recurseSimplify(i0, mid); mid2 = recurseSimplify(mid, i1); % concatenate indices of all portions innerInds = [mid1 mid mid2]; end %% Inner function for finding index of furthest point in POLY function ind = furthestPointIndex(i0, i1) % for single edges, return empty result if i1 - i0 < 2 ind = []; return; end % vertices of the current edge v0 = poly(i0, :); v1 = poly(i1, :); % find vertex with the greatest distance dists = distancePointEdge(poly(i0+1:i1-1, :), [v0 v1]); [maxi, ind] = max(dists); % update index only if distance criterion is verified if maxi > tol ind = i0 + ind; else ind = []; end end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonToRow.m0000644000000000000000000000013214055375162020644 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonToRow.m0000644000175000017500000000574614055375162021745 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function row = polygonToRow(polygon, varargin) %POLYGONTOROW Convert polygon coordinates to a row vector. % % ROW = polygonToRow(POLY); % where POLY is a N-by-2 array of points representing vertices of the % polygon, converts the vertex coordinates into a linear array: % ROW = [X1 Y1 X2 Y2 .... XN YN] % % ROW = polygonToRow(POLY, TYPE); % Can coose another format for converting polygon. Possibilities are: % 'interlaced' (default}, as described above % 'packed': ROW has format [X1 X2 ... XN Y1 Y2 ... YN]. % % Example % square = [10 10 ; 20 10 ; 20 20 ; 10 20]; % row = polygonToRow(square) % row = % 10 10 20 10 20 20 10 20 % % % the same with different ordering % row = polygonToRow(square, 'packed') % row = % 10 20 20 10 10 10 20 20 % % % See also % polygons2d, rowToPolygon % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % determines ordering type type = 'interlaced'; if ~isempty(varargin) type = varargin{1}; end if strcmp(type, 'interlaced') % ordering is [X1 Y1 X2 X2... XN YN] Np = size(polygon, 1); row = reshape(polygon', [1 2*Np]); elseif strcmp(type, 'packed') % ordering is [X1 X2 X3... XN Y1 Y2 Y3... YN] row = polygon(:)'; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/minimumCaliperDiameter.m0000644000000000000000000000013214055375162022610 xustar0030 mtime=1622538866.082813553 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/minimumCaliperDiameter.m0000644000175000017500000001160014055375162023673 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [min_width, min_angle] = minimumCaliperDiameter(points) %MINIMUMCALIPERDIAMETER Minimum caliper diameter of a set of points. % % WIDTH = minimumCaliperDiameter(POINTS) % Computes the minimum width of a set of points. As polygons and % polylines are represented as point lists, this function works also for % polygons and polylines. % % [WIDTH THETA] = minimumCaliperDiameter(POINTS) % Also returns the direction of minimum width. The direction corresponds % to the horizontal angle of the edge that minimizes the width. THETA is % given in radians, between 0 and PI. % % % Example % % Compute minimal caliper diameter, and check coords of rotated points % % have expected extent % points = randn(30, 2); % [width theta] = minimumCaliperDiameter(points); % points2 = transformPoint(points, createRotation(-theta)); % diff = max(points2) - min(points2); % abs(width - diff(2)) < 1e-10 % ans = % 1 % % References % Algorithms use rotating caliper. Implementation was based on that of % Wikipedia: % http://en.wikipedia.org/wiki/Rotating_calipers % % See also % polygons2d, convexHull, orientedBox % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-04-08, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % first, compute convex hull of the polygon inds = convhull(points(:,1), points(:,2)); hull = points(inds, :); % if first and last points are the same, remove the last one if inds(1) == inds(end) hull = hull(1:end-1, :); end % number of hull vertices nV = size(hull, 1); % default values rotated_angle = 0; min_width = inf; min_angle = 0; % avoid degenerated cases if nV < 3 return; end [tmp, p_a] = min(hull(:, 2)); %#ok [tmp, p_b] = max(hull(:, 2)); %#ok caliper_a = [ 1 0]; % Caliper A points along the positive x-axis caliper_b = [-1 0]; % Caliper B points along the negative x-axis while rotated_angle < pi % compute the direction vectors corresponding to each edge ind_a2 = mod(p_a, nV) + 1; vector_a = hull(ind_a2, :) - hull(p_a, :); ind_b2 = mod(p_b, nV) + 1; vector_b = hull(ind_b2, :) - hull(p_b, :); % Determine the angle between each caliper and the next adjacent edge % in the polygon angle_a = vectorAngle(caliper_a, vector_a); angle_b = vectorAngle(caliper_b, vector_b); % Determine the smallest of these angles minAngle = min(angle_a, angle_b); % Rotate the calipers by the smallest angle caliper_a = rotateVector(caliper_a, minAngle); caliper_b = rotateVector(caliper_b, minAngle); rotated_angle = rotated_angle + minAngle; % compute current width, and update opposite vertex if angle_a < angle_b line = createLine(hull(p_a, :), hull(ind_a2, :)); width = distancePointLine(hull(p_b, :), line); p_a = mod(p_a, nV) + 1; else line = createLine(hull(p_b, :), hull(ind_b2, :)); width = distancePointLine(hull(p_a, :), line); p_b = mod(p_b, nV) + 1; end % update minimum width and corresponding angle if needed if width < min_width min_width = width; min_angle = rotated_angle; end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/medialAxisConvex.m0000644000000000000000000000013214055375162021425 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.082813553 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/medialAxisConvex.m0000644000175000017500000001352114055375162022514 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges] = medialAxisConvex(points) %MEDIALAXISCONVEX Compute medial axis of a convex polygon. % % [N, E] = medialAxisConvex(POLYGON); % where POLYGON is given as a set of points [x1 y1;x2 y2 ...], returns % the medial axis of the polygon as a graph. % N is a set of nodes. The first elements of N are the vertices of the % original polygon. % E is a set of edges, containing indices of source and target nodes. % Edges are sorted according to order of creation. Index of first vertex % is lower than index of last vertex, i.e. edges always point to newly % created nodes. % % Notes: % - Is not fully implemented, need more development (usually crashes for % polygons with more than 6-7 points...) % - Works only for convex polygons. % - Complexity is not optimal: this algorithm is O(n*log n), but linear % algorithms exist. % % See also: % polygons2d, bisector % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/07/2005. % % HISTORY % 18/04/2007: fix some typos, note the function to be unimplemented % TODO: is not fully implemented, need to finish it % eventually remove the last point if it is the same as the first one if points(1,:) == points(end, :) nodes = points(1:end-1, :); else nodes = points; end % special case of triangles: % compute directly the gravity center, and simplify computation. if size(nodes, 1)==3 nodes = [nodes; mean(nodes, 1)]; edges = [1 4;2 4;3 4]; return end % number of nodes, and also of initial rays N = size(nodes, 1); % create ray of each vertex rays = zeros(N, 4); rays(1, 1:4) = bisector(nodes([2 1 N], :)); rays(N, 1:4) = bisector(nodes([1 N N-1], :)); for i=2:N-1 rays(i, 1:4) = bisector(nodes([i+1, i, i-1], :)); end % add indices of edges producing rays (indices of first vertex, second % vertex is obtained by adding one modulo N). rayEdges = [[N (1:N-1)]' (1:N)']; pint = intersectLines(rays, rays([2:N 1], :)); % compute the distance between each intersection point and the closest % edge. This distance is used as marker to propagate processing front. ti = zeros(N, 1); for i = 1:N line = createLine(points(mod(i-2, N)+1, :), points(i, :)); ti(i) = abs(distancePointLine(pint(i,:), line)); end % create list of events. % terms are : R1 R2 X Y t0 % R1 and R2 are indices of involved rays % X and Y is coordinate of intersection point % t0 is position of point on rays events = sortrows([ (1:N)' [2:N 1]' pint ti], 5); % initialize edges edges = zeros(0, 2); % ------------------- % process each event until there is no more % start after index of last vertex, and process N-3 intermediate rays for i = N+1:2*N-3 % add new node at the rays intersection nodes(i,:) = events(1, 3:4); % add new couple of edges edges = [edges; events(1,1) i; events(1,2) i]; %#ok % find the two edges creating the new emanating ray n1 = rayEdges(events(1, 1), 1); n2 = rayEdges(events(1, 2), 2); % create the new ray line1 = createLine(nodes(n1, :), nodes(mod(n1,N)+1, :)); line2 = createLine(nodes(mod(n2,N)+1, :), nodes(n2, :)); ray0 = bisector(line1, line2); % set its origin to emanating point ray0(1:2) = nodes(i, :); % add the new ray to the list rays = [rays; ray0]; %#ok rayEdges(size(rayEdges, 1)+1, 1:2) = [n1 n2]; % find the two neighbour rays ind = sum(ismember(events(:,1:2), events(1, 1:2)), 2) ~= 0; ir = unique(events(ind, 1:2)); ir = ir(~ismember(ir, events(1,1:2))); % create new intersections pint = intersectLines(ray0, rays(ir, :)); ti = abs(distancePointLine(pint, line1)); % remove all events involving old intersected rays ind = sum(ismember(events(:,1:2), events(1, 1:2)), 2) == 0; events = events(ind, :); % add the newly formed events events = [events; ir(1) i pint(1,:) ti(1); ir(2) i pint(2,:) ti(2)]; %#ok % and sort them according to 'position' parameter events = sortrows(events, 5); end % centroid computation for last 3 rays nodes = [nodes; mean(events(:, 3:4))]; edges = [edges; [unique(events(:,1:2)) ones(3, 1)*(2*N-2)]]; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonEquivalentEllipse.m0000644000000000000000000000013214055375162023225 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonEquivalentEllipse.m0000644000175000017500000000666014055375162024322 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function elli = polygonEquivalentEllipse(poly) % Compute equivalent ellipse with same second order moments as polygon. % % ELLI = polygonEquivalentEllipse(POLY) % % Example % % convert an ellipse to polygon, and check that it equivalent ellipse % is close to original ellipse % elli = [50 50 50 30 20]; % poly = ellipseToPolygon(elli, 1000); % polygonEquivalentEllipse(poly) % ans = % 50.0000 50.0000 49.9998 29.9999 20.0000 % % % compute equivalent ellipse of more complex figure % img = imread('circles.png'); % img = imfill(img, 'holes'); % figure; imshow(img); hold on; % B = bwboundaries(img); % poly = B{1}(:,[2 1]); % drawPolygon(poly, 'r'); % elli = polygonEquivalentEllipse(poly); % drawEllipse(elli, 'color', 'g', 'linewidth', 2); % % % See also % polygons2d, polygonSecondAreaMoments, polygonCentroid, % equivalentEllipse, ellipseToPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-09-08, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. % first re-center the polygon centroid = polygonCentroid(poly); poly = bsxfun(@minus, poly, centroid); % compute non-normalized inertia moments [Ix, Iy, Ixy] = polygonSecondAreaMoments(poly); % noralaize with polygon area area = polygonArea(poly); Ix = Ix / area; Iy = Iy / area; Ixy = Ixy / area; % compute ellipse semi-axis lengths common = sqrt( (Ix - Iy)^2 + 4 * Ixy^2); ra = sqrt(2) * sqrt(Ix + Iy + common); rb = sqrt(2) * sqrt(Ix + Iy - common); % compute ellipse angle and convert into degrees % (different formula from the equivalentEllipse function, as the definition % for Ix and Iy do not refer to same axes) theta = atan2(2 * Ixy, Iy - Ix) / 2; theta = theta * 180 / pi; % compute centroid and concatenate results into ellipse format elli = [centroid ra rb theta]; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polylinePoint.m0000644000000000000000000000013214055375162021027 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polylinePoint.m0000644000175000017500000000611014055375162022112 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = polylinePoint(poly, pos) %POLYLINEPOINT Extract a point from a polyline. % % POINT = polylinePoint(POLYLINE, POS) % POLYLINE is a N*2 array containing coordinate of polyline vertices % POS is comprised between 0 (first point of polyline) and Nv-1 (last % point of the polyline). % % % Example % poly = [10 10;20 10;20 20;30 30]; % polylinePoint(poly, 0) % [10 10] % polylinePoint(poly, 3) % [30 30] % polylinePoint(poly, 1.4) % [20 14] % % % See also % polygons2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-04-30, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % number of points to compute Np = length(pos(:)); % number of vertices in polyline Nv = size(poly, 1); % allocate memory results point = zeros(Np, 2); % iterate on points for i=1:Np % compute index of edge (between 0 and Nv) ind = floor(pos(i)); % special case of last point of polyline if ind==Nv-1 point(i,:) = poly(end,:); continue; end % format index to ensure being on polyline ind = min(max(ind, 0), Nv-2); % position on current edge t = min(max(pos(i)-ind, 0), 1); % parameters of current edge x0 = poly(ind+1, 1); y0 = poly(ind+1, 2); dx = poly(ind+2,1)-x0; dy = poly(ind+2,2)-y0; % compute position of current point point(i, :) = [x0+t*dx, y0+t*dy]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/randomPointInPolygon.m0000644000000000000000000000013214055375162022313 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/randomPointInPolygon.m0000644000175000017500000001021414055375162023376 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = randomPointInPolygon(poly, varargin) %RANDOMPOINTINPOLYGON Generate random point(s) in a polygon. % % POINT = randomPointInPolygon(POLY) % POINTS = randomPointInPolygon(POLY, NPTS) % Generate random point(s) within the specified polygon. If the number of % points is not specified, only one point is generated. % % POINT = randomPointInPolygon(POLY, NPTS, QRS) % Specifies a Quasi-random number generator QRS used to generate point. % coordinates (requires the statistics toolbox). % % Example % % generate an ellipse-like polygon, and fill it with points % elli = [50 50 50 30 30]; % poly = ellipseToPolygon(elli, 200); % pts = randomPointInPolygon(poly, 500); % figure; hold on; % drawPolygon(poly, 'k'); % drawPoint(pts, 'b.'); % axis equal; axis([0 100 0 100]); % % % use halton sequence to distribute points within the polygon % qrs = haltonset(2, 'Skip', 1e3, 'Leap', 1e2); % pts = randomPointInPolygon(poly, 500, qrs); % figure; hold on; % drawPolygon(poly, 'k'); % drawPoint(pts, 'b.'); % axis equal; axis([0 100 0 100]); % % See also % polygons2d, randomPointInBox, drawPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-08-28, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. % determine number of points to generate nPts = 1; if nargin > 1 nPts = varargin{1}; varargin(1) = []; end % if additional input arg is provided, use it as quasi-random generator stream = []; if ~isempty(varargin) stream = qrandstream(varargin{1}); end % polygon extreme coordinates box = polygonBounds(poly); xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % compute size of box boxSizeX = xmax - xmin; boxSizeY = ymax - ymin; % allocate memory for result points = zeros(nPts, 2); % contains indices of remaining points to process ind = (1:nPts)'; % iterate until all points have been sampled within the polygon if isempty(stream) % use default random number generator while ~isempty(ind) NI = length(ind); x = rand(NI, 1) * boxSizeX + xmin; y = rand(NI, 1) * boxSizeY + ymin; points(ind, :) = [x y]; ind = ind(~polygonContains(poly, points(ind, :))); end else % use specified quasi-random generator while ~isempty(ind) NI = length(ind); pts = qrand(stream, NI); x = pts(:, 1) * boxSizeX + xmin; y = pts(:, 2) * boxSizeY + ymin; points(ind, :) = [x y]; ind = ind(~polygonContains(poly, points(ind, :))); end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonSkeleton.m0000644000000000000000000000013214055375162021356 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonSkeleton.m0000644000175000017500000001441514055375162022450 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polygonSkeleton(poly, varargin) % Skeletonization of a polygon with a dense distribution of vertices. % % [V, ADJ] = polygonSkeleton(POLY) % POLY is given as a N-by-2 array of polygon vertex coordinates. The % result is given a Nv-by-2 array of skeleton vertex coordinates, and an % adjacency list, as a NV-by-1 cell array. Each cell contains indices of % vertices adjacent to the vertex indexed by the cell. % % [V, ADJ, RAD] = polygonSkeleton(POLY) % Also returns the radius of each vertex, corresponding to the distance % between the vertex and the closest point of the original contour % polygon. % % SKEL = polygonSkeleton(POLY) % Concatenates the results in a struct SKEL with following fields: % * vertices the Nv-by-2 array of skeleton vertex coordinates % * adjList the adjacency list of each vertex, as a Nv-by-1 cell array. % * radius the Nv-by-1 array of radius for each vertex % % Example % % start from a binary shape % img = imread('circles.png'); % img = imFillHoles(img); % figure; imshow(img); hold on; % % compute a smooth contour % cntList = imContours(img); % cnts = smoothPolygon(cntList{1}, 5); % drawPolygon(cnts, 'g'); % % compute skeleton % [vertices, adjList] = polygonSkeleton(poly); % % convert adjacency list to an edge array % edges = adjacencyListToEdges(adjList); % % draw the skeleton graph % drawGraphEdges(vertices, edges); % % See also % graphs, adjacencyListToEdges % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-05-29, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. %% Voronoi Diagram computation % Compute Voronoi Diagram, using polygon vertices as germs. [V, C] = voronoin(poly); % compute number of elements of each array nVertices = size(V, 1); nCells = size(C, 1); % Detection of the vertices located inside the contour insideFlag = inpolygon(V(:,1), V(:,2), poly(:,1), poly(:,2)); innerVertices = V(insideFlag, :); % indices of inner vertices indsInside = find(insideFlag); nInnerVertices = length(indsInside); % compute map between voronoi vertex indices and skeleton vertex indices. vertexIndexMap = zeros(nVertices, 1); for iVertex = 1:length(indsInside) vertexIndexMap(indsInside(iVertex)) = iVertex; end %% Compute the topology of the skeleton % % Compute the topology as a list of adjacent vertex indices for each vertex % inside the polygon. % Need to convert between voronoi indices and skeleton indices. % allocate adjacncy list adjList = cell(nInnerVertices, 1); vertexGermInds = zeros(nInnerVertices, 1); % iterate on voronoi cells to compute skeleton by linking adjacent vertices % (avoiding first cell which is located at infinity by convention) for iGerm = 2:nCells % vertices of current cell cellVertices = C{iGerm}; nCellVertices = length(cellVertices); % iterate on vertices of current cell for k = 1:nCellVertices % index of current voronoi vertex iVertex = cellVertices(k); % process only vertices within the contour if insideFlag(iVertex) == 0 continue; end % convert voronoi vertex index to skeleton vertex index indV1 = vertexIndexMap(iVertex); % update the reference germ associated to current skeleton vertex vertexGermInds(indV1) = iGerm; % compute indices of adjacent vertices (in cell) iPrev = cellVertices(mod(k - 2, nCellVertices) + 1); iNext = cellVertices(mod(k, nCellVertices) + 1); % keep only the neighbors within the polygon if insideFlag(iPrev) == 1 adjList{indV1} = [adjList{indV1} vertexIndexMap(iPrev)]; end if insideFlag(iNext) == 1 adjList{indV1} = [adjList{indV1} vertexIndexMap(iNext)]; end end end % cleanup to avoid duplicate indices for iVertex = 1:nInnerVertices adjList{iVertex} = unique(adjList{iVertex}); end %% Compute radius list % for each voronoi vertex inside the polygon, compute the distance to % original polygon. % Find indices of germs associated to each vertex. % By construction, each vertex is the circumcenter of three germs. radiusList = zeros(nInnerVertices, 1); for iVertex = 1:nInnerVertices radiusList(iVertex) = norm(poly(vertexGermInds(iVertex),:) - innerVertices(iVertex,:)); end %% Format output if nargout <= 1 % format output to a struct varargout{1} = struct('vertices', {innerVertices}, 'adjList', {adjList}, 'radius', {radiusList}); elseif nargout == 2 varargout = {innerVertices, adjList}; elseif nargout == 3 varargout = {innerVertices, adjList, radiusList}; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/distancePolygons.m0000644000000000000000000000013214055375162021507 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/distancePolygons.m0000644000175000017500000000572414055375162022604 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function dist = distancePolygons(poly1, poly2) %DISTANCEPOLYGONS Compute the shortest distance between 2 polygons. % % DIST = distancePolygons(POLY1, POLY2) % Computes the shortest distance between the boundaries of the two % polygons. Each polygon is given by a N-by-2 array containing the vertex % coordinates. % % In the case the two polygons are known not to intersect, the function % 'distancePolygonsNoCross' may be used more efficiently (no test for % crossing is done). % % Example % % Computes the distance between a square and a triangle % poly1 = [10 10;20 10;20 20;10 20]; % poly2 = [30 20;50 20;40 45]; % distancePolygons(poly1, poly2) % ans = % 10 % % See also % polygons2d, distancePolygonsNoCross, distancePolylines, % distancePointPolygon % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-06-17, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % cjeck if the two polygons intersect pts = intersectPolylines(poly1([1:end 1], :), poly2([1:end 1], :)); if size(pts, 1) > 0 dist = 0; return; end % compute distance of each vertex of a polygon to the other polygon dist1 = min(distancePointPolygon(poly1, poly2)); dist2 = min(distancePointPolygon(poly2, poly1)); % keep the minimum of the two distances dist = min(dist1, dist2); matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonLoops.m0000644000000000000000000000013214055375162020666 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonLoops.m0000644000175000017500000001363514055375162021763 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function loops = polygonLoops(poly, varargin) %POLYGONLOOPS Divide a possibly self-intersecting polygon into a set of simple loops. % % LOOPS = polygonLoops(POLYGON); % POLYGON is a polygone defined by a series of vertices, % LOOPS is a cell array of polygons, containing the same vertices of the % original polygon, but no loop self-intersect, and no couple of loops % intersect each other. % % Example: % poly = [0 0;0 10;20 10;20 20;10 20;10 0]; % loops = polygonLoops(poly); % figure(1); hold on; % drawPolygon(loops); % polygonArea(loops) % % See also % polygons2d, polygonSelfIntersections % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2009-06-15, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % tolerance for detecting two vertices as equal tol = 1e-14; % parse optional arguments while length(varargin) > 1 pname = varargin{1}; if ~ischar(pname) error('Expect optional arguments as name-value pairs'); end if strcmpi(pname, 'tolerance') tol = varargin{2}; else error(['Unknown parameter name: ' pname]); end varargin(1:2) = []; end %% Initialisations % compute intersections [inters, pos1, pos2] = polygonSelfIntersections(poly, 'tolerance', tol); % case of a polygon without self-intersection if isempty(inters) loops = {poly}; return; end % array for storing loops loops = cell(0, 1); % sort intersection points with respect to their position on the polygon [positions, order] = sortrows([pos1 pos2 ; pos2 pos1]); inters = [inters ; inters]; inters = inters(order, :); %% First loop % initialize the beginning of the loop pos0 = 0; loop = polygonSubcurve(poly, pos0, positions(1, 1)); loop(end, :) = inters(1,:); vertex = inters(1,:); % prepare iteration on positions pos = positions(1, 2); positions(1, :) = []; inters(1,:) = []; while true % index of next intersection point ind = find(positions(:,1) > pos, 1, 'first'); % if not index is found, the current loop is complete if isempty(ind) break; end % compute the portion of curve between the two intersection points portion = polygonSubcurve(poly, pos, positions(ind, 1)); % ensure extremities have been computed only once portion(1, :) = vertex; vertex = inters(ind, :); portion(end, :) = vertex; % add the current portion of curve loop = [loop; portion]; %#ok % update current position on the polygon pos = positions(ind, 2); % remove processed intersection positions(ind, :) = []; inters(ind,:) = []; end % append the last portion of curve loop = [loop ; polygonSubcurve(poly, pos, pos0)]; % remove redundant vertices loop(sum(loop(1:end-1,:) == loop(2:end,:) ,2)==2, :) = []; if sum(diff(loop([1 end], :)) == 0) == 2 loop(end, :) = []; end % add current loop to the list of loops loops{1} = loop; %% Other loops Nl = 1; while ~isempty(positions) % initialize the next loop loop = []; pos0 = positions(1, 2); pos = positions(1, 2); vertex = inters(1,:); while true % index of next intersection point ind = find(positions(:,1) > pos, 1, 'first'); % compute the portion of curve between the two intersection points portion = polygonSubcurve(poly, pos, positions(ind, 1)); % ensure extremities have been computed only once portion(1, :) = vertex; vertex = inters(ind, :); portion(end, :) = vertex; % append the current portion of curve loop = [loop ; portion]; %#ok % update current position on the polygon pos = positions(ind, 2); % remove processed intersection positions(ind, :) = []; inters(ind,:) = []; % if not found, current loop is processed if pos == pos0 break; end end % remove redundant vertices loop(sum(loop(1:end-1,:) == loop(2:end,:) ,2)==2, :) = []; %#ok if sum(diff(loop([1 end], :))==0) == 2 loop(end, :) = []; end % add current loop to the list of loops Nl = Nl + 1; loops{Nl} = loop; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/isPointInPolygon.m0000644000000000000000000000013214055375162021446 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/isPointInPolygon.m0000644000175000017500000000703714055375162022542 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isPointInPolygon(point, poly) %ISPOINTINPOLYGON Test if a point is located inside a polygon. % % B = isPointInPolygon(POINT, POLYGON) % Returns true if the point is located within the given polygon. % % This function is simply a wrapper for the function inpolygon, to avoid % decomposition of point and polygon coordinates. % % Example % pt1 = [30 20]; % pt2 = [30 5]; % poly = [10 10;50 10;50 50;10 50]; % isPointInPolygon([pt1;pt2], poly) % ans = % 1 % 0 % % poly = [0 0; 10 0;10 10;0 10;NaN NaN;3 3;3 7;7 7;7 3]; % pts = [5 1;5 4]; % isPointInPolygon(pts, poly); % ans = % 1 % 0 % % % See also % points2d, polygons2d, inpolygon, isPointInTriangle % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2009-06-19, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % HISTORY % 2013-04-24 add support for multiply connected polygons % In case of a multiple polygon, decompose into a set of contours, and % performs test for each contour if iscell(poly) || any(isnan(poly(:))) % transform as a cell array of simple polygons polygons = splitPolygons(poly); N = length(polygons); Np = size(point, 1); % compute orientation of polygon, and format to have Np*N matrix areas = zeros(N, 1); for i = 1:N areas(i) = polygonArea(polygons{i}); end ccw = areas > 0; ccw = repmat(ccw', Np, 1); % test if point inside each polygon in = false(size(point, 1), N); for i = 1:N poly = polygons{i}; in(:, i) = inpolygon(point(:,1), point(:,2), poly(:,1), poly(:,2)); end % count polygons containing point, weighted by polygon orientation b = sum(in.*(ccw==1) - in.*(ccw==0), 2) > 0; else % standard test for simple polygons b = inpolygon(point(:,1), point(:,2), poly(:,1), poly(:,2)); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/rowToPolygon.m0000644000000000000000000000013214055375162020644 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/rowToPolygon.m0000644000175000017500000000716214055375162021737 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly = rowToPolygon(row, varargin) %ROWTOPOLYGON Create a polygon from a row vector. % % POLY = rowToPolygon(ROW) % Convert a 1-by-2*N row vector that concatenates all polygon vertex % coordinates into a N-by-2 array of coordinates. % Default ordering of coordinates in ROW is: % [X1 Y1 X2 Y2 X3 Y3 .... XN YN]. % % POLY = rowToPolygon(ROW, METHOD) % Specifies the method for concatenating coordinates. METHOS is one of: % 'interlaced': default method, described above. % 'packed': the vector ROW has format: % [X1 X2 X3 ... XN Y1 Y2 Y3 ... YN]. % % POLYS = rowToPolygon(ROWS, ...) % When ROWS is a NP-by-NV array containing the vertex coordinates of NP % polygons, returns a 1-by-NP cell array containing in each cell the % coordinates of the polygon. % % % Example % % Concatenate coordinates of a circle and draw it as a polygon % t = linspace (0, 2*pi, 200); % row = [cos(t) sin(t)]; % poly = rowToPolygon(row, 'packed'); % figure;drawPolygon(poly) % % See also % polygons2d, polygonToRow % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-07-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % HISTORY % 2014-01-29 add support for multiple rows type = 'interlaced'; if ~isempty(varargin) type = varargin{1}; end % number of polygons nPolys = size(row, 1); % polygon vertex number Np = size(row, 2) / 2; if strcmp(type, 'interlaced') % ordering is [X1 Y1 X2 X2... XN YN] if nPolys == 1 poly = reshape(row, [2 Np])'; else poly = cell(1, nPolys); for i = 1:nPolys poly{i} = reshape(row(i,:), [2 Np])'; end end elseif strcmp(type, 'packed') % ordering is [X1 X2 X3... XN Y1 Y2 Y3... YN] if nPolys == 1 poly = [row(1:Np)' row(Np+1:end)']; else poly = cell(1, nPolys); for i = 1:nPolys poly{i} = [row(i, 1:Np)' row(i, Np+1:end)']; end end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/changelog.txt0000644000000000000000000000013214055375161020473 xustar0030 mtime=1622538865.994813885 30 atime=1622538865.994813885 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/changelog.txt0000644000175000017500000000134114055375161021557 0ustar00juanpijuanpi00000000000000change log for geom2d geom2d, release 2011.06.30 ========================== Changes - re-organized the library in three sub-directories: geom2d, polygons2d, and polynomialCurves2d - cleanup of code and doc New functions - added function drawOrientedBox - added function pointSetBounds, that computes bounding box of a set of points - added function pointSetsAverage - added function minimumCaliperDiameter - added function isPointInTriangle - added function findPoint Changes - function intersectLinePolygon now returns unique intersections - enhanced intersectLinePolygon - enhanced polygonSelfIntersections Bug fixes - general code and doc cleanup - fixed bugs in polygonLength and parametrize matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/private0000644000000000000000000000013214055375161017400 xustar0030 mtime=1622538865.994813885 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/private/0000755000175000017500000000000014055375161020542 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/polygons2d/private/PaxHeaders.19757/InterX.m0000644000000000000000000000013214055375162021045 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/private/InterX.m0000644000175000017500000001171514055375162022137 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function P = InterX(L1,varargin) %INTERX Intersection of curves. % P = INTERX(L1,L2) returns the intersection points of two curves L1 % and L2. The curves L1,L2 can be either closed or open and are described % by two-row-matrices, where each row contains its x- and y- coordinates. % The intersection of groups of curves (e.g. contour lines, multiply % connected regions etc) can also be computed by separating them with a % column of NaNs as for example % % L = [x11 x12 x13 ... NaN x21 x22 x23 ...; % y11 y12 y13 ... NaN y21 y22 y23 ...] % % P has the same structure as L1 and L2, and its rows correspond to the % x- and y- coordinates of the intersection points of L1 and L2. If no % intersections are found, the returned P is empty. % % P = INTERX(L1) returns the self-intersection points of L1. To keep % the code simple, the points at which the curve is tangent to itself are % not included. P = INTERX(L1,L1) returns all the points of the curve % together with any self-intersection points. % % Example: % t = linspace(0,2*pi); % r1 = sin(4*t)+2; x1 = r1.*cos(t); y1 = r1.*sin(t); % r2 = sin(8*t)+2; x2 = r2.*cos(t); y2 = r2.*sin(t); % P = InterX([x1;y1],[x2;y2]); % plot(x1,y1,x2,y2,P(1,:),P(2,:),'ro') % Author : NS % Version: 3.0, 21 Sept. 2010 % Two words about the algorithm: Most of the code is self-explanatory. % The only trick lies in the calculation of C1 and C2. To be brief, this % is essentially the two-dimensional analog of the condition that needs % to be satisfied by a function F(x) that has a zero in the interval % [a,b], namely % F(a)*F(b) <= 0 % C1 and C2 exactly do this for each segment of curves 1 and 2 % respectively. If this condition is satisfied simultaneously for two % segments then we know that they will cross at some point. % Each factor of the 'C' arrays is essentially a matrix containing % the numerators of the signed distances between points of one curve % and line segments of the other. %...Argument checks and assignment of L2 narginchk(1,2); if nargin == 1 L2 = L1; hF = @lt; %...Avoid the inclusion of common points else L2 = varargin{1}; hF = @le; end %...Preliminary stuff x1 = L1(1,:)'; x2 = L2(1,:); y1 = L1(2,:)'; y2 = L2(2,:); dx1 = diff(x1); dy1 = diff(y1); dx2 = diff(x2); dy2 = diff(y2); %...Determine 'signed distances' S1 = dx1.*y1(1:end-1) - dy1.*x1(1:end-1); S2 = dx2.*y2(1:end-1) - dy2.*x2(1:end-1); C1 = feval(hF,D(bsxfun(@times,dx1,y2)-bsxfun(@times,dy1,x2),S1),0); C2 = feval(hF,D((bsxfun(@times,y1,dx2)-bsxfun(@times,x1,dy2))',S2'),0)'; %...Obtain the segments where an intersection is expected [i,j] = find(C1 & C2); if isempty(i),P = zeros(2,0);return; end; %...Transpose and prepare for output i=i'; dx2=dx2'; dy2=dy2'; S2 = S2'; L = dy2(j).*dx1(i) - dy1(i).*dx2(j); i = i(L~=0); j=j(L~=0); L=L(L~=0); %...Avoid divisions by 0 %...Solve system of eqs to get the common points P = unique([dx2(j).*S1(i) - dx1(i).*S2(j), ... dy2(j).*S1(i) - dy1(i).*S2(j)]./[L L],'rows')'; function u = D(x,y) u = bsxfun(@minus,x(:,1:end-1),y).*bsxfun(@minus,x(:,2:end),y); end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonInertiaEllipse.m0000644000000000000000000000013214055375162022503 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonInertiaEllipse.m0000644000175000017500000000703714055375162023577 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function elli = polygonInertiaEllipse(poly) %POLYGONINERTIAELLIPSE Compute ellipse with same inertia moments as polygon. % % ELLI = polygonInertiaEllipse(POLY) % % Example % % convert an ellipse to polygon, and check that inertia ellipse is % % close to original ellipse % elli = [50 50 50 30 20]; % poly = ellipseToPolygon(elli, 1000); % polygonInertiaEllipse(poly) % ans = % 50.0000 50.0000 49.9998 29.9999 20.0000 % % % compute inertia ellipse of more complex figure % img = imread('circles.png'); % img = imfill(img, 'holes'); % figure; imshow(img); hold on; % B = bwboundaries(img); % poly = B{1}(:,[2 1]); % drawPolygon(poly, 'r'); % elli = polygonInertiaEllipse(poly); % drawEllipse(elli, 'color', 'g', 'linewidth', 2); % % % See also % polygons2d, polygonSecondAreaMoments, polygonCentroid, inertiaEllipse % ellipseToPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-09-08, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. warning('MatGeom:deprecated', ... 'function ''polygonInertiaEllipse'' is obsolete, use ''polygonEquivalentEllipse'' instead'); % first re-center the polygon centroid = polygonCentroid(poly); poly = bsxfun(@minus, poly, centroid); % compute non-normalized inertia moments [Ix, Iy, Ixy] = polygonSecondAreaMoments(poly); % noralaize with polygon area area = polygonArea(poly); Ix = Ix / area; Iy = Iy / area; Ixy = Ixy / area; % compute ellipse semi-axis lengths common = sqrt( (Ix - Iy)^2 + 4 * Ixy^2); ra = sqrt(2) * sqrt(Ix + Iy + common); rb = sqrt(2) * sqrt(Ix + Iy - common); % compute ellipse angle and convert into degrees % (different formula from the inertiaEllipse function, as the definition % for Ix and Iy do not refer to same axes) theta = atan2(2 * Ixy, Iy - Ix) / 2; theta = theta * 180 / pi; % compute centroid and concatenate results into ellipse format elli = [centroid ra rb theta]; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/resamplePolygonByLength.m0000644000000000000000000000013214055375162022777 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/resamplePolygonByLength.m0000644000175000017500000000524414055375162024071 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function poly2 = resamplePolygonByLength(poly, step) %RESAMPLEPOLYGONBYLENGTH Resample a polygon with a fixed sampling step. % % RES = resamplePolygon(POLY, STEP) % Resample the input polygon POLY by distributing new vertices on the % original polygon such that the (curvilinear) distance between the new % vertices is approximately equal to STEP. % % Example % % creates a polygon from an ellipse % elli = [20 30 40 20 30]; % poly = ellipseToPolygon(elli, 500); % figure; drawPolygon(poly, 'b'); % poly2 = resamplePolygonByLength(poly, 10); % hold on; % drawPolygon(poly2, 'm'); % drawPoint(poly2, 'mo'); % axis equal; axis([-20 60 0 60]); % legend('Original polygon', 'Resampled polygon', 'Location', 'NorthWest'); % % See also % polygons2d, simplifyPolygon, resamplePolygon, % resamplePolylineByLength % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-09, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. poly2 = resamplePolylineByLength(poly([1:end 1],:), step); poly2(end, :) = []; matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/intersectPolylines.m0000644000000000000000000000013214055375162022061 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/intersectPolylines.m0000644000175000017500000001515114055375162023151 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pts = intersectPolylines(poly1, varargin) %INTERSECTPOLYLINES Find the common points between 2 polylines. % % INTERS = intersectPolylines(POLY1, POLY2) % Returns the intersection points between two polylines. Each polyline is % defined by a N-by-2 array representing coordinates of its vertices: % [X1 Y1 ; X2 Y2 ; ... ; XN YN] % INTERS is a NP-by-2 array containing coordinates of intersection % points. % % INTERS = intersectPolylines(POLY1) % Compute self-intersections of the polyline. % % Example % % Compute intersection points between 2 simple polylines % poly1 = [20 10 ; 20 50 ; 60 50 ; 60 10]; % poly2 = [10 40 ; 30 40 ; 30 60 ; 50 60 ; 50 40 ; 70 40]; % pts = intersectPolylines(poly1, poly2); % figure; hold on; % drawPolyline(poly1, 'b'); % drawPolyline(poly2, 'm'); % drawPoint(pts); % axis([0 80 0 80]); % % This function is largely based on the 'interX' function, found on the % FileExchange: % https://fr.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections % % See also % polygons2d, polylineSelfIntersections, intersectLinePolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2009-06-15, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % The code is a slight rewritting of the interX function, consisting in % avoiding argument transposition in the begining of the function. Comment % of original submission are kept here for information. % %INTERX Intersection of curves % P = INTERX(L1,L2) returns the intersection points of two curves L1 % and L2. The curves L1,L2 can be either closed or open and are described % by two-row-matrices, where each row contains its x- and y- coordinates. % The intersection of groups of curves (e.g. contour lines, multiply % connected regions etc) can also be computed by separating them with a % column of NaNs as for example % % L = [x11 x12 x13 ... NaN x21 x22 x23 ...; % y11 y12 y13 ... NaN y21 y22 y23 ...] % % P has the same structure as L1 and L2, and its rows correspond to the % x- and y- coordinates of the intersection points of L1 and L2. If no % intersections are found, the returned P is empty. % % P = INTERX(L1) returns the self-intersection points of L1. To keep % the code simple, the points at which the curve is tangent to itself are % not included. P = INTERX(L1,L1) returns all the points of the curve % together with any self-intersection points. % % Example: % t = linspace(0,2*pi); % r1 = sin(4*t)+2; x1 = r1.*cos(t); y1 = r1.*sin(t); % r2 = sin(8*t)+2; x2 = r2.*cos(t); y2 = r2.*sin(t); % P = InterX([x1;y1],[x2;y2]); % plot(x1,y1,x2,y2,P(1,:),P(2,:),'ro') % % Author : NS % Version: 3.0, 21 Sept. 2010 % % Two words about the algorithm: Most of the code is self-explanatory. % The only trick lies in the calculation of C1 and C2. To be brief, this % is essentially the two-dimensional analog of the condition that needs % to be satisfied by a function F(x) that has a zero in the interval % [a,b], namely % F(a)*F(b) <= 0 % C1 and C2 exactly do this for each segment of curves 1 and 2 % respectively. If this condition is satisfied simultaneously for two % segments then we know that they will cross at some point. % Each factor of the 'C' arrays is essentially a matrix containing % the numerators of the signed distances between points of one curve % and line segments of the other. % Check number of inputs narginchk(1, 2); % Specific init depending on number of inputs if nargin == 1 % Compute self-intersections % -> Avoid the inclusion of common points poly2 = poly1; hF = @lt; else % Compute intersections between distinct lines poly2 = varargin{1}; hF = @le; end % Get coordinates of polyline vertices x1 = poly1(:,1); x2 = poly2(:,1)'; y1 = poly1(:,2); y2 = poly2(:,2)'; % differentiate coordinate arrays dx1 = diff(x1); dy1 = diff(y1); dx2 = diff(x2); dy2 = diff(y2); % Determine 'signed distances' S1 = dx1 .* y1(1:end-1) - dy1 .* x1(1:end-1); S2 = dx2 .* y2(1:end-1) - dy2 .* x2(1:end-1); C1 = feval(hF, D(bsxfun(@times,dx1,y2) - bsxfun(@times,dy1,x2), S1), 0); C2 = feval(hF, D((bsxfun(@times,y1,dx2) - bsxfun(@times,x1,dy2))', S2'), 0)'; % Obtain the segments where an intersection is expected [i, j] = find(C1 & C2); % Process case of no intersection if isempty(i) pts = zeros(0, 2); return; end % Transpose and prepare for output i=i'; dx2=dx2'; dy2=dy2'; S2 = S2'; L = dy2(j).*dx1(i) - dy1(i).*dx2(j); % Avoid divisions by zero i = i(L~=0); j = j(L~=0); L = L(L~=0); % Solve system of eqs to get the common points res = [dx2(j).*S1(i) - dx1(i).*S2(j), dy2(j).*S1(i) - dy1(i).*S2(j)] ./ [L L]; pts = unique(res, 'rows'); % Innre function computing a kind of cross-product function u = D(x,y) u = bsxfun(@minus, x(:,1:end-1), y) .* bsxfun(@minus, x(:,2:end), y); end end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/supportFunction.m0000644000000000000000000000013214055375162021404 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/supportFunction.m0000644000175000017500000000505414055375162022475 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function h = supportFunction(polygon, varargin) %SUPPORTFUNCTION Compute support function of a polygon. % % H = supportFunction(POLYGON, N) % uses N points for suport function approximation % % H = supportFunction(POLYGON) % assume 24 points for approximation % % H = supportFunction(POLYGON, V) % where V is a vector, uses vector V of angles to compute support % function. % % See also: % polygons2d, convexification % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 20/12/2004. % N = 24; u = 0:2*pi/N:2*pi*(1-1/N); if length(varargin)==1 var = varargin{1}; if length(var)==1 N = var; u = 0:2*pi/N:2*pi*(1-1/N); else u = var; end end % ensure u vertical vector if size(u, 1)==1 u=u'; end h = zeros(size(u)); for i=1:length(u) v = repmat([cos(u(i)) sin(u(i))], [size(polygon, 1), 1]); h(i) = max(dot(polygon, v, 2)); end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/polygonEdges.m0000644000000000000000000000013214055375162020621 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/polygonEdges.m0000644000175000017500000000554614055375162021720 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges = polygonEdges(poly) %POLYGONEDGES Return the edges of a simple or multiple polygon. % % EDGES = polygonEdges(POLY) % Return the set of edges of the polygon specified by POLY. POLY may be % either a simple polygon given as a N-by-2 array of vertices, or a % multiple polygon given by a cell array of linear rings, each ring being % given as N-by-2 array of vertices. % % % Example % poly = [50 10;60 10;60 20;50 20]; % polygonEdges(poly) % ans = % 50 10 60 10 % 60 10 60 20 % 60 20 50 20 % 50 20 50 10 % % See also % polygons2d, polygonVertices % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-08-29, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. % test presence of NaN values if isnumeric(poly) && any(isnan(poly(:))) poly = splitPolygons(poly); end % create the array of polygon edges if iscell(poly) % process multiple polygons edges = zeros(0, 4); for i = 1:length(poly) pol = poly{i}; N = size(pol, 1); edges = [edges; pol(1:N, :) pol([2:N 1], :)]; %#ok end else % get edges of a simple polygon N = size(poly, 1); edges = [poly(1:N, :) poly([2:N 1], :)]; end matgeom-1.2.3/inst/polygons2d/PaxHeaders.19757/curvature.m0000644000000000000000000000013214055375162020202 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polygons2d/curvature.m0000644000175000017500000001334714055375162021277 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function kappa = curvature(varargin) %CURVATURE Estimate curvature of a polyline defined by points. % % KAPPA = curvature(T, PX, PY, METHOD, DEGREE) % First compute an approximation of the curve given by PX and PY, with % the parametrization T. METHOD used for approximation can be only: % 'polynom', with specified degree % Further methods will be provided in a future version. % T, PX, and PY are N*1 array of the same length. % Then compute the curvature of approximated curve for each point. % % For example: % KAPPA = curvature(t, px, py, 'polynom', 6) % % KAPPA = curvature(T, POINTS, METHOD, DEGREE) % specify curve as a suite of points. POINTS is size [N*2]. % % KAPPA = curvature(PX, PY, METHOD, DEGREE) % KAPPA = curvature(POINTS, METHOD, DEGREE) % compute implicite normalization of the curve, based on euclidian % distance between 2 consecutive points, and normalized between 0 and 1. % % % See Also: % polygons2d, parametrize % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 07/04/2003. % % default values degree = 5; t=0; % parametrization of curve tc=0; % indices of points wished for curvature % ================================================================= % Extract method and degree ------------------------------ nargin = length(varargin); varN = varargin{nargin}; varN2 = varargin{nargin-1}; if ischar(varN2) % method and degree are specified method = varN2; degree = varN; varargin = varargin(1:nargin-2); elseif ischar(varN) % only method is specified, use degree 6 as default method = varN; varargin = varargin{1:nargin-1}; else % method and degree are implicit : use 'polynom' and 6 method = 'polynom'; end % extract input parametrization and curve. ----------------------- nargin = length(varargin); if nargin==1 % parameters are just the points -> compute caracterization. var = varargin{1}; px = var(:,1); py = var(:,2); elseif nargin==2 var = varargin{2}; if size(var, 2)==2 % parameters are t and POINTS px = var(:,1); py = var(:,2); t = varargin{1}; else % parameters are px and py px = varargin{1}; py = var; end elseif nargin==3 var = varargin{2}; if size(var, 2)==2 % parameters are t, POINTS, and tc px = var(:,1); py = var(:,2); t = varargin{1}; else % parameters are t, px and py t = varargin{1}; px = var; py = varargin{3}; end elseif nargin==4 % parameters are t, px, py and tc t = varargin{1}; px = varargin{2}; py = varargin{3}; tc = varargin{4}; end % compute implicit parameters -------------------------- % if t and/or tc are not computed, use implicit definition if t==0 t = parametrize(px, py); t = t/t(length(t)); % normalize between 0 and 1 end % if tc not defined, compute curvature for all points if tc==0 tc = t; else % else convert from indices to parametrization values tc = t(tc); end % ================================================================= % compute curvature for each point of the curve if strcmp(method, 'polynom') % compute coefficients of interpolation functions x0 = polyfit(t, px, degree); y0 = polyfit(t, py, degree); % compute coefficients of first and second derivatives. In the case of a % polynom, it is possible to compute coefficient of derivative by % multiplying with a matrix. derive = diag(degree:-1:0); xp = circshift(x0*derive, [0 1]); yp = circshift(y0*derive, [0 1]); xs = circshift(xp*derive, [0 1]); ys = circshift(yp*derive, [0 1]); % compute values of first and second derivatives for needed points xprime = polyval(xp, tc); yprime = polyval(yp, tc); xsec = polyval(xs, tc); ysec = polyval(ys, tc); % compute value of curvature kappa = (xprime.*ysec - xsec.*yprime)./ ... power(xprime.*xprime + yprime.*yprime, 3/2); else error('unknown method'); end matgeom-1.2.3/inst/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162015657 xustar0030 mtime=1622538866.030813749 30 atime=1622538866.030813749 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/Contents.m0000644000175000017500000000554414055375162016754 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % MATGEOM Geometric Computing Toolbox % Version 1.0 26-07-2017 . % % MatGeom Provides low-level functions for geometric computing. It is % possible to create, display, compute intersections... of various % geometrical primitives, in 2D and 3D. % % The library is organized into several modules: % geom2d - General function in euclidean plane % polygons2d - Functions operating on point lists % graphs - Manipulation of geometric graphs % polynomialCurves2d - Representation of smooth polynomial curves % geom3d - General function in 3D euclidean space % meshes3d - Manipulation of 3D surfacic meshes % % Type 'help(MODULENAME)' for further info. % % To install the library, with all sub-directories, run the script % 'setupMatGeom'. % % More information on the project homepage: % https://github.com/mattools/matGeom % % Online documentation: % https://github.com/mattools/matGeom % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-03-21, using Matlab 7.9.0.529 (R2009b) % Project homepage: http://github.com/mattools/matGeom % http://www.pfl-cepia.inra.fr/index.php?page=geom3d % Copyright 2011 INRA - Cepia Software Platform. help(mfilename); matgeom-1.2.3/inst/PaxHeaders.19757/utils0000644000000000000000000000013214055375161014766 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/utils/0000755000175000017500000000000014055375161016130 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/utils/PaxHeaders.19757/isAxisHandle.m0000644000000000000000000000013214055375162017576 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/utils/isAxisHandle.m0000644000175000017500000000454314055375162020671 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function b = isAxisHandle(arg) %ISAXISHANDLE Check if the input corresponds to a valid axis handle. % % B = isAxisHandle(VAR) % If the value of VAR is scalar, corresponds to a valid matlab handle, % and has type equal to 'axis', then returns TRUE. Otherwise, returns % false. % This function is used to check if first argument of drawing functions % corresponds to data or to axis handle to draw in. % % Example % isAxisHandle(gca) % ans = % 1 % % See also % drawPoint, drawLine, drawEdge % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-09-21, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. b = isscalar(arg) && ishandle(arg) && strcmp(get(arg, 'type'), 'axes'); matgeom-1.2.3/inst/PaxHeaders.19757/meshes3d0000644000000000000000000000013214055375161015341 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/0000755000175000017500000000000014055375161016503 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/mergeCoplanarFaces.m0000644000000000000000000000013214055375162021316 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/mergeCoplanarFaces.m0000644000175000017500000002653314055375162022414 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = mergeCoplanarFaces(nodes, varargin) %MERGECOPLANARFACES Merge coplanar faces of a polyhedral mesh. % % [NODES, FACES] = mergeCoplanarFaces(NODES, FACES) % [NODES, EDGES, FACES] = mergeCoplanarFaces(NODES, EDGES, FACES) % NODES is a set of 3D points (as a nNodes-by-3 array), % and FACES is one of: % - a nFaces-by-X array containing vertex indices of each face, with each % face having the same number of vertices, % - a nFaces-by-1 cell array, each cell containing indices of a face. % The function groups faces which are coplanar and contiguous, resulting % in a "lighter" mesh. This can be useful for visualizing binary 3D % images for example. % % FACES = mergeCoplanarFaces(..., PRECISION) % Adjust the threshold for deciding if two faces are coplanar or % parallel. Default value is 1e-5. % % Example % [v, e, f] = createCube; % figure; drawMesh(v, f); view(3); axis equal; % [v2, f2] = mergeCoplanarFaces(v, f); % figure; drawMesh(v2, f2); % view(3); axis equal; view(3); % % See also % meshes3d, drawMesh, minConvexHull, triangulateFaces % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-07-05 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % 20/07/2006 add tolerance for coplanarity test % 21/08/2006 fix small bug due to difference of methods to test % coplanaritity, sometimes resulting in 3 points of a face not coplanar ! % Also add control on precision % 14/08/2007 rename minConvexHull->meshReduce, and extend to non convex % shapes % 2011-01-14 code clean up % 2013-02-22 rename from meshReduce to mergeCoplanarFaces %% Process input arguments % set up precision acc = 1e-5; if ~isempty(varargin) var = varargin{end}; if length(var) == 1 acc = var; varargin(end) = []; end end % extract faces and edges if length(varargin) == 1 faces = varargin{1}; else faces = varargin{2}; end %% Initialisations % number of faces nNodes = size(nodes, 1); nFaces = size(faces, 1); % compute number of vertices of each face Fn = ones(nFaces, 1) * size(faces, 2); % compute normal of each faces normals = meshFaceNormals(nodes, faces); % initialize empty faces and edges faces2 = cell(0, 1); edges2 = zeros(0, 2); % Processing flag for each face % 1: face to process, 0: already processed % in the beginning, every triangle face need to be processed flag = ones(nFaces, 1); %% Main iteration % iterate on each face for iFace = 1:nFaces % check if face was already performed if ~flag(iFace) continue; end % indices of faces with same normal ind = find(vectorNorm3d(crossProduct3d(normals(iFace, :), normals)) < acc); % keep only coplanar faces (test coplanarity of points in both face) ind2 = false(size(ind)); for j = 1:length(ind) ind2(j) = isCoplanar(nodes([faces(iFace,:) faces(ind(j),:)], :), acc); end ind2 = ind(ind2); % compute edges of all faces in the plane planeEdges = zeros(sum(Fn(ind2)), 2); pos = 1; for i = 1:length(ind2) face = faces(ind2(i), :); faceEdges = sort([face' face([2:end 1])'], 2); planeEdges(pos:sum(Fn(ind2(1:i))), :) = faceEdges; pos = sum(Fn(ind2(1:i)))+1; end planeEdges = unique(planeEdges, 'rows'); % relabel plane edges [planeNodes, I, J] = unique(planeEdges(:)); %#ok planeEdges2 = reshape(J, size(planeEdges)); % The set of coplanar faces may not necessarily form a single connected % component. The following computes label of each connected component. component = grLabel(nodes(planeNodes, :), planeEdges2); % compute degree (number of adjacent faces) of each edge. Npe = size(planeEdges, 1); edgeDegrees = zeros(Npe, 1); for i = 1:length(ind2) face = faces(ind2(i), :); faceEdges = sort([face' face([2:end 1])'], 2); for j = 1:size(faceEdges, 1) indEdge = find(sum(ismember(planeEdges, faceEdges(j,:)),2)==2); edgeDegrees(indEdge) = edgeDegrees(indEdge)+1; end end % extract unique edges and nodes of the plane planeEdges = planeEdges(edgeDegrees==1, :); planeEdges2 = planeEdges2(edgeDegrees==1, :); % find connected component of each edge planeEdgesComp = zeros(size(planeEdges, 1), 1); for iEdge = 1:size(planeEdges, 1) planeEdgesComp(iEdge) = component(planeEdges2(iEdge, 1)); end % iterate on connected faces for c = 1:max(component) % convert to chains of nodes loops = graph2Contours(nodes, planeEdges(planeEdgesComp==c, :)); % add a simple Polygon for each loop facePolygon = loops{1}; for l = 2:length(loops) facePolygon = [facePolygon, NaN, loops{l}]; %#ok end faces2{length(faces2)+1, 1} = facePolygon; % also add news edges edges2 = unique([edges2; planeEdges], 'rows'); end % mark processed faces flag(ind2) = 0; end %% Additional processing on nodes % select only nodes which appear in at least one edge indNodes = unique(edges2(:)); % for each node, compute index of corresponding new node (or 0 if dropped) refNodes = zeros(nNodes, 1); for i = 1:length(indNodes) refNodes(indNodes(i)) = i; end % changes indices of nodes in edges2 array for i = 1:length(edges2(:)) edges2(i) = refNodes(edges2(i)); end % changes indices of nodes in faces2 array for iFace = 1:length(faces2) face = faces2{iFace}; for i = 1:length(face) if ~isnan(face(i)) face(i) = refNodes(face(i)); end end faces2{iFace} = face; end % keep only boundary nodes nodes2 = nodes(indNodes, :); %% Process output arguments if nargout == 1 varargout{1} = faces2; elseif nargout == 2 varargout{1} = nodes2; varargout{2} = faces2; elseif nargout == 3 varargout{1} = nodes2; varargout{2} = edges2; varargout{3} = faces2; end function labels = grLabel(nodes, edges) %GRLABEL associate a label to each connected component of the graph % LABELS = grLabel(NODES, EDGES) % Returns an array with as many rows as the array NODES, containing index % number of each connected component of the graph. If the graph is % totally connected, returns an array of 1. % % Example % nodes = rand(6, 2); % edges = [1 2;1 3;4 6]; % labels = grLabel(nodes, edges); % labels = % 1 % 1 % 1 % 2 % 3 % 2 % % See also % getNeighbourNodes % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-08-14, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % init nNodes = size(nodes, 1); labels = (1:nNodes)'; % iteration modif = true; while modif modif = false; for i=1:nNodes neigh = getNeighbourNodes(i, edges); neighLabels = labels([i;neigh]); % check for a modification if length(unique(neighLabels))>1 modif = true; end % put new labels labels(ismember(labels, neighLabels)) = min(neighLabels); end end % change to have fewer labels labels2 = unique(labels); for i = 1:length(labels2) labels(labels==labels2(i)) = i; end function nodes2 = getNeighbourNodes(node, edges) %GETNEIGHBOURNODES find nodes adjacent to a given node % % NEIGHS = getNeighbourNodes(NODE, EDGES) % NODE: index of the node % EDGES: the complete edges list % NEIGHS: the nodes adjacent to the given node. % % NODE can also be a vector of node indices, in this case the result is % the set of neighbors of any input node. % % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 16/08/2004. % % HISTORY % 10/02/2004 documentation % 13/07/2004 faster algorithm % 03/10/2007 can specify several input nodes [i, j] = find(ismember(edges, node)); %#ok nodes2 = edges(i,1:2); nodes2 = unique(nodes2(:)); nodes2 = sort(nodes2(~ismember(nodes2, node))); function curves = graph2Contours(nodes, edges) %#ok %GRAPH2CONTOURS convert a graph to a set of contour curves % % CONTOURS = GRAPH2CONTOURS(NODES, EDGES) % NODES, EDGES is a graph representation (type "help graph" for details) % The algorithm assume every node has degree 2, and the set of edges % forms only closed loops. The result is a list of indices arrays, each % array containing consecutive point indices of a contour. % % To transform contours into drawable curves, please use : % CURVES{i} = NODES(CONTOURS{i}, :); % % % NOTE : contours are not oriented. To manage contour orientation, edges % also need to be oriented. So we must precise generation of edges. % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 05/08/2004. % curves = {}; c = 0; while size(edges,1)>0 % find first point of the curve n0 = edges(1,1); curve = n0; % second point of the curve n = edges(1,2); e = 1; while true % add current point to the curve curve = [curve n]; %#ok % remove current edge from the list edges = edges((1:size(edges,1))~=e,:); % find index of edge containing reference to current node e = find(edges(:,1)==n | edges(:,2)==n); e = e(1); % get index of next current node % (this is the other node of the current edge) if edges(e,1)==n n = edges(e,2); else n = edges(e,1); end % if node is same as start node, loop is closed, and we stop % node iteration. if n==n0 break; end end % remove the last edge of the curve from edge list. edges = edges((1:size(edges,1))~=e,:); % add the current curve to the list, and start a new curve c = c+1; curves{c} = curve; %#ok end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createTetrahedron.m0000644000000000000000000000013214055375162021240 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createTetrahedron.m0000644000175000017500000000570514055375162022334 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createTetrahedron() %CREATETETRAHEDRON Create a 3D mesh representing a tetrahedron. % % [V, E, F] = createTetrahedron % create a simple tetrahedron, using mesh representation. The tetrahedron % is inscribed in the unit cube. % V is a 4-by-3 array with vertex coordinates, % E is a 6-by-2 array containing indices of neighbour vertices, % F is a 4-by-3 array containing vertices array of each (triangular) face. % % [V, F] = createTetrahedron; % Returns only the vertices and the faces. % % MESH = createTetrahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % % Example % % Create and display a tetrahedron % [V, E, F] = createTetrahedron; % drawMesh(V, F); % % See also % meshes3d, drawMesh % createCube, createOctahedron, createDodecahedron, createIcosahedron % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 21/03/2005. % % HISTORY % 04/01/2007: remove unused variables x0 = 0; dx= 1; y0 = 0; dy= 1; z0 = 0; dz= 1; nodes = [... x0 y0 z0; ... x0+dx y0+dy z0; ... x0+dx y0 z0+dz; ... x0 y0+dy z0+dz]; edges = [1 2;1 3;1 4;2 3;3 4;4 2]; faces = [1 2 3;1 3 4;1 4 2;4 3 2]; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/triangulatePolygonPair.m0000644000000000000000000000013214055375162022300 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/triangulatePolygonPair.m0000644000175000017500000001263514055375162023374 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, faces] = triangulatePolygonPair(poly1, poly2, varargin) % Compute triangulation between a pair of 3D closed curves. % % [V, F] = triangulatePolygonPair(POLY1, POLY2) % % [V, F] = triangulatePolygonPair(..., 'recenter', FLAG) % Where FLAG is a boolean, specifies whether the second curve should be % translated to have the same centroid as the first curve. This can % improve mathcing of vertices. Default is true. % % % Example % % triangulate a surface patch between two ellipses % % create two sample curves % poly1 = ellipseToPolygon([50 50 40 20 0], 36); % poly2 = ellipseToPolygon([50 50 40 20 60], 36); % poly1 = poly1(1:end-1,:); % poly2 = poly2(1:end-1,:); % % transform to 3D polygons / curves % curve1 = [poly1 10*ones(size(poly1, 1), 1)]; % curve2 = [poly2 20*ones(size(poly2, 1), 1)]; % % draw as 3D curves % figure(1); clf; hold on; % drawPolygon3d(curve1, 'b'); drawPoint3d(curve1, 'bo'); % drawPolygon3d(curve2, 'g'); drawPoint3d(curve2, 'go'); % view(3); axis equal; % [vertices, faces] = triangulatePolygonPair(curve1, curve2); % % display the resulting mesh % figure(2); clf; hold on; % drawMesh(vertices, faces); % drawPolygon3d(curve1, 'color', 'b', 'linewidth', 2); % drawPolygon3d(curve2, 'color', 'g', 'linewidth', 2); % view(3); axis equal; % % See also % meshes3D, triangulateCurvePair, meshSurfaceArea % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-05-18, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. %% Settings recenterFlag = true; while length(varargin) > 1 pname = varargin{1}; if strcmpi(pname, 'recenter') recenterFlag = varargin{2}; else error('Unknown parameter name: %s', pname); end varargin(1:2) = []; end %% Memory allocation % concatenate vertex coordinates for creating mesh vertices = [poly1 ; poly2]; % number of vertices on each polygon n1 = size(poly1, 1); n2 = size(poly2, 1); % allocate the array of facets (each edge of each polygon provides a facet) nFaces = n1 + n2; faces = zeros(nFaces, 3); % Translate the second polygon such that the centroids of the bounding % boxes coincide. This is expected to improve the matching of the two % curves. if recenterFlag box1 = boundingBox3d(poly1); box2 = boundingBox3d(poly2); center1 = (box1(2:2:end) + box1(1:2:end-1)) / 2; center2 = (box2(2:2:end) + box2(1:2:end-1)) / 2; vecTrans = center1 - center2; trans = createTranslation3d(vecTrans); poly2 = transformPoint3d(poly2, trans); end %% Init iteration % find the pair of points with smallest distance. % This will be the current diagonal. [dists, inds] = minDistancePoints(poly1, poly2); [dummy, ind1] = min(dists); %#ok ind2 = inds(ind1); % consider two consecutive vertices on each polygon currentIndex1 = ind1; currentIndex2 = ind2; %% Main iteration % For each diagonal, consider the two possible facets (one for each 'next' % vertex on each polygon), each create current facet according to the % closest one. % Then update current diagonal for next iteration. for iFace = 1:nFaces nextIndex1 = mod(currentIndex1, n1) + 1; nextIndex2 = mod(currentIndex2, n2) + 1; % compute lengths of diagonals dist1 = distancePoints(poly1(currentIndex1, :), poly2(nextIndex2,:)); dist2 = distancePoints(poly1(nextIndex1, :), poly2(currentIndex2,:)); if dist1 < dist2 % keep current vertex of curve1, use next vertex on curve2 face = [currentIndex1 currentIndex2+n1 nextIndex2+n1]; currentIndex2 = nextIndex2; else % keep current vertex of curve2, use next vertex on curve1 face = [currentIndex1 currentIndex2+n1 nextIndex1]; currentIndex1 = nextIndex1; end % create the facet faces(iFace, :) = face; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshVertexNormals.m0000644000000000000000000000013214055375162021263 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshVertexNormals.m0000644000175000017500000000620114055375162022347 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [normals, faceNormals] = meshVertexNormals(varargin) %MESHVERTEXNORMALS Compute normals to a mesh vertices. % % N = meshVertexNormals(V, F) % Computes vertex normals of the mesh given by vertices V and F. % V is a vertex array with 3 columns, F is either a NF-by-3 or NF-by-4 % index array, or a cell array with NF elements. % % Example % % Draw the vertex normals of a sphere % s = [10 20 30 20]; % [v f] = sphereMesh(s); % figure; drawMesh(v, f); % view(3);axis equal; light; lighting gouraud; % normals = meshVertexNormals(v, f); % drawVector3d(v, normals*2); % % See also % meshes3d, meshFaceNormals, triangulateFaces % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-19, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. [vertices, faces] = parseMeshData(varargin{:}); nv = size(vertices, 1); nf = size(faces, 1); % unit normals to the faces faceNormals = normalizeVector3d(meshFaceNormals(vertices, faces)); % compute normal of each vertex: sum of normals to each face normals = zeros(nv, 3); if isnumeric(faces) for i = 1:nf face = faces(i, :); for j = 1:length(face) v = face(j); normals(v, :) = normals(v,:) + faceNormals(i,:); end end else for i = 1:nf face = faces{i}; for j = 1:length(face) v = face(j); normals(v, :) = normals(v,:) + faceNormals(i,:); end end end % normalize vertex normals to unit vectors normals = normalizeVector3d(normals); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/writeMesh_stl.m0000644000000000000000000000013214055375162020426 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/writeMesh_stl.m0000644000175000017500000000506214055375162021516 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function writeMesh_stl(fileName, vertices, faces, varargin) %WRITEMESH_STL Write mesh data in the STL format. % % writeMesh_stl(FNAME, VERTICES, FACES) % % writeMesh_stl(FNAME, MESH) % % writeMesh_stl(FNAME, VERTICES, FACES, ...) see stlwrite for additonal % options % % Example % mesh = cylinderMesh([60 50 40 10 20 30 5], 1); % writeMesh_stl('Cylinder.stl', mesh, 'bin'); % % References % Wrapper function for MATLAB's build-in stlwrite. % % See also % meshes3d, writeMesh, writeMesh_off, writeMesh_ply % ------ % Author: oqilipo % Created: 2021-02-13, using Matlab 9.9.0.1538559 (R2020b) % Copyright 2021 %% Check inputs if ~ischar(fileName) error('First argument must contain the name of the file'); end % optionnaly parses data if isstruct(vertices) if nargin > 2 varargin = [{faces} varargin{:}]; end faces = vertices.faces; vertices = vertices.vertices; end %% Write STL TR = triangulation(faces, vertices); stlwrite(TR,fileName, varargin{:}) end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/intersectPlaneMesh.m0000644000000000000000000000013214055375162021372 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/intersectPlaneMesh.m0000644000175000017500000001476214055375162022471 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polys = intersectPlaneMesh(plane, v, f) % Compute the polygons resulting from plane-mesh intersection. % % POLYS = intersectPlaneMesh(P, V, F) % Computes the interection between a plane and a mesh given by vertex and % face lists. The result is a cell array of polygons. % % The function currently returns at most one polygon in the cell array % POLYS. % % % Example % % Intersect a cube by a plane % [v f] = createCube; v = v * 10; % plane = createPlane([5 5 5], [3 4 5]); % % draw the primitives % figure; hold on; set(gcf, 'renderer', 'opengl'); % axis([-10 20 -10 20 -10 20]); view(3); % drawMesh(v, f); drawPlane3d(plane); % % compute intersection polygon % polys = intersectPlaneMesh(plane, v, f); % drawPolygon3d(polys, 'LineWidth', 2); % % % Intersect a torus by a set of planes, and draw the results % % first creates a torus slightly shifted and rotated % torus = [.5 .6 .7 30 10 3 4]; % figure; drawTorus(torus, 'nTheta', 180, 'nPhi', 180); % hold on; view (3); axis equal; light; % % convert to mesh representation % [v, f] = torusMesh(torus, 'nTheta', 64, 'nPhi', 64); % % compute intersections with collection of planes % xList = -50:5:50; % polySet = cell(length(xList), 1); % for i = 1:length(xList) % x0 = xList(i); % plane = createPlane([x0 .5 .5], [1 .2 .3]); % polySet{i} = intersectPlaneMesh2(plane, v, f); % end % % draw the resulting 3D polygons % drawPolygon3d(polySet, 'lineWidth', 2, 'color', 'k') % % % See also % meshes3d, intersectPlanes, intersectEdgePlane % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-07-31, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. e = []; if isstruct(v) f = v.faces; if isfield(v, 'edges') e = v.edges; end v = v.vertices; end %% Computation of crossing edges % compute the edge list if isempty(e) e = meshEdges(f); end edges = [ v(e(:,1), :) v(e(:,2), :) ]; % identify which edges cross the mesh inds = isBelowPlane(v, plane); edgeCrossInds = find(sum(inds(e), 2) == 1); % compute one intersection point for each edge intersectionPoints = intersectEdgePlane(edges(edgeCrossInds, :), plane); %% mapping edges <-> faces % identify for each face the indices of edges that intersect the plane, as % well as for each edge, the indices of the two faces around it. % We expect each face to contain either 0 or 2 intersecting edges. % nFaces = length(f); faceEdges = cell(1, nFaces); nCrossEdges = length(edgeCrossInds); crossEdgeFaces = zeros(nCrossEdges, 2); for iEdge = 1:length(edgeCrossInds) edge = e(edgeCrossInds(iEdge), :); indFaces = find(sum(ismember(f, edge), 2) == 2); if length(indFaces) ~= 2 error('crossing edge %d (%d,%d) is associated to %d faces', ... iEdge, edge(1), edge(2), length(indFaces)); end crossEdgeFaces(iEdge, :) = indFaces; for iFace = 1:length(indFaces) indEdges = faceEdges{indFaces(iFace)}; indEdges = [indEdges iEdge]; %#ok faceEdges{indFaces(iFace)} = indEdges; end end %% Iterate on edges and faces to form polygons % initialize an array indicating which indices need to be processed nCrossEdges = length(edgeCrossInds); remainingCrossEdges = true(nCrossEdges, 1); % create empty cell array of polygons polys = {}; % iterate while there are some crossing edges to process while any(remainingCrossEdges) % start at any edge, mark it as current startEdgeIndex = find(remainingCrossEdges, 1, 'first'); currentEdgeIndex = startEdgeIndex; % mark current edge as processed remainingCrossEdges(currentEdgeIndex) = false; % initialize new set of edge indices polyEdgeInds = currentEdgeIndex; % choose one of the two faces around the edge currentFace = crossEdgeFaces(currentEdgeIndex, 1); % iterate along current face-edge couples until back to first edge while true % find the index of next crossing edge inds = faceEdges{currentFace}; currentEdgeIndex = inds(inds ~= currentEdgeIndex); % mark current edge as processed remainingCrossEdges(currentEdgeIndex) = false; % find the index of the other face containing current edge inds = crossEdgeFaces(currentEdgeIndex, :); currentFace = inds(inds ~= currentFace); % check end of current loop if currentEdgeIndex == startEdgeIndex break; end % add index of current edge polyEdgeInds = [polyEdgeInds currentEdgeIndex]; %#ok end % create polygon, and add it to list of polygons poly = intersectionPoints(polyEdgeInds, :); polys = [polys, {poly}]; %#ok end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFacePolygons.m0000644000000000000000000000013214055375162021043 xustar0030 mtime=1622538866.086813538 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFacePolygons.m0000644000175000017500000000514114055375162022131 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polys = meshFacePolygons(varargin) %MESHFACEPOLYGONS Returns the set of polygons that constitutes a mesh. % % POLYGONS = meshFacePolygons(V, F) % POLYGONS = meshFacePolygons(MESH) % % Example % [v f] = createCubeOctahedron; % polygons = meshFacePolygons(v, f); % areas = polygonArea3d(polygons); % sum(areas) % ans = % 18.9282 % % See also % meshes3d, meshFace, polygonArea3d % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-08-20, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % extract vertices and faces [v, f] = parseMeshData(varargin{:}); % number of faces if iscell(f) nFaces = length(f); else nFaces = size(f, 1); end % allocate cell array for result polys = cell(nFaces, 1); % compute polygon corresponding to each face if iscell(f) for i = 1:nFaces polys{i} = v(f{i}, :); end else for i = 1:nFaces polys{i} = v(f(i,:), :); end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/intersectEdgeMesh3d.m0000644000000000000000000000013214055375162021426 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.086813538 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/intersectEdgeMesh3d.m0000644000175000017500000000553414055375162022522 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [points, pos, faceInds] = intersectEdgeMesh3d(edge, varargin) % Intersection points of a 3D edge with a mesh. % % INTERS = intersectEdgeMesh3d(EDGE, VERTICES, FACES) % Compute the intersection points between a 3D edge and a 3D mesh defined % by vertices and faces. % % [INTERS, POS, INDS] = intersectEdgeMesh3d(EDGE, VERTICES, FACES) % Also returns the position of each intersection point on the input edge, % and the index of the intersected faces. % For edges, the values of POS are expected to be comprised between 0 and % 1. % % Example % [V, F] = createCube; % edge = [-1 0.5 0.5 +3 0.5 0.5]; % pts = intersectEdgeMesh3d(edge, V, F) % pts = % 1.0000 0.5000 0.5000 % 0 0.5000 0.5000 % % See also % meshes3d, interesectLineMesh3d, triangulateFaces % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2021-02-24, using Matlab 9.9.0.1570001 (R2020b) Update 4 % Copyright 2021 INRA - Cepia Software Platform. % perform computation on supporting line line = edgeToLine3d(edge); [points, pos, faceInds] = intersectLineMesh3d(line, varargin{:}); % identifies intersection points within parameterization bounds inds = pos >= 0 & pos <= 1; % select relevant results points = points(inds, :); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFaceAdjacency.m0000644000000000000000000000013214055375162021112 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFaceAdjacency.m0000644000175000017500000000524614055375162022206 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function adjList = meshFaceAdjacency(vertices, edges, faces) %MESHFACEADJACENCY Compute adjacency list of face around each face. % % % Example % % Create a sample 3D mesh % [v, e, f] = createDodecahedron; % adjList = meshFaceAdjacency(v, e, f); % figure; hold on; axis equal; view([100 40]); % drawMesh(v, f); % % draw sample face in a different color % drawMesh(v, f(1, :), 'faceColor', 'b'); % % draw the neighbors of a sample face % drawMesh(v, f(adjList{1}, :), 'faceColor', 'g') % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. edgeFaceList = meshEdgeFaces(vertices, edges, faces); % allocate memory for adjacency list nFaces = max(edgeFaceList(:)); adjList = cell(1, nFaces); % iterate over edges to populate adjacency list for iEdge = 1:size(edgeFaceList) f1 = edgeFaceList(iEdge, 1); f2 = edgeFaceList(iEdge, 2); adjList{f1} = [adjList{f1} f2]; adjList{f2} = [adjList{f2} f1]; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/removeMeshFaces.m0000644000000000000000000000013214055375162020651 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/removeMeshFaces.m0000644000175000017500000000700514055375162021740 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = removeMeshFaces(v, f, fI) %REMOVEMESHFACES Remove faces from a mesh by face indices. % [V2, F2] = removeMeshFaces(V, F, FI) removes faces from the mesh by % the face indices FI into faces F of the mesh. The mesh is represented % by the vertex array V and the face array F. The result is the new set % of vertices V2 and faces F2 without the faces indexed by FI. FI can be % either a linear or a logical index. % % [V2, F2] = removeMeshFaces(MESH, FI) with the struct MESH containing % the fields "vertices" (V) and "faces" (F) % % MESH2 = removeMeshFaces(V, F, FI) with the struct MESH2 containing the % fields "vertices" (V2) and "faces" (F2) % % MESH2 = removeMeshFaces(MESH, FI) with the structs MESH and MESH2 % containing the fields "vertices" (V, V2) and "faces" (F, F2) % % Example % [v, f] = createSoccerBall; % f = triangulateFaces(f); % fI = true(length(f),1); % fI(1:length(f)/2) = false; % [v2, f2] = removeMeshFaces(v, f, fI); % drawMesh(v, f, 'faceColor', 'none', 'faceAlpha', .2); % drawMesh(v2, f2, 'faceAlpha', .7); % view(3); axis equal % % See also % meshes3d, drawMesh % % --------- % Authors: oqilipo, David Legland % Created: 2017-07-04 % parse inputs narginchk(2,3) nargoutchk(1,2) if nargin == 2 fI = f; [v, f] = parseMeshData(v); end p = inputParser; isIndexToFaces = @(x) ... (islogical(x) && isequal(length(x), size(f,1))) || ... (all(floor(x)==x) && min(x)>=1 && max(x)<=size(f,1)); addRequired(p,'fI',isIndexToFaces) parse(p, fI); if ~islogical(p.Results.fI) fI=false(size(f,1),1); fI(p.Results.fI)=true; else fI=p.Results.fI; end % algorithm f2 = f(~fI,:); [unqVertIds, ~, newVertIndices] = unique(f2); v2 = v(unqVertIds,:); f2 = reshape(newVertIndices,size(f2)); % parse outputs if nargout == 1 mesh2.vertices=v2; mesh2.faces=f2; varargout{1}=mesh2; else varargout{1}=v2; varargout{2}=f2; end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshVertexClustering.m0000644000000000000000000000013214055375162021767 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshVertexClustering.m0000644000175000017500000001112414055375162023053 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = meshVertexClustering(vertices, faces, spacing, varargin) %MESHVERTEXCLUSTERING Simplifies a mesh using vertex clustering. % % [V2, F2] = meshVertexClustering(V, F, SPACING) % [V2, F2] = meshVertexClustering(MESH, SPACING) % MESH2 = meshVertexClustering(...) % % Simplifies a mesh using vertex clustering. Input mesh is specified % either by a pair V, F containing the vertex coordinates and the faces % informations, or by a structure with fields 'vertices' and 'faces'. % % The SPACING input defines the size of the grid. It can be either a % scalar (uniform grid) or a 1-by-3 row vector. % % The output is specified either in two outputs, or in a structure with % fields 'vertices' and 'faces'. % % Example % [x, y, z] = meshgrid(1:100, 1:100, 1:100); % img = hypot3(x-51.12, y-52.23, z-53.34); % [faces, vertices] = isosurface(img, 45); % [v2, f2] = meshVertexClustering(vertices, faces, 10); % figure; axis equal; axis([0 100 0 100 0 100]); % drawMesh(v2, f2); % % See also % reducepatch, smoothMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-28, using Matlab 9.5.0.944444 (R2018b) % Copyright 2019 INRA - Cepia Software Platform. %% Initialisation if isstruct(vertices) if nargin > 2 varargin = [{spacing} varargin(:)]; end spacing = faces; mesh = vertices; vertices = mesh.vertices; faces = mesh.faces; end % ensure input mesh is a triangulation faces = triangulateFaces(faces); % ensure spacing is a 1-by-3 array if isscalar(spacing) spacing = [spacing spacing spacing]; end % extract grid origin origin = [0 0 0]; if ~isempty(varargin) origin = varargin{1}; end %% Apply grid simplification % identify the vertices belonging to the same grid [v2, I, J] = unique(round(bsxfun(@rdivide, bsxfun(@minus, vertices, origin), spacing)), 'rows'); %% compute reduced vertex coordinates % compute coordinates of new vertices for iVertex = 1:length(I) gridVertices = vertices(J == iVertex, :); v2(iVertex, :) = mean(gridVertices, 1); end %% Compute new faces % create empty array faces2 = zeros(0, 3); % iterate over old faces, and keep only faces whose vertices belong to % different cell grids nFaces = size(faces, 1); for iFace = 1:nFaces % current face face = faces(iFace, :); % equivalent face with new vertices face2 = J(face)'; % some vertices may belong to same cell, so we need to adjust % processing nInds = length(unique(face2)); if nInds == 3 % vertices belong to three different cells -> create a new face % keep smaller vertex at first position [tmp, indMin] = min(face2); %#ok face2 = circshift(face2, [1-indMin 0]); % append the new face to the array faces2 = [faces2 ; face2]; %#ok end end % remove duplicate faces faces2 = unique(faces2, 'rows'); if nargout == 1 varargout{1} = struct('vertices', v2, 'faces', faces2); else varargout = {v2, faces2}; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createSoccerBall.m0000644000000000000000000000013214055375162020772 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createSoccerBall.m0000644000175000017500000000525714055375162022070 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createSoccerBall() %CREATESOCCERBALL Create a 3D mesh representing a soccer ball. % % It is basically a wrapper of the 'bucky' function in matlab. % [V, E, F] = createSoccerBall % return vertices, edges and faces that constitute a soccerball % V is a 60-by-3 array containing vertex coordinates % E is a 90-by-2 array containing indices of neighbor vertices % F is a 32-by-1 cell array containing vertex indices of each face % Example % [v, f] = createSoccerBall; % drawMesh(v, f); % % See also % meshes, drawMesh, bucky % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-08-09 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 2007-01-04 remove unused variables, enhance output processing % 2010-12-07 clean up edges, uses formatMeshOutput % get vertices and adjacency matrix of the buckyball [b, n] = bucky; % compute edges [i, j] = find(b); e = [i j]; e = unique(sort(e, 2), 'rows'); % compute polygons that correspond to each 3D face f = minConvexHull(n)'; % format output varargout = formatMeshOutput(nargout, n, e, f); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshEdgeFaces.m0000644000000000000000000000013214055375162020260 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshEdgeFaces.m0000644000175000017500000001164614055375162021355 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edgeFaces = meshEdgeFaces(vertices, edges, faces) %#ok %MESHEDGEFACES Compute index of faces adjacent to each edge of a mesh. % % EF = meshEdgeFaces(V, E, F) % Compute index array of faces adjacent to each edge of a mesh. % V, E and F define the mesh: V is vertex array, E contains vertex % indices of edge extremities, and F contains vertex indices of each % face, either as a numerical array or as a cell array. % The result EF has as many rows as the number of edges, and two column. % The first column contains index of faces located on the left of the % corresponding edge, whereas the second column contains index of the % face located on the right. Some indices may be 0 if the mesh is not % 'closed'. % % Note: a faster version is available for triangular meshes. % % Example % meshEdgeFaces % % See also % meshes3d, trimeshEdgeFaces, meshDihedralAngles, polyhedronMeanBreadth % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. Ne = size(edges, 1); % indices of faces adjacent to each edge edgeFaces = zeros(Ne, 2); % different method for extracting current face depending if faces are % stored as index 2D array or as cell array of 1D arrays. if isnumeric(faces) Nf = size(faces, 1); for i = 1:Nf face = faces(i, :); processFace(face, i) end elseif iscell(faces) Nf = length(faces); for i = 1:Nf face = faces{i}; processFace(face, i) end end function processFace(face, indFace) % iterate on face edges for j = 1:length(face) % build edge: array of vertices j2 = mod(j, length(face)) + 1; % do not process edges with same vertices if face(j) == face(j2) continue; end % vertex indices of current edge currentEdge = [face(j) face(j2)]; % find index of current edge, assuming face is left-located b1 = ismember(edges, currentEdge, 'rows'); indEdge = find(b1); if ~isempty(indEdge) if edgeFaces(indEdge, 1) ~= 0 error('meshes3d:IllegalTopology', ... 'Two faces were found on left side of edge %d ', indEdge); end edgeFaces(indEdge, 1) = indFace; continue; end % otherwise, assume the face is right-located b2 = ismember(edges, currentEdge([2 1]), 'rows'); indEdge = find(b2); if ~isempty(indEdge) if edgeFaces(indEdge, 2) ~= 0 error('meshes3d:IllegalTopology', ... 'Two faces were found on left side of edge %d ', indEdge); end edgeFaces(indEdge, 2) = indFace; continue; end % If face was neither left nor right, error warning('meshes3d:IllegalTopology', ... 'Edge %d of face %d was not found in edge array', ... j, indFace); continue; end end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/intersectLineMesh3d.m0000644000000000000000000000013214055375162021451 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/intersectLineMesh3d.m0000644000175000017500000001140714055375162022541 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [points, pos, faceInds] = intersectLineMesh3d(line, vertices, varargin) % Intersection points of a 3D line with a mesh. % % INTERS = intersectLineMesh3d(LINE, VERTICES, FACES) % Compute the intersection points between a 3D line and a 3D mesh defined % by vertices and faces. % % [INTERS, POS, INDS] = intersectLineMesh3d(LINE, VERTICES, FACES) % Also returns the position of each intersection point on the input line, % and the index of the intersected faces. % If POS > 0, the point is also on the ray corresponding to the line. % % Example % [V, F] = createCube; % line = [.2 .3 .4 1 0 0]; % pts = intersectLineMesh3d(line, V, F) % pts = % 1.0000 0.3000 0.4000 % 0 0.3000 0.4000 % % See also % meshes3d, triangulateFaces, intersectLineTriangle3d % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-12-20, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % tolerance for detecting if a point is on line or within edge bounds tol = 1e-12; % parsing if ~isempty(varargin) if isscalar(varargin{1}) tol = varargin{1}; [vertices, faces] = parseMeshData(vertices); else faces = varargin{1}; varargin(1) = []; if ~isempty(varargin) tol = varargin{1}; end end else [vertices, faces] = parseMeshData(vertices); end % ensure the mesh has triangular faces tri2Face = []; if iscell(faces) || size(faces, 2) ~= 3 [faces, tri2Face] = triangulateFaces(faces); end % find triangle edge vectors t0 = vertices(faces(:,1), :); u = vertices(faces(:,2), :) - t0; v = vertices(faces(:,3), :) - t0; % triangle normal n = normalizeVector3d(crossProduct3d(u, v)); % direction vector of line dv = line(4:6); % vector between triangle origin and line origin w0 = bsxfun(@minus, line(1:3), t0); a = -dot(n, w0, 2); b = dot(n, repmat(dv, size(n, 1), 1), 2); valid = abs(b) > tol & vectorNorm3d(n) > tol; % compute intersection point of line with supporting plane % If pos < 0: point before ray % IF pos > |dir|: point after edge pos = a ./ b; % coordinates of intersection point points = bsxfun(@plus, line(1:3), bsxfun(@times, pos, dv)); %% test if intersection point is inside triangle % normalize direction vectors of triangle edges uu = dot(u, u, 2); uv = dot(u, v, 2); vv = dot(v, v, 2); % coordinates of vector v in triangle basis w = points - t0; wu = dot(w, u, 2); wv = dot(w, v, 2); % normalization constant D = uv.^2 - uu .* vv; % test first coordinate s = (uv .* wv - vv .* wu) ./ D; ind1 = s < -tol | s > (1.0 + tol); points(ind1, :) = NaN; pos(ind1) = NaN; % test second coordinate, and third triangle edge t = (uv .* wu - uu .* wv) ./ D; ind2 = t < -tol | (s + t) > (1.0 + tol); points(ind2, :) = NaN; pos(ind2) = NaN; % keep only interesting points inds = ~ind1 & ~ind2 & valid; points = points(inds, :); if nargout > 1 pos = pos(inds); faceInds = find(inds); % convert to face indices of original mesh if ~isempty(tri2Face) faceInds = tri2Face(faceInds); end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/steinerPolytope.m0000644000000000000000000000013214055375162021002 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/steinerPolytope.m0000644000175000017500000000645714055375162022103 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, faces] = steinerPolytope(vectors) %STEINERPOLYTOPE Create a steiner polytope from a set of vectors. % % [VERTICES FACES] = steinerPolygon(VECTORS) % Creates the Steiner polytope defined by the set of vectors VECTORS. % % Example % % Creates and display a planar Steiner polytope (ie, a polygon) % [v f] = steinerPolytope([1 0;0 1;1 1]); % fillPolygon(v); % % % Creates and display a 3D Steiner polytope % [v f] = steinerPolytope([1 0 0;0 1 0;0 0 1;1 1 1]); % drawMesh(v, f); % view(3); axis vis3d % % See also % meshes3d, drawMesh, steinerPolygon, mergeCoplanarFaces % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-04-28 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % History % 2013-02-22 merge coplanar faces, add management of 2D case, update doc % compute vectors dimension nd = size(vectors, 2); % create candidate vertices vertices = zeros(1, size(vectors, 2)); for i = 1:length(vectors) nv = size(vertices, 1); vertices = [vertices; vertices+repmat(vectors(i,:), [nv 1])]; %#ok end if nd == 2 % for planar case, use specific function convhull K = convhull(vertices(:,1), vertices(:,2)); vertices = vertices(K, :); faces = 1:length(K); else % Process the general case (tested only for nd==3) % compute convex hull K = convhulln(vertices); % keep only relevant points, and update faces indices ind = unique(K); for i = 1:length(ind) K(K==ind(i)) = i; end % return results vertices = vertices(ind, :); faces = K; % in case of 3D meshes, merge coplanar faces if nd == 3 faces = mergeCoplanarFaces(vertices, faces); end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/writeMesh_ply.m0000644000000000000000000000013214055375162020430 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/writeMesh_ply.m0000644000175000017500000001262314055375162021521 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function writeMesh_ply(fileName, vertices, faces, varargin) %WRITEMESH_PLY Write a mesh into a file in PLY format. % % writeMesh_ply(FNAME, VERTICES, FACES) % % writeMesh_ply(FNAME, MESH) % % writeMesh_ply(..., FORMAT) also specifies a file format for the written % file. FORMAT can be either 'binary' (default) or 'ascii'. % % Example % mesh = createSoccerBall; % fileName = 'SoccerBall.ply'; % writeMesh_ply(fileName, mesh, 'Bin'); % mesh2 = readMesh(fileName); % drawMesh(mesh2); axis equal % % See also % meshes3d, writeMesh, readMesh_ply, writeMesh_off, writeMesh_stl % ------ % Author: David Legland, oqilipo % e-mail: david.legland@inrae.fr % Created: 2018-04-26, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. %% Check inputs % optionnaly parses data if isstruct(vertices) if nargin > 2 varargin = [{faces} varargin{:}]; end faces = vertices.faces; vertices = vertices.vertices; end % Parsing p = inputParser; addRequired(p,'fileName',@(x) validateattributes(x,{'char'},{'nonempty'})); suppModes = {'ascii','binary_little_endian'}; addOptional(p,'mode','binary_little_endian',@(x) any(validatestring(x,suppModes))); parse(p,fileName,varargin{:}); fileName = p.Results.fileName; mode = suppModes{startsWith(suppModes, p.Results.mode, 'IgnoreCase',1)}; %% Initializations % number of vertices and faces nVertices = size(vertices, 1); nFaces = size(faces, 1); if iscell(faces) nFaces = length(faces); end % open file for writing text f = fopen(fileName, 'wt'); if (f == -1) error('Couldn''t open the file %s', fileName); end %% Write Header % write the header line fprintf(f, 'ply\n'); % write format (only ASCII supported) fprintf(f, 'format %s 1.0\n', mode); % some comments fprintf(f, 'comment Created by MatGeom for MATLAB\n'); % write declaration for vertices fprintf(f, 'element vertex %d\n', nVertices); fprintf(f, 'property double x\n'); fprintf(f, 'property double y\n'); fprintf(f, 'property double z\n'); % write declaration for faces fprintf(f, 'element face %d\n', nFaces); fprintf(f, 'property list int int vertex_index\n'); % end of header fprintf(f, 'end_header\n'); %% Write data switch mode case 'ascii' % write vertex info format = '%0.17f %0.17f %0.17f\n'; fprintf(f, format, vertices'); % write face info if isnumeric(faces) % simply write face vertex indices ns = size(faces, 2); plyFaces = [ns * ones(nFaces, 1) faces-1]; format = ['%d' repmat(' %d', 1, ns) '\n']; fprintf(f, format, plyFaces'); else % if faces are stored in a cell array, the number of vertices in each % face may be different, and we need to process each face individually for iFace = 1:nFaces ns = length(faces{iFace}); format = ['%d' repmat(' %d', 1, ns) '\n']; fprintf(f, format, ns, faces{iFace} - 1); end end case 'binary_little_endian' % close the file fclose(f); % open file with little-endian format f = fopen(fileName,'a','ieee-le'); % write vertex info fwrite(f, vertices', 'double'); % write face info if isnumeric(faces) % simply write face vertex indices plyFaces = [size(faces, 2) * ones(nFaces, 1) faces-1]; fwrite(f, plyFaces', 'int'); else % if faces are stored in a cell array, the number of vertices in each % face may be different, and we need to process each face individually for iFace = 1:nFaces fwrite(f, [length(faces{iFace}), faces{iFace}-1], 'int'); end end otherwise error(['Format ''' mode ''' is not supported']) end % close the file fclose(f); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/torusMesh.m0000644000000000000000000000013214055375162017566 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/torusMesh.m0000644000175000017500000000750314055375162020660 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = torusMesh(torus, varargin) %TORUSMESH Create a 3D mesh representing a torus. % % [V, F] = torusMesh(TORUS) % Converts the torus in TORUS into a face-vertex quadrangular mesh. % TORUS is given by [XC YC ZY R1 R2 THETA PHI] % where (XC YZ ZC) is the center of the torus, R1 is the main radius, R2 % is the radius of the torus section, and (THETA PHI) is the angle of the % torus normal vector (both in degrees). % % [V, F] = torusMesh(TORUS, 'nTheta', NT, 'nPhi', NP) % Creates a mesh using NP circles, each circle being discretized with NT % vertices. Default are 60 for both parameters. % % [V, F] = torusMesh() % Creates a mesh representing a default torus. % % Example % [v, f] = torusMesh([50 50 50 30 10 30 45]); % figure; drawMesh(v, f, 'linestyle', 'none'); % view(3); axis equal; % lighting gouraud; light; % % % See also % meshes3d, drawTorus, revolutionSurface, cylinderMesh, sphereMesh % drawMesh % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-10-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % HISTORY % 2013-04-30 add support for empty argument %% Extract data for torus if nargin == 0 torus = [0 0 0 30 10 0 0 0]; end center = torus(1:3); r1 = torus(4); r2 = torus(5); if size(torus, 2) >= 7 normal = torus(6:7); end %% Extract data for discretisation % number nTheta = 60; nPhi = 60; while length(varargin) > 1 argName = varargin{1}; switch lower(argName) case 'ntheta' nTheta = varargin{2}; case 'nphi' nPhi = varargin{2}; otherwise error('Unknown optional argument: %s', argName); end varargin(1:2) = []; end %% Discretize torus % create base torus circle = circleToPolygon([r1 0 r2], nTheta); [x, y, z] = revolutionSurface(circle, linspace(0, 2*pi, nPhi)); % transform torus trans = localToGlobal3d([center normal]); [x, y, z] = transformPoint3d(x, y, z, trans); % convert to FV mesh [vertices, faces] = surfToMesh(x, y, z, 'xPeriodic', true, 'yPeriodic', true); % format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/sphereMesh.m0000644000000000000000000000013214055375162017700 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/sphereMesh.m0000644000175000017500000000670614055375162020776 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = sphereMesh(sphere, varargin) % Create a 3D mesh representing a sphere. % % [V, F] = sphereMesh(S) % Creates a 3D mesh representing the sphere S given by [xc yc zy r]. % % [V, F] = sphereMesh(); % Assumes sphere is the unit sphere centered at the origin. % % [V, F] = sphereMesh(S, 'nTheta', NT, 'nPhi', NP); % Specifies the number of discretisation steps for the meridians and the % parallels. Default values are nTheta = 16 and nPhi = 32. % % % Example % s = [10 20 30 40]; % [v, f] = sphereMesh(s); % drawMesh(v, f); % view(3); axis equal; light; lighting gouraud; % % See also % meshes3d, drawSphere, ellipsoidMesh, cylinderMesh, surfToMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-10-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. if nargin == 0 sphere = [0 0 0 1]; end % number of meridians nPhi = 32; % number of parallels nTheta = 16; % process input arguments while length(varargin) > 1 paramName = varargin{1}; switch lower(paramName) case 'ntheta', nTheta = varargin{2}; case 'nphi', nPhi = varargin{2}; otherwise error(['Could not recognise parameter: ' paramName]); end varargin(1:2) = []; end % extract sphere data xc = sphere(:,1); yc = sphere(:,2); zc = sphere(:,3); r = sphere(:,4); % compute spherical coordinates theta = linspace(0, pi, nTheta+1); phi = linspace(0, 2*pi, nPhi+1); % convert to cartesian coordinates sintheta = sin(theta); x = xc + cos(phi') * sintheta * r; y = yc + sin(phi') * sintheta * r; z = zc + ones(length(phi),1) * cos(theta) * r; % convert to FV mesh [vertices, faces] = surfToMesh(x, y, z, 'yperiodic', true); % format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/subdivideMesh.m0000644000000000000000000000013214055375162020370 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/subdivideMesh.m0000644000175000017500000001557214055375162021467 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices2, faces2] = subdivideMesh(vertices, faces, n) %SUBDIVIDEMESH Subdivides each face of the mesh. % % [V2 F2] = subdivideMesh(V, F, N) % Subdivides the mesh specified by (V,F) such that each face F is divided % into N^2 smaller faces. % % Example % [v, f] = createOctahedron; % figure; drawMesh(v, f); view(3); % [v2, f2] = subdivideMesh(v, f, 4); % figure; drawMesh(v2, f2); view(3) % % See also % meshes3d, drawMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2013-08-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. %% Initialisations edges = []; faceEdgeIndices = []; if isstruct(vertices) % get relevant inputs mesh = vertices; n = faces; % parse fields from a mesh structure vertices = mesh.vertices; faces = mesh.faces; if isfield(mesh, 'edges') edges = mesh.edges; end if isfield(mesh, 'faceEdges') faceEdgeIndices = mesh.faceEdges; end end if ~isnumeric(faces) || size(faces, 2) ~= 3 error('Requires a triangular mesh'); end % compute the edge array if isempty(edges) edges = meshEdges(faces); end nEdges = size(edges, 1); % index of edges around each face if isempty(faceEdgeIndices) faceEdgeIndices = meshFaceEdges(vertices, edges, faces); end %% Create new vertices on edges % several interpolated positions t = linspace(0, 1, n + 1)'; coef2 = t(2:end-1); coef1 = 1 - t(2:end-1); % initialise the array of new vertices vertices2 = vertices; % keep an array containing index of new vertices for each original edge edgeNewVertexIndices = zeros(nEdges, n-1); % create new vertices on each edge for iEdge = 1:nEdges % extract each extremity as a point v1 = vertices(edges(iEdge, 1), :); v2 = vertices(edges(iEdge, 2), :); % compute new points newPoints = coef1 * v1 + coef2 * v2; % add new vertices, and keep their indices edgeNewVertexIndices(iEdge,:) = size(vertices2, 1) + (1:n-1); vertices2 = [vertices2 ; newPoints]; %#ok end %% Process each face faces2 = zeros(0, 3); nFaces = size(faces, 1); for iFace = 1:nFaces % compute index of each corner vertex face = faces(iFace, :); iv1 = face(1); iv2 = face(2); iv3 = face(3); % compute index of each edge faceEdges = faceEdgeIndices{iFace}; ie1 = faceEdges(1); ie2 = faceEdges(2); ie3 = faceEdges(3); % indices of new vertices on edges edge1NewVertexIndices = edgeNewVertexIndices(ie1, :); edge2NewVertexIndices = edgeNewVertexIndices(ie2, :); edge3NewVertexIndices = edgeNewVertexIndices(ie3, :); % keep vertex 1 as reference for edges 1 and 3 if edges(ie1, 1) ~= iv1 edge1NewVertexIndices = edge1NewVertexIndices(end:-1:1); end if edges(ie3, 1) ~= iv1 edge3NewVertexIndices = edge3NewVertexIndices(end:-1:1); end % create the first new face, on 'top' of the original face topVertexInds = [edge1NewVertexIndices(1) edge3NewVertexIndices(1)]; newFace = [iv1 topVertexInds]; faces2 = [faces2; newFace]; %#ok % iterate over middle strips for iStrip = 2:n-1 % index of extreme vertices of current row ivr1 = edge1NewVertexIndices(iStrip); ivr2 = edge3NewVertexIndices(iStrip); % extreme vertices as points v1 = vertices2(ivr1, :); v2 = vertices2(ivr2, :); % create additional vertices within the bottom row of the strip t = linspace(0, 1, iStrip+1)'; coef2 = t(2:end-1); coef1 = 1 - t(2:end-1); newPoints = coef1 * v1 + coef2 * v2; % compute indices of new vertices in result array newInds = size(vertices2, 1) + (1:iStrip-1); botVertexInds = [ivr1 newInds ivr2]; % add new vertices vertices2 = [vertices2 ; newPoints]; %#ok % create top faces of current strip for k = 1:iStrip-1 newFace = [topVertexInds(k) botVertexInds(k+1) topVertexInds(k+1)]; faces2 = [faces2; newFace]; %#ok end % create bottom faces of current strip for k = 1:iStrip newFace = [topVertexInds(k) botVertexInds(k) botVertexInds(k+1)]; faces2 = [faces2; newFace]; %#ok end % bottom vertices of current strip are top vertices of next strip topVertexInds = botVertexInds; end % for edge 2, keep vertex 2 of the current face as reference if edges(ie2, 1) ~= iv2 edge2NewVertexIndices = edge2NewVertexIndices(end:-1:1); end % consider new vertices together with extremities botVertexInds = [iv2 edge2NewVertexIndices iv3]; % create top faces for last strip for k = 1:n-1 newFace = [topVertexInds(k) botVertexInds(k+1) topVertexInds(k+1)]; faces2 = [faces2; newFace]; %#ok end % create bottom faces for last strip for k = 1:n newFace = [topVertexInds(k) botVertexInds(k) botVertexInds(k+1)]; faces2 = [faces2; newFace]; %#ok end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/removeMeshEars.m0000644000000000000000000000013214055375162020522 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/removeMeshEars.m0000644000175000017500000000522714055375162021615 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = removeMeshEars(varargin) %REMOVEMESHEARS Remove vertices that are connected to only one face. % % [V, F] = removeMeshEars(V, F) % [V, F] = removeMeshEars(MESH) % Remove vertices that are connected to only one face. This removes also % "pending" faces. % Note that if the mesh has boundary, this may remove some regular faces % located on the boundary. % % Example % removeMeshEars % % See also % meshes3d, ensureManifoldMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-08, using Matlab 8.6.0.267246 (R2015b) % Copyright 2019 INRA - Cepia Software Platform. [vertices, faces] = parseMeshData(varargin{:}); nVertices = size(vertices, 1); % for each vertex, determine the number of faces it belongs to vertexDegree = zeros(nVertices, 1); for iv = 1:nVertices vertexDegree(iv) = sum(sum(faces == iv, 2) > 0); end % remove vertices with degree 1 inds = find(vertexDegree == 1); [vertices, faces] = removeMeshVertices(vertices, faces, inds); %% Format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/drawPolyhedron.m0000644000000000000000000000013214055375162020576 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/drawPolyhedron.m0000644000175000017500000001132614055375162021666 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPolyhedron(nodes, faces, varargin) %DRAWPOLYHEDRON Draw polyhedron defined by vertices and faces. % % drawPolyhedron(NODES, FACES) % Draws the polyhedron defined by vertices NODES and the faces FACES. % NODES is a NV-by-3 array containing coordinates of vertices, and FACES % is either a NF-by3 or NF-by-4 array containing indices of vertices of % the triangular or rectangular faces. % FACES can also be a cell array, in the content of each cell is an array % of indices to the nodes of the current face. Faces can have different % number of vertices. % % H = drawPolyhedron(...); % Also returns a handle to the created patche. % % Example: % [n f] = createSoccerBall; % drawPolyhedron(n, f); % % See also: % polyhedra, drawMesh, drawPolygon % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % HISTORY % 07/11/2005 update doc. % 04/01/2007 typo % 18/01/2007 add support for 2D polyhedra ("nodes" is N-by-2 array), and % make 'cnodes' a list of points instead of a list of indices % 14/08/2007 add comment, add support for NaN in faces (complex polygons) % 14/09/2007 rename as drawPolyhedron % 16/10/2008 better support for colors % 27/07/2010 copy to 'drawMesh' %% Initialisations % process input arguments switch length(varargin) case 0 % default color is red varargin = {'facecolor', [1 0 0]}; case 1 % use argument as color for faces varargin = {'facecolor', varargin{1}}; otherwise % otherwise do nothing end % overwrites on current figure hold on; % if nodes are 2D points, add a z=0 coordinate if size(nodes, 2) == 2 nodes(1,3) = 0; end %% main loop : for each face if iscell(faces) % array FACES is a cell array h = zeros(length(faces(:)), 1); for f = 1:length(faces(:)) % get nodes of the cell face = faces{f}; if sum(isnan(face))~=0 % Special processing in case of multiple polygonal face. % each polygonal loop is separated by a NaN. % find indices of loops breaks inds = find(isnan(face)); % replace NaNs by index of first vertex of each polygon face(inds(2:end)) = face(inds(1:end-1)+1); face(inds(1)) = face(1); face(length(face)+1)= face(inds(end)+1); end % draw current face cnodes = nodes(face, :); h(f) = patch(cnodes(:, 1), cnodes(:, 2), cnodes(:, 3), [1 0 0]); end else % array FACES is a NC*NV indices array, with NV : number of vertices of % each face, and NC number of faces h = zeros(size(faces, 1), 1); for f = 1:size(faces, 1) % get nodes of the cell cnodes = nodes(faces(f,:)', :); h(f) = patch(cnodes(:, 1), cnodes(:, 2), cnodes(:, 3), [1 0 0]); end end % set up drawing options if ~isempty(varargin) set(h, varargin{:}); end % format output parameters if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/readMesh_stl.m0000644000000000000000000000013214055375162020207 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/readMesh_stl.m0000644000175000017500000000420714055375162021277 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = readMesh_stl(fileName) %READMESH_STL Read mesh data stored in STL format. % % [VERTICES, FACES] = readMesh_stl(FNAME) % % MESH = readMesh_stl(FNAME) % % Example % readMesh_stl % % References % Wrapper function for MATLAB's build-in stlread. % % See also % meshes3d, readMesh, readMesh_off, readMesh_ply % ------ % Author: oqilipo % Created: 2021-02-12, using Matlab 9.9.0.1538559 (R2020b) % Copyright 2021 TR = stlread(fileName); vertices = TR.Points; faces = TR.ConnectivityList; varargout = formatMeshOutput(nargout, vertices, faces); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/removeInvalidBorderFaces.m0000644000000000000000000000013214055375162022501 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/removeInvalidBorderFaces.m0000644000175000017500000000575114055375162023576 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, faces] = removeInvalidBorderFaces(varargin) %REMOVEINVALIDBORDERFACES Remove faces whose edges are connected to 3, 3, and 1 faces. % % [V2, F2] = removeInvalidBorderFaces(V, F) % % Example % removeInvalidBorderFaces % % See also % isManifoldMesh, collapseEdgesWithManyFaces % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-31, using Matlab 9.5.0.944444 (R2018b) % Copyright 2019 INRA - Cepia Software Platform. vertices = varargin{1}; faces = varargin{2}; % compute edge to vertex array if nargin == 3 edges = faces; faces = varargin{3}; else % compute edge to vertex array edges = meshEdges(faces); end % compute face to edge indices array % as a nFaces-by-3 array (each face connected to exactly three edges) faceEdgeInds = meshFaceEdges(vertices, edges, faces); % compute number of faces incident each edge edgeFaces = trimeshEdgeFaces(faces); edgeFaceDegrees = sum(edgeFaces > 0, 2); % for each face, concatenate the face degree of each edge faceEdgeDegrees = zeros(size(faces, 1), 3); for iFace = 1:size(faces, 1) edgeInds = faceEdgeInds{iFace}; faceEdgeDegrees(iFace, :) = edgeFaceDegrees(edgeInds); end % remove faces containing edges connected to 1 face and edges connected to % 3 faces inds = sum(faceEdgeDegrees == 1, 2) > 0 & sum(faceEdgeDegrees == 3, 2); % inds = sum(ismember(faceEdgeDegrees, [1 3 4]), 2) == 3; faces(inds, :) = []; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/vertexNormal.m0000644000000000000000000000013214055375162020263 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/vertexNormal.m0000644000175000017500000000615414055375162021356 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function normals = vertexNormal(vertices, faces) %VERTEXNORMAL Compute normals to a mesh vertices. % % N = vertexNormal(V, F) % Computes vertex normals of the mesh given by vertices V and F. % V is a vertex array with 3 columns, F is either a NF-by-3 or NF-by-4 % index array, or a cell array with NF elements. % % Example % % Draw the vertex normals of a sphere % s = [10 20 30 40]; % [v f] = sphereMesh(s); % drawMesh(v, f); % view(3);axis equal; light; lighting gouraud; % normals = vertexNormal(v, f); % drawVector3d(v, normals); % % See also % meshes3d, meshFaceNormals, triangulateFaces % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-12-19, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. nv = size(vertices, 1); nf = size(faces, 1); % unit normals to the faces faceNormals = normalizeVector3d(meshFaceNormals(vertices, faces)); % compute normal of each vertex: sum of normals to each face normals = zeros(nv, 3); if isnumeric(faces) for i = 1:nf face = faces(i, :); for j = 1:length(face) v = face(j); normals(v, :) = normals(v,:) + faceNormals(i,:); end end else for i = 1:nf face = faces{i}; for j = 1:length(face) v = face(j); normals(v, :) = normals(v,:) + faceNormals(i,:); end end end % normalize vertex normals to unit vectors normals = normalizeVector3d(normals); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/polyhedronMeanBreadth.m0000644000000000000000000000013214055375162022053 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/polyhedronMeanBreadth.m0000644000175000017500000000712514055375162023145 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function breadth = polyhedronMeanBreadth(vertices, edges, faces) %POLYHEDRONMEANBREADTH Mean breadth of a convex polyhedron. % % BREADTH = polyhedronMeanBreadth(V, E, F) % Return the mean breadth (average of polyhedron caliper diameter over % all direction) of a convex polyhedron. % % The mean breadth is computed using the sum, over the edges of the % polyhedron, of the edge dihedral angles multiplied by the edge length, % the final sum being divided by (4*PI). % % Note: the function assumes that the faces are correctly oriented. The % face vertices should be indexed counter-clockwise when considering the % supporting plane of the plane, with the outer normal oriented outwards % of the polyhedron. % % Typical values for classical polyhedra are: % cube side a breadth = (3/2)*a % cuboid sides a, b, c breadth = (a+b+c)/2 % tetrahedron side a breadth = 0.9123*a % octaedron side a beradth = 1.175*a % dodecahedron, side a breadth = 15*arctan(2)*a/(2*pi) % icosaehdron, side a breadth = 15*arcsin(2/3)*a/(2*pi) % % Example % [v e f] = createCube; % polyhedronMeanBreadth(v, e, f) % ans = % 1.5 % % See also % meshes3d, meshEdgeFaces, meshDihedralAngles, checkMeshAdjacentFaces % trimeshMeanBreadth % % References % Stoyan D., Kendall W.S., Mecke J. (1995) "Stochastic Geometry and its % Applications", John Wiley and Sons, p. 26 % Ohser, J., Muescklich, F. (2000) "Statistical Analysis of % Microstructures in Materials Sciences", John Wiley and Sons, p.352 % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % compute dihedral angle of each edge alpha = meshDihedralAngles(vertices, edges, faces); % compute length of each edge lengths = meshEdgeLength(vertices, edges); % compute product of length by angles breadth = sum(alpha.*lengths)/(4*pi); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/polyhedra.m0000644000000000000000000000013214055375162017564 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/polyhedra.m0000644000175000017500000000563714055375162020664 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polyhedra(varargin) %POLYHEDRA Index of classical polyhedral meshes. % % Polyhedra are specific meshes, with additional assumptions: % * the set of faces is assumed to enclose a single 3D domain % * each face has a neighbor face for each edge % * some functions also assume that normals of all faces point outwards % % Most polyhedron creation functions follow the patterns: % * [V, F] = createXXX(); % returns vertex and face arrays % * [V, E, F] = createXXX(); % returns also edge array % * M = createXXX(); % return a data structure with 'vertices', % % 'edges' and 'faces' fields. % % Example % % create a soccer ball mesh and display it % [n, f] = createSoccerBall; % drawMesh(n, f, 'faceColor', 'g', 'linewidth', 2); % axis equal; % % See also % meshes3d % createCube, createCubeOctahedron, createIcosahedron, createOctahedron % createRhombododecahedron, createTetrahedron, createTetrakaidecahedron % createDodecahedron, createSoccerBall, createMengerSponge % steinerPolytope, minConvexHull % polyhedronNormalAngle, polyhedronMeanBreadth % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-10-13, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/transformMesh.m0000644000000000000000000000013214055375162020425 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/transformMesh.m0000644000175000017500000000475014055375162021520 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = transformMesh(varargin) %TRANSFORMMESH Applies a 3D affine transform to a mesh. % % MESH2 = transformMesh(MESH1, TRANSFO) % MESH2 = transformMesh(VERTICES, FACES, TRANSFO) % [V2, F2] = transformMesh(...) % % Example % mesh1 = createOctahedron; % transfo = eulerAnglesToRotation3d([30 20 10]); % mesh2 = transformMesh(mesh1, transfo); % figure; axis equal; hold on; drawMesh(mesh2, 'faceColor', 'g'); view(3); % % See also % meshes3d, transformPoint3d, drawMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-08-08, using Matlab 9.6.0.1072779 (R2019a) % Copyright 2019 INRA - Cepia Software Platform. % parses input arguments [vertices, edges, faces] = parseMeshData(varargin{1:end-1}); transfo = varargin{end}; vertices2 = transformPoint3d(vertices, transfo); % format output varargout = formatMeshOutput(nargout, vertices2, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/mergeMeshVertices.m0000644000000000000000000000013214055375162021216 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/mergeMeshVertices.m0000644000175000017500000000503114055375162022302 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, faces] = mergeMeshVertices(vertices, faces, vertexInds, varargin) %MERGEMESHVERTICES Merge two vertices and removes eventual degenerated faces. % % output = mergeMeshVertices(input) % % Example % mergeMeshVertices % % See also % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-31, using Matlab 9.5.0.944444 (R2018b) % Copyright 2019 INRA - Cepia Software Platform. newPos = vertices(vertexInds(1), :); if nargin > 3 newPos = varargin{1}; end vertices(vertexInds(1), :) = newPos; vertices(vertexInds(2:end), :) = NaN; % replace face-vertex indices by index of first vertex faces(ismember(faces, vertexInds)) = vertexInds(1); % need to check existence of degenerated faces with same vertex twice nFaces = size(faces, 1); dgnFaces = false(nFaces, 1); dims = [1 2;1 3;2 3]; for i = 1:3 dgnFaces = dgnFaces | faces(:,dims(i,1)) == faces(:,dims(i,2)); end % remove degenerated faces faces(dgnFaces, :) = []; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFaceNormals.m0000644000000000000000000000013214055375162020644 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFaceNormals.m0000644000175000017500000000666414055375162021745 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function normals = meshFaceNormals(varargin) %MESHFACENORMALS Compute normal vector of faces in a 3D mesh. % % NORMALS = meshFaceNormals(VERTICES, FACES) % VERTICES is a set of 3D points (as a N-by-3 array), and FACES is either % a N-by-3 index array or a cell array of indices. The function computes % the normal vector of each face. % The orientation of the normal is defined by the sign of cross product % between vectors joining vertices 1 to 2 and 1 to 3. % % % Example % [v e f] = createIcosahedron; % normals1 = meshFaceNormals(v, f); % centros1 = meshFaceCentroids(v, f); % figure; drawMesh(v, f); % hold on; axis equal; view(3); % drawVector3d(centros1, normals1); % % pts = rand(50, 3); % hull = minConvexHull(pts); % normals2 = meshFaceNormals(pts, hull); % % See also % meshes3d, meshFaceCentroids, meshVertexNormals, drawFaceNormals % drawMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-07-05 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 2011-11-24 rename from faceNormal to meshFaceNormals % parse input data [vertices, faces] = parseMeshData(varargin{:}); if isnumeric(faces) % compute vector of first edges v1 = vertices(faces(:,2),1:3) - vertices(faces(:,1),1:3); v2 = vertices(faces(:,3),1:3) - vertices(faces(:,1),1:3); % compute normals using cross product (nodes have same size) normals = cross(v1, v2, 2); else % initialize empty array normals = zeros(length(faces), 3); for i = 1:length(faces) face = faces{i}; % compute vector of first edges v1 = vertices(face(2),1:3) - vertices(face(1),1:3); v2 = vertices(face(3),1:3) - vertices(face(1),1:3); % compute normals using cross product normals(i, :) = cross(v1, v2, 2); end end normals = normalizeVector3d(normals); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/writeMesh_off.m0000644000000000000000000000013214055375162020376 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/writeMesh_off.m0000644000175000017500000000632414055375162021470 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function writeMesh_off(fileName, vertices, faces) %WRITEMESH_OFF Write a mesh into a text file in OFF format. % % writeMesh_off(FNAME, V, F) % % Example % writeMesh_off % % See also % meshes3d, writeMesh, readMesh_off, writeMesh_ply % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2018-04-26, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. if ~ischar(fileName) error('First argument must contain the name of the file'); end % optionnaly parses data if isstruct(vertices) faces = vertices.faces; vertices = vertices.vertices; end % open file for writing text f = fopen(fileName, 'wt'); if (f == -1) error('Couldn''t open the file %s', fileName); end % write the header line fprintf(f, 'OFF\n'); % write number of vertices and of faces nVertices = size(vertices, 1); nFaces = size(faces, 1); if iscell(faces) nFaces = length(faces); end fprintf(f, '%d %d 0\n', nVertices, nFaces); % Write vertex info format = '%g %g %g\n'; for iv = 1:nVertices fprintf(f, format, vertices(iv, :)); end % Write face info if isnumeric(faces) % simply write face vertex indices ns = size(faces, 2); format = ['%d' repmat(' %d', 1, ns) '\n']; for iFace = 1:nFaces fprintf(f, format, ns, faces(iFace, :)-1); end else % if faces are stored in a cell array, the number of vertices in each % face may be different, and we need to process each face individually for iFace = 1:nFaces ns = length(faces{iFace}); format = ['%d' repmat(' %d', 1, ns) '\n']; fprintf(f, format, ns, faces{iFace}-1); end end % close the file fclose(f); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshDihedralAngles.m0000644000000000000000000000013214055375162021320 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshDihedralAngles.m0000644000175000017500000000660014055375162022407 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function alpha = meshDihedralAngles(vertices, edges, faces) %MESHDIHEDRALANGLES Dihedral at edges of a polyhedal mesh. % % ALPHA = meshDihedralAngles(V, E, F) % where V, E and F represent vertices, edges and faces of a mesh, % computes the dihedral angle between the two adjacent faces of each edge % in the mesh. ALPHA is a column array with as many rows as the number of % edges. The i-th element of ALPHA corresponds to the i-th edge. % % Note: the function assumes that the faces are correctly oriented. The % face vertices should be indexed counter-clockwise when considering the % supporting plane of the face, with the outer normal oriented outwards % of the mesh. % % Example % [v, e, f] = createCube; % rad2deg(meshDihedralAngles(v, e, f)) % ans = % 90 % 90 % 90 % 90 % 90 % 90 % 90 % 90 % 90 % 90 % 90 % 90 % % See also % meshes3d, polyhedronMeanBreadth, trimeshMeanBreadth, dihedralAngle, meshEdgeFaces % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % compute normal of each face normals = meshFaceNormals(vertices, faces); % indices of faces adjacent to each edge edgeFaces = meshEdgeFaces(vertices, edges, faces); % allocate memory for resulting angles Ne = size(edges, 1); alpha = zeros(Ne, 1); % iterate over edges for i = 1:Ne % indices of adjacent faces indFace1 = edgeFaces(i, 1); indFace2 = edgeFaces(i, 2); % normal vector of adjacent faces normal1 = normals(indFace1, :); normal2 = normals(indFace2, :); % compute dihedral angle of two vectors alpha(i) = vectorAngle3d(normal1, normal2); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshAdjacencyMatrix.m0000644000000000000000000000013214055375162021520 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshAdjacencyMatrix.m0000644000175000017500000000625514055375162022615 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function adj = meshAdjacencyMatrix(faces, varargin) %MESHADJACENCYMATRIX Compute adjacency matrix of a mesh from set of faces. % % ADJMAT = meshAdjacencyMatrix(FACES) % Returns a sparse NV-by-NV matrix (NV being the largest vertex index) % containing vertex adjacency of the mesh represented by FACES. % FACES is either a NF-by-3, a NF-by-4 index array, or a Nf-by-1 cell % array. % % Example % [v f] = createCube; % adj = meshAdjacencyMatrix(f); % % See also % meshes3d, triangulateFaces, smoothMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2013-04-30, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. % Ensures faces is a N-by-3 or N-by-4 array if iscell(faces) || (isnumeric(faces) && size(faces, 2) > 4) faces = triangulateFaces(faces); end % forces faces to be floating point array, for sparse function if ~isfloat(faces) faces = double(faces); end nv = max(faces(:)); % populate a sparse matrix if size(faces, 2) == 3 adj = sparse(... [faces(:,1); faces(:,1); faces(:,2); faces(:,2); faces(:,3); faces(:,3)], ... [faces(:,3); faces(:,2); faces(:,1); faces(:,3); faces(:,2); faces(:,1)], ... 1.0, nv, nv); elseif size(faces, 2) == 4 adj = sparse(... [faces(:,1); faces(:,1); faces(:,2); faces(:,2); faces(:,3); faces(:,3); faces(:,4); faces(:,4)], ... [faces(:,4); faces(:,2); faces(:,1); faces(:,3); faces(:,2); faces(:,4); faces(:,3); faces(:,1)], ... 1.0, nv, nv); end % remove double adjacencies adj = min(adj, 1); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/cylinderMesh.m0000644000000000000000000000013214055375162020223 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/cylinderMesh.m0000644000175000017500000001223014055375162021306 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cylinderMesh(cyl, varargin) % Create a 3D mesh representing a cylinder. % % [V, F] = cylinderMesh(CYL) % Computes vertex coordinates and face vertex indices of a mesh % representing a 3D cylinder given as [X1 Y1 Z1 X2 Y2 Z2 R]. % % [V, F] = cylinderMesh(..., OPT) % with OPT = 'open' (0) (default) or 'closed' (1), specify if the bases % of the cylinder should be included. % % [V, F] = cylinderMesh(..., NAME, VALUE); % Specifies one or several options using parameter name-value pairs. % Available options are: % 'nPerimeter' the number of circles represeting the perimeter % 'nRho' the number of circles along the hight % % Example % % Draw a rotated cylinder % cyl = [0 0 0 10 20 30 5]; % [v, f] = cylinderMesh(cyl); % figure;drawMesh(v, f, 'FaceColor', 'r'); % view(3); axis equal; % % % Draw three mutually intersecting cylinders % p0 = [30 30 30]; % p1 = [90 30 30]; % p2 = [30 90 30]; % p3 = [30 30 90]; % [v1 f1] = cylinderMesh([p0 p1 25]); % [v2 f2] = cylinderMesh([p0 p2 25]); % [v3 f3] = cylinderMesh([p0 p3 25],'closed','nPeri',40,'nRho',20); % figure; hold on; % drawMesh(v1, f1, 'FaceColor', 'r'); % drawMesh(v2, f2, 'FaceColor', 'g'); % drawMesh(v3, f3, 'FaceColor', 'b'); % view(3); axis equal % set(gcf, 'renderer', 'opengl') % % See also % drawCylinder, torusMesh, sphereMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-10-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. parser = inputParser; addRequired(parser, 'cyl', @(x) validateattributes(x, {'numeric'},... {'size',[1 7],'real','finite','nonnan'})); capParValidFunc = @(x) (islogical(x) ... || isequal(x,1) || isequal(x,0) || any(validatestring(x, {'open','closed'}))); addOptional(parser,'cap','open', capParValidFunc); addParameter(parser, 'nPerimeter', 20, @(x) validateattributes(x,{'numeric'},... {'integer','scalar','>=',4})); addParameter(parser, 'nRho', 10, @(x) validateattributes(x,{'numeric'},... {'integer','scalar','>=',2})); parse(parser,cyl,varargin{:}); cyl=parser.Results.cyl; cap=lower(parser.Results.cap(1)); NoPP=parser.Results.nPerimeter; nRho=parser.Results.nRho; % extract cylinder data p1 = cyl(:, 1:3); p2 = cyl(:, 4:6); r = cyl(:, 7); % compute length and orientation [theta, phi, rho] = cart2sph2d(p2 - p1); % parametrisation on x t = linspace(0, 2*pi, NoPP); lx = r * cos(t); ly = r * sin(t); % parametrisation on z lz = linspace(0, rho, nRho); % generate surface grids x = repmat(lx, [length(lz) 1]); y = repmat(ly, [length(lz) 1]); z = repmat(lz', [1 length(t)]); % transform points trans = localToGlobal3d(p1, theta, phi, 0); [x, y, z] = transformPoint3d(x, y, z, trans); % convert to FV mesh [vertices, faces] = surfToMesh(x, y, z, 'xPeriodic', true); % Close cylinder if cap == 'c' || cap == 1 toe.vertices = [x(1,1:NoPP-1); y(1,1:NoPP-1); z(1,1:NoPP-1)]'; toe.vertices(NoPP,:) = transformPoint3d([0 0 0], trans); toe.faces = [repmat(NoPP, 1, NoPP-1); [2:NoPP-1 1]; 1:NoPP-1]'; top.vertices = [x(end,1:NoPP-1); y(end,1:NoPP-1); z(end,1:NoPP-1)]'; top.vertices(NoPP,:) = transformPoint3d([0 0 rho], trans); top.faces = fliplr(toe.faces); [vertices, faces] = concatenateMeshes(vertices, triangulateFaces(faces), ... toe.vertices, toe.faces, top.vertices, top.faces); end % format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/polyhedronNormalAngle.m0000644000000000000000000000013214055375162022100 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/polyhedronNormalAngle.m0000644000175000017500000001025014055375162023163 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function theta = polyhedronNormalAngle(varargin) %POLYHEDRONNORMALANGLE Compute normal angle at a vertex of a 3D polyhedron. % % THETA = polyhedraNormalAngle(NODES, EDGES, FACES, IND); % THETA = polyhedraNormalAngle(NODES, FACES, IND); % where NODES is a set of 3D points, and FACES a set of faces, whose % elements are indices to NODES array, compute the normal angle at the % vertex whose index is given by IND. % % THETA = polyhedraNormalAngle(GRAPH, IND); % Uses a graph structure. GRAPH should contain at least fields : 'nodes' % and 'faces'. % % Example : % % create a simple (irregular) tetrahedra % nodes = [0 0 0;1 0 0;0 1 0;0 0 1]; % faces = [1 2 3;1 2 4;1 3 4;2 3 4]; % % compute normal angle at each vertex % theta = polyhedronNormalAngle(nodes, faces, 1:size(nodes, 1)); % % sum of normal angles should be equal to 4*pi : % sum(theta) % % % TODO works only for polyhedra with convex faces ! ! ! % % See also % polyhedra, polygon3dNormalAngle % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2005-11-30 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin)==4 nodes = varargin{1}; faces = varargin{3}; ind = varargin{4}; elseif length(varargin)==3 nodes = varargin{1}; faces = varargin{2}; ind = varargin{3}; elseif length(varargin)==2 graph = varargin{1}; nodes = graph.nodes; faces = graph.faces; ind = varargin{2}; else error('wrong number of arguments'); end % number of angles to compute na = length(ind); theta = zeros(na, 1); for i=1:na thetaf = []; % find faces containing given vertex, % and compute normal angle at each face containing vertex if iscell(faces) for j=1:length(faces) if ismember(ind(i), faces{j}) % create 3D polygon face = nodes(faces{j}, :); % index of point in polygon indp = find(faces{j}==i); % compute normal angle of vertex thetaf = [thetaf polygon3dNormalAngle(face, indp)]; %#ok end end else indf = find(sum(ismember(faces, ind(i)), 2)); thetaf = zeros(length(indf), 1); for j=1:length(indf) ind2 = faces(indf(j), :); face = nodes(ind2, :); indp = find(ind2==ind(i)); thetaf(j) = pi - polygon3dNormalAngle(face, indp); end end % compute normal angle of polyhedron, by use of angle defect formula theta(i) = 2*pi - sum(thetaf); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/icosahedron.ply0000644000000000000000000000013214055375161020442 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/icosahedron.ply0000644000175000017500000000120614055375161021526 0ustar00juanpijuanpi00000000000000ply format ascii 1.0 comment created by platoply element vertex 12 property float32 x property float32 y property float32 z element face 20 property list uint8 int32 vertex_indices end_header 0 -0.525731 0.850651 0.850651 0 0.525731 0.850651 0 -0.525731 -0.850651 0 -0.525731 -0.850651 0 0.525731 -0.525731 0.850651 0 0.525731 0.850651 0 0.525731 -0.850651 0 -0.525731 -0.850651 0 0 -0.525731 -0.850651 0 0.525731 -0.850651 0 0.525731 0.850651 3 6 2 1 3 2 7 1 3 5 4 3 3 8 3 4 3 11 5 6 3 10 6 5 3 2 10 9 3 3 9 10 3 9 8 7 3 0 7 8 3 1 0 11 3 4 11 0 3 10 2 6 3 11 6 1 3 10 5 3 3 11 4 5 3 9 7 2 3 0 1 7 3 8 9 3 3 0 8 4 matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/smoothMesh.m0000644000000000000000000000013214055375162017723 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/smoothMesh.m0000644000175000017500000001030714055375162021011 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = smoothMesh(varargin) %SMOOTHMESH Smooth mesh by replacing each vertex by the average of its neighbors. % % V2 = smoothMesh(V, F) % [V2, F2] = smoothMesh(V, F) % Performs smoothing of the values given in V, by using adjacency % information given in F. % V is a numeric array representing either vertex coordinate, or value % field associated to each vertex. F is an array of faces, given either % as a NF-by-3 or NF-by-4 numeric array, or as a cell array. % Artifact adjacencies are added if faces have more than 4 vertices. % % ... = smoothMesh(V, F, NITER) % Repeat the smoothing procedure NITER times. This is equivalent to % calling the smoothMesh function NITER times. % % % Example % [v f] = torusMesh([50 50 50 30 10 30 45]); % v = v + randn(size(v)); % [v2 f] = smoothMesh(v, f, 3); % figure; drawMesh(v2, f); % l = light; lighting gouraud % % See also % meshes3d, meshAdjacencyMatrix, triangulateFaces, drawMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2013-04-29, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. var1 = varargin{1}; if isstruct(var1) vertices = var1.vertices; faces = var1.faces; varargin(1) = []; else vertices = varargin{1}; faces = varargin{2}; varargin(1:2) = []; end % determine number of iterations nIter = 1; if ~isempty(varargin) nIter = varargin{1}; end % compute adjacency matrix, % result is a Nv-by-Nv matrix with zeros on the diagonal adj = meshAdjacencyMatrix(faces); % ensure the size of the matrix is Nv-by-Nv % (this can not be the case if some vertices are not referenced) nv = size(vertices, 1); if size(adj, 1) < nv adj(nv, nv) = 0; end % Add "self adjacencies" adj = adj + speye(nv); % weight each vertex by the number of its neighbors w = spdiags(full(sum(adj, 2).^(-1)), 0, nv, nv); adj = w * adj; % do averaging to smooth the field v2 = vertices; for k = 1:nIter v2 = adj * v2; end varargout = formatMeshOutput(nargout, v2, faces); %% Old version % % Compute vertex adjacencies % edges = computeMeshEdges(faces); % v2 = zeros(size(vertices)); % % % apply several smoothing % for iter = 1:nIter % % % replace the coords of each vertex by the average coordinate in the % % neighborhood % for i = 1:size(vertices, 1) % edgeInds = sum(edges == i, 2) > 0; % neighInds = unique(edges(edgeInds, :)); % v2(i, :) = mean(vertices(neighInds, :)); % end % % % update for next iteration % vertices = v2; % end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createDodecahedron.m0000644000000000000000000000013214055375162021340 xustar0030 mtime=1622538866.090813524 30 atime=1622538866.090813524 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createDodecahedron.m0000644000175000017500000001007414055375162022427 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createDodecahedron() %CREATEDODECAHEDRON Create a 3D mesh representing a dodecahedron. % % [V, E, F] = createDodecahedron; % Create a 3D mesh representing a dodecahedron % V is the 20-by-3 array of vertex coordinates % E is the 30-by-2 array of edge vertex indices % F is the 12-by-5 array of face vertex indices % % [V, F] = createDodecahedron; % Returns only the vertices and the face vertex indices. % % MESH = createDodecahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Example % [v, e, f] = createDodecahedron; % drawMesh(v, f); % % Use values given by P. Bourke, see: % http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/ % faces are re-oriented to have normals pointing outwards. % % See also % meshes3d, drawMesh % createCube, createOctahedron, createIcosahedron, createTetrahedron % % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 29/07/2010. % % HISTORY % golden ratio phi = (1+sqrt(5))/2; % coordinates pre-computations b = 1 / phi ; c = 2 - phi ; % use values given by P. Bourke, see: % http://local.wasp.uwa.edu.au/~pbourke/geometry/platonic/ tmp = [ ... c 0 1 ; b b b ; 0 1 c ; -b b b ; -c 0 1 ; ... -c 0 1 ; -b -b b ; 0 -1 c ; b -b b ; c 0 1 ; ... c 0 -1 ; b -b -b ; 0 -1 -c ; -b -b -b ; -c 0 -1 ; ... -c 0 -1 ; -b b -b ; 0 1 -c ; b b -b ; c 0 -1 ; ... 0 1 -c ; 0 1 c ; b b b ; 1 c 0 ; b b -b ; ... 0 1 c ; 0 1 -c ; -b b -b ; -1 c 0 ; -b b b ; ... 0 -1 -c ; 0 -1 c ; -b -b b ; -1 -c 0 ; -b -b -b ; ... 0 -1 c ; 0 -1 -c ; b -b -b ; 1 -c 0 ; b -b b ; ... 1 c 0 ; b b b ; c 0 1 ; b -b b ; 1 -c 0 ; ... 1 -c 0 ; b -b -b ; c 0 -1 ; b b -b ; 1 c 0 ; ... -1 c 0 ; -b b -b ; -c 0 -1 ; -b -b -b ; -1 -c 0 ; ... -1 -c 0 ; -b -b b ; -c 0 1 ; -b b b ; -1 c 0 ; ... ]; % extract coordinates of unique vertices [verts, M, N] = unique(tmp, 'rows', 'first'); %#ok % compute indices of face vertices, put result in a 12-by-5 index array ind0 = reshape((1:60), [5 12])'; faces = N(ind0); % extract edges from faces edges = [reshape(faces(:, 1:5), [60 1]) reshape(faces(:, [2:5 1]), [60 1])]; edges = unique(sort(edges, 2), 'rows'); % format output varargout = formatMeshOutput(nargout, verts, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/triangulateCurvePair.m0000644000000000000000000000013214055375162021735 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/triangulateCurvePair.m0000644000175000017500000001000114055375162023012 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, facets] = triangulateCurvePair(curve1, curve2) %TRIANGULATECURVEPAIR Compute triangulation between a pair of 3D open curves. % % [V, F] = testTriangulateCurvePair(CURVE1, CURVE2) % % Example % % triangulate a surface patch between two open curves % % create two sample curves % t = linspace(0, 2*pi, 100); % curve1 = [linspace(0, 10, 100)' 5 * sin(t') zeros(100,1)]; % curve2 = [linspace(0, 10, 100)' 2 * sin(t') 2*ones(100,1)]; % figure; hold on; % drawPolyline3d(curve1, 'b'); % drawPolyline3d(curve2, 'g'); % view(3); axis equal; % [v, f] = triangulateCurvePair(curve1, curve2); % figure; drawMesh(v, f, 'linestyle', 'none'); % view(3); axis equal % % See also % meshes3D, triangulatePolygonPair, meshSurfaceArea % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-05-18, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. %% Memory allocation % number of vertices on each curve n1 = size(curve1, 1); n2 = size(curve2, 1); % allocate the array of facets (each edge of each curve provides a facet) nFacets = n1 + n2 - 2; facets = zeros(nFacets, 3); % look for the closest ends of two curves and reverse the second curve if % needed p1 = curve1(1, :); if distancePoints(p1, curve2(1,:)) > distancePoints(p1, curve2(end,:)) curve2 = curve2(end:-1:1,:); end currentIndex1 = 1; currentIndex2 = 1; % concatenate vertex coordinates for creating mesh vertices = [curve1 ; curve2]; %% Main iteration % For each diagonal, consider the two possible facets (one for each 'next' % vertex on each curve), each create current facet according to the closest % one. % Then update current diagonal for next iteration. for i = 1:nFacets nextIndex1 = mod(currentIndex1, n1) + 1; nextIndex2 = mod(currentIndex2, n2) + 1; % compute lengths of diagonals dist1 = distancePoints(curve1(currentIndex1, :), curve2(nextIndex2,:)); dist2 = distancePoints(curve1(nextIndex1, :), curve2(currentIndex2,:)); if dist1 < dist2 % keep current vertex of curve1, use next vertex on curve2 facet = [currentIndex1 currentIndex2+n1 nextIndex2+n1]; currentIndex2 = nextIndex2; else % keep current vertex of curve2, use next vertex on curve1 facet = [currentIndex1 currentIndex2+n1 nextIndex1]; currentIndex1 = nextIndex1; end % create the facet facets(i, :) = facet; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createTetrakaidecahedron.m0000644000000000000000000000013214055375162022542 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createTetrakaidecahedron.m0000644000175000017500000000700314055375162023627 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createTetrakaidecahedron() %CREATETETRAKAIDECAHEDRON Create a 3D mesh representing a tetrakaidecahedron. % % [V, E, F] = createTetrakaidecahedron; % Create a mesh structure representing a tetrakaidecahedron, composed of % both square and hexagonal faces. Tetrakaidecahedron can be used to tile % the 3D Euclidean space. % % V is a 24-by-3 array with vertex coordinates, % E is a 36-by-2 array containing indices of neighbour vertices, % F is a 14-by-1 cell array containing vertex indices array of each face. % % [V, F] = createTetrakaidecahedron; % Returns only the vertices and the face vertex indices. % % MESH = createTetrakaidecahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Example % [n, e, f] = createTetrakaidecahedron; % drawMesh(n, f); % % See also % meshes3d, drawMesh % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % HISTORY % 04/01/2007: remove unused variables nodes = [... 1 0 2;0 1 2;-1 0 2;0 -1 2;... 2 0 1;0 2 1;-2 0 1;0 -2 1;... 2 1 0;1 2 0;-1 2 0;-2 1 0;-2 -1 0;-1 -2 0;1 -2 0;2 -1 0;... 2 0 -1;0 2 -1;-2 0 -1;0 -2 -1;... 1 0 -2;0 1 -2;-1 0 -2;0 -1 -2]; edges = [... 1 2;1 4;1 5;2 3;2 6;3 4;3 7;4 8;... 5 9;5 16;6 10;6 11;7 12;7 13;8 14;8 15;... 9 10;9 17;10 18;11 12;11 18;12 19;13 14;13 19;14 20;15 16;15 20;16 17;.... 17 21;18 22;19 23;20 24;21 22;21 24;22 23;23 24]; faces = {... [1 2 3 4], ... [1 4 8 15 16 5], [1 5 9 10 6 2], [2 6 11 12 7 3], [3 7 13 14 8 4],... [5 16 17 9], [6 10 18 11], [7 12 19 13], [8 14 20 15],... [9 17 21 22 18 10], [11 18 22 23 19 12], [13 19 23 24 20 14], [15 20 24 21 17 16], ... [21 24 23 22]}; faces = faces'; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/clipConvexPolyhedronHP.m0000644000000000000000000000013214055375162022203 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/clipConvexPolyhedronHP.m0000644000175000017500000001417214055375162023275 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, faces2] = clipConvexPolyhedronHP(nodes, faces, plane) %CLIPCONVEXPOLYHEDRONHP Clip a convex polyhedron by a plane. % % [NODES2, FACES2] = clipConvexPolyhedronHP(NODES, FACES, PLANE) % % return the new (convex) polyhedron whose vertices are 'below' the % specified plane, and with faces clipped accordingly. NODES2 contains % clipped vertices and new created vertices, FACES2 contains references % to NODES2 vertices. % % Example % [N, F] = createCube; % P = createPlane([.5 .5 .5], [1 1 1]); % [N2, F2] = clipConvexPolyhedronHP(N, F, P); % figure('color','w'); view(3); axis equal % drawPolyhedron(N2, F2); % % [v, f] = createSoccerBall; % p = createPlane([-.5 .5 -.5], [1 1 1]); % [v2, f2] = clipConvexPolyhedronHP(v, f, p); % figure('color','w'); view(3); axis equal % drawMesh(v, f, 'faceColor', 'none'); % drawMesh(v2, f2); % % See also % meshes3d, polyhedra, planes3d % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2007-09-14, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Preprocessing % used for identifying identical vertices tol = 1e-10; % if faces is a numeric array, convert it to cell array if isnumeric(faces) faces2 = cell(size(faces, 1), 1); for f = 1:length(faces2) faces2{f} = faces(f,:); end faces = faces2; end % find vertices below the plane b = isBelowPlane(nodes, plane); % initialize results Nn = size(nodes, 1); nodes2 = zeros(0, 3); % list of new nodes faces2 = faces; % list of new faces. Start with initial list, and remove some of them %% Main iteration on faces % iterate on each face, and test if either: % - all points below plane -> keep all face % - all points up plane -> remove face % - both -> clip the polygon keep = true(length(faces), 1); for f = 1:length(faces) % current face face = faces{f}; bf = b(face); % face totally above plane if sum(bf) == 0 keep(f) = false; continue; end % face totally below plane if sum(bf == 1) == length(bf) continue; end % clip polygon formed by face poly = nodes(face, :); clipped = clipConvexPolygon3dHP(poly, plane); % identify indices of polygon vertices inds = zeros(1, size(clipped, 1)); faceb = face(bf==1); % indices of vertices still in clipped face [minDists, I] = minDistancePoints(nodes(faceb,:), clipped); %#ok for i = 1:length(I) inds(I(i)) = faceb(i); end % indices of new points in clipped polygon indNews = find(inds == 0); if size(nodes2, 1) < 2 nodes2 = [nodes2; clipped(indNews, :)]; %#ok inds(indNews(1)) = Nn + 1; inds(indNews(2)) = Nn + 2; faces2{f} = inds; continue; end % distances from new vertices to already added vertices [minDists, I] = minDistancePoints(clipped(indNews, :), nodes2); % compute index of first vertex if minDists(1) < tol inds(indNews(1)) = Nn + I(1); else nodes2 = [nodes2; clipped(indNews(1), :)]; %#ok inds(indNews(1)) = Nn + size(nodes2, 1); end % compute index of second vertex if minDists(2) < tol inds(indNews(2)) = Nn + I(2); else nodes2 = [nodes2; clipped(indNews(2), :)]; %#ok inds(indNews(2)) = Nn + size(nodes2, 1); end % stores the modified face faces2{f} = inds; end %% Postprocessing % creates a new face formed by the added nodes [sortedNodes, I] = angleSort3d(nodes2); % compute normal vector of new face, and reverse order if face points in % the opposite direction as plane normal newFaceNormal = meshFaceNormals(sortedNodes, 1:length(sortedNodes)); if dot(newFaceNormal, planeNormal(plane)) < 0 I(2:end) = I(end:-1:2); end % compute vertex indices of new face newFace = I' + Nn; % remove faces outside plane and add the new face faces2 = {faces2{keep}, newFace}; % remove clipped nodes, and add new nodes to list of nodes N2 = size(nodes2, 1); nodes2 = [nodes(b, :); nodes2]; % new nodes are inside half-space by definition b = [b; ones(N2, 1)]; % create look up table between old indices and new indices inds = zeros(size(nodes2, 1), 1); indb = find(b); for i = 1:length(indb) inds(indb(i)) = i; end % update indices of faces for f = 1:length(faces2) face = faces2{f}; faces2{f} = inds(face)'; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/tetrahedronVolume.m0000644000000000000000000000013214055375162021304 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/tetrahedronVolume.m0000644000175000017500000000557314055375162022403 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vol = tetrahedronVolume(vertices, varargin) %TETRAHEDRONVOLUME Signed volume of a tetrahedron. % % VOL = tetrahedronVolume(TETRA) % Comptues the siged volume of the tetrahedron TETRA defined by a 4-by-4 % array representing the polyhedron vertices. % % Example % vi = [0 0 0;1 0 0;0 1 0;0 0 1]; % tetrahedronVolume(vi) % ans = % 0.1667 % % [V F] = createTetrahedron; % tetrahedronVolume(V) % ans = % -.3333 % % See also % meshes3d, createTetrahedron, meshVolume % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2012-04-05, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. if nargin == 2 tetras = varargin{1}; nTetras = size(tetras, 1); vol = zeros(nTetras, 1); for i = 1:nTetras tetra = tetras(i,:); vol(i) = det(bsxfun(@minus, vertices(tetra(2:4),:), vertices(tetra(1),:))) / 6; end return; end % control on inputs if nargin == 4 vertices = [vertices ; varargin{1} ; varargin{2} ; varargin{3}]; end if size(vertices, 1) < 4 error('Input vertex array requires at least 4 vertices'); end % compute volume of tetrahedron, using first vertex as origin vol = det(vertices(2:4,:) - vertices([1 1 1],:)) / 6; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createStellatedMesh.m0000644000000000000000000000013214055375162021517 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createStellatedMesh.m0000644000175000017500000000637114055375162022613 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createStellatedMesh(vertices, faces, varargin) %CREATESTELLATEDMESH Replaces each face of a mesh by a pyramid. % % [V2, F2] = createStellatedMesh(V, F) % % Example % [v, f] = createCube % [v2, f2] = createStellatedMesh(v, f); % figure; drawMesh(v2, f2); axis equal; view(3); % % See also % meshes3d, drawMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-11-27, using Matlab 9.5.0.944444 (R2018b) % Copyright 2018 INRA - Cepia Software Platform. % properties of mesh nVertices = size(vertices, 1); nFaces = size(faces, 1); % shift coefficients for computing new vertices coeffs = ones(nFaces, 1); if ~isempty(varargin) var1 = varargin{1}; if isnumeric(var1) && isscalar(var1) coeffs = coeffs * var1; elseif isnumeric(var1) && length(var1) == nFaces coeffs = var1(:); else error('Coefficients must be either a scalar or a nFaces-by-1 array'); end end % supporting line of new vertices fc = meshFaceCentroids(vertices, faces); fn = meshFaceNormals(vertices, faces); % position of new vertices nv = fc + bsxfun(@times, fn, coeffs); % create data for new mesh v2 = [vertices ; nv]; f2 = zeros(nFaces * 3, 3); indF = 0; % iterate over faces for iFace = 1:nFaces % indices of vertices of current face face = meshFace(faces, iFace); % face = faces(iFace, :); % iterate over edges to create new triangular faces for ivf = 1:length(face) ind1 = face(ivf); ind2 = face(mod(ivf, length(face)) + 1); indF = indF + 1; f2(indF, :) = [ind1 ind2 iFace+nVertices]; end end % format output varargout = formatMeshOutput(nargout, v2, f2); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFaceEdges.m0000644000000000000000000000013214055375162020260 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFaceEdges.m0000644000175000017500000000546314055375162021355 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function FE = meshFaceEdges(vertices, edges, faces) %MESHFACEEDGES Computes edge indices of each face. % % FE = meshFaceEdges(V, E, F) % Returns a 1-by-NF cell array containing for each face, the set of edge % indices corresponding to adjacent edges. % % Example % meshFaceEdges % % See also % meshes3d, meshEdgeFaces % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2013-08-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. nFaces = meshFaceNumber(vertices, faces); FE = cell(nFaces, 1); % impose ordering of edge indices edges = sort(edges, 2); for iFace = 1:nFaces % extract vertex indices of current face face = meshFace(faces, iFace); nv = length(face); % for each couple of adjacent vertices, find the index of the matching % row in the edges array fei = zeros(1, nv); for iEdge = 1:nv % compute index of each edge vertex edge = sort([face(iEdge) face(mod(iEdge, nv) + 1)]); v1 = edge(1); v2 = edge(2); % find the matching row ind = find(edges(:,1) == v1 & edges(:,2) == v2); fei(iEdge) = ind; end FE{iFace} = fei; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/checkMeshAdjacentFaces.m0000644000000000000000000000013214055375162022063 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/checkMeshAdjacentFaces.m0000644000175000017500000000766314055375162023164 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function checkMeshAdjacentFaces(vertices, edges, faces) %CHECKMESHADJACENTFACES Check if adjacent faces of a mesh have similar orientation. % % checkMeshAdjacentFaces(VERTICES, EDGES, FACES) % The functions returns no output, but if two faces share a common edge % with the same direction (meaning that adjacent faces have normals in % opposite direction), a warning is displayed. % % Example % [v e f] = createCube(); % checkMeshAdjacentFaces(v, e, f); % % no output -> all faces have normal outwards of the cube % % v = [0 0 0; 10 0 0; 0 10 0; 10 10 0]; % e = [1 2;1 3;2 3;2 4;3 4]; % f = [1 2 3; 2 3 4]; % checkMeshAdjacentFaces(v, e, f); % Warning: Faces 1 and 2 run through the edge 3 (2-3) in the same direction % % See also % meshes3d, trimeshMeanBreadth % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-10-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % the message pattern that is displayed when an inconsistency is encountered pattern = 'Faces %d and %d run through the edge %d (%d-%d) in the same direction'; % If edges are not specified, compute them if nargin == 2 faces = edges; edges = meshEdges(vertices, faces); end % compute edges to faces map edgeFaces = meshEdgeFaces(vertices, edges, faces); Ne = size(edgeFaces, 1); for i = 1:Ne % indices of extreimty vertices v1 = edges(i, 1); v2 = edges(i, 2); % index of adjacent faces indF1 = edgeFaces(i, 1); indF2 = edgeFaces(i, 2); % if one of the faces has index 0, then the edge is at the boundary if indF1 == 0 || indF2 == 0 continue; end % vertices of adjacent faces face1 = meshFace(faces, indF1); face2 = meshFace(faces, indF2); % position of vertices in face vertex array ind11 = find(face1 == v1); ind12 = find(face1 == v2); ind21 = find(face2 == v1); ind22 = find(face2 == v2); % check if edge is traveled forward or backard direct1 = (ind12 == ind11+1) | (ind12 == 1 & ind11 == length(face1)); direct2 = (ind22 == ind21+1) | (ind22 == 1 & ind21 == length(face2)); % adjacent faces should travel the edge in opposite direction if direct1 == direct2 warning(pattern, indF1, indF2, i, v1, v2); %#ok end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/splitMesh.m0000644000000000000000000000013214055375162017545 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/splitMesh.m0000644000175000017500000001327514055375162020642 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function meshes = splitMesh(vertices, faces, varargin) %SPLITMESH Return the connected components of a mesh. % % MESHES = splitMesh(VERTICES, FACES) returns the connected components of % the mesh defined by vertices and faces as a struct array with the % fields vertices and faces sorted by increasing vertex number % % MESHES = splitMesh(MESH) with the vertices-faces-struct MESH is also % possible % % ... = splitMesh(..., 'mostVertices') returns only the component with % the most vertices. Other options are 'all' (default), % 'maxBoundingBox' that returns the component with the largest bounding % box, and 'maxVolume' returns the component with the largest volume. % % % Example % [v1, f1] = boxToMesh([1 0 -1 0 -1 0]); % [v2, f2] = boxToMesh([-1 0 1 0 -1 0]); % [v3, f3] = createSoccerBall; % f1 = triangulateFaces(f1); % f2 = triangulateFaces(f2); % f3 = triangulateFaces(f3); % [vertices, faces] = concatenateMeshes(v1, f1, v3, f3, v2, f2); % meshes = splitMesh(vertices, faces); % figure('color','w'); view(3); axis equal % cmap=hsv(length(meshes)); % for m=1:length(meshes) % drawMesh(meshes(m), cmap(m,:)) % end % % See also % concatenateMeshes % % Source % Local functions are part of the gptoolbox of Alec Jacobson % https://github.com/alecjacobson/gptoolbox % % --------- % Author: oqilipo % Created: 2017-09-17 % Copyright 2017 % input parsing if isstruct(vertices) if nargin > 1; varargin = [faces, varargin]; end [vertices, faces]=parseMeshData(vertices); end parser = inputParser; validStrings = {'all','mostVertices','maxBoundingBox','maxVolume'}; addOptional(parser,'components','all',@(x) any(validatestring(x, validStrings))); parse(parser,varargin{:}); outputComp = validatestring(parser.Results.components, validStrings); % algorithm CC = connected_components(faces); [a,~]=hist(CC,unique(CC)); [~,b] = sort(a); meshes=repmat(struct('vertices',[],'faces',[]),length(b),1); for cc=b meshes(cc)=removeMeshVertices(vertices, faces, ~(CC'==b(cc))); end % output parsing switch outputComp case 'mostVertices' meshes=meshes(end); case 'maxBoundingBox' [~,sortingIndices] = sort(arrayfun(@(x) box3dVolume(boundingBox3d(x.vertices)), meshes)); meshes = meshes(sortingIndices(end)); case 'maxVolume' [~,sortingIndices] = sort(arrayfun(@(x) meshVolume(x.vertices, x.faces), meshes)); meshes = meshes(sortingIndices(end)); end end %% Local functions are part of the gptoolbox by Alec Jacobson function C = connected_components(F) % CONNECTED_COMPONENTS Determine the connected components of a mesh % described by the simplex list F. Components are determined with respect % to the edges of the mesh. That is, a single component may contain % non-manifold edges and vertices. % % C = connected_components(F) % % Inputs: % F #F by simplex-size list of simplices % Outputs: % C #V list of ids for each CC % % Examples: % trisurf(F,V(:,1),V(:,2),V(:,3), ... % connected_components([F;repmat(size(V,1),1,3)])); % build adjacency list A = adjacency_matrix(F); [~,C] = conncomp(A); end function [A] = adjacency_matrix(E) % ADJACENCY_MATRIX Build sparse adjacency matrix from edge list or face list % % [A] = adjacency_matrix(E) % [A] = adjacency_matrix(F) % [A] = adjacency_matrix(T) % % Inputs: % E #E by 2 edges list % or % F #F by 3 triangle list % or % T #F by 4 tet list % Outputs: % A #V by #V adjacency matrix (#V = max(E(:))) % % See also: facet_adjacency_matrix % if size(E,2)>2 F = E; E = meshEdges(F); end A = sparse([E(:,1) E(:,2)],[E(:,2) E(:,1)],1); end function [S,C] = conncomp(G) % CONNCOMP Drop in replacement for graphconncomp.m from the bioinformatics % toobox. G is an n by n adjacency matrix, then this identifies the S % connected components C. This is also an order of magnitude faster. % % [S,C] = conncomp(G) % % Inputs: % G n by n adjacency matrix % Outputs: % S scalar number of connected components % C % Transpose to match graphconncomp G = G'; [p,~,r] = dmperm(G+speye(size(G))); S = numel(r)-1; C = cumsum(full(sparse(1,r(1:end-1),1,1,size(G,1)))); C(p) = C; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshEdgeLength.m0000644000000000000000000000013214055375162020460 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshEdgeLength.m0000644000175000017500000000423514055375162021551 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function lengths = meshEdgeLength(vertices, edges, faces) %#ok %MESHEDGELENGTH Lengths of edges of a polygonal or polyhedral mesh. % % output = meshEdgeLength(V, E, F) % % Example % meshEdgeLength % % See also % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-10-04, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % extract vertices p1 = vertices(edges(:, 1), :); p2 = vertices(edges(:, 2), :); % compute euclidean distance betwenn the two vertices lengths = sqrt(sum((p2-p1).^2, 2)); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/distancePointMesh.m0000644000000000000000000000013214055375162021216 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/distancePointMesh.m0000644000175000017500000003013114055375162022301 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [dist, proj] = distancePointMesh(point, vertices, faces, varargin) %DISTANCEPOINTMESH Shortest distance between a (3D) point and a triangle mesh. % % DIST = distancePointMesh(POINT, VERTICES, FACES) % Returns the shortest distance between the query point POINT and the % triangular mesh defined by the set of vertex coordinates VERTICES and % the set of faces FACES. VERTICES is a NV-by-3 array, and FACES is a % NF-by-3 array of vertex indices. % If FACES is NF-by-4 array, it is converted to a (NF*2)-by-3 array. % % [DIST, PROJ] = distancePointMesh(...) % Also returns the projection of the query point on the triangular mesh. % % ... = distancePointMesh(..., 'algorithm', ALGO) % Allows to choose the type of algorithm. Options are: % * sequential: process each face sequentially, using the function % distancePointTriangle3d % * vectorized: vectorized algorithm, usually faster for large number % of faces % * auto: (default) automatically choose the most appropriate % between sequential and vectorized. % % Example % [V, F] = torusMesh(); % F2 = triangulateFaces(F); % P = [10 20 30]; % [D, PROJ] = distancePointMesh(P, V, F2); % figure; drawMesh(V, F) % view(3); axis equal; lighting gouraud; light; % drawPoint3d(P); % drawPoint3d(PROJ, 'm*'); % drawEdge3d([P PROJ], 'linewidth', 2, 'color', 'b'); % % See also % distancePointTriangle3d % % References % * "Distance Between Point and Triangle in 3D", David Eberly (1999) % https://www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf % * Distance between a point and a triangle in 3d, by Gwendolyn Fischer. % * Distance Between Point and Triangulated Surface, by Daniel Frisch. % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-03-08, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. %% Parses input arguments % check the case of mesh given as structure if isstruct(vertices) faces = vertices.faces; vertices = vertices.vertices; end % default option algo = 'auto'; % check optional arguments while length(varargin) > 1 varName = varargin{1}; if ~ischar(varName) error('Require options as parameter name-value pairs'); end if strcmpi(varName, 'algorithm') algo = varargin{2}; else error(['Unknown option name: ' varName]); end varargin(1:2) = []; end % number of faces nFaces = size(faces, 1); if size(faces, 2) > 3 || iscell(faces) faces = triangulateFaces(faces); end % If algorithm is chosen automatically, choose depending on face number if strcmpi(algo, 'auto') if size(faces, 1) > 30 algo = 'vectorized'; else algo = 'sequential'; end end % switch to vectorized algorithm if necessary if strcmpi(algo, 'vectorized') if nargout > 1 [dist, proj] = distancePointTrimesh_vectorized(point, vertices, faces); else dist = distancePointTrimesh_vectorized(point, vertices, faces); end return; end %% Sequential algorithm % For each point, iterates over the triangular faces % allocate memory for result nPoints = size(point, 1); dist = zeros(nPoints, 1); if nargout > 1 projPoints = zeros(nPoints, 3); end % iterate over points for i = 1:nPoints % % min distance and projection for current point minDist = inf; proj = [0 0 0]; % iterate over faces for iFace = 1:nFaces % create triange for current face face = faces(iFace, :); triangle = vertices(face, :); [distf, projf] = distancePointTriangle3d(point(i,:), triangle); if distf < minDist minDist = distf; proj = projf; end end dist(i) = minDist; if nargout > 1 projPoints(i,:) = proj; end end end function [dist, proj] = distancePointTrimesh_vectorized(point, vertices, faces) %DISTANCEPOINTTRIMESH Vectorized version of the distancePointTrimesh function % % output = distancePointTrimesh_vectorized(input) % % This version is vectorized over faces: for each query point, the % minimum distance to each triangular face is computed in parallel. % Then the minimum distance over faces is kept. % % Example % distancePointTrimesh % % See also % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-03-08, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. % Regions are not numbered as in the original paper of D. Eberly to allow % automated computation of regions from the 3 conditions on lines. % Region indices are computed as follow: % IND = b2 * 2^2 + b1 * 2 + b0 % with: % b0 = 1 if s < 0, 0 otherwise % b1 = 1 if t < 0, 0 otherwise % b2 = 1 if s+t > 1, 0 otherwise % resulting ion the following region indices: % /\ t % | % \ R5 | % \ | % \ | % \ | % \| P3 % * % |\ % | \ % R1 | \ R4 % | \ % | R0 \ % | \ % | P1 \ P2 % ------*-------*------> s % | \ % R3 | R2 \ R6 % allocate memory for result nPoints = size(point, 1); dist = zeros(nPoints, 1); proj = zeros(nPoints, 3); % triangle origins and direction vectors p1 = vertices(faces(:,1),:); v12 = vertices(faces(:,2),:) - p1; v13 = vertices(faces(:,3),:) - p1; % identify coefficients of second order equation that do not depend on % query point a = dot(v12, v12, 2); b = dot(v12, v13, 2); c = dot(v13, v13, 2); % iterate on query points for i = 1:nPoints % coefficients of second order equation that depend on query point diffP = bsxfun(@minus, p1, point(i, :)); d = dot(v12, diffP, 2); e = dot(v13, diffP, 2); % compute position of projected point in the plane of the triangle det = a .* c - b .* b; s = b .* e - c .* d; t = b .* d - a .* e; % compute region index (one for each face) regIndex = (s < 0) + 2 * (t < 0) + 4 * (s + t > det); % for each region, process all faces whose projection fall within it % region 0 % the minimum distance occurs inside the triangle inds = regIndex == 0; s(inds) = s(inds) ./ det(inds); t(inds) = t(inds) ./ det(inds); % region 1 (formerly region 3) % The minimum distance must occur on the line s = 0 inds = find(regIndex == 1); s(inds) = 0; t(inds(e(inds) >= 0)) = 0; inds2 = inds(e(inds) < 0); bool3 = c(inds2) <= -e(inds2); t(inds2(bool3)) = 1; inds3 = inds2(~bool3); t(inds3) = -e(inds3) ./ c(inds3); % region 2 (formerly region 5) % The minimum distance must occur on the line t = 0 inds = find(regIndex == 2); t(inds) = 0; s(inds(d(inds) >= 0)) = 0; inds2 = inds(d(inds) < 0); bool3 = a(inds2) <= -d(inds2); s(inds2(bool3)) = 1; inds3 = inds2(~bool3); s(inds3) = -d(inds3) ./ a(inds3); % region 3 (formerly region 4) % The minimum distance must occur % * on the line t = 0 % * on the line s = 0 with t >= 0 % * at the intersection of the two lines inds = find(regIndex == 3); inds2 = inds(d(inds) < 0); % minimum on edge t = 0 with s > 0. t(inds2) = 0; bool3 = a(inds2) <= -d(inds2); s(inds2(bool3)) = 1; inds3 = inds2(~bool3); s(inds3) = -d(inds3) ./ a(inds3); inds2 = inds(d(inds) >= 0); % minimum on edge s = 0 s(inds2) = 0; bool3 = e(inds2) >= 0; t(inds2(bool3)) = 0; bool3 = e(inds2) < 0 & c(inds2) <= e(inds2); t(inds2(bool3)) = 1; bool3 = e(inds2) < 0 & c(inds2) > e(inds2); inds3 = inds2(bool3); t(inds3) = -e(inds3) ./ c(inds3); % region 4 (formerly region 1) % The minimum distance must occur on the line s + t = 1 inds = find(regIndex == 4); numer = (c(inds) + e(inds)) - (b(inds) + d(inds)); s(inds(numer <= 0)) = 0; inds2 = inds(numer > 0); numer = numer(numer > 0); denom = a(inds2) - 2 * b(inds2) + c(inds2); s(inds2(numer > denom)) = 1; bool3 = numer <= denom; s(inds2(bool3)) = numer(bool3) ./ denom(bool3); t(inds) = 1 - s(inds); % Region 5 (formerly region 2) % The minimum distance must occur: % * on the line s + t = 1 % * on the line s = 0 with t <= 1 % * or at the intersection of the two (s=0; t=1) inds = find(regIndex == 5); tmp0 = b(inds) + d(inds); tmp1 = c(inds) + e(inds); % minimum on edge s+t = 1, with s > 0 bool2 = tmp1 > tmp0; inds2 = inds(bool2); numer = tmp1(bool2) - tmp0(bool2); denom = a(inds2) - 2 * b(inds2) + c(inds2); bool3 = numer < denom; s(inds2(~bool3)) = 1; inds3 = inds2(bool3); s(inds3) = numer(bool3) ./ denom(bool3); t(inds2) = 1 - s(inds2); % minimum on edge s = 0, with t <= 1 inds2 = inds(~bool2); s(inds2) = 0; t(inds2(tmp1(~bool2) <= 0)) = 1; t(inds2(tmp1(~bool2) > 0 & e(inds2) >= 0)) = 0; inds3 = inds2(tmp1(~bool2) > 0 & e(inds2) < 0); t(inds3) = -e(inds3) ./ c(inds3); % region 6 (formerly region 6) % The minimum distance must occur % * on the line s + t = 1 % * on the line t = 0, with s <= 1 % * at the intersection of the two lines (s=1; t=0) inds = find(regIndex == 6); tmp0 = b(inds) + e(inds); tmp1 = a(inds) + d(inds); % minimum on edge s+t=1, with t > 0 bool2 = tmp1 > tmp0; inds2 = inds(bool2); numer = tmp1(bool2) - tmp0(bool2); denom = a(inds2) - 2 * b(inds2) + c(inds2); bool3 = numer <= denom; t(inds2(~bool3)) = 1; inds3 = inds2(bool3); t(inds3) = numer(bool3) ./ denom(bool3); s(inds2) = 1 - t(inds2); % minimum on edge t = 0 with s <= 1 inds2 = inds(~bool2); t(inds2) = 0; s(inds2(tmp1(~bool2) <= 0)) = 1; s(inds2(tmp1(~bool2) > 0 & d(inds2) >= 0)) = 0; inds3 = inds2(tmp1(~bool2) > 0 & d(inds2) < 0); s(inds3) = -d(inds3) ./ a(inds3); % compute coordinates of closest point on plane projList = p1 + bsxfun(@times, s, v12) + bsxfun(@times, t, v13); % squared distance between point and closest point on plane [dist(i), ind] = min(sum((bsxfun(@minus, point(i,:), projList)).^2, 2)); % keep the valid projection proj(i, :) = projList(ind,:); end % convert squared distance to distance dist = sqrt(dist); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createDurerPolyhedron.m0000644000000000000000000000013214055375162022106 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createDurerPolyhedron.m0000644000175000017500000000777114055375162023207 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createDurerPolyhedron(varargin) %CREATEDURERPOLYHEDRON Create a mesh representing Durer's polyhedron . % % [V, F] = createDurerPolyhedron % [V, E, F] = createDurerPolyhedron % Returns a mesh data structure that represents Durer's polyhedron shown % in "Melancholia". Vertices are stored in V as Nv-by-3 array of 3D % coordinates, faces are stored in Nf-by-1 cell array containing the % vertex indices of each face. % Several hypotheses exist on the exact geometry of the solid. The one % described in Mathworld (see references) is used here. % % Durer's polyhedron is generated from a centered unit cube. Several % transforms are applied succesively: % * Rotation around Oz by PI / 4 % * Rotation around Oy by asec(sqrt(3)) % * z-scaling by sqrt(1 + 3 / sqrt(5) ) % * truncation by two horizontal planes located at a distance of % (3 - sqrt(5)) / 2 from each azimutal vertex. % % Durer's polyhedron is composed of six pentagonal faces and 2 triangular % faces. Pentagonal faces have angles 126, 108, 72, 108, and 126 degrees. % triangular faces are equilateral. % % Example % % Display Durer's polyhedron % [v f] = createDurerPolyhedron; % figure; hold on; set(gcf, 'renderer', 'opengl'); % drawMesh(v, f, 'FaceColor', [.7 .7 .7]); % axis equal; axis([-1 1 -1 1 -1 1]); % view(3) % % See also % meshes3d, createCube, createOctahedron % % References % http://mathworld.wolfram.com/DuerersSolid.html % http://en.wikipedia.org/wiki/Dürer_graph % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-07-31, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % start from a cube basis [v, f] = createCube; % recenter, rotate, and rescale v = v -.5; rot1 = createRotationOz(pi/4); rot2 = createRotationOy(asec(sqrt(3))); sca = createScaling3d([1 1 sqrt(1+3/sqrt(5))]); v = transformPoint3d(v, sca * rot2 * rot1); % compute the height of the two clipping planes d = (3 - sqrt(5)) / 2; zmax = max(v(:,3)); z1 = zmax - d; % clip by two horizontal planes plane1 = createPlane([0 0 z1], [0 0 1]); [v, f] = clipConvexPolyhedronHP(v, f, plane1); plane2 = createPlane([0 0 -z1], [0 0 -1]); [v, f] = clipConvexPolyhedronHP(v, f, plane2); % complete with edge information e = meshEdges(f); % format output varargout = formatMeshOutput(nargout, v, e, f); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshBoundary.m0000644000000000000000000000013214055375162020235 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshBoundary.m0000644000175000017500000001024014055375162021317 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function polyList = meshBoundary(varargin) %MESHBOUNDARY Boundary of a mesh as a collection of 3D line strings. % % CURVES = meshBoundary(V, F) % % Example % % create centered icosahedron % [v, f] = createIcosahedron; % v(:,3) = v(:,3) - mean(v(:,3)); % % convert to simili-sphere % [v2, f2] = subdivideMesh(v, f, 3); % v3 = normalizeVector3d(v2); % % clip with plane % plane = createPlane([0 0 0], [-1 -2 3]); % [vc, fc] = clipMeshVertices(v3, f2, plane, 'shape', 'plane'); % figure; drawMesh(vc, fc); axis equal; view(3); % % draw mesh boundary % curves = meshBoundary(vc, fc); % hold on; drawPolygon3d(curves{1}, 'linewidth', 2, 'color', 'b'); % % See also % meshes3d, meshBoundaryEdgeIndices, meshBoundaryVertexIndices % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-05-01, using Matlab 8.6.0.267246 (R2015b) % Copyright 2019 INRA - Cepia Software Platform. [vertices, edges, faces] = parseMeshData(varargin{:}); % Compute edge-vertex map if not specified if isempty(edges) edges = meshEdges(vertices, faces); end bndEdgeInds = meshBoundaryEdgeIndices(vertices, edges, faces); bndEdges = edges(bndEdgeInds, :); if isempty(bndEdgeInds) polyList = {}; return; end % allocate empty array polyList = {}; nPolys = 0; while ~isempty(bndEdges) nPolys = nPolys + 1; % current edge edge = bndEdges(1, :); % initialize new polyline at first vertex ind0 = edge(1); vertexInds = ind0; % current vertex index = edge(2); bndEdges(1, :) = []; % iterate over edges until current vertex becomes ind0 while index ~= ind0 % append current vertex to list of indices for current polygon vertexInds = [vertexInds ; index]; %#ok % index of the next edge containing current vertex edgeInd = find(sum(bndEdges == index, 2) > 0); % check validity if isempty(edgeInd) error('could not find next edge for vertex index %d', index); end if length(edgeInd) > 1 error('two many edges contains vertex index %d', index); end % remove current edge from the list of edges to process edge = bndEdges(edgeInd, :); bndEdges(edgeInd, :) = []; % % check if current edge closes current polygon % if index == ind0 % break; % end % identify the next index index = edge(edge ~= index); end % create the 3D polyline polyList{nPolys} = vertices(vertexInds, :); %#ok end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createOctahedron.m0000644000000000000000000000013214055375162021047 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createOctahedron.m0000644000175000017500000000624114055375162022137 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createOctahedron() %CREATEOCTAHEDRON Create a 3D mesh representing an octahedron. % % [V, E, F] = createOctahedron; % Create a 3D mesh representing an octahedron % V is a 6-by-3 array with vertices coordinate, E is a 12-by-2 array % containing indices of neighbour vertices, and F is a 8-by-3 array % containing array of vertex index for each face. % % [V, F] = createOctahedron; % Returns only the vertices and the face vertex indices. % % MESH = createOctahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Vertices are located on grid vertices: % ( ±1, 0, 0 ) % ( 0, ±1, 0 ) % ( 0, 0, ±1 ) % % Edge length of returned octahedron is sqrt(2). % Surface area of octahedron is 2*sqrt(3)*a^2, approximately 6.9282 in % this case. % Volume of octahedron is sqrt(2)/3*a^3, approximately 1.3333 in this % case. % % Example % [v, e, f] = createOctahedron; % drawMesh(v, f); % % See also % meshes3d, drawMesh % createCube, createIcosahedron, createDodecahedron, createTetrahedron % createCubeOctahedron % % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % HISTORY % 04/01/2007: remove unused variables nodes = [1 0 0;0 1 0;-1 0 0;0 -1 0;0 0 1;0 0 -1]; edges = [1 2;1 4;1 5; 1 6;2 3;2 5;2 6;3 4;3 5;3 6;4 5;4 6]; faces = [1 2 5;2 3 5;3 4 5;4 1 5;1 6 2;2 6 3;3 6 4;1 4 6]; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshBoundaryVertexIndices.m0000644000000000000000000000013214055375162022732 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshBoundaryVertexIndices.m0000644000175000017500000000562014055375162024022 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function inds = meshBoundaryVertexIndices(varargin) %MESHBOUNDARYVERTEXINDICES Indices of boundary vertices of a mesh. % % INDS = meshBoundaryVertexIndices(V, F) % INDS = meshBoundaryVertexIndices(V, E, F) % % Example % % create centered icosahedron % [v, f] = createIcosahedron; % v(:,3) = v(:,3) - mean(v(:,3)); % % convert to simili-sphere % [v2, f2] = subdivideMesh(v, f, 3); % v3 = normalizeVector3d(v2); % % clip with plane % plane = createPlane([0 0 0], [-1 -2 3]); % [vc, fc] = clipMeshVertices(v3, f2, plane, 'shape', 'plane'); % figure; drawMesh(vc, fc); axis equal; view(3); % % draw boundary vertices % inds = meshBoundaryVertexIndices(vc, fc); % hold on; drawPoint3d(vc(inds,:), 'k*'); % % See also % meshes3d, meshBoundary, meshBoundaryEdgeIndices, meshEdgeFaces % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-05-01, using Matlab 8.6.0.267246 (R2015b) % Copyright 2019 INRA - Cepia Software Platform. [vertices, edges, faces] = parseMeshData(varargin{:}); % Compute edge-vertex map if not specified if isempty(edges) edges = meshEdges(vertices, faces); end % compute edges to faces map edgeFaces = meshEdgeFaces(vertices, edges, faces); borderEdges = sum(edgeFaces == 0, 2) > 0; inds = edges(borderEdges, :); inds = unique(inds(:)); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/clipMeshVertices.m0000644000000000000000000000013214055375162021046 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/clipMeshVertices.m0000644000175000017500000001071014055375162022132 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = clipMeshVertices(v, f, b, varargin) %CLIPMESHVERTICES Clip vertices of a surfacic mesh and remove outer faces. % % [V2, F2] = clipMeshVertices(V, F, B) % Clip a mesh represented by vertex array V and face array F, with the % box represented by B. The result is the set of vertices contained in % the box, and a new set of faces corresponding to original faces with % all vertices within the box. % % [V2, F2] = clipMeshVertices(..., 'shape', 'sphere') Specify the shape. % Default is 'box'. But it is also possible to use 'sphere' or 'plane'. % % [V2, F2] = clipMeshVertices(..., 'inside', false) removes the inner % faces instead of the outer faces. % % [V2, F2] = clipMeshVertices(..., 'trimMesh', TF) % Also specifies if the isolated vertices need to be removed (TF=true) ot % not (TF=false). Default is false. % % % Example % [v, f] = createSoccerBall; % f = triangulateFaces(f); % box = [0 2 -1 2 -.5 2]; % [v2, f2] = clipMeshVertices(v, f, box, 'inside', false); % figure('color','w'); view(3); axis equal % drawMesh(v, f, 'faceColor', 'none', 'faceAlpha', .2); % drawBox3d(box) % drawMesh(v2, f2, 'faceAlpha', .7); % % See also % meshes3d, clipPoints3d % % ------ % Author: David Legland, oqilipo % e-mail: david.legland@inra.fr % Created: 2011-04-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % if input is given as a structure, parse fields if isstruct(v) if nargin > 2 varargin = [b, varargin]; end b = f; f = v.faces; v = v.vertices; end parser = inputParser; validStrings = {'box', 'sphere', 'plane'}; addParameter(parser, 'shape', 'box', @(x) any(validatestring(x, validStrings))); addParameter(parser, 'inside', true, @islogical); addParameter(parser, 'trimMesh', false, @islogical); parse(parser, varargin{:}); % clip the vertices [v2, indVertices] = clipPoints3d(v, b,... 'shape', parser.Results.shape, 'inside', parser.Results.inside); % create index array for face indices relabeling refInds = zeros(size(indVertices)); for i = 1:length(indVertices) refInds(indVertices(i)) = i; end % select the faces with all vertices within the box if isnumeric(f) % Faces given as numeric array indFaces = sum(~ismember(f, indVertices), 2) == 0; f2 = refInds(f(indFaces, :)); elseif iscell(f) % Faces given as cell array nFaces = length(f); indFaces = false(nFaces, 1); for i = 1:nFaces indFaces(i) = sum(~ismember(f{i}, indVertices), 2) == 0; end f2 = f(indFaces, :); % re-label indices of face vertices (keeping horizontal index array) for i = 1:length(f2) f2{i} = refInds(f2{i})'; end end if parser.Results.trimMesh [v2, f2] = trimMesh(v2, f2); end varargout = formatMeshOutput(nargout, v2, f2); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFaceAreas.m0000644000000000000000000000013214055375162020264 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFaceAreas.m0000644000175000017500000000637714055375162021366 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function areas = meshFaceAreas(vertices, faces) %MESHFACEAREAS Surface area of each face of a mesh. % % areas = meshFaceAreas(vertices, faces) % % Example % [v, f] = createOctahedron; % meshFaceAreas(v, f)' % ans = % 1.7321 1.7321 1.7321 1.7321 1.7321 1.7321 1.7321 1.7321 % % See also % meshes3d, meshSurfaceArea, meshFaceCentroids % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-06-21, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. if isnumeric(faces) % trimesh or quadmesh nf = size(faces, 1); areas = zeros(nf, 1); if size(vertices, 2) == 2 % planar case for f = 1:nf areas(f,:) = polygonArea(vertices(faces(f,:), :)); end else % 3D case if size(faces, 2) == 3 % For triangular meshes, uses accelerated method v1 = vertices(faces(:,1), :); v12 = vertices(faces(:,2), :) - v1; v13 = vertices(faces(:,3), :) - v1; areas = vectorNorm3d(crossProduct3d(v12, v13))/2; else % for quad (or larger) meshes, use slower but more precise method for f = 1:nf areas(f) = polygonArea3d(vertices(faces(f,:), :)); end end end else % mesh with faces stored as cell array nf = length(faces); areas = zeros(nf, 1); if size(vertices, 2) == 2 % planar case for f = 1:nf areas(f) = polygonArea(vertices(faces{f}, :)); end else % 3D case for f = 1:nf areas(f) = polygonArea3d(vertices(faces{f}, :)); end end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/polyhedronSlice.m0000644000000000000000000000013214055375162020740 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/polyhedronSlice.m0000644000175000017500000000622114055375162022026 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function points = polyhedronSlice(nodes, faces, plane) %POLYHEDRONSLICE Intersect a convex polyhedron with a plane. % % SLICE = polyhedronSlice(NODES, FACES, PLANE) % NODES: a Nx3 array % FACES: either a cell array or a Nf*3 or Nf*4 array % PLANE: a plane representation [x0 y0 z0 dx1 dy1 dz1 dx2 dy2 dz2]. % return the intersection polygon of the polyhedra with the plane, in the % form of a set of ordered points. % % Works only for convex polyhedra. % % Example % polyhedronSlice % % See also % polyhedra, clipConvexPolyhedronHP, intersectPlaneMesh % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2007-09-18, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % if faces is a numeric array, convert it to cell array if isnumeric(faces) faces2 = cell(size(faces, 1), 1); for f = 1:length(faces2) faces2{f} = faces(f,:); end faces = faces2; else % ensure we have face with horizontal vectors... for f = 1:length(faces) face = faces{f}; faces{f} = face(:)'; end end % compute edges of the polyhedron inds = zeros(0, 2); for f = 1:length(faces) face = faces{f}'; inds = [inds ; sort([face face([2:end 1])], 2)]; %#ok end inds = unique(inds, 'rows'); edges = [nodes(inds(:,1), :) nodes(inds(:,2), :)]; % intersection of edges with plane points = intersectEdgePlane(edges, plane); points = points(sum(isfinite(points), 2)==3, :); if ~isempty(points) points = angleSort3d(points); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/averageMesh.m0000644000000000000000000000013214055375162020024 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/averageMesh.m0000644000175000017500000001010514055375162021106 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [refMesh, distListIters, refVerticesIters] = averageMesh(meshList, varargin) % Compute average mesh from a list of meshes. % % AVG = averageMesh(MESHLIST) % % Example % averageMesh % % See also % meshes3d % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-01-31, using Matlab 9.7.0.1247435 (R2019b) Update 2 % Copyright 2020 INRAE. %% Parse input values % default values nIters = 10; verbose = false; % parse input arguments while length(varargin) > 1 name = varargin{1}; if ~ischar(name) error('require parameter name-value pairs'); end if strcmpi(name, 'verbose') verbose = varargin{2}; elseif strcmpi(name, 'nIters') nIters = varargin{2}; else error(['Unknown parameter name: ' name]); end varargin(1:2) = []; end %% Initialisations nMeshes = length(meshList); % initialize kd-trees to accelerate nearest-neighbor searches treeList = cell(nMeshes, 1); for iMesh = 1:nMeshes treeList{iMesh} = KDTreeSearcher(meshList{iMesh}.vertices); end % choose arbitrary initial mesh refMesh = struct('vertices', meshList{1}.vertices, 'faces', meshList{1}.faces); refVerticesIters = cell(1, nIters); distListIters = cell(1, nIters); %% Main iteration for iIter = 1:nIters if verbose fprintf('iter %d/%d\n', iIter, nIters); end refMesh = smoothMesh(refMesh); % create new array for average vertices newVerts = zeros(size(refMesh.vertices)); distList = zeros(size(refMesh.vertices, 1), 1); % iterate over all meshes for iMesh = 1:nMeshes if verbose fprintf(' mesh %d/%d\n', iMesh, nMeshes); end % mesh = meshList{iMesh}; inds = knnsearch(treeList{iMesh}, refMesh.vertices); % closest = mesh.vertices(inds,:); closest = treeList{iMesh}.X(inds,:); newVerts = newVerts + closest; distList = distList + sum((closest - refMesh.vertices).^2, 2); end % update new vertices newVerts = newVerts / nMeshes; refVerticesIters{iIter} = newVerts; refMesh.vertices = newVerts; % keep list of distances distList = sqrt(distList / nMeshes); distListIters{iIter} = distList; end % figure; drawMesh(refMesh, 'lineStyle', 'none', 'faceColor', [.5 .5 .5]) % axis equal; view(3); hold on; axis([-2.5 2.5 -2 2 -3.5 3.5]); light; % lighting gouraud % title('Average mesh'); % print(gcf, 'averageMesh_initial.png', '-dpng'); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/polyhedronCentroid.m0000644000000000000000000000013214055375162021450 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/polyhedronCentroid.m0000644000175000017500000000656114055375162022545 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function centroid = polyhedronCentroid(vertices, faces) %#ok %POLYHEDRONCENTROID Compute the centroid of a 3D convex polyhedron. % % CENTRO = polyhedronCentroid(V, F) % Computes the centroid (center of mass) of the polyhedron defined by % vertices V and faces F. % The polyhedron is assumed to be convex. % % Example % % Creates a polyhedron centered on origin, and add an arbitrary % % translation % [v, f] = createDodecahedron; % v2 = bsxfun(@plus, v, [3 4 5]); % % computes the centroid, that should equal the translation vector % centroid = polyhedronCentroid(v2, f) % centroid = % 3.0000 4.0000 5.0000 % % % See also % meshes3d, meshVolume, meshSurfaceArea, polyhedronMeanBreadth % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2012-04-05, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % 2015.11.13 use delaunayTriangulation instead of delaunayn (strange bug % with icosahedron...) % compute set of elementary tetrahedra DT = delaunayTriangulation(vertices); T = DT.ConnectivityList; % number of tetrahedra nT = size(T, 1); % initialize result centroid = zeros(1, 3); vt = 0; % Compute the centroid and the volume of each tetrahedron for i = 1:nT % coordinates of tetrahedron vertices tetra = vertices(T(i, :), :); % centroid is the average of vertices. centi = mean(tetra); % compute volume of tetrahedron vol = det(tetra(1:3,:) - tetra([4 4 4],:)) / 6; % add weighted centroid of current tetraedron centroid = centroid + centi * vol; % compute the sum of tetraedra volumes vt = vt + vol; end % compute by sum of tetrahedron volumes centroid = centroid / vt; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/concatenateMeshes.m0000644000000000000000000000013214055375162021226 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/concatenateMeshes.m0000644000175000017500000001016214055375162022313 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = concatenateMeshes(varargin) % CONCATENATEMESHES Concatenate multiple meshes. % % [V,F] = concatenateMeshes(V1,F1,V2,F2, ...) % Returns one mesh represented by vertices V and faces F by concatenating % the meshes defined by V1, V2, ... and F1, F2, ... % % [V,F] = concatenateMeshes(MESH1, MESH2, ...) % where MESH1, MESH2, ... are structs or struct arrays with the fields % vertices and faces % % See also % splitMesh % % --------- % Authors: oqilipo (parsing), Alec Jacobson (loop) % Created: 2017-09-12 % Copyright 2017 %% parsing inputs assert(~isempty(varargin)) if isstruct(varargin{1}) VF_fields = {'vertices','faces'}; errorStructFields=['If the first input argument is a struct '... 'with the fields vertices and faces the additonal ' ... 'arguments must have the same format']; % Check, if all input arguments are structs assert(all(cellfun(@isstruct, varargin)), errorStructFields) % Check, if all structs contain the two fields vertices and faces assert(all(cellfun(@(x) all(ismember(fieldnames(x), ... VF_fields)), varargin)), errorStructFields) if length(varargin)==1 errorArgAndStructLength = ['If the input is only one struct ' ... 'it has to contain more than one mesh.']; assert(length(varargin{1})>1, ... errorArgAndStructLength) end % Order of the fields: vertices, faces varargin = cellfun(@(x) orderfields(x, VF_fields),varargin, 'UniformOutput',0); % Convert the structs into one cell array varargin = ... cellfun(@struct2cell, varargin, 'UniformOutput', false); varargin = cellfun(@squeeze, varargin, 'UniformOutput',0); varargin = reshape([varargin{:}],[],1)'; end NoA = length(varargin); assert(mod(NoA,2)==0); cellfun(@(x) validateattributes(x, {'numeric'},... {'size',[NaN,3],'finite'}), varargin(1:2:end)) cellfun(@(x) validateattributes(x, {'numeric'},... {'integer'}), varargin(2:2:end)) % Check if all faces have the same number of columns errorFacesRows='The faces of all meshes must have the same number of columns'; assert(numel(unique(cellfun(@(x) size(x,2), varargin(2:2:end))))==1, errorFacesRows) %% loop v=[]; f=[]; for m = 1:NoA/2 vm = varargin{2*m-1}; fm = varargin{2*m}; f = [f; fm+size(v,1)]; %#ok v = [v; vm]; %#ok end %% parsing outputs [v, f] = trimMesh(v, f); switch nargout case 1 mesh.vertices=v; mesh.faces=f; varargout{1}=mesh; case 2 varargout{1}=v; varargout{2}=f; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/removeMeshVertices.m0000644000000000000000000000013214055375162021414 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/removeMeshVertices.m0000644000175000017500000000701714055375162022506 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = removeMeshVertices(vertices, faces, indsToRemove) %REMOVEMESHVERTICES Remove vertices and associated faces from a mesh. % % [V2, F2] = removeMeshVertices(VERTS, FACES, VERTINDS) % Removes the vertices specified by the vertex indices VERTINDS, and % remove the faces containing one of the removed vertices. % % Example % % remove some vertices from a soccerball polyhedron % [v, f] = createSoccerBall; % plane = createPlane([.6 0 0], [1 0 0]); % indAbove = find(~isBelowPlane(v, plane)); % [v2, f2] = removeMeshVertices(v, f, indAbove); % drawMesh(v2, f2); % axis equal; hold on; % % See also % meshes3d, trimMesh % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2016-02-03, using Matlab 8.6.0.267246 (R2015b) % Copyright 2016 INRA - Cepia Software Platform. % parse inputs if nargin == 2 indsToRemove = faces; [vertices, faces] = parseMeshData(vertices); end % create array of indices to keep nVertices = size(vertices, 1); newInds = (1:nVertices)'; newInds(indsToRemove) = []; % create new vertex array vertices2 = vertices(newInds, :); % compute map from old indices to new indices oldNewMap = zeros(nVertices, 1); for iIndex = 1:size(newInds, 1) oldNewMap(newInds(iIndex)) = iIndex; end % change labels of vertices referenced by faces if isnumeric(faces) faces2 = oldNewMap(faces); if size(faces2,2)==1; faces2=faces2'; end % keep only faces with valid vertices faces2 = faces2(sum(faces2 == 0, 2) == 0, :); elseif iscell(faces) faces2 = cell(1, length(faces)); for iFace = 1:length(faces) newFace = oldNewMap(faces{iFace}); % add the new face only if all vertices are valid if ~any(newFace == 0) faces2{iFace} = newFace; end end % remove empty faces faces2 = faces2(~cellfun(@isempty, faces2)); end % format output arguments varargout = formatMeshOutput(nargout, vertices2, faces2); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/mushroom.off0000644000000000000000000000013214055375161017763 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/mushroom.off0000644000175000017500000003036714055375161021061 0ustar00juanpijuanpi00000000000000OFF 226 448 0 0.0184074 0.354329 -0.024123 0.34662 0.338337 -0.0333459 0.619946 0.233133 -0.0410264 0.802164 0.111095 -0.0461463 0.945962 0 -0.0501877 0.933888 -0.0967886 -0.0498478 0.876808 -0.16496 -0.0482442 0.666049 -0.144762 -0.0423219 0.320274 -0.0875299 -0.032606 0.10293 -0.131295 -0.0264984 0.0974423 -0.305513 -0.0263437 0.234654 -0.600927 -0.0301999 0.307102 -0.806286 -0.0322353 0.243436 -0.877825 -0.0304465 0.150131 -0.8854 -0.0278245 0.0184074 -0.881192 -0.024123 0.295122 0.338337 0.103678 0.525565 0.233133 0.210107 0.679193 0.111095 0.28106 0.80043 0 0.337053 0.790249 -0.0967886 0.332351 0.742125 -0.16496 0.310125 0.564434 -0.144762 0.228059 0.272911 -0.0875299 0.0934197 0.0896685 -0.131295 0.00878897 0.0850418 -0.305513 0.00665224 0.200725 -0.600927 0.0600799 0.261806 -0.806286 0.0882906 0.208128 -0.877825 0.0635003 0.129464 -0.8854 0.0271679 0.208881 0.338337 0.165273 0.367504 0.233133 0.322996 0.473253 0.111095 0.428146 0.556706 0 0.511125 0.549698 -0.0967886 0.504157 0.516572 -0.16496 0.471219 0.39426 -0.144762 0.3496 0.193592 -0.0875299 0.15007 0.0674588 -0.131295 0.0246511 0.0642744 -0.305513 0.021484 0.143904 -0.600927 0.100663 0.185948 -0.806286 0.142468 0.149 -0.877825 0.10573 0.0948524 -0.8854 0.0518889 0.103718 0.338337 0.27331 0.174762 0.233133 0.521005 0.222124 0.111095 0.686136 0.259502 0 0.816448 0.256363 -0.0967886 0.805506 0.241527 -0.16496 0.753779 0.186745 -0.144762 0.562785 0.0968705 -0.0875299 0.249435 0.0403771 -0.131295 0.0524739 0.0389509 -0.305513 0.0474993 0.0746154 -0.600927 0.171844 0.0934461 -0.806286 0.237499 0.0768974 -0.877825 0.179803 0.0526457 -0.8854 0.0952486 0.0184074 0.338337 0.338198 0.0184074 0.233133 0.639931 0.0184074 0.111095 0.841086 0.0184074 0 0.99983 0.0184074 -0.0967886 0.9865 0.0184074 -0.16496 0.923487 0.0184074 -0.144762 0.690826 0.0184074 -0.0875299 0.309116 0.0184074 -0.131295 0.0691839 0.0184074 -0.305513 0.0631256 0.0184074 -0.600927 0.214597 0.0184074 -0.806286 0.294575 0.0184074 -0.877825 0.224292 0.0184074 -0.8854 0.12129 -0.11218 0.338337 0.310618 -0.22093 0.233133 0.589383 -0.29343 0.111095 0.775226 -0.350644 0 0.921885 -0.34584 -0.0967886 0.909571 -0.323129 -0.16496 0.851354 -0.239273 -0.144762 0.636403 -0.101699 -0.0875299 0.28375 -0.0152218 -0.131295 0.0620819 -0.0130384 -0.305513 0.0564835 -0.0676323 -0.600927 0.196425 -0.0964574 -0.806286 0.270315 -0.0711259 -0.877825 0.205383 -0.0340018 -0.8854 0.110222 -0.196264 0.338337 0.216986 -0.375037 0.233133 0.417774 -0.494219 0.111095 0.551634 -0.588273 0 0.657271 -0.580376 -0.0967886 0.648401 -0.543042 -0.16496 0.606469 -0.405193 -0.144762 0.451643 -0.179033 -0.0875299 0.197633 -0.0368757 -0.131295 0.0379687 -0.033286 -0.305513 0.0339365 -0.123031 -0.600927 0.134735 -0.170418 -0.806286 0.187956 -0.128775 -0.877825 0.141186 -0.0677482 -0.8854 0.072643 -0.249622 0.338337 0.12377 -0.472831 0.233133 0.246932 -0.621637 0.111095 0.32904 -0.739067 0 0.393836 -0.729206 -0.0967886 0.388395 -0.682593 -0.16496 0.362674 -0.51048 -0.144762 0.267706 -0.228108 -0.0875299 0.111898 -0.0506171 -0.131295 0.0139635 -0.0461344 -0.305513 0.0114895 -0.158187 -0.600927 0.0733188 -0.217351 -0.806286 0.105964 -0.165359 -0.877825 0.077275 -0.0891635 -0.8854 0.0352323 -0.269476 0.338337 0.00354499 -0.509218 0.233133 0.0265865 -0.669046 0.111095 0.0419476 -0.795175 0 0.0540695 -0.784585 -0.0967886 0.0530524 -0.734518 -0.16496 0.0482405 -0.549657 -0.144762 0.0304735 -0.246368 -0.0875299 0.00132441 -0.0557303 -0.131295 -0.0169984 -0.0509157 -0.305513 -0.0174609 -0.171268 -0.600927 -0.00589341 -0.234814 -0.806286 0.000214196 -0.178971 -0.877825 -0.00515362 -0.0971306 -0.8854 -0.0130181 -0.262652 0.338337 -0.148301 -0.496709 0.233133 -0.251713 -0.652749 0.111095 -0.320654 -0.775889 0 -0.37506 -0.765549 -0.0967886 -0.370492 -0.716668 -0.16496 -0.348895 -0.53619 -0.144762 -0.269155 -0.240091 -0.0875299 -0.138333 -0.0539721 -0.131295 -0.056102 -0.0492721 -0.305513 -0.0540252 -0.166772 -0.600927 -0.105939 -0.228812 -0.806286 -0.133349 -0.174291 -0.877825 -0.109261 -0.0943927 -0.8854 -0.0739595 -0.222887 0.338337 -0.280322 -0.42383 0.233133 -0.493681 -0.557793 0.111095 -0.635918 -0.66351 0 -0.748166 -0.654633 -0.0967886 -0.738741 -0.612669 -0.16496 -0.694184 -0.457724 -0.144762 -0.529668 -0.203519 -0.0875299 -0.259759 -0.0437324 -0.131295 -0.0901003 -0.0396975 -0.305513 -0.0858162 -0.140572 -0.600927 -0.192923 -0.193834 -0.806286 -0.249477 -0.147028 -0.877825 -0.199779 -0.0784332 -0.8854 -0.126946 -0.114676 0.338337 -0.332426 -0.225506 0.233133 -0.589172 -0.299392 0.111095 -0.760337 -0.357699 0 -0.895414 -0.352803 -0.0967886 -0.884071 -0.329658 -0.16496 -0.830453 -0.2442 -0.144762 -0.63248 -0.103994 -0.0875299 -0.307679 -0.0158656 -0.131295 -0.103519 -0.0136396 -0.305513 -0.0983633 -0.0692771 -0.600927 -0.227252 -0.0986528 -0.806286 -0.295306 -0.0728375 -0.877825 -0.235502 -0.0350042 -0.8854 -0.147856 0.0184074 0.338337 -0.339672 0.0184074 0.233133 -0.602454 0.0184074 0.111095 -0.777642 0.0184074 0 -0.915893 0.0184074 -0.0967886 -0.904283 0.0184074 -0.16496 -0.849405 0.0184074 -0.144762 -0.646779 0.0184074 -0.0875299 -0.314343 0.0184074 -0.131295 -0.105385 0.0184074 -0.305513 -0.100108 0.0184074 -0.600927 -0.232027 0.0184074 -0.806286 -0.301679 0.0184074 -0.877825 -0.24047 0.0184074 -0.8854 -0.150764 0.128226 0.338337 -0.295865 0.219678 0.233133 -0.522163 0.280648 0.111095 -0.67303 0.328761 0 -0.792087 0.324722 -0.0967886 -0.78209 0.305622 -0.16496 -0.734831 0.235105 -0.144762 -0.560335 0.119411 -0.0875299 -0.274052 0.0466887 -0.131295 -0.0941032 0.0448519 -0.305513 -0.0895592 0.0907615 -0.600927 -0.203163 0.115003 -0.806286 -0.263146 0.0937007 -0.877825 -0.210434 0.0624815 -0.8854 -0.133183 0.247039 0.338337 -0.245139 0.437438 0.233133 -0.429196 0.56437 0.111095 -0.5519 0.66454 0 -0.648734 0.656129 -0.0967886 -0.640603 0.616367 -0.16496 -0.602166 0.469553 -0.144762 -0.460242 0.228688 -0.0875299 -0.227399 0.0772853 -0.131295 -0.0810402 0.0734624 -0.305513 -0.077344 0.169045 -0.600927 -0.169742 0.219512 -0.806286 -0.218528 0.175162 -0.877825 -0.175656 0.110165 -0.8854 -0.112824 0.333673 0.338337 -0.162777 0.596218 0.233133 -0.278246 0.771249 0.111095 -0.355224 0.909376 0 -0.415972 0.897777 -0.0967886 -0.410871 0.842948 -0.16496 -0.386758 0.640503 -0.144762 -0.297722 0.308368 -0.0875299 -0.151648 0.0995963 -0.131295 -0.0598303 0.0943245 -0.305513 -0.0575109 0.226125 -0.600927 -0.115477 0.295714 -0.806286 -0.146083 0.234559 -0.877825 -0.119187 0.144936 -0.8854 -0.0797698 3 16 1 0 3 2 1 16 3 3 2 17 3 4 3 18 3 5 4 19 3 6 5 20 3 7 6 21 3 8 7 22 3 9 8 23 3 10 9 24 3 11 10 25 3 12 11 26 3 13 12 27 3 14 13 28 3 29 15 14 3 30 16 0 3 17 16 30 3 18 17 31 3 19 18 32 3 20 19 33 3 21 20 34 3 22 21 35 3 23 22 36 3 24 23 37 3 25 24 38 3 26 25 39 3 27 26 40 3 28 27 41 3 29 28 42 3 43 15 29 3 44 30 0 3 31 30 44 3 32 31 45 3 33 32 46 3 34 33 47 3 35 34 48 3 36 35 49 3 37 36 50 3 38 37 51 3 39 38 52 3 40 39 53 3 41 40 54 3 42 41 55 3 43 42 56 3 57 15 43 3 58 44 0 3 45 44 58 3 46 45 59 3 47 46 60 3 48 47 61 3 49 48 62 3 50 49 63 3 51 50 64 3 52 51 65 3 53 52 66 3 54 53 67 3 55 54 68 3 56 55 69 3 57 56 70 3 71 15 57 3 72 58 0 3 59 58 72 3 60 59 73 3 61 60 74 3 62 61 75 3 63 62 76 3 64 63 77 3 65 64 78 3 66 65 79 3 67 66 80 3 68 67 81 3 69 68 82 3 70 69 83 3 71 70 84 3 85 15 71 3 86 72 0 3 73 72 86 3 74 73 87 3 75 74 88 3 76 75 89 3 77 76 90 3 78 77 91 3 79 78 92 3 80 79 93 3 81 80 94 3 82 81 95 3 83 82 96 3 84 83 97 3 85 84 98 3 99 15 85 3 100 86 0 3 87 86 100 3 88 87 101 3 89 88 102 3 90 89 103 3 91 90 104 3 92 91 105 3 93 92 106 3 94 93 107 3 95 94 108 3 96 95 109 3 97 96 110 3 98 97 111 3 99 98 112 3 113 15 99 3 114 100 0 3 101 100 114 3 102 101 115 3 103 102 116 3 104 103 117 3 105 104 118 3 106 105 119 3 107 106 120 3 108 107 121 3 109 108 122 3 110 109 123 3 111 110 124 3 112 111 125 3 113 112 126 3 127 15 113 3 128 114 0 3 115 114 128 3 116 115 129 3 117 116 130 3 118 117 131 3 119 118 132 3 120 119 133 3 121 120 134 3 122 121 135 3 123 122 136 3 124 123 137 3 125 124 138 3 126 125 139 3 127 126 140 3 141 15 127 3 142 128 0 3 129 128 142 3 130 129 143 3 131 130 144 3 132 131 145 3 133 132 146 3 134 133 147 3 135 134 148 3 136 135 149 3 137 136 150 3 138 137 151 3 139 138 152 3 140 139 153 3 141 140 154 3 155 15 141 3 156 142 0 3 143 142 156 3 144 143 157 3 145 144 158 3 146 145 159 3 147 146 160 3 148 147 161 3 149 148 162 3 150 149 163 3 151 150 164 3 152 151 165 3 153 152 166 3 154 153 167 3 155 154 168 3 169 15 155 3 170 156 0 3 157 156 170 3 158 157 171 3 159 158 172 3 160 159 173 3 161 160 174 3 162 161 175 3 163 162 176 3 164 163 177 3 165 164 178 3 166 165 179 3 167 166 180 3 168 167 181 3 169 168 182 3 183 15 169 3 184 170 0 3 171 170 184 3 172 171 185 3 173 172 186 3 174 173 187 3 175 174 188 3 176 175 189 3 177 176 190 3 178 177 191 3 179 178 192 3 180 179 193 3 181 180 194 3 182 181 195 3 183 182 196 3 197 15 183 3 198 184 0 3 185 184 198 3 186 185 199 3 187 186 200 3 188 187 201 3 189 188 202 3 190 189 203 3 191 190 204 3 192 191 205 3 193 192 206 3 194 193 207 3 195 194 208 3 196 195 209 3 197 196 210 3 211 15 197 3 212 198 0 3 199 198 212 3 200 199 213 3 201 200 214 3 202 201 215 3 203 202 216 3 204 203 217 3 205 204 218 3 206 205 219 3 207 206 220 3 208 207 221 3 209 208 222 3 210 209 223 3 211 210 224 3 225 15 211 3 1 212 0 3 213 212 1 3 214 213 2 3 215 214 3 3 216 215 4 3 217 216 5 3 218 217 6 3 219 218 7 3 220 219 8 3 221 220 9 3 222 221 10 3 223 222 11 3 224 223 12 3 225 224 13 3 14 15 225 3 16 17 2 3 17 18 3 3 18 19 4 3 19 20 5 3 20 21 6 3 21 22 7 3 22 23 8 3 23 24 9 3 24 25 10 3 25 26 11 3 26 27 12 3 27 28 13 3 28 29 14 3 30 31 17 3 31 32 18 3 32 33 19 3 33 34 20 3 34 35 21 3 35 36 22 3 36 37 23 3 37 38 24 3 38 39 25 3 39 40 26 3 40 41 27 3 41 42 28 3 42 43 29 3 44 45 31 3 45 46 32 3 46 47 33 3 47 48 34 3 48 49 35 3 49 50 36 3 50 51 37 3 51 52 38 3 52 53 39 3 53 54 40 3 54 55 41 3 55 56 42 3 56 57 43 3 58 59 45 3 59 60 46 3 60 61 47 3 61 62 48 3 62 63 49 3 63 64 50 3 64 65 51 3 65 66 52 3 66 67 53 3 67 68 54 3 68 69 55 3 69 70 56 3 70 71 57 3 72 73 59 3 73 74 60 3 74 75 61 3 75 76 62 3 76 77 63 3 77 78 64 3 78 79 65 3 79 80 66 3 80 81 67 3 81 82 68 3 82 83 69 3 83 84 70 3 84 85 71 3 86 87 73 3 87 88 74 3 88 89 75 3 89 90 76 3 90 91 77 3 91 92 78 3 92 93 79 3 93 94 80 3 94 95 81 3 95 96 82 3 96 97 83 3 97 98 84 3 98 99 85 3 100 101 87 3 101 102 88 3 102 103 89 3 103 104 90 3 104 105 91 3 105 106 92 3 106 107 93 3 107 108 94 3 108 109 95 3 109 110 96 3 110 111 97 3 111 112 98 3 112 113 99 3 114 115 101 3 115 116 102 3 116 117 103 3 117 118 104 3 118 119 105 3 119 120 106 3 120 121 107 3 121 122 108 3 122 123 109 3 123 124 110 3 124 125 111 3 125 126 112 3 126 127 113 3 128 129 115 3 129 130 116 3 130 131 117 3 131 132 118 3 132 133 119 3 133 134 120 3 134 135 121 3 135 136 122 3 136 137 123 3 137 138 124 3 138 139 125 3 139 140 126 3 140 141 127 3 142 143 129 3 143 144 130 3 144 145 131 3 145 146 132 3 146 147 133 3 147 148 134 3 148 149 135 3 149 150 136 3 150 151 137 3 151 152 138 3 152 153 139 3 153 154 140 3 154 155 141 3 156 157 143 3 157 158 144 3 158 159 145 3 159 160 146 3 160 161 147 3 161 162 148 3 162 163 149 3 163 164 150 3 164 165 151 3 165 166 152 3 166 167 153 3 167 168 154 3 168 169 155 3 170 171 157 3 171 172 158 3 172 173 159 3 173 174 160 3 174 175 161 3 175 176 162 3 176 177 163 3 177 178 164 3 178 179 165 3 179 180 166 3 180 181 167 3 181 182 168 3 182 183 169 3 184 185 171 3 185 186 172 3 186 187 173 3 187 188 174 3 188 189 175 3 189 190 176 3 190 191 177 3 191 192 178 3 192 193 179 3 193 194 180 3 194 195 181 3 195 196 182 3 196 197 183 3 198 199 185 3 199 200 186 3 200 201 187 3 201 202 188 3 202 203 189 3 203 204 190 3 204 205 191 3 205 206 192 3 206 207 193 3 207 208 194 3 208 209 195 3 209 210 196 3 210 211 197 3 212 213 199 3 213 214 200 3 214 215 201 3 215 216 202 3 216 217 203 3 217 218 204 3 218 219 205 3 219 220 206 3 220 221 207 3 221 222 208 3 222 223 209 3 223 224 210 3 224 225 211 3 1 2 213 3 2 3 214 3 3 4 215 3 4 5 216 3 5 6 217 3 6 7 218 3 7 8 219 3 8 9 220 3 9 10 221 3 10 11 222 3 11 12 223 3 12 13 224 3 13 14 225 # End of OFF # matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshComplement.m0000644000000000000000000000013214055375162020555 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshComplement.m0000644000175000017500000000502614055375162021645 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = meshComplement(varargin) % Reverse the normal of each face in the mesh. % % [V2, F2] = meshComplement(V, F) % % Example % [v, f] = createOctahedron; % meshVolume(v, f) % ans = % 1.3333 % [v2, f2] = meshComplement(v, f); % meshVolume(v2, f2) % ans = % -1.3333 % % See also % meshes3d, meshVolume % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-01-22, using Matlab 9.7.0.1247435 (R2019b) Update 2 % Copyright 2020 INRAE. % extract mesh data mesh = parseMeshData(varargin{:}); faces = mesh.faces; % iterate over faces to invert order of vertex indices if isnumeric(faces) for i = 1:size(faces, 1) faces(i,:) = faces(i, end:-1:1); end else for i = 1:size(faces, 1) faces{i} = faces{i}(end:-1:1); end end % create new mesh data varargout = formatMeshOutput(nargout, mesh.vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/boxToMesh.m0000644000000000000000000000013214055375162017505 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/boxToMesh.m0000644000175000017500000000657014055375162020602 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = boxToMesh(varargin) % BOXTOMESH Convert a box into a quad mesh with the same size. % % [V E F] = boxToMesh(BOX) % Create a box as a polyhedra representation. The box is defined by its % coordinate extents: BOX = [XMIN XMAX YMIN YMAX ZMIN ZMAX] % The result has the form [V E F], where V is a 8-by-3 array with vertex % coordinates, E is a 12-by-2 array containing indices of neighbour % vertices, and F is a 6-by-4 array containing vertices array of each % face. % % [V F] = boxToMesh(BOX) % Returns only the vertices and the face vertex indices. % % MESH = boxToMesh(BOX) % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % ... = boxToMesh() % Creates a unit cube % % Example % [v, f] = boxToMesh([-2 -1 0 pi 2 3]) % drawMesh(v, f); % % See also % meshes3d, drawMesh, triangulateFaces % --------- % authors: David Legland, oqilipo % created the 22/09/2016. p = inputParser; boxDefault = [0 1 0 1 0 1]; boxDatatype = {'numeric'}; boxAttribs = {'nonempty','vector','numel',6,'real','finite'}; addOptional(p,'box',boxDefault,@(x)validateattributes(x,boxDatatype,boxAttribs)) parse(p,varargin{:}) xmin = p.Results.box(1); xmax = p.Results.box(2); ymin = p.Results.box(3); ymax = p.Results.box(4); zmin = p.Results.box(5); zmax = p.Results.box(6); vertices = [... xmin, ymin, zmin; ... xmax, ymin, zmin; ... xmin, ymax, zmin; ... xmax, ymax, zmin; ... xmin, ymin, zmax; ... xmax, ymin, zmax; ... xmin, ymax, zmax; ... xmax, ymax, zmax; ... ]; edges = [1 2;1 3;1 5;2 4;2 6;3 4;3 7;4 8;5 6;5 7;6 8;7 8]; % faces are oriented such that normals point outwards faces = [2 4 3 1;7 8 6 5;6 8 4 2;3 7 5 1;5 6 2 1;4 8 7 3]; % format output varargout = formatMeshOutput(nargout, vertices, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/ensureManifoldMesh.m0000644000000000000000000000013214055375162021365 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/ensureManifoldMesh.m0000644000175000017500000000560514055375162022460 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = ensureManifoldMesh(varargin) %ENSUREMANIFOLDMESH Apply several simplification to obtain a manifold mesh. % % Try to transform an input mesh into a manifold mesh. % % Not all cases of "non-manifoldity" are checked, so please use with % care. % % [V2, F2] = ensureManifoldMesh(V, F); % [V2, F2] = ensureManifoldMesh(MESH); % MESH2 = ensureManifoldMesh(...); % % Example % ensureManifoldMesh % % See also % meshes3d, isManifoldMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-02-01, using Matlab 9.5.0.944444 (R2018b) % Copyright 2019 INRA - Cepia Software Platform. %% Parse input arguments [vertices, faces] = parseMeshData(varargin{:}); verbose = true; %% Pre-processing % remove duplicate faces if any if verbose disp('remove duplicate faces'); end faces = removeDuplicateFaces(faces); %% Iterative processing of multiple edges % Reduces all edges connected to more than two faces, by collapsing second % vertex onto the first one. % iter = 0; % while ~isManifoldMesh(vertices, faces) && iter < 10 % iter = iter + 1; if verbose disp('collapse edges with many faces'); end [vertices, faces] = collapseEdgesWithManyFaces(vertices, faces); % end %% Format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/triangulateFaces.m0000644000000000000000000000013214055375162021056 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/triangulateFaces.m0000644000175000017500000001100214055375162022135 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [tri, inds] = triangulateFaces(faces) %TRIANGULATEFACES Convert face array to an array of triangular faces. % % TRI = triangulateFaces(FACES) % Returns a 3-columns array of indices, based on the data stored in the % argument FACES: % - if FACES is a N-by-3 array, returns the same array % - if FACES is a N-by-4 array, returns an array with 2*N rows and 3 % columns, splitting each square into 2 triangles (uses first and % third vertex of each square as diagonal). % - if FACES is a cell array, split each face into a set of triangles, % and returns the union of all triangles. Faces are assumed to be % convex. % % [TRI INDS] = triangulateFaces(FACES) % Also returns original face index of each new triangular face. INDS has % the same number of rows as TRI, and has values between 1 and the % number of rows of the original FACES array. % % % Example % % create a basic shape % [n e f] = createCubeOctahedron; % % draw with plain faces % figure; % drawMesh(n, f); % % draw as a triangulation % tri = triangulateFaces(f); % figure; % patch('vertices', n, 'faces', tri, 'facecolor', 'r'); % % See also % meshes3d, drawMesh, mergeCoplanarFaces % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2008-09-08, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Tri mesh case: return original set of faces if isnumeric(faces) && size(faces, 2) == 3 tri = faces; if nargout > 1 inds = (1:size(faces, 1))'; end return; end %% Square faces: split each square into 2 triangles if isnumeric(faces) && size(faces, 2) == 4 nf = size(faces, 1); tri = zeros(nf * 2, 3); tri(1:2:end, :) = faces(:, [1 2 3]); tri(2:2:end, :) = faces(:, [1 3 4]); if nargout > 1 inds = kron(1:size(faces, 1), ones(1,2))'; end return; end %% Pentagonal faces (for dodecahedron...): split into 3 triangles if isnumeric(faces) && size(faces, 2) == 5 nf = size(faces, 1); tri = zeros(nf * 3, 3); tri(1:3:end, :) = faces(:, [1 2 3]); tri(2:3:end, :) = faces(:, [1 3 4]); tri(3:3:end, :) = faces(:, [1 4 5]); if nargout > 1 inds = kron(1:size(faces, 1), ones(1,2))'; end return; end %% Faces as cell array % number of faces nf = length(faces); % compute total number of triangles ni = zeros(nf, 1); for i = 1:nf % as many triangles as the number of vertices minus 1 ni(i) = length(faces{i}) - 2; end nt = sum(ni); % allocate memory for triangle array tri = zeros(nt, 3); inds = zeros(nt, 1); % convert faces to triangles t = 1; for i = 1:nf face = faces{i}; nv = length(face); v0 = face(1); for j = 3:nv tri(t, :) = [v0 face(j-1) face(j)]; inds(t) = i; t = t + 1; end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createMengerSponge.m0000644000000000000000000000013214055375162021352 xustar0030 mtime=1622538866.094813507 30 atime=1622538866.094813507 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createMengerSponge.m0000644000175000017500000001154514055375162022445 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createMengerSponge() %CREATEMENGERSPONGE Create a cube with an inside cross removed. % % [n, e, f] = createMengerSponge; % Main use is to test possibility of drawing polyhedra with complex faces % (polygonal faces with holes) % % Example % [n, e, f] = createMengerSponge; % drawMesh(n, f); % % See also % meshes3d, drawMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-10-18 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY % 2008-10-17 finishes implementation nodes =[... ... % main cube corners (1->8) 0 0 0; ... 3 0 0; ... 0 3 0; ... 3 3 0; ... 0 0 3; ... 3 0 3; ... 0 3 3; ... 3 3 3; ... ... % outer cube inner face corners 1 1 0; ... % face z=0 (9->12) 2 1 0; ... 1 2 0; ... 2 2 0; ... 1 1 3; ... % face z=3 (13->16) 2 1 3; ... 1 2 3; ... 2 2 3; ... 1 0 1; ... % face y=0 (17->20) 2 0 1; ... 1 0 2; ... 2 0 2; ... 1 3 1; ... % face y=3 (21->24) 2 3 1; ... 1 3 2; ... 2 3 2; ... 0 1 1; ... % face x=0 (25->28) 0 2 1; ... 0 1 2; ... 0 2 2; ... 3 1 1; ... % face x=3 (29->32) 3 2 1; ... 3 1 2; ... 3 2 2; ... ... % inner cube corners (33->40) 1 1 1; ... 2 1 1; ... 1 2 1; ... 2 2 1; ... 1 1 2; ... 2 1 2; ... 1 2 2; ... 2 2 2; ... ]; edges = [... 1 2;1 3;2 4;3 4;5 6;5 7;6 8;7 8;1 5;2 6;3 7;4 8;... % outer cube 9 10;9 11;10 12;11 12;13 14;13 15;14 16;15 16; ... 17 18;17 19;18 20;19 20; 21 22;21 23;22 24;23 24; ... 25 26;25 27;26 28;27 28; 29 30;29 31;30 32;31 32; ... 33 34;33 35;34 36;35 36; 37 38;37 39;38 40;39 40; ... % inner cube 33 37;34 38;35 39;36 40; ... 9 33;10 34;11 35;12 36; ... % parallel to xy 13 37;14 38;15 39;16 40; ... 17 33;18 34;19 37;20 38; ... % parallel to yz 21 35;22 36;23 39;24 40; ... 25 33;26 35;27 37;28 39; ... % parallel to xz 29 34;30 36;31 38;32 40; ... ]; % Alternative definition for faces: % [1 2 4 3 NaN 9 11 12 10], ... % [5 6 8 7 NaN 13 15 16 14], ... % [1 5 7 3 NaN 25 26 28 27], .... % [2 6 8 4 NaN 29 30 32 31], ... % [1 2 6 5 NaN 17 18 20 19], ... % [3 4 8 7 NaN 21 22 24 23], ... faces = {... ... % 6 square faces with a square hole [1 2 4 3 1 9 11 12 10 9], ... [5 6 8 7 5 13 15 16 14 13], ... [1 5 7 3 1 25 26 28 27 25], .... [2 6 8 4 2 29 30 32 31 29], ... [1 2 6 5 1 17 18 20 19 17], ... [3 4 8 7 3 21 22 24 23 21], ... ... % faces orthogonal to XY plane, parallel to Oz axis [ 9 10 34 33], [ 9 11 35 33], [10 12 36 34], [11 12 36 35], ... [13 14 38 37], [13 15 39 37], [14 16 40 38], [15 16 40 39], ... ... % faces orthogonal to YZ plane, parallel to Oy axis [17 18 34 33], [17 19 37 33], [18 20 38 34], [19 20 38 37], ... [21 22 36 35], [21 23 39 35], [22 24 40 36], [23 24 40 39], ... ...% faces orthogonal to the YZ plane, parallel to Ox axis [25 33 35 26], [25 33 37 27], [26 35 39 28], [27 37 39 28], ... [29 30 36 34], [29 31 38 34], [30 32 40 36], [31 32 40 38], ... }; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/cutMeshByPlane.m0000644000000000000000000000013214055375162020460 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/cutMeshByPlane.m0000644000175000017500000001256314055375162021554 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cutMeshByPlane(v, f, plane, varargin) %CUTMESHBYPLANE Cut a mesh by a plane. % % [ABOVE, IN, BELOW] = cutMeshByPlane(MESH, PLANE) % where MESH, ABOVE, IN, BELOW are structs with the fields vertices and % faces, and PLANE is given as a row containing initial point and 2 % direction vectors. ABOVE, IN, BELOW contain the corresponding parts of % the input mesh. % % [ABOVE_V, ABOVE_F, IN_V, IN_F, BELOW_V,BELOW_F] = ... % cutMeshByPlane(V, F, PLANE) where V is a [NVx3] array containing % coordinates and F is a [NFx3] array containing indices of vertices of % the triangular faces. % % BELOW = cutMeshByPlane(V, F, PLANE, 'part', 'below') BELOW is a struct % with the fields vertices and faces. Other options are: % 'part' - 'above': Faces above the plane % - 'in' : Faces in the plane % - 'below': Faces below the plane % % [BELOW_V, BELOW_F] = cutMeshByPlane(MESH, PLANE, 'part', 'below') is % possible, too. % % --------- % Authors: oqilipo, David Legland % Created: 2017-07-09 % Copyright 2017 narginchk(2,5) nargoutchk(1,6) %% Parse inputs % If first argument is a struct if nargin == 2 || nargin == 4 if ~isempty(varargin) varargin = [{plane}, varargin(:)']; end plane = f; [v, f] = parseMeshData(v); end p = inputParser; addRequired(p,'plane',@isPlane) validStrings = {'above','in','below'}; addParameter(p,'part','above',@(x) any(validatestring(x, validStrings))) parse(p, plane, varargin{:}); part=p.Results.part; %% Algorithm % Logical index to the vertices below the plane VBPl_LI = isBelowPlane(v, plane); % Logical index to three vertices of each face FBP_LI = VBPl_LI(f); switch nargout case {1, 2} switch part case 'above' % Faces above the plane, all three vertices == 0 -> sum has to be 0 above = removeMeshFaces(v, f, ~(sum(FBP_LI, 2) == 0) ); case 'in' % Faces in the plane, 1 or 2 vertices == 0 -> sum can be 1 or 2 inside = removeMeshFaces(v, f, ~((sum(FBP_LI, 2) > 0 & sum(FBP_LI, 2) < 3))); case 'below' % Faces below the plane, all three vertices == 1 -> sum has to be 3 below = removeMeshFaces(v, f, ~(sum(FBP_LI, 2) == 3) ); end case {3, 6} % Faces above the plane, all three vertices == 0 -> sum has to be 0 above = removeMeshFaces(v, f, ~(sum(FBP_LI, 2) == 0) ); % Faces in the plane, 1 or 2 vertices == 0 -> sum can be 1 or 2 inside = removeMeshFaces(v, f, ~((sum(FBP_LI, 2) > 0 & sum(FBP_LI, 2) < 3))); % Faces below the plane, all three vertices == 1 -> sum has to be 3 below = removeMeshFaces(v, f, ~(sum(FBP_LI, 2) == 3) ); otherwise error('Invalid number of output arguments') end %% Parse outputs switch nargout case 1 switch part case 'above' varargout{1}=above; case 'in' varargout{1}=inside; case 'below' varargout{1}=below; end case 2 switch part case 'above' varargout{1}=above.vertices; varargout{2}=above.faces; case 'in' varargout{1}=inside.vertices; varargout{2}=inside.faces; case 'below' varargout{1}=below.vertices; varargout{2}=below.faces; end case 3 varargout{1}=above; varargout{2}=inside; varargout{3}=below; case 6 varargout{1}=above.vertices; varargout{2}=above.faces; varargout{3}=inside.vertices; varargout{4}=inside.faces; varargout{5}=below.vertices; varargout{6}=below.faces; otherwise error('Invalid number of output arguments') end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/surfToMesh.m0000644000000000000000000000013214055375162017674 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/surfToMesh.m0000644000175000017500000001026714055375162020767 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = surfToMesh(x, y, varargin) % Convert surface grids into face-vertex mesh. % % [V, F] = surfToMesh(X, Y) % [V, F] = surfToMesh(X, Y, Z) % Converts the surface grid given by two or three coordinate arrays into % a face-vertex quad mesh. % % Example % % transform a surface into a mesh % [X, Y] = meshgrid(-2:.2:2, -2:.2:2); % Z = X .* exp(-X.^2 - Y.^2); % [V, F] = surfToMesh(X, Y, Z); % figure; % drawMesh(V, F); view(3); % % % Transform surface of a cylinder as a mesh % [x, y, z] = cylinder(5*ones(1, 10)); % [v, f] = surfToMesh(x, y, z, 'xPeriodic', true); % figure; % drawMesh(v, f); % view(3); axis equal; % % See also % meshes3d, meshgrid, drawMesh, torusMesh, sphereMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-10-25, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. %% Parse inputs % check if z-value is present if ~isempty(varargin) && isnumeric(varargin{1}) z = varargin{1}; varargin(1) = []; end % default periodicities xPeriodic = false; yPeriodic = false; % parse input options while length(varargin) > 1 paramName = lower(varargin{1}); switch paramName case 'xperiodic' xPeriodic = varargin{2}; case 'yperiodic' yPeriodic = varargin{2}; otherwise error(['Unknown parameter name: ' paramName]); end varargin(1:2) = []; end %% Compute vertex indices % size along each direction (arrays are (y,x)-indexed) n1 = size(x, 1); n2 = size(x, 2); % in case of periodicity, the last vertex of the grid is drop (it is % assumed to be the same as the first one) if xPeriodic n2 = n2 - 1; end if yPeriodic n1 = n1 - 1; end % new size of vertex grid dim = [n1 n2]; nv = n1 * n2; %% Create vertex array % eventually remove boundary vertices x = x(1:n1, 1:n2); y = y(1:n1, 1:n2); % create vertex array if ~exist('z', 'var') vertices = [x(:) y(:)]; else z = z(1:n1, 1:n2); vertices = [x(:) y(:) z(:)]; end %% Create face array % vertex indices in grid inds = reshape(1:nv, dim); if xPeriodic inds = inds(:, [1:end 1]); end if yPeriodic inds = inds([1:end 1], :); end % vertex indices for each face v1 = inds(1:end-1, 1:end-1); v2 = inds(1:end-1, 2:end); v3 = inds(2:end, 2:end); v4 = inds(2:end, 1:end-1); % concatenate indices faces = [v1(:) v2(:) v3(:) v4(:)]; %% format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createRhombododecahedron.m0000644000000000000000000000013214055375162022547 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createRhombododecahedron.m0000644000175000017500000000612214055375162023635 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createRhombododecahedron() %CREATERHOMBODODECAHEDRON Create a 3D mesh representing a rhombododecahedron. % % [V, E, F] = createRhombododecahedron % V is a 14-by-3 array with vertex coordinate, % E is a 12-by-2 array containing indices of neighbour vertices, % F is a 8-by-3 array containing vertices array of each face. % % [V, F] = createRhombododecahedron; % Returns only the vertices and the face vertex indices. % % MESH = createRhombododecahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Example % [v, e, f] = createRhombododecahedron; % drawMesh(v, f); % % % See also % meshes3d, drawMesh % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % HISTORY % 04/01/2007: remove unused variables nodes = [0 0 2;... 1 -1 1;1 1 1;-1 1 1;-1 -1 1;... 2 0 0;0 2 0;-2 0 0;0 -2 0;... 1 -1 -1;1 1 -1;-1 1 -1;-1 -1 -1;... 0 0 -2]; edges = [... 1 2;1 3;1 4;1 5;... 2 6;2 9;3 6;3 7;4 7;4 8;5 8;5 9;... 6 10;6 11;7 11;7 12;8 12;8 13;9 10;9 13; ... 10 14;11 14;12 14;13 14]; faces = [... 1 2 6 3;... 1 3 7 4;... 1 4 8 5;... 1 5 9 2;... 2 9 10 6;... 3 6 11 7;... 4 7 12 8;... 5 8 13 9;... 6 10 14 11;... 7 11 14 12;... 8 12 14 13;... 9 13 14 10]; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createCube.m0000644000000000000000000000013214055375162017637 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createCube.m0000644000175000017500000000610014055375162020721 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createCube() %CREATECUBE Create a 3D mesh representing the unit cube. % % [V, E, F] = createCube % Create a unit cube, as a polyhedra representation. % c has the form [V E F], where V is a 8-by-3 array with vertices % coordinates, E is a 12-by-2 array containing indices of neighbour % vertices, and F is a 6-by-4 array containing vertices array of each % face. % % [V, F] = createCube; % Returns only the vertices and the face vertex indices. % % MESH = createCube; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Example % [n, e, f] = createCube; % drawMesh(n, f); % % See also % meshes3d, drawMesh % createOctahedron, createTetrahedron, createDodecahedron % createIcosahedron, createCubeOctahedron % % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % HISTORY % 04/01/2007: remove unused variables x0 = 0; dx= 1; y0 = 0; dy= 1; z0 = 0; dz= 1; nodes = [... x0 y0 z0; ... x0+dx y0 z0; ... x0 y0+dy z0; ... x0+dx y0+dy z0; ... x0 y0 z0+dz; ... x0+dx y0 z0+dz; ... x0 y0+dy z0+dz; ... x0+dx y0+dy z0+dz]; edges = [1 2;1 3;1 5;2 4;2 6;3 4;3 7;4 8;5 6;5 7;6 8;7 8]; % faces are oriented such that normals point outwards faces = [1 3 4 2;5 6 8 7;2 4 8 6;1 5 7 3;1 2 6 5;3 7 8 4]; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/drawMesh.m0000644000000000000000000000013214055375162017347 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/drawMesh.m0000644000175000017500000001351614055375162020442 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawMesh(varargin) %DRAWMESH Draw a 3D mesh defined by vertex and face arrays. % % drawMesh(VERTICES, FACES) % Draws the 3D mesh defined by vertices VERTICES and the faces FACES. % vertices is a NV-by-3 array containing coordinates of vertices, and % FACES is either a NF-by-3 or NF-by-4 array containing face vertex % indices of the triangular or rectangular faces. % FACES can also be a cell array, in the content of each cell is an array % of indices to the vertices of the current face. Faces can have % different number of vertices. % % drawMesh(MESH) % Specifies the mesh as a structure with at least the fields 'vertices' % and 'faces'. % % drawMesh(..., COLOR) % Use the specified color to render the mesh faces. % % drawMesh(..., NAME, VALUE) % Use one or several pairs of parameter name/value to specify drawing % options. Options are the same as the 'patch' function. % % drawMesh(AX,...) % Draw into the axis specified by AX instead of the current axis. % % % H = drawMesh(...); % Also returns a handle to the created patch. % % Example: % [v, f] = createSoccerBall; % drawMesh(v, f); % % See also: % meshes3d, polyhedra, patch % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % HISTORY % 07/11/2005 update doc. % 04/01/2007 typo % 18/01/2007 add support for 2D polyhedra ("vertices" is N-by-2 array), and % make 'cnodes' a list of points instead of a list of indices % 14/08/2007 add comment, add support for NaN in faces (complex polygons) % 14/09/2007 rename as drawPolyhedron % 16/10/2008 better support for colors % 27/07/2010 renamed as drawMesh % 09/11/2010 update doc % 07/12/2010 update management of mesh structures %% Parse input arguments % extract first argument var1 = varargin{1}; varargin(1) = []; % Check if first input argument is an axes handle if isAxisHandle(var1) ax = var1; var1 = varargin{1}; varargin(1) = []; else ax = gca; end % Check if the input is a mesh structure if isstruct(var1) % extract data to display vertices = var1.vertices; faces = var1.faces; else % assumes input is given with vertices+faces arrays vertices = var1; faces = varargin{1}; varargin(1) = []; end % process input arguments switch length(varargin) case 0 % default color is red varargin = {'facecolor', [1 0 0]}; case 1 % use argument as color for faces varargin = {'facecolor', varargin{1}}; otherwise % otherwise add default settings before new options varargin = [{'facecolor', [1 0 0 ]} varargin]; end % overwrites on current figure hold(ax, 'on'); % if vertices are 2D points, add a z=0 coordinate if size(vertices, 2) == 2 vertices(1, 3) = 0; end %% Use different processing depending on the type of faces if isnumeric(faces) % array FACES is a NC*NV indices array, with NV : number of vertices of % each face, and NC number of faces h = patch('vertices', vertices, 'faces', faces, varargin{:}, ... 'Parent', ax); elseif iscell(faces) % array FACES is a cell array h = zeros(length(faces(:)), 1); for f = 1:length(faces(:)) % get vertices of the cell face = faces{f}; % Special processing in case of multiple polygonal face: % each polygonal loop is separated by a NaN. if sum(isnan(face)) ~= 0 % find indices of loops breaks inds = find(isnan(face)); % replace NaNs by index of first vertex of each polygon face(inds(2:end)) = face(inds(1:end-1)+1); face(inds(1)) = face(1); face(length(face)+1)= face(inds(end)+1); end % draw current face cnodes = vertices(face, :); h(f) = patch(ax, cnodes(:, 1), cnodes(:, 2), cnodes(:, 3), [1 0 0]); end % set up drawing options set(h, varargin{:}); else error('second argument must be a face array'); end %% Process output arguments % format output parameters if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/apple.ply0000644000000000000000000000013214055375161017245 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/apple.ply0000644000175000017500000014212614055375161020340 0ustar00juanpijuanpi00000000000000ply format ascii 1.0 element vertex 867 property float32 x property float32 y property float32 z element face 1704 property list uint8 int32 vertex_indices end_header 0.00472708 0.0012 -0.000833515 0.0048 0.0012 0 0 0 0 0.00451052 0.0012 -0.0016417 0.00415692 0.0012 -0.00240001 0.00367701 0.0012 -0.00308539 0.00308537 0.0012 -0.00367702 0.00239999 0.0012 -0.00415693 0.00164168 0.0012 -0.00451053 0.000833496 0.0012 -0.00472708 -1.79482e-08 0.0012 -0.0048 -0.00083353 0.0012 -0.00472707 -0.00164172 0.0012 -0.00451052 -0.00240002 0.0012 -0.00415691 -0.0030854 0.0012 -0.003677 -0.00367703 0.0012 -0.00308536 -0.00415694 0.0012 -0.00239997 -0.00451054 0.0012 -0.00164167 -0.00472708 0.0012 -0.000833477 -0.0048 0.0012 3.70407e-08 -0.00472707 0.0012 0.000833549 -0.00451051 0.0012 0.00164173 -0.0041569 0.0012 0.00240004 -0.00367698 0.0012 0.00308542 -0.00308534 0.0012 0.00367704 -0.00239996 0.0012 0.00415694 -0.00164165 0.0012 0.00451054 -0.000833458 0.0012 0.00472709 5.49888e-08 0.0012 0.0048 0.000833568 0.0012 0.00472707 0.00164175 0.0012 0.0045105 0.00240005 0.0012 0.00415689 0.00308543 0.0012 0.00367697 0.00367705 0.0012 0.00308533 0.00415695 0.0012 0.00239994 0.00451055 0.0012 0.00164163 0.00472709 0.0012 0.000833438 0.00945418 0.0024 -0.00166703 0.0096 0.0024 0 0.00902102 0.0024 -0.0032834 0.00831384 0.0024 -0.0048 0.00735403 0.0024 -0.00617078 0.00617074 0.0024 -0.00735403 0.00479998 0.0024 -0.00831384 0.00328337 0.0024 -0.00902107 0.00166699 0.0024 -0.00945418 -3.58963e-08 0.0024 -0.0096 -0.00166706 0.0024 -0.00945413 -0.00328344 0.0024 -0.00902102 -0.00480005 0.0024 -0.00831384 -0.00617078 0.0024 -0.00735398 -0.00735408 0.0024 -0.00617074 -0.00831389 0.0024 -0.00479995 -0.00902107 0.0024 -0.00328333 -0.00945418 0.0024 -0.00166695 -0.0096 0.0024 7.40813e-08 -0.00945413 0.0024 0.0016671 -0.00902102 0.0024 0.00328347 -0.00831379 0.0024 0.0048001 -0.00735398 0.0024 0.00617083 -0.00617069 0.0024 0.00735408 -0.00479991 0.0024 0.00831389 -0.0032833 0.0024 0.00902107 -0.00166692 0.0024 0.00945418 1.09978e-07 0.0024 0.0096 0.00166714 0.0024 0.00945413 0.0032835 0.0024 0.00902102 0.0048001 0.0024 0.00831379 0.00617088 0.0024 0.00735394 0.00735413 0.0024 0.00617064 0.00831389 0.0024 0.00479988 0.00902112 0.0024 0.00328326 0.00945418 0.0024 0.00166688 0.0155994 0.0012 -0.00275059 0.01584 0.0012 0 0.0148847 0.0012 -0.00541762 0.0137178 0.0012 -0.00792 0.0121341 0.0012 -0.0101818 0.0101817 0.0012 -0.0121342 0.00791995 0.0012 -0.0137179 0.00541757 0.0012 -0.0148848 0.00275053 0.0012 -0.0155994 -5.92291e-08 0.0012 -0.01584 -0.00275065 0.0012 -0.0155993 -0.00541766 0.0012 -0.0148847 -0.00792005 0.0012 -0.0137178 -0.0101818 0.0012 -0.0121341 -0.0121342 0.0012 -0.0101817 -0.0137179 0.0012 -0.0079199 -0.0148848 0.0012 -0.00541752 -0.0155994 0.0012 -0.00275047 -0.01584 0.0012 1.22234e-07 -0.0155993 0.0012 0.00275071 -0.0148847 0.0012 0.00541771 -0.0137178 0.0012 0.00792014 -0.0121341 0.0012 0.0101819 -0.0101816 0.0012 0.0121343 -0.00791986 0.0012 0.0137179 -0.00541742 0.0012 0.0148848 -0.00275041 0.0012 0.0155994 1.81464e-07 0.0012 0.01584 0.00275077 0.0012 0.0155993 0.00541776 0.0012 0.0148847 0.00792019 0.0012 0.0137177 0.0101819 0.0012 0.012134 0.0121343 0.0012 0.0101816 0.013718 0.0012 0.00791981 0.0148848 0.0012 0.00541738 0.0155994 0.0012 0.00275035 0.0212718 -0.00048 -0.00375081 0.0216 -0.00048 0 0.0202974 -0.00048 -0.00738763 0.0187061 -0.00048 -0.0108 0.0165466 -0.00048 -0.0138842 0.0138842 -0.00048 -0.0165466 0.0108 -0.00048 -0.0187062 0.00738758 -0.00048 -0.0202974 0.00375073 -0.00048 -0.0212719 -8.07667e-08 -0.00048 -0.0216 -0.00375089 -0.00048 -0.0212718 -0.00738773 -0.00048 -0.0202973 -0.0108001 -0.00048 -0.0187061 -0.0138843 -0.00048 -0.0165465 -0.0165467 -0.00048 -0.0138841 -0.0187062 -0.00048 -0.0107999 -0.0202974 -0.00048 -0.00738749 -0.0212719 -0.00048 -0.00375065 -0.0216 -0.00048 1.66683e-07 -0.0212718 -0.00048 0.00375097 -0.0202973 -0.00048 0.00738782 -0.018706 -0.00048 0.0108002 -0.0165464 -0.00048 0.0138844 -0.013884 -0.00048 0.0165467 -0.0107998 -0.00048 0.0187063 -0.00738744 -0.00048 0.0202974 -0.00375057 -0.00048 0.0212719 2.4745e-07 -0.00048 0.0216 0.00375106 -0.00048 0.0212718 0.00738787 -0.00048 0.0202973 0.0108002 -0.00048 0.018706 0.0138844 -0.00048 0.0165464 0.0165468 -0.00048 0.013884 0.0187063 -0.00048 0.0107997 0.0202975 -0.00048 0.00738734 0.0212719 -0.00048 0.00375048 0.0250535 -0.0012 -0.00441762 0.02544 -0.0012 0 0.0239058 -0.0012 -0.00870101 0.0220317 -0.0012 -0.01272 0.0194881 -0.0012 -0.0163525 0.0163525 -0.0012 -0.0194882 0.01272 -0.0012 -0.0220317 0.00870091 -0.0012 -0.0239058 0.00441753 -0.0012 -0.0250535 -9.51254e-08 -0.0012 -0.02544 -0.00441771 -0.0012 -0.0250535 -0.0087011 -0.0012 -0.0239057 -0.0127201 -0.0012 -0.0220316 -0.0163526 -0.0012 -0.0194881 -0.0194883 -0.0012 -0.0163524 -0.0220318 -0.0012 -0.0127199 -0.0239058 -0.0012 -0.00870082 -0.0250536 -0.0012 -0.00441743 -0.02544 -0.0012 1.96316e-07 -0.0250535 -0.0012 0.00441781 -0.0239057 -0.0012 0.0087012 -0.0220316 -0.0012 0.0127202 -0.019488 -0.0012 0.0163527 -0.0163524 -0.0012 0.0194883 -0.0127198 -0.0012 0.0220318 -0.00870072 -0.0012 0.0239059 -0.00441733 -0.0012 0.0250536 2.91441e-07 -0.0012 0.02544 0.00441791 -0.0012 0.0250535 0.0087013 -0.0012 0.0239057 0.0127203 -0.0012 0.0220315 0.0163528 -0.0012 0.019488 0.0194884 -0.0012 0.0163523 0.0220319 -0.0012 0.0127197 0.0239059 -0.0012 0.00870063 0.0250536 -0.0012 0.00441723 0.0283625 0 -0.00500107 0.0288 0 0 0.0270631 0 -0.00985022 0.0249415 0 -0.0144 0.0220621 0 -0.0185123 0.0185123 0 -0.0220621 0.0144 0 -0.0249416 0.00985008 0 -0.0270632 0.00500098 0 -0.0283625 -1.07689e-07 0 -0.0288 -0.00500117 0 -0.0283624 -0.00985032 0 -0.0270631 -0.0144001 0 -0.0249415 -0.0185124 0 -0.022062 -0.0220622 0 -0.0185122 -0.0249416 0 -0.0143999 -0.0270632 0 -0.00984998 -0.0283625 0 -0.00500088 -0.0288 0 2.22244e-07 -0.0283624 0 0.00500131 -0.0270631 0 0.00985042 -0.0249414 0 0.0144002 -0.0220619 0 0.0185125 -0.0185121 0 0.0220622 -0.0143998 0 0.0249417 -0.00984989 0 0.0270633 -0.00500074 0 0.0283625 3.29933e-07 0 0.0288 0.00500141 0 0.0283624 0.00985051 0 0.027063 0.0144003 0 0.0249413 0.0185126 0 0.0220619 0.0220623 0 0.018512 0.0249418 0 0.0143997 0.0270633 0 0.00984979 0.0283625 0 0.00500064 0.0354531 0.0072 -0.00625133 0.036 0.0072 0 0.0338289 0.0072 -0.0123128 0.0311769 0.0072 -0.018 0.0275776 0.0072 -0.0231404 0.0231403 0.0072 -0.0275776 0.0179999 0.0072 -0.031177 0.0123126 0.0072 -0.033829 0.00625123 0.0072 -0.0354531 -1.34611e-07 0.0072 -0.036 -0.00625147 0.0072 -0.035453 -0.0123129 0.0072 -0.0338289 -0.0180001 0.0072 -0.0311768 -0.0231405 0.0072 -0.0275775 -0.0275777 0.0072 -0.0231402 -0.031177 0.0072 -0.0179998 -0.033829 0.0072 -0.0123125 -0.0354531 0.0072 -0.00625109 -0.036 0.0072 2.77805e-07 -0.035453 0.0072 0.00625162 -0.0338288 0.0072 0.012313 -0.0311768 0.0072 0.0180003 -0.0275774 0.0072 0.0231406 -0.0231401 0.0072 0.0275778 -0.0179997 0.0072 0.0311771 -0.0123124 0.0072 0.0338291 -0.00625094 0.0072 0.0354531 4.12417e-07 0.0072 0.036 0.00625176 0.0072 0.035453 0.0123132 0.0072 0.0338288 0.0180004 0.0072 0.0311767 0.0231407 0.0072 0.0275773 0.0275779 0.0072 0.02314 0.0311772 0.0072 0.0179996 0.0338291 0.0072 0.0123122 0.0354532 0.0072 0.0062508 0.0415983 0.0144 -0.00733493 0.04224 0.0144 0 0.0396926 0.0144 -0.0144469 0.0365809 0.0144 -0.02112 0.0323577 0.0144 -0.0271514 0.0271513 0.0144 -0.0323578 0.0211199 0.0144 -0.0365809 0.0144468 0.0144 -0.0396926 0.00733478 0.0144 -0.0415983 -1.57944e-07 0.0144 -0.04224 -0.00733507 0.0144 -0.0415982 -0.0144471 0.0144 -0.0396925 -0.0211202 0.0144 -0.0365808 -0.0271515 0.0144 -0.0323576 -0.0323579 0.0144 -0.0271512 -0.036581 0.0144 -0.0211198 -0.0396927 0.0144 -0.0144467 -0.0415983 0.0144 -0.00733459 -0.04224 0.0144 3.25958e-07 -0.0415982 0.0144 0.00733522 -0.0396925 0.0144 0.0144473 -0.0365807 0.0144 0.0211203 -0.0323575 0.0144 0.0271517 -0.0271511 0.0144 0.032358 -0.0211196 0.0144 0.0365811 -0.0144465 0.0144 0.0396928 -0.00733445 0.0144 0.0415983 4.83902e-07 0.0144 0.04224 0.00733541 0.0144 0.0415982 0.0144474 0.0144 0.0396925 0.0211205 0.0144 0.0365807 0.0271518 0.0144 0.0323574 0.0323581 0.0144 0.0271509 0.0365812 0.0144 0.0211195 0.0396928 0.0144 0.0144464 0.0415984 0.0144 0.00733426 0.0472708 0.024 -0.00833515 0.048 0.024 0 0.0451052 0.024 -0.016417 0.0415692 0.024 -0.024 0.0367701 0.024 -0.0308539 0.0308537 0.024 -0.0367702 0.0239999 0.024 -0.0415693 0.0164168 0.024 -0.0451053 0.00833496 0.024 -0.0472708 -1.79482e-07 0.024 -0.048 -0.0083353 0.024 -0.0472707 -0.0164172 0.024 -0.0451052 -0.0240002 0.024 -0.0415691 -0.030854 0.024 -0.03677 -0.0367703 0.024 -0.0308536 -0.0415694 0.024 -0.0239997 -0.0451054 0.024 -0.0164167 -0.0472708 0.024 -0.00833477 -0.048 0.024 3.70407e-07 -0.0472707 0.024 0.00833549 -0.0451051 0.024 0.0164173 -0.041569 0.024 0.0240004 -0.0367698 0.024 0.0308542 -0.0308534 0.024 0.0367705 -0.0239996 0.024 0.0415695 -0.0164165 0.024 0.0451054 -0.00833458 0.024 0.0472709 5.49888e-07 0.024 0.048 0.00833568 0.024 0.0472707 0.0164175 0.024 0.045105 0.0240005 0.024 0.0415689 0.0308543 0.024 0.0367697 0.0367705 0.024 0.0308533 0.0415696 0.024 0.0239994 0.0451055 0.024 0.0164163 0.0472709 0.024 0.00833438 0.0496344 0.0336 -0.00875189 0.0504 0.0336 0 0.0473605 0.0336 -0.0172379 0.0436477 0.0336 -0.0252 0.0386086 0.0336 -0.0323965 0.0323964 0.0336 -0.0386087 0.0251999 0.0336 -0.0436477 0.0172377 0.0336 -0.0473605 0.0087517 0.0336 -0.0496344 -1.88456e-07 0.0336 -0.0504 -0.00875208 0.0336 -0.0496344 -0.017238 0.0336 -0.0473605 -0.0252002 0.0336 -0.0436476 -0.0323967 0.0336 -0.0386085 -0.0386089 0.0336 -0.0323963 -0.0436478 0.0336 -0.0251997 -0.0473606 0.0336 -0.0172375 -0.0496344 0.0336 -0.0087515 -0.0504 0.0336 3.88928e-07 -0.0496344 0.0336 0.00875227 -0.0473604 0.0336 0.0172382 -0.0436475 0.0336 0.0252004 -0.0386083 0.0336 0.0323969 -0.0323961 0.0336 0.0386089 -0.0251996 0.0336 0.0436479 -0.0172373 0.0336 0.0473607 -0.00875131 0.0336 0.0496344 5.77382e-07 0.0336 0.0504 0.00875246 0.0336 0.0496344 0.0172384 0.0336 0.0473603 0.0252006 0.0336 0.0436474 0.032397 0.0336 0.0386082 0.0386091 0.0336 0.032396 0.043648 0.0336 0.0251994 0.0473608 0.0336 0.0172371 0.0496344 0.0336 0.00875112 0.051289 0.0432 -0.00904363 0.05208 0.0432 0 0.0489394 0.0432 -0.0178125 0.0451026 0.0432 -0.0260401 0.0398955 0.0432 -0.0334764 0.0334763 0.0432 -0.0398956 0.0260399 0.0432 -0.0451027 0.0178123 0.0432 -0.0489394 0.00904344 0.0432 -0.051289 -1.94737e-07 0.0432 -0.05208 -0.00904382 0.0432 -0.051289 -0.0178127 0.0432 -0.0489389 -0.0260402 0.0432 -0.0451025 -0.0334766 0.0432 -0.0398954 -0.0398958 0.0432 -0.0334762 -0.0451028 0.0432 -0.0260397 -0.0489394 0.0432 -0.0178121 -0.051289 0.0432 -0.0090432 -0.05208 0.0432 4.01892e-07 -0.0512885 0.0432 0.00904402 -0.0489389 0.0432 0.0178128 -0.0451024 0.0432 0.0260404 -0.0398953 0.0432 0.0334767 -0.033476 0.0432 0.0398959 -0.0260395 0.0432 0.0451029 -0.0178119 0.0432 0.0489394 -0.00904301 0.0432 0.051289 5.9663e-07 0.0432 0.05208 0.00904421 0.0432 0.0512885 0.017813 0.0432 0.0489389 0.0260406 0.0432 0.0451023 0.0334769 0.0432 0.0398952 0.0398961 0.0432 0.0334758 0.045103 0.0432 0.0260394 0.0489394 0.0432 0.0178117 0.051289 0.0432 0.00904282 0.0510523 0.05232 -0.00900192 0.05184 0.05232 0 0.0487138 0.05232 -0.0177304 0.0448947 0.05232 -0.0259201 0.0397117 0.05232 -0.0333222 0.033322 0.05232 -0.0397118 0.0259199 0.05232 -0.0448948 0.0177302 0.05232 -0.0487138 0.00900178 0.05232 -0.0510523 -1.9384e-07 0.05232 -0.05184 -0.00900211 0.05232 -0.0510523 -0.0177305 0.05232 -0.0487138 -0.0259202 0.05232 -0.0448946 -0.0333223 0.05232 -0.0397116 -0.0397119 0.05232 -0.0333219 -0.0448949 0.05232 -0.0259197 -0.0487138 0.05232 -0.01773 -0.0510523 0.05232 -0.00900154 -0.05184 0.05232 4.0004e-07 -0.0510523 0.05232 0.00900235 -0.0487133 0.05232 0.0177307 -0.0448945 0.05232 0.0259204 -0.0397114 0.05232 0.0333225 -0.0333217 0.05232 0.0397121 -0.0259196 0.05232 0.044895 -0.0177298 0.05232 0.0487138 -0.00900134 0.05232 0.0510523 5.9388e-07 0.05232 0.05184 0.00900254 0.05232 0.0510523 0.0177309 0.05232 0.0487133 0.0259206 0.05232 0.0448944 0.0333227 0.05232 0.0397113 0.0397122 0.05232 0.0333216 0.0448951 0.05232 0.0259194 0.0487138 0.05232 0.0177296 0.0510528 0.05232 0.00900115 0.0501072 0.05904 -0.00883522 0.05088 0.05904 0 0.0478116 0.05904 -0.017402 0.0440633 0.05904 -0.0254401 0.0389763 0.05904 -0.0327051 0.0327049 0.05904 -0.0389764 0.0254399 0.05904 -0.0440634 0.0174019 0.05904 -0.0478116 0.00883507 0.05904 -0.0501072 -1.9025e-07 0.05904 -0.05088 -0.00883541 0.05904 -0.0501072 -0.0174022 0.05904 -0.0478115 -0.0254402 0.05904 -0.0440632 -0.0327052 0.05904 -0.0389761 -0.0389765 0.05904 -0.0327048 -0.0440635 0.05904 -0.0254397 -0.0478117 0.05904 -0.0174017 -0.0501072 0.05904 -0.00883483 -0.05088 0.05904 3.92632e-07 -0.0501067 0.05904 0.00883565 -0.0478114 0.05904 0.0174024 -0.0440631 0.05904 0.0254404 -0.0389761 0.05904 0.0327054 -0.0327047 0.05904 0.0389767 -0.0254396 0.05904 0.0440636 -0.0174015 0.05904 0.0478117 -0.00883469 0.05904 0.0501072 5.82883e-07 0.05904 0.05088 0.00883579 0.05904 0.0501067 0.0174026 0.05904 0.0478114 0.0254406 0.05904 0.044063 0.0327056 0.05904 0.0389759 0.0389768 0.05904 0.0327045 0.0440637 0.05904 0.0254394 0.0478118 0.05904 0.0174013 0.0501072 0.05904 0.00883445 0.0467981 0.066 -0.00825178 0.04752 0.066 0 0.0446542 0.066 -0.0162528 0.0411535 0.066 -0.02376 0.0364024 0.066 -0.0305453 0.0305452 0.066 -0.0364025 0.0237599 0.066 -0.0411536 0.0162527 0.066 -0.0446543 0.00825158 0.066 -0.0467981 -1.77687e-07 0.066 -0.04752 -0.00825197 0.066 -0.046798 -0.016253 0.066 -0.0446541 -0.0237602 0.066 -0.0411534 -0.0305455 0.066 -0.0364023 -0.0364026 0.066 -0.030545 -0.0411537 0.066 -0.0237598 -0.0446543 0.066 -0.0162525 -0.0467981 0.066 -0.00825144 -0.04752 0.066 3.66703e-07 -0.046798 0.066 0.00825216 -0.0446541 0.066 0.0162532 -0.0411533 0.066 0.0237604 -0.0364021 0.066 0.0305456 -0.0305449 0.066 0.0364027 -0.0237596 0.066 0.0411538 -0.0162523 0.066 0.0446544 -0.00825125 0.066 0.0467982 5.44392e-07 0.066 0.04752 0.0082523 0.066 0.046798 0.0162533 0.066 0.044654 0.0237605 0.066 0.0411532 0.0305458 0.066 0.0364021 0.0364029 0.066 0.0305448 0.0411539 0.066 0.0237594 0.0446545 0.066 0.0162521 0.0467982 0.066 0.00825106 0.0430164 0.07032 -0.00758496 0.04368 0.07032 0 0.0410458 0.07032 -0.0149395 0.037828 0.07032 -0.0218401 0.0334608 0.07032 -0.028077 0.0280769 0.07032 -0.0334609 0.0218399 0.07032 -0.037828 0.0149393 0.07032 -0.0410458 0.00758482 0.07032 -0.0430164 -1.63328e-07 0.07032 -0.04368 -0.00758515 0.07032 -0.0430164 -0.0149396 0.07032 -0.0410457 -0.0218402 0.07032 -0.0378279 -0.0280772 0.07032 -0.0334607 -0.033461 0.07032 -0.0280768 -0.0378281 0.07032 -0.0218398 -0.0410459 0.07032 -0.0149391 -0.0430164 0.07032 -0.00758462 -0.04368 0.07032 3.3707e-07 -0.0430164 0.07032 0.0075853 -0.0410457 0.07032 0.0149398 -0.0378278 0.07032 0.0218403 -0.0334606 0.07032 0.0280773 -0.0280766 0.07032 0.0334611 -0.0218396 0.07032 0.0378282 -0.014939 0.07032 0.041046 -0.00758448 0.07032 0.0430165 5.004e-07 0.07032 0.04368 0.00758549 0.07032 0.0430163 0.01494 0.07032 0.0410456 0.0218405 0.07032 0.0378277 0.0280774 0.07032 0.0334605 0.0334612 0.07032 0.0280765 0.0378283 0.07032 0.0218395 0.041046 0.07032 0.0149388 0.0430165 0.07032 0.00758429 0.0382893 0.07272 -0.00675144 0.03888 0.07272 0 0.0365352 0.07272 -0.0132978 0.033671 0.07272 -0.01944 0.0297838 0.07272 -0.0249916 0.0249915 0.07272 -0.0297839 0.0194399 0.07272 -0.0336711 0.0132976 0.07272 -0.0365353 0.0067513 0.07272 -0.0382894 -1.4538e-07 0.07272 -0.03888 -0.00675158 0.07272 -0.0382893 -0.0132979 0.07272 -0.0365352 -0.0194402 0.07272 -0.033671 -0.0249917 0.07272 -0.0297837 -0.029784 0.07272 -0.0249914 -0.0336712 0.07272 -0.0194398 -0.0365353 0.07272 -0.0132975 -0.0382894 0.07272 -0.00675115 -0.03888 0.07272 3.0003e-07 -0.0382893 0.07272 0.00675178 -0.0365352 0.07272 0.0132981 -0.0336709 0.07272 0.0194403 -0.0297836 0.07272 0.0249919 -0.0249913 0.07272 0.029784 -0.0194397 0.07272 0.0336713 -0.0132973 0.07272 0.0365354 -0.00675101 0.07272 0.0382894 4.4541e-07 0.07272 0.03888 0.00675192 0.07272 0.0382893 0.0132982 0.07272 0.0365351 0.0194404 0.07272 0.0336708 0.024992 0.07272 0.0297835 0.0297841 0.07272 0.0249912 0.0336713 0.07272 0.0194395 0.0365354 0.07272 0.0132972 0.0382894 0.07272 0.00675086 0.0330895 0.07416 -0.00583459 0.0336 0.07416 0 0.0315737 0.07416 -0.0114919 0.0290984 0.07416 -0.0168 0.025739 0.07416 -0.0215977 0.0215976 0.07416 -0.0257391 0.0168 0.07416 -0.0290985 0.0114918 0.07416 -0.0315737 0.00583445 0.07416 -0.0330896 -1.25637e-07 0.07416 -0.0336 -0.00583474 0.07416 -0.0330895 -0.011492 0.07416 -0.0315736 -0.0168001 0.07416 -0.0290984 -0.0215978 0.07416 -0.025739 -0.0257392 0.07416 -0.0215975 -0.0290986 0.07416 -0.0167998 -0.0315737 0.07416 -0.0114917 -0.0330896 0.07416 -0.00583435 -0.0336 0.07416 2.59285e-07 -0.0330895 0.07416 0.00583483 -0.0315736 0.07416 0.0114922 -0.0290983 0.07416 0.0168002 -0.0257389 0.07416 0.0215979 -0.0215974 0.07416 0.0257393 -0.0167997 0.07416 0.0290986 -0.0114915 0.07416 0.0315738 -0.00583421 0.07416 0.0330896 3.84922e-07 0.07416 0.0336 0.00583498 0.07416 0.0330895 0.0114923 0.07416 0.0315735 0.0168004 0.07416 0.0290982 0.021598 0.07416 0.0257388 0.0257394 0.07416 0.0215973 0.0290987 0.07416 0.0167996 0.0315738 0.07416 0.0114914 0.0330896 0.07416 0.00583406 0.0271807 0.0744 -0.0047927 0.0276 0.0744 0 0.0259355 0.0744 -0.00943978 0.0239023 0.0744 -0.0138 0.0211428 0.0744 -0.017741 0.0177409 0.0744 -0.0211428 0.0138 0.0744 -0.0239023 0.00943968 0.0744 -0.0259356 0.0047926 0.0744 -0.0271807 -1.03202e-07 0.0744 -0.0276 -0.0047928 0.0744 -0.0271807 -0.00943987 0.0744 -0.0259355 -0.0138001 0.0744 -0.0239022 -0.017741 0.0744 -0.0211428 -0.0211429 0.0744 -0.0177408 -0.0239024 0.0744 -0.0137999 -0.0259356 0.0744 -0.00943958 -0.0271807 0.0744 -0.00479249 -0.0276 0.0744 2.12984e-07 -0.0271807 0.0744 0.00479291 -0.0259355 0.0744 0.00943997 -0.0239022 0.0744 0.0138002 -0.0211427 0.0744 0.0177411 -0.0177408 0.0744 0.021143 -0.0137998 0.0744 0.0239025 -0.00943949 0.0744 0.0259356 -0.00479239 0.0744 0.0271808 3.16186e-07 0.0744 0.0276 0.00479301 0.0744 0.0271806 0.00944006 0.0744 0.0259354 0.0138003 0.0744 0.0239021 0.0177412 0.0744 0.0211426 0.0211431 0.0744 0.0177407 0.0239025 0.0744 0.0137997 0.0259356 0.0744 0.00943939 0.0271808 0.0744 0.00479228 0.0212718 0.07416 -0.00375081 0.0216 0.07416 0 0.0202974 0.07416 -0.00738763 0.0187061 0.07416 -0.0108 0.0165466 0.07416 -0.0138842 0.0138842 0.07416 -0.0165466 0.0108 0.07416 -0.0187062 0.00738758 0.07416 -0.0202974 0.00375073 0.07416 -0.0212719 -8.07667e-08 0.07416 -0.0216 -0.00375089 0.07416 -0.0212718 -0.00738773 0.07416 -0.0202973 -0.0108001 0.07416 -0.0187061 -0.0138843 0.07416 -0.0165465 -0.0165467 0.07416 -0.0138841 -0.0187062 0.07416 -0.0107999 -0.0202974 0.07416 -0.00738749 -0.0212719 0.07416 -0.00375065 -0.0216 0.07416 1.66683e-07 -0.0212718 0.07416 0.00375097 -0.0202973 0.07416 0.00738782 -0.018706 0.07416 0.0108002 -0.0165464 0.07416 0.0138844 -0.013884 0.07416 0.0165467 -0.0107998 0.07416 0.0187063 -0.00738744 0.07416 0.0202974 -0.00375057 0.07416 0.0212719 2.4745e-07 0.07416 0.0216 0.00375106 0.07416 0.0212718 0.00738787 0.07416 0.0202973 0.0108002 0.07416 0.018706 0.0138844 0.07416 0.0165464 0.0165468 0.07416 0.013884 0.0187063 0.07416 0.0107997 0.0202975 0.07416 0.00738734 0.0212719 0.07416 0.00375048 0.0155994 0.07344 -0.00275059 0.01584 0.07344 0 0.0148847 0.07344 -0.00541762 0.0137178 0.07344 -0.00792 0.0121341 0.07344 -0.0101818 0.0101817 0.07344 -0.0121342 0.00791995 0.07344 -0.0137179 0.00541757 0.07344 -0.0148848 0.00275053 0.07344 -0.0155994 -5.92291e-08 0.07344 -0.01584 -0.00275065 0.07344 -0.0155993 -0.00541766 0.07344 -0.0148847 -0.00792005 0.07344 -0.0137178 -0.0101818 0.07344 -0.0121341 -0.0121342 0.07344 -0.0101817 -0.0137179 0.07344 -0.0079199 -0.0148848 0.07344 -0.00541752 -0.0155994 0.07344 -0.00275047 -0.01584 0.07344 1.22234e-07 -0.0155993 0.07344 0.00275071 -0.0148847 0.07344 0.00541771 -0.0137178 0.07344 0.00792014 -0.0121341 0.07344 0.0101819 -0.0101816 0.07344 0.0121343 -0.00791986 0.07344 0.0137179 -0.00541742 0.07344 0.0148848 -0.00275041 0.07344 0.0155994 1.81464e-07 0.07344 0.01584 0.00275077 0.07344 0.0155993 0.00541776 0.07344 0.0148847 0.00792019 0.07344 0.0137177 0.0101819 0.07344 0.012134 0.0121343 0.07344 0.0101816 0.013718 0.07344 0.00791981 0.0148848 0.07344 0.00541738 0.0155994 0.07344 0.00275035 0.0103996 0.072 -0.00183373 0.01056 0.072 0 0.00992314 0.072 -0.00361174 0.0091452 0.072 -0.00528 0.00808944 0.072 -0.00678787 0.00678782 0.072 -0.00808944 0.00528 0.072 -0.00914525 0.0036117 0.072 -0.00992318 0.00183369 0.072 -0.0103996 -3.9486e-08 0.072 -0.01056 -0.00183377 0.072 -0.0103996 -0.00361178 0.072 -0.00992314 -0.00528005 0.072 -0.0091452 -0.00678787 0.072 -0.00808939 -0.00808949 0.072 -0.00678778 -0.00914525 0.072 -0.00527995 -0.00992318 0.072 -0.00361166 -0.0103996 0.072 -0.00183365 -0.01056 0.072 8.14896e-08 -0.0103995 0.072 0.00183381 -0.00992314 0.072 0.00361182 -0.0091452 0.072 0.0052801 -0.00808934 0.072 0.00678792 -0.00678778 0.072 0.00808949 -0.0052799 0.072 0.0091453 -0.00361163 0.072 0.00992318 -0.00183361 0.072 0.0103996 1.20975e-07 0.072 0.01056 0.00183385 0.072 0.0103995 0.00361186 0.072 0.00992309 0.0052801 0.072 0.00914515 0.00678797 0.072 0.00808934 0.00808954 0.072 0.00678773 0.0091453 0.072 0.00527986 0.00992318 0.072 0.00361159 0.0103996 0.072 0.00183357 0.00543614 0.0696 -0.000958541 0.00552 0.0696 0 0.00518712 0.0696 -0.00188796 0.00478045 0.0696 -0.00276 0.00422856 0.0696 -0.00354819 0.00354818 0.0696 -0.00422857 0.00275999 0.0696 -0.00478047 0.00188794 0.0696 -0.00518712 0.000958522 0.0696 -0.00543614 -2.06404e-08 0.0696 -0.00552 -0.00095856 0.0696 -0.00543614 -0.00188797 0.0696 -0.00518707 -0.00276002 0.0696 -0.00478045 -0.00354821 0.0696 -0.00422855 -0.00422858 0.0696 -0.00354816 -0.00478048 0.0696 -0.00275997 -0.00518712 0.0696 -0.00188792 -0.00543614 0.0696 -0.000958498 -0.00552 0.0696 4.25968e-08 -0.00543614 0.0696 0.000958584 -0.00518707 0.0696 0.00188799 -0.00478044 0.0696 0.00276004 -0.00422853 0.0696 0.00354823 -0.00354815 0.0696 0.0042286 -0.00275995 0.0696 0.00478049 -0.0018879 0.0696 0.00518712 -0.000958478 0.0696 0.00543614 6.32371e-08 0.0696 0.00552 0.000958603 0.0696 0.00543614 0.00188802 0.0696 0.00518707 0.00276006 0.0696 0.00478043 0.00354824 0.0696 0.00422852 0.00422861 0.0696 0.00354813 0.0047805 0.0696 0.00275993 0.00518712 0.0696 0.00188787 0.00543614 0.0696 0.000958454 0 0.0672 0 0.00162276 0.0648 -0.000434817 0.00231822 0.072 -0.000621168 0.0024 0.072 0 0.00168 0.0648 0 0.00370916 0.0792 -0.000993869 0.00384 0.0792 0 0.00145492 0.0648 -0.00084 0.00207846 0.072 -0.0012 0.00332554 0.0792 -0.00192 0.00118794 0.0648 -0.00118794 0.00169705 0.072 -0.00169706 0.00271528 0.0792 -0.00271529 0.000839995 0.0648 -0.00145492 0.0012 0.072 -0.00207846 0.00191999 0.0792 -0.00332554 0.000434811 0.0648 -0.00162276 0.000621158 0.072 -0.00231822 0.000993854 0.0792 -0.00370916 -6.28186e-09 0.0648 -0.00168 -8.97408e-09 0.072 -0.0024 -1.43585e-08 0.0792 -0.00384 -0.000434823 0.0648 -0.00162276 -0.000621178 0.072 -0.00231822 -0.000993883 0.0792 -0.00370915 -0.00084001 0.0648 -0.00145492 -0.00120001 0.072 -0.00207845 -0.00192002 0.0792 -0.00332553 -0.00118795 0.0648 -0.00118793 -0.00169706 0.072 -0.00169704 -0.00271531 0.0792 -0.00271527 -0.00145493 0.0648 -0.00083999 -0.00207847 0.072 -0.00119999 -0.00332555 0.0792 -0.00191998 -0.00162276 0.0648 -0.000434805 -0.00231823 0.072 -0.000621149 -0.00370916 0.0792 -0.00099384 -0.00168 0.0648 1.29643e-08 -0.0024 0.072 1.85204e-08 -0.00384 0.0792 2.96326e-08 -0.00162275 0.0648 0.00043483 -0.00231822 0.072 0.000621187 -0.00370915 0.0792 0.000993898 -0.00145491 0.0648 0.000840014 -0.00207845 0.072 0.00120002 -0.00332552 0.0792 0.00192003 -0.00118793 0.0648 0.00118795 -0.00169704 0.072 0.00169707 -0.00271526 0.0792 0.00271532 -0.000839986 0.0648 0.00145493 -0.00119998 0.072 0.00207847 -0.00191997 0.0792 0.00332556 -0.000434799 0.0648 0.00162276 -0.000621139 0.072 0.00231823 -0.000993826 0.0792 0.00370917 1.8445e-08 0.0648 0.00168 2.635e-08 0.072 0.0024 4.216e-08 0.0792 0.00384 0.000434834 0.0648 0.00162275 0.000621192 0.072 0.00231821 0.000993907 0.0792 0.00370914 0.000840019 0.0648 0.00145491 0.00120002 0.072 0.00207845 0.00192004 0.0792 0.00332552 0.00118795 0.0648 0.00118792 0.00169708 0.072 0.00169704 0.00271532 0.0792 0.00271526 0.00145493 0.0648 0.000839981 0.00207848 0.072 0.00119998 0.00332556 0.0792 0.00191996 0.00162276 0.0648 0.000434795 0.00231823 0.072 0.000621134 0.00370917 0.0792 0.000993816 0 0.07776 0 3 0 1 2 3 3 0 2 3 4 3 2 3 5 4 2 3 6 5 2 3 7 6 2 3 8 7 2 3 9 8 2 3 10 9 2 3 11 10 2 3 12 11 2 3 13 12 2 3 14 13 2 3 15 14 2 3 16 15 2 3 17 16 2 3 18 17 2 3 19 18 2 3 20 19 2 3 21 20 2 3 22 21 2 3 23 22 2 3 24 23 2 3 25 24 2 3 26 25 2 3 27 26 2 3 28 27 2 3 29 28 2 3 30 29 2 3 31 30 2 3 32 31 2 3 33 32 2 3 34 33 2 3 35 34 2 3 36 35 2 3 1 36 2 3 0 37 38 3 0 38 1 3 3 39 37 3 3 37 0 3 4 40 39 3 4 39 3 3 5 41 40 3 5 40 4 3 6 42 41 3 6 41 5 3 7 43 42 3 7 42 6 3 8 44 43 3 8 43 7 3 9 45 44 3 9 44 8 3 10 46 45 3 10 45 9 3 11 47 46 3 11 46 10 3 12 48 47 3 12 47 11 3 13 49 48 3 13 48 12 3 14 50 49 3 14 49 13 3 15 51 50 3 15 50 14 3 16 52 51 3 16 51 15 3 17 53 52 3 17 52 16 3 18 54 53 3 18 53 17 3 19 55 54 3 19 54 18 3 20 56 55 3 20 55 19 3 21 57 56 3 21 56 20 3 22 58 57 3 22 57 21 3 23 59 58 3 23 58 22 3 24 60 59 3 24 59 23 3 25 61 60 3 25 60 24 3 26 62 61 3 26 61 25 3 27 63 62 3 27 62 26 3 28 64 63 3 28 63 27 3 29 65 64 3 29 64 28 3 30 66 65 3 30 65 29 3 31 67 66 3 31 66 30 3 32 68 67 3 32 67 31 3 33 69 68 3 33 68 32 3 34 70 69 3 34 69 33 3 35 71 70 3 35 70 34 3 36 72 71 3 36 71 35 3 1 38 72 3 1 72 36 3 37 73 74 3 37 74 38 3 39 75 73 3 39 73 37 3 40 76 75 3 40 75 39 3 41 77 76 3 41 76 40 3 42 78 77 3 42 77 41 3 43 79 78 3 43 78 42 3 44 80 79 3 44 79 43 3 45 81 80 3 45 80 44 3 46 82 81 3 46 81 45 3 47 83 82 3 47 82 46 3 48 84 83 3 48 83 47 3 49 85 84 3 49 84 48 3 50 86 85 3 50 85 49 3 51 87 86 3 51 86 50 3 52 88 87 3 52 87 51 3 53 89 88 3 53 88 52 3 54 90 89 3 54 89 53 3 55 91 90 3 55 90 54 3 56 92 91 3 56 91 55 3 57 93 92 3 57 92 56 3 58 94 93 3 58 93 57 3 59 95 94 3 59 94 58 3 60 96 95 3 60 95 59 3 61 97 96 3 61 96 60 3 62 98 97 3 62 97 61 3 63 99 98 3 63 98 62 3 64 100 99 3 64 99 63 3 65 101 100 3 65 100 64 3 66 102 101 3 66 101 65 3 67 103 102 3 67 102 66 3 68 104 103 3 68 103 67 3 69 105 104 3 69 104 68 3 70 106 105 3 70 105 69 3 71 107 106 3 71 106 70 3 72 108 107 3 72 107 71 3 38 74 108 3 38 108 72 3 73 109 110 3 73 110 74 3 75 111 109 3 75 109 73 3 76 112 111 3 76 111 75 3 77 113 112 3 77 112 76 3 78 114 113 3 78 113 77 3 79 115 114 3 79 114 78 3 80 116 115 3 80 115 79 3 81 117 116 3 81 116 80 3 82 118 117 3 82 117 81 3 83 119 118 3 83 118 82 3 84 120 119 3 84 119 83 3 85 121 120 3 85 120 84 3 86 122 121 3 86 121 85 3 87 123 122 3 87 122 86 3 88 124 123 3 88 123 87 3 89 125 124 3 89 124 88 3 90 126 125 3 90 125 89 3 91 127 126 3 91 126 90 3 92 128 127 3 92 127 91 3 93 129 128 3 93 128 92 3 94 130 129 3 94 129 93 3 95 131 130 3 95 130 94 3 96 132 131 3 96 131 95 3 97 133 132 3 97 132 96 3 98 134 133 3 98 133 97 3 99 135 134 3 99 134 98 3 100 136 135 3 100 135 99 3 101 137 136 3 101 136 100 3 102 138 137 3 102 137 101 3 103 139 138 3 103 138 102 3 104 140 139 3 104 139 103 3 105 141 140 3 105 140 104 3 106 142 141 3 106 141 105 3 107 143 142 3 107 142 106 3 108 144 143 3 108 143 107 3 74 110 144 3 74 144 108 3 109 145 146 3 109 146 110 3 111 147 145 3 111 145 109 3 112 148 147 3 112 147 111 3 113 149 148 3 113 148 112 3 114 150 149 3 114 149 113 3 115 151 150 3 115 150 114 3 116 152 151 3 116 151 115 3 117 153 152 3 117 152 116 3 118 154 153 3 118 153 117 3 119 155 154 3 119 154 118 3 120 156 155 3 120 155 119 3 121 157 156 3 121 156 120 3 122 158 157 3 122 157 121 3 123 159 158 3 123 158 122 3 124 160 159 3 124 159 123 3 125 161 160 3 125 160 124 3 126 162 161 3 126 161 125 3 127 163 162 3 127 162 126 3 128 164 163 3 128 163 127 3 129 165 164 3 129 164 128 3 130 166 165 3 130 165 129 3 131 167 166 3 131 166 130 3 132 168 167 3 132 167 131 3 133 169 168 3 133 168 132 3 134 170 169 3 134 169 133 3 135 171 170 3 135 170 134 3 136 172 171 3 136 171 135 3 137 173 172 3 137 172 136 3 138 174 173 3 138 173 137 3 139 175 174 3 139 174 138 3 140 176 175 3 140 175 139 3 141 177 176 3 141 176 140 3 142 178 177 3 142 177 141 3 143 179 178 3 143 178 142 3 144 180 179 3 144 179 143 3 110 146 180 3 110 180 144 3 145 181 182 3 145 182 146 3 147 183 181 3 147 181 145 3 148 184 183 3 148 183 147 3 149 185 184 3 149 184 148 3 150 186 185 3 150 185 149 3 151 187 186 3 151 186 150 3 152 188 187 3 152 187 151 3 153 189 188 3 153 188 152 3 154 190 189 3 154 189 153 3 155 191 190 3 155 190 154 3 156 192 191 3 156 191 155 3 157 193 192 3 157 192 156 3 158 194 193 3 158 193 157 3 159 195 194 3 159 194 158 3 160 196 195 3 160 195 159 3 161 197 196 3 161 196 160 3 162 198 197 3 162 197 161 3 163 199 198 3 163 198 162 3 164 200 199 3 164 199 163 3 165 201 200 3 165 200 164 3 166 202 201 3 166 201 165 3 167 203 202 3 167 202 166 3 168 204 203 3 168 203 167 3 169 205 204 3 169 204 168 3 170 206 205 3 170 205 169 3 171 207 206 3 171 206 170 3 172 208 207 3 172 207 171 3 173 209 208 3 173 208 172 3 174 210 209 3 174 209 173 3 175 211 210 3 175 210 174 3 176 212 211 3 176 211 175 3 177 213 212 3 177 212 176 3 178 214 213 3 178 213 177 3 179 215 214 3 179 214 178 3 180 216 215 3 180 215 179 3 146 182 216 3 146 216 180 3 181 217 218 3 181 218 182 3 183 219 217 3 183 217 181 3 184 220 219 3 184 219 183 3 185 221 220 3 185 220 184 3 186 222 221 3 186 221 185 3 187 223 222 3 187 222 186 3 188 224 223 3 188 223 187 3 189 225 224 3 189 224 188 3 190 226 225 3 190 225 189 3 191 227 226 3 191 226 190 3 192 228 227 3 192 227 191 3 193 229 228 3 193 228 192 3 194 230 229 3 194 229 193 3 195 231 230 3 195 230 194 3 196 232 231 3 196 231 195 3 197 233 232 3 197 232 196 3 198 234 233 3 198 233 197 3 199 235 234 3 199 234 198 3 200 236 235 3 200 235 199 3 201 237 236 3 201 236 200 3 202 238 237 3 202 237 201 3 203 239 238 3 203 238 202 3 204 240 239 3 204 239 203 3 205 241 240 3 205 240 204 3 206 242 241 3 206 241 205 3 207 243 242 3 207 242 206 3 208 244 243 3 208 243 207 3 209 245 244 3 209 244 208 3 210 246 245 3 210 245 209 3 211 247 246 3 211 246 210 3 212 248 247 3 212 247 211 3 213 249 248 3 213 248 212 3 214 250 249 3 214 249 213 3 215 251 250 3 215 250 214 3 216 252 251 3 216 251 215 3 182 218 252 3 182 252 216 3 217 253 254 3 217 254 218 3 219 255 253 3 219 253 217 3 220 256 255 3 220 255 219 3 221 257 256 3 221 256 220 3 222 258 257 3 222 257 221 3 223 259 258 3 223 258 222 3 224 260 259 3 224 259 223 3 225 261 260 3 225 260 224 3 226 262 261 3 226 261 225 3 227 263 262 3 227 262 226 3 228 264 263 3 228 263 227 3 229 265 264 3 229 264 228 3 230 266 265 3 230 265 229 3 231 267 266 3 231 266 230 3 232 268 267 3 232 267 231 3 233 269 268 3 233 268 232 3 234 270 269 3 234 269 233 3 235 271 270 3 235 270 234 3 236 272 271 3 236 271 235 3 237 273 272 3 237 272 236 3 238 274 273 3 238 273 237 3 239 275 274 3 239 274 238 3 240 276 275 3 240 275 239 3 241 277 276 3 241 276 240 3 242 278 277 3 242 277 241 3 243 279 278 3 243 278 242 3 244 280 279 3 244 279 243 3 245 281 280 3 245 280 244 3 246 282 281 3 246 281 245 3 247 283 282 3 247 282 246 3 248 284 283 3 248 283 247 3 249 285 284 3 249 284 248 3 250 286 285 3 250 285 249 3 251 287 286 3 251 286 250 3 252 288 287 3 252 287 251 3 218 254 288 3 218 288 252 3 253 289 290 3 253 290 254 3 255 291 289 3 255 289 253 3 256 292 291 3 256 291 255 3 257 293 292 3 257 292 256 3 258 294 293 3 258 293 257 3 259 295 294 3 259 294 258 3 260 296 295 3 260 295 259 3 261 297 296 3 261 296 260 3 262 298 297 3 262 297 261 3 263 299 298 3 263 298 262 3 264 300 299 3 264 299 263 3 265 301 300 3 265 300 264 3 266 302 301 3 266 301 265 3 267 303 302 3 267 302 266 3 268 304 303 3 268 303 267 3 269 305 304 3 269 304 268 3 270 306 305 3 270 305 269 3 271 307 306 3 271 306 270 3 272 308 307 3 272 307 271 3 273 309 308 3 273 308 272 3 274 310 309 3 274 309 273 3 275 311 310 3 275 310 274 3 276 312 311 3 276 311 275 3 277 313 312 3 277 312 276 3 278 314 313 3 278 313 277 3 279 315 314 3 279 314 278 3 280 316 315 3 280 315 279 3 281 317 316 3 281 316 280 3 282 318 317 3 282 317 281 3 283 319 318 3 283 318 282 3 284 320 319 3 284 319 283 3 285 321 320 3 285 320 284 3 286 322 321 3 286 321 285 3 287 323 322 3 287 322 286 3 288 324 323 3 288 323 287 3 254 290 324 3 254 324 288 3 289 325 326 3 289 326 290 3 291 327 325 3 291 325 289 3 292 328 327 3 292 327 291 3 293 329 328 3 293 328 292 3 294 330 329 3 294 329 293 3 295 331 330 3 295 330 294 3 296 332 331 3 296 331 295 3 297 333 332 3 297 332 296 3 298 334 333 3 298 333 297 3 299 335 334 3 299 334 298 3 300 336 335 3 300 335 299 3 301 337 336 3 301 336 300 3 302 338 337 3 302 337 301 3 303 339 338 3 303 338 302 3 304 340 339 3 304 339 303 3 305 341 340 3 305 340 304 3 306 342 341 3 306 341 305 3 307 343 342 3 307 342 306 3 308 344 343 3 308 343 307 3 309 345 344 3 309 344 308 3 310 346 345 3 310 345 309 3 311 347 346 3 311 346 310 3 312 348 347 3 312 347 311 3 313 349 348 3 313 348 312 3 314 350 349 3 314 349 313 3 315 351 350 3 315 350 314 3 316 352 351 3 316 351 315 3 317 353 352 3 317 352 316 3 318 354 353 3 318 353 317 3 319 355 354 3 319 354 318 3 320 356 355 3 320 355 319 3 321 357 356 3 321 356 320 3 322 358 357 3 322 357 321 3 323 359 358 3 323 358 322 3 324 360 359 3 324 359 323 3 290 326 360 3 290 360 324 3 325 361 362 3 325 362 326 3 327 363 361 3 327 361 325 3 328 364 363 3 328 363 327 3 329 365 364 3 329 364 328 3 330 366 365 3 330 365 329 3 331 367 366 3 331 366 330 3 332 368 367 3 332 367 331 3 333 369 368 3 333 368 332 3 334 370 369 3 334 369 333 3 335 371 370 3 335 370 334 3 336 372 371 3 336 371 335 3 337 373 372 3 337 372 336 3 338 374 373 3 338 373 337 3 339 375 374 3 339 374 338 3 340 376 375 3 340 375 339 3 341 377 376 3 341 376 340 3 342 378 377 3 342 377 341 3 343 379 378 3 343 378 342 3 344 380 379 3 344 379 343 3 345 381 380 3 345 380 344 3 346 382 381 3 346 381 345 3 347 383 382 3 347 382 346 3 348 384 383 3 348 383 347 3 349 385 384 3 349 384 348 3 350 386 385 3 350 385 349 3 351 387 386 3 351 386 350 3 352 388 387 3 352 387 351 3 353 389 388 3 353 388 352 3 354 390 389 3 354 389 353 3 355 391 390 3 355 390 354 3 356 392 391 3 356 391 355 3 357 393 392 3 357 392 356 3 358 394 393 3 358 393 357 3 359 395 394 3 359 394 358 3 360 396 395 3 360 395 359 3 326 362 396 3 326 396 360 3 361 397 398 3 361 398 362 3 363 399 397 3 363 397 361 3 364 400 399 3 364 399 363 3 365 401 400 3 365 400 364 3 366 402 401 3 366 401 365 3 367 403 402 3 367 402 366 3 368 404 403 3 368 403 367 3 369 405 404 3 369 404 368 3 370 406 405 3 370 405 369 3 371 407 406 3 371 406 370 3 372 408 407 3 372 407 371 3 373 409 408 3 373 408 372 3 374 410 409 3 374 409 373 3 375 411 410 3 375 410 374 3 376 412 411 3 376 411 375 3 377 413 412 3 377 412 376 3 378 414 413 3 378 413 377 3 379 415 414 3 379 414 378 3 380 416 415 3 380 415 379 3 381 417 416 3 381 416 380 3 382 418 417 3 382 417 381 3 383 419 418 3 383 418 382 3 384 420 419 3 384 419 383 3 385 421 420 3 385 420 384 3 386 422 421 3 386 421 385 3 387 423 422 3 387 422 386 3 388 424 423 3 388 423 387 3 389 425 424 3 389 424 388 3 390 426 425 3 390 425 389 3 391 427 426 3 391 426 390 3 392 428 427 3 392 427 391 3 393 429 428 3 393 428 392 3 394 430 429 3 394 429 393 3 395 431 430 3 395 430 394 3 396 432 431 3 396 431 395 3 362 398 432 3 362 432 396 3 397 433 434 3 397 434 398 3 399 435 433 3 399 433 397 3 400 436 435 3 400 435 399 3 401 437 436 3 401 436 400 3 402 438 437 3 402 437 401 3 403 439 438 3 403 438 402 3 404 440 439 3 404 439 403 3 405 441 440 3 405 440 404 3 406 442 441 3 406 441 405 3 407 443 442 3 407 442 406 3 408 444 443 3 408 443 407 3 409 445 444 3 409 444 408 3 410 446 445 3 410 445 409 3 411 447 446 3 411 446 410 3 412 448 447 3 412 447 411 3 413 449 448 3 413 448 412 3 414 450 449 3 414 449 413 3 415 451 450 3 415 450 414 3 416 452 451 3 416 451 415 3 417 453 452 3 417 452 416 3 418 454 453 3 418 453 417 3 419 455 454 3 419 454 418 3 420 456 455 3 420 455 419 3 421 457 456 3 421 456 420 3 422 458 457 3 422 457 421 3 423 459 458 3 423 458 422 3 424 460 459 3 424 459 423 3 425 461 460 3 425 460 424 3 426 462 461 3 426 461 425 3 427 463 462 3 427 462 426 3 428 464 463 3 428 463 427 3 429 465 464 3 429 464 428 3 430 466 465 3 430 465 429 3 431 467 466 3 431 466 430 3 432 468 467 3 432 467 431 3 398 434 468 3 398 468 432 3 433 469 470 3 433 470 434 3 435 471 469 3 435 469 433 3 436 472 471 3 436 471 435 3 437 473 472 3 437 472 436 3 438 474 473 3 438 473 437 3 439 475 474 3 439 474 438 3 440 476 475 3 440 475 439 3 441 477 476 3 441 476 440 3 442 478 477 3 442 477 441 3 443 479 478 3 443 478 442 3 444 480 479 3 444 479 443 3 445 481 480 3 445 480 444 3 446 482 481 3 446 481 445 3 447 483 482 3 447 482 446 3 448 484 483 3 448 483 447 3 449 485 484 3 449 484 448 3 450 486 485 3 450 485 449 3 451 487 486 3 451 486 450 3 452 488 487 3 452 487 451 3 453 489 488 3 453 488 452 3 454 490 489 3 454 489 453 3 455 491 490 3 455 490 454 3 456 492 491 3 456 491 455 3 457 493 492 3 457 492 456 3 458 494 493 3 458 493 457 3 459 495 494 3 459 494 458 3 460 496 495 3 460 495 459 3 461 497 496 3 461 496 460 3 462 498 497 3 462 497 461 3 463 499 498 3 463 498 462 3 464 500 499 3 464 499 463 3 465 501 500 3 465 500 464 3 466 502 501 3 466 501 465 3 467 503 502 3 467 502 466 3 468 504 503 3 468 503 467 3 434 470 504 3 434 504 468 3 469 505 506 3 469 506 470 3 471 507 505 3 471 505 469 3 472 508 507 3 472 507 471 3 473 509 508 3 473 508 472 3 474 510 509 3 474 509 473 3 475 511 510 3 475 510 474 3 476 512 511 3 476 511 475 3 477 513 512 3 477 512 476 3 478 514 513 3 478 513 477 3 479 515 514 3 479 514 478 3 480 516 515 3 480 515 479 3 481 517 516 3 481 516 480 3 482 518 517 3 482 517 481 3 483 519 518 3 483 518 482 3 484 520 519 3 484 519 483 3 485 521 520 3 485 520 484 3 486 522 521 3 486 521 485 3 487 523 522 3 487 522 486 3 488 524 523 3 488 523 487 3 489 525 524 3 489 524 488 3 490 526 525 3 490 525 489 3 491 527 526 3 491 526 490 3 492 528 527 3 492 527 491 3 493 529 528 3 493 528 492 3 494 530 529 3 494 529 493 3 495 531 530 3 495 530 494 3 496 532 531 3 496 531 495 3 497 533 532 3 497 532 496 3 498 534 533 3 498 533 497 3 499 535 534 3 499 534 498 3 500 536 535 3 500 535 499 3 501 537 536 3 501 536 500 3 502 538 537 3 502 537 501 3 503 539 538 3 503 538 502 3 504 540 539 3 504 539 503 3 470 506 540 3 470 540 504 3 505 541 542 3 505 542 506 3 507 543 541 3 507 541 505 3 508 544 543 3 508 543 507 3 509 545 544 3 509 544 508 3 510 546 545 3 510 545 509 3 511 547 546 3 511 546 510 3 512 548 547 3 512 547 511 3 513 549 548 3 513 548 512 3 514 550 549 3 514 549 513 3 515 551 550 3 515 550 514 3 516 552 551 3 516 551 515 3 517 553 552 3 517 552 516 3 518 554 553 3 518 553 517 3 519 555 554 3 519 554 518 3 520 556 555 3 520 555 519 3 521 557 556 3 521 556 520 3 522 558 557 3 522 557 521 3 523 559 558 3 523 558 522 3 524 560 559 3 524 559 523 3 525 561 560 3 525 560 524 3 526 562 561 3 526 561 525 3 527 563 562 3 527 562 526 3 528 564 563 3 528 563 527 3 529 565 564 3 529 564 528 3 530 566 565 3 530 565 529 3 531 567 566 3 531 566 530 3 532 568 567 3 532 567 531 3 533 569 568 3 533 568 532 3 534 570 569 3 534 569 533 3 535 571 570 3 535 570 534 3 536 572 571 3 536 571 535 3 537 573 572 3 537 572 536 3 538 574 573 3 538 573 537 3 539 575 574 3 539 574 538 3 540 576 575 3 540 575 539 3 506 542 576 3 506 576 540 3 541 577 578 3 541 578 542 3 543 579 577 3 543 577 541 3 544 580 579 3 544 579 543 3 545 581 580 3 545 580 544 3 546 582 581 3 546 581 545 3 547 583 582 3 547 582 546 3 548 584 583 3 548 583 547 3 549 585 584 3 549 584 548 3 550 586 585 3 550 585 549 3 551 587 586 3 551 586 550 3 552 588 587 3 552 587 551 3 553 589 588 3 553 588 552 3 554 590 589 3 554 589 553 3 555 591 590 3 555 590 554 3 556 592 591 3 556 591 555 3 557 593 592 3 557 592 556 3 558 594 593 3 558 593 557 3 559 595 594 3 559 594 558 3 560 596 595 3 560 595 559 3 561 597 596 3 561 596 560 3 562 598 597 3 562 597 561 3 563 599 598 3 563 598 562 3 564 600 599 3 564 599 563 3 565 601 600 3 565 600 564 3 566 602 601 3 566 601 565 3 567 603 602 3 567 602 566 3 568 604 603 3 568 603 567 3 569 605 604 3 569 604 568 3 570 606 605 3 570 605 569 3 571 607 606 3 571 606 570 3 572 608 607 3 572 607 571 3 573 609 608 3 573 608 572 3 574 610 609 3 574 609 573 3 575 611 610 3 575 610 574 3 576 612 611 3 576 611 575 3 542 578 612 3 542 612 576 3 577 613 614 3 577 614 578 3 579 615 613 3 579 613 577 3 580 616 615 3 580 615 579 3 581 617 616 3 581 616 580 3 582 618 617 3 582 617 581 3 583 619 618 3 583 618 582 3 584 620 619 3 584 619 583 3 585 621 620 3 585 620 584 3 586 622 621 3 586 621 585 3 587 623 622 3 587 622 586 3 588 624 623 3 588 623 587 3 589 625 624 3 589 624 588 3 590 626 625 3 590 625 589 3 591 627 626 3 591 626 590 3 592 628 627 3 592 627 591 3 593 629 628 3 593 628 592 3 594 630 629 3 594 629 593 3 595 631 630 3 595 630 594 3 596 632 631 3 596 631 595 3 597 633 632 3 597 632 596 3 598 634 633 3 598 633 597 3 599 635 634 3 599 634 598 3 600 636 635 3 600 635 599 3 601 637 636 3 601 636 600 3 602 638 637 3 602 637 601 3 603 639 638 3 603 638 602 3 604 640 639 3 604 639 603 3 605 641 640 3 605 640 604 3 606 642 641 3 606 641 605 3 607 643 642 3 607 642 606 3 608 644 643 3 608 643 607 3 609 645 644 3 609 644 608 3 610 646 645 3 610 645 609 3 611 647 646 3 611 646 610 3 612 648 647 3 612 647 611 3 578 614 648 3 578 648 612 3 613 649 650 3 613 650 614 3 615 651 649 3 615 649 613 3 616 652 651 3 616 651 615 3 617 653 652 3 617 652 616 3 618 654 653 3 618 653 617 3 619 655 654 3 619 654 618 3 620 656 655 3 620 655 619 3 621 657 656 3 621 656 620 3 622 658 657 3 622 657 621 3 623 659 658 3 623 658 622 3 624 660 659 3 624 659 623 3 625 661 660 3 625 660 624 3 626 662 661 3 626 661 625 3 627 663 662 3 627 662 626 3 628 664 663 3 628 663 627 3 629 665 664 3 629 664 628 3 630 666 665 3 630 665 629 3 631 667 666 3 631 666 630 3 632 668 667 3 632 667 631 3 633 669 668 3 633 668 632 3 634 670 669 3 634 669 633 3 635 671 670 3 635 670 634 3 636 672 671 3 636 671 635 3 637 673 672 3 637 672 636 3 638 674 673 3 638 673 637 3 639 675 674 3 639 674 638 3 640 676 675 3 640 675 639 3 641 677 676 3 641 676 640 3 642 678 677 3 642 677 641 3 643 679 678 3 643 678 642 3 644 680 679 3 644 679 643 3 645 681 680 3 645 680 644 3 646 682 681 3 646 681 645 3 647 683 682 3 647 682 646 3 648 684 683 3 648 683 647 3 614 650 684 3 614 684 648 3 649 685 686 3 649 686 650 3 651 687 685 3 651 685 649 3 652 688 687 3 652 687 651 3 653 689 688 3 653 688 652 3 654 690 689 3 654 689 653 3 655 691 690 3 655 690 654 3 656 692 691 3 656 691 655 3 657 693 692 3 657 692 656 3 658 694 693 3 658 693 657 3 659 695 694 3 659 694 658 3 660 696 695 3 660 695 659 3 661 697 696 3 661 696 660 3 662 698 697 3 662 697 661 3 663 699 698 3 663 698 662 3 664 700 699 3 664 699 663 3 665 701 700 3 665 700 664 3 666 702 701 3 666 701 665 3 667 703 702 3 667 702 666 3 668 704 703 3 668 703 667 3 669 705 704 3 669 704 668 3 670 706 705 3 670 705 669 3 671 707 706 3 671 706 670 3 672 708 707 3 672 707 671 3 673 709 708 3 673 708 672 3 674 710 709 3 674 709 673 3 675 711 710 3 675 710 674 3 676 712 711 3 676 711 675 3 677 713 712 3 677 712 676 3 678 714 713 3 678 713 677 3 679 715 714 3 679 714 678 3 680 716 715 3 680 715 679 3 681 717 716 3 681 716 680 3 682 718 717 3 682 717 681 3 683 719 718 3 683 718 682 3 684 720 719 3 684 719 683 3 650 686 720 3 650 720 684 3 685 721 722 3 685 722 686 3 687 723 721 3 687 721 685 3 688 724 723 3 688 723 687 3 689 725 724 3 689 724 688 3 690 726 725 3 690 725 689 3 691 727 726 3 691 726 690 3 692 728 727 3 692 727 691 3 693 729 728 3 693 728 692 3 694 730 729 3 694 729 693 3 695 731 730 3 695 730 694 3 696 732 731 3 696 731 695 3 697 733 732 3 697 732 696 3 698 734 733 3 698 733 697 3 699 735 734 3 699 734 698 3 700 736 735 3 700 735 699 3 701 737 736 3 701 736 700 3 702 738 737 3 702 737 701 3 703 739 738 3 703 738 702 3 704 740 739 3 704 739 703 3 705 741 740 3 705 740 704 3 706 742 741 3 706 741 705 3 707 743 742 3 707 742 706 3 708 744 743 3 708 743 707 3 709 745 744 3 709 744 708 3 710 746 745 3 710 745 709 3 711 747 746 3 711 746 710 3 712 748 747 3 712 747 711 3 713 749 748 3 713 748 712 3 714 750 749 3 714 749 713 3 715 751 750 3 715 750 714 3 716 752 751 3 716 751 715 3 717 753 752 3 717 752 716 3 718 754 753 3 718 753 717 3 719 755 754 3 719 754 718 3 720 756 755 3 720 755 719 3 686 722 756 3 686 756 720 3 721 757 758 3 721 758 722 3 723 759 757 3 723 757 721 3 724 760 759 3 724 759 723 3 725 761 760 3 725 760 724 3 726 762 761 3 726 761 725 3 727 763 762 3 727 762 726 3 728 764 763 3 728 763 727 3 729 765 764 3 729 764 728 3 730 766 765 3 730 765 729 3 731 767 766 3 731 766 730 3 732 768 767 3 732 767 731 3 733 769 768 3 733 768 732 3 734 770 769 3 734 769 733 3 735 771 770 3 735 770 734 3 736 772 771 3 736 771 735 3 737 773 772 3 737 772 736 3 738 774 773 3 738 773 737 3 739 775 774 3 739 774 738 3 740 776 775 3 740 775 739 3 741 777 776 3 741 776 740 3 742 778 777 3 742 777 741 3 743 779 778 3 743 778 742 3 744 780 779 3 744 779 743 3 745 781 780 3 745 780 744 3 746 782 781 3 746 781 745 3 747 783 782 3 747 782 746 3 748 784 783 3 748 783 747 3 749 785 784 3 749 784 748 3 750 786 785 3 750 785 749 3 751 787 786 3 751 786 750 3 752 788 787 3 752 787 751 3 753 789 788 3 753 788 752 3 754 790 789 3 754 789 753 3 755 791 790 3 755 790 754 3 756 792 791 3 756 791 755 3 722 758 792 3 722 792 756 3 757 793 758 3 759 793 757 3 760 793 759 3 761 793 760 3 762 793 761 3 763 793 762 3 764 793 763 3 765 793 764 3 766 793 765 3 767 793 766 3 768 793 767 3 769 793 768 3 770 793 769 3 771 793 770 3 772 793 771 3 773 793 772 3 774 793 773 3 775 793 774 3 776 793 775 3 777 793 776 3 778 793 777 3 779 793 778 3 780 793 779 3 781 793 780 3 782 793 781 3 783 793 782 3 784 793 783 3 785 793 784 3 786 793 785 3 787 793 786 3 788 793 787 3 789 793 788 3 790 793 789 3 791 793 790 3 792 793 791 3 758 793 792 3 794 795 796 3 794 796 797 3 795 798 799 3 795 799 796 3 800 801 795 3 800 795 794 3 801 802 798 3 801 798 795 3 803 804 801 3 803 801 800 3 804 805 802 3 804 802 801 3 806 807 804 3 806 804 803 3 807 808 805 3 807 805 804 3 809 810 807 3 809 807 806 3 810 811 808 3 810 808 807 3 812 813 810 3 812 810 809 3 813 814 811 3 813 811 810 3 815 816 813 3 815 813 812 3 816 817 814 3 816 814 813 3 818 819 816 3 818 816 815 3 819 820 817 3 819 817 816 3 821 822 819 3 821 819 818 3 822 823 820 3 822 820 819 3 824 825 822 3 824 822 821 3 825 826 823 3 825 823 822 3 827 828 825 3 827 825 824 3 828 829 826 3 828 826 825 3 830 831 828 3 830 828 827 3 831 832 829 3 831 829 828 3 833 834 831 3 833 831 830 3 834 835 832 3 834 832 831 3 836 837 834 3 836 834 833 3 837 838 835 3 837 835 834 3 839 840 837 3 839 837 836 3 840 841 838 3 840 838 837 3 842 843 840 3 842 840 839 3 843 844 841 3 843 841 840 3 845 846 843 3 845 843 842 3 846 847 844 3 846 844 843 3 848 849 846 3 848 846 845 3 849 850 847 3 849 847 846 3 851 852 849 3 851 849 848 3 852 853 850 3 852 850 849 3 854 855 852 3 854 852 851 3 855 856 853 3 855 853 852 3 857 858 855 3 857 855 854 3 858 859 856 3 858 856 855 3 860 861 858 3 860 858 857 3 861 862 859 3 861 859 858 3 863 864 861 3 863 861 860 3 864 865 862 3 864 862 861 3 797 796 864 3 797 864 863 3 796 799 865 3 796 865 864 3 866 799 798 3 866 798 802 3 866 802 805 3 866 805 808 3 866 808 811 3 866 811 814 3 866 814 817 3 866 817 820 3 866 820 823 3 866 823 826 3 866 826 829 3 866 829 832 3 866 832 835 3 866 835 838 3 866 838 841 3 866 841 844 3 866 844 847 3 866 847 850 3 866 850 853 3 866 853 856 3 866 856 859 3 866 859 862 3 866 862 865 3 866 865 799 matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFaceNumber.m0000644000000000000000000000013214055375162020461 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFaceNumber.m0000644000175000017500000000474714055375162021562 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function nFaces = meshFaceNumber(varargin) %MESHFACENUMBER Returns the number of faces in this mesh. % % NF = meshFaceNumber(V, F) % NF = meshFaceNumber(V, E, F) % NF = meshFaceNumber(MESH) % Returns the number of faces in the given mesh. As the face array may be % represented either as numeric array or as cell array of indices, this % function is a convenient way to get the number of faces independanlty % of the mesh representation. % % Example % [v f] = createCube; % meshFaceNumber(v, f) % ans = % 6 % % See also % meshes3d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2013-08-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2013 INRA - Cepia Software Platform. [vertices, faces] = parseMeshData(varargin{:}); %#ok if iscell(faces) nFaces = length(faces); else nFaces = size(faces, 1); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/isPointInMesh.m0000644000000000000000000000013214055375162020326 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/isPointInMesh.m0000644000175000017500000000571014055375162021416 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = isPointInMesh(point, v, f, varargin) %ISPOINTINMESH Check if a point is inside a 3D mesh. % % B = isPointInMesh(PT, V, F) % Check if the point PT (given as a 1-by-3 array) is inside the mesh % defined by the vertices V and the face array F. The result is a % boolean. % % If PT is a N-by-3 point array, the result is a N-by-1 array of logical. % % Example % [v, f] = torusMesh([50 50 50 30 10 30 45]); % [x, y, z] = meshgrid(5:5:100, 5:5:100, 5:5:100); % res = false(size(x)); % res(:) = isPointInMesh([x(:) y(:) z(:)], v, f); % figure; plot3(x(res), y(res), z(res), 'b.'); axis equal; % % Algorithm: % The method computes the intersection with a ray starting from the % point(s) and with a random orientation. Some errors are possible if % rays crosses the mesh between two or three faces. % % See also % meshes3d, intersectLineMesh3d % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2018-01-26, using Matlab 9.3.0.713579 (R2017b) % Copyright 2018 INRA - Cepia Software Platform. % choose a random vector vect = rand(1, 3); % initialize array for result np = size(point, 1); res = false(np, 1); % iterate over the various points for i = 1:np % disp(i); line = createLine3d(point(i,:), vect); [inters, pos] = intersectLineMesh3d(line, v, f); %#ok res(i) = mod(sum(pos > 0), 2) > 0; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshBoundaryEdgeIndices.m0000644000000000000000000000013214055375162022321 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshBoundaryEdgeIndices.m0000644000175000017500000000567414055375162023422 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function inds = meshBoundaryEdgeIndices(varargin) %MESHBOUNDARYEDGEINDICES Indices of boundary edges of a mesh. % % INDS = meshBoundaryVertexIndices(V, F) % INDS = meshBoundaryVertexIndices(V, E, F) % % Example % % create centered icosahedron % [v, f] = createIcosahedron; % v(:,3) = v(:,3) - mean(v(:,3)); % % convert to simili-sphere % [v2, f2] = subdivideMesh(v, f, 3); % v3 = normalizeVector3d(v2); % % clip with plane % plane = createPlane([0 0 0], [-1 -2 3]); % [vc, fc] = clipMeshVertices(v3, f2, plane, 'shape', 'plane'); % figure; drawMesh(vc, fc); axis equal; view(3); % % draw boundary vertices % ec = meshEdges(vc, fc); % inds = meshBoundaryEdgeIndices(vc, ec, fc); % edges = [vc(ec(inds, 1), :) vc(ec(inds, 2), :)]; % hold on; drawEdge3d(edges, 'linewidth', 2, 'color', 'b'); % % See also % meshes3d, meshBoundary, meshBoundaryVertexIndices, meshEdgeFaces % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-05-01, using Matlab 8.6.0.267246 (R2015b) % Copyright 2019 INRA - Cepia Software Platform. [vertices, edges, faces] = parseMeshData(varargin{:}); % Compute edge-vertex map if not specified if isempty(edges) edges = meshEdges(vertices, faces); end % compute edges to faces map edgeFaces = meshEdgeFaces(vertices, edges, faces); inds = find(sum(edgeFaces == 0, 2) > 0); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/readMesh_off.m0000644000000000000000000000013214055375162020157 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/readMesh_off.m0000644000175000017500000001221714055375162021247 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = readMesh_off(fileName) % Read mesh data stored in OFF format. % % [VERTICES, FACES] = readMesh_off(FILENAME) % Read the data stored in file FILENAME and return the vertex and face % arrays as NV-by-3 array and NF-by-N array respectively, where NV is the % number of vertices and NF is the number of faces. % % MESH = readMesh_off(FILENAME) % Read the data stored in file FILENAME and return the mesh into a struct % with fields 'vertices' and 'faces'. % % Example % [v, f] = readMesh_off('mushroom.off'); % figure; drawMesh(v, f, 'faceColor', [0 1 0], 'edgeColor', 'none') % view([5 80]); light; lighting gouraud % % See also % meshes3d, readMesh, writeMesh_off, drawMesh % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-12-20, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. %% Read header % open file f = fopen(fileName, 'r'); if f == -1 error('matGeom:readMesh_off:FileNotFound', ... ['Could not find file: ' fileName]); end % check format line = fgetl(f); % -1 if eof if ~strcmp(line(1:3), 'OFF') error('matGeom:readMesh_off:FileFormatError', ... 'Not a valid OFF file'); end % number of faces and vertices line = fgetl(f); vals = sscanf(line, '%d %d'); nVertices = vals(1); nFaces = vals(2); %% Read vertex data [vertices, count] = fscanf(f, '%f ', [3 nVertices]); if count ~= nVertices * 3 error('matGeom:readMesh_off:FileFormatError', ... ['Could not read all the ' num2str(nVertices) ' vertices']); end vertices = vertices'; %% Read Face data % First try to read faces as an homogeneous array. It if fails, start from % face offset and parse each face individually. In the latter case, faces % can have different number of vertices. % keep position of face info within file faceOffset = ftell(f); % read first face to assess number of vertices per face line = fgetl(f); if line == -1 error('matGeom:readMesh_off:FileFormatError', ... 'Unexpected end of file'); end tokens = split(line); face1 = str2double(tokens(2:end))' + 1; nv = length(face1); try % attenpt to read the remaining faces assuming they all have the same % number of vertices pattern = ['%d' repmat(' %d', 1, nv) '\n']; [faces, count] = fscanf(f, pattern, [(nv+1) (nFaces-1)]); if count ~= (nFaces-1) * (nv+1) error('matGeom:readMesh_off:FileFormatError', ... 'Could not read all the %d faces', nFaces); end % transpose, remove first column, use 1-indexing, and concatenate with % first face faces = [face1 ; faces(2:end,:)'+1]; catch % if attempt failed, switch to slower face-by-face parsing disp('readMesh_off: Inhomogeneous number of vertices per face, switching to face-per-face parsing'); fseek(f, faceOffset, 'bof'); % allocate cell array faces = cell(1, nFaces); % iterate over faces for iFace = 1:nFaces % read next line line = fgetl(f); if line == -1 error('matGeom:readMesh_off:FileFormatError', ... 'Unexpected end of file'); end % parse vertex indices for current face tokens = split(line); faces{iFace} = str2double(tokens(2:end))' + 1; end end %% Post-processing % close the file fclose(f); % format output arguments if nargout < 2 mesh.vertices = vertices; mesh.faces = faces; varargout = {mesh}; else varargout = {vertices, faces}; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshVolume.m0000644000000000000000000000013214055375162017721 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshVolume.m0000644000175000017500000000650614055375162021015 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function vol = meshVolume(varargin) % (Signed) volume of the space enclosed by a polygonal mesh. % % V = meshVolume(VERTS, FACES) % Computes the volume of the space enclosed by the polygonal mesh % represented by vertices VERTS (as a Nv-by-3 array of cooridnates) and % the array of faces FACES (either as a Nf-by-3 array of vertex indices, % or as a cell array of arrays of vertex indices). % % The volume is computed as the sum of the signed volumes of tetrahedra % formed by triangular faces and the centroid of the mesh. Faces need to % be oriented such that normal points outwards the mesh. See: % http://stackoverflow.com/questions/1838401/general-formula-to-calculate-polyhedron-volume % % Example % % computes the volume of a unit cube (should be equal to 1...) % [v f] = createCube; % meshVolume(v, f) % ans = % 1 % % See also % meshes3d, meshSurfaceArea, tetrahedronVolume, meshComplement % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2012-10-01, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % HISTORY % 2013-08-16 speed improvement by Sven Holcombe % parse input [vertices, faces] = parseMeshData(varargin{:}); % ensure mesh has triangle faces faces = triangulateFaces(faces); % initialize an array of volume nFaces = size(faces, 1); vols = zeros(nFaces, 1); % Shift all vertices to the mesh centroid vertices = bsxfun(@minus, vertices, mean(vertices,1)); % compute volume of each tetraedron for i = 1:nFaces % consider the tetrahedron formed by face and mesh centroid tetra = vertices(faces(i, :), :); % volume of current tetrahedron vols(i) = det(tetra) / 6; end vol = sum(vols); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFaceCentroids.m0000644000000000000000000000013214055375162021163 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFaceCentroids.m0000644000175000017500000000751014055375162022253 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function centroids = meshFaceCentroids(varargin) %MESHFACECENTROIDS Compute centroids of faces in a mesh. % % CENTROIDS = meshFaceCentroids(VERTICES, FACES) % VERTICES is a set of 3D points (as a N-by-3 array), and FACES is % either a N-by-3 index array or a cell array of indices. The function % computes the centroid of each face, and returns a Nf-by-3 array % containing their coordinates. % % Example % [v, e, f] = createIcosahedron; % normals1 = meshFaceNormals(v, f); % centros1 = meshFaceCentroids(v, f); % figure; hold on; axis equal; view(3); % drawMesh(v, f); % drawVector3d(centros1, normals1); % % % See also: % meshes3d, drawMesh, meshFaceNormals, meshFaceAreas, convhull % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-07-05 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 2007-09-18 fix: worked only for 2D case, now works also for 3D % 2017-11-24 rename from faceCentroids to meshFaceCentroids % parse input data [vertices, faces] = parseMeshData(varargin{:}); if isnumeric(faces) % trimesh or quadmesh nf = size(faces, 1); centroids = zeros(nf, size(vertices, 2)); if size(vertices, 2) == 2 % planar case for f = 1:nf centroids(f,:) = polygonCentroid(vertices(faces(f,:), :)); end else % 3D case if size(faces, 2) == 3 % For triangular meshes, uses accelerated method % (taken from https://github.com/alecjacobson/gptoolbox) for ff = 1:3 centroids = centroids + 1/3 * vertices(faces(:,ff),:); end else % for quad (or larger) meshes, use slower but more precise method for f = 1:nf centroids(f,:) = polygonCentroid3d(vertices(faces(f,:), :)); end end end else % mesh with faces stored as cell array nf = length(faces); centroids = zeros(nf, size(vertices, 2)); if size(vertices, 2) == 2 % planar case for f = 1:nf centroids(f,:) = polygonCentroid(vertices(faces{f}, :)); end else % 3D case for f = 1:nf centroids(f,:) = polygonCentroid3d(vertices(faces{f}, :)); end end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/collapseEdgesWithManyFaces.m0000644000000000000000000000013214055375162022772 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/collapseEdgesWithManyFaces.m0000644000175000017500000000566414055375162024072 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, faces] = collapseEdgesWithManyFaces(vertices, faces, varargin) % removes mesh edges adjacent to more than two faces % % [V2, F2] = collapseEdgesWithManyFaces(V, F) % Count the number of faces adjacent to each edge, and collapse the edges % adjacent to more than two faces. % % % Example % collapseEdgesWithManyFaces % % See also % trimMesh, isManifoldMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-31, using Matlab 9.5.0.944444 (R2018b) % Copyright 2019 INRA - Cepia Software Platform. verbose = false; while length(varargin) > 1 && ischar(varargin{1}) name = varargin{1}; if strcmpi(name, 'verbose') verbose = varargin{2}; else error(['Unknown optional argument: ' name]); end varargin(1:2) = []; end while true % compute edge to vertex mapping edges = meshEdges(faces); % compute number of faces incident to each edge edgeFaces = trimeshEdgeFaces(faces); edgeFaceDegrees = sum(edgeFaces > 0, 2); inds = find(edgeFaceDegrees > 2); if isempty(inds) break; end edge = edges(inds(1), :); if verbose fprintf('remove edge with index %d: (%d, %d)\n', inds(1), edge); end [vertices, faces] = mergeMeshVertices(vertices, faces, edge); end % trim [vertices, faces] = trimMesh(vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/minConvexHull.m0000644000000000000000000000013214055375162020370 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/minConvexHull.m0000644000175000017500000001212614055375162021457 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function newFaces = minConvexHull(points, varargin) %MINCONVEXHULL Return the unique minimal convex hull of a set of 3D points. % % FACES = minConvexHull(PTS) % NODES is a set of 3D points (as a Nx3 array). The function computes % the convex hull, and merge contiguous coplanar faces. The result is a % set of polygonal faces, such that there are no coplanar faces. % FACES is a cell array, each cell containing the vector of indices of % nodes given in NODES for the corresponding face. % % FACES = minConvexHull(PTS, PRECISION) % Adjust the threshold for deciding if two faces are coplanar or % parallel. Default value is 1e-14. % % Example % % extract square faces from a cube % [n, e, f] = createCube; % f2 = minConvexHull(n); % drawMesh(n, f2); % % % Subdivides and smooths a mesh rpresenting a cube % [n, e, f] = createCube; % [n2, f2] = subdivideMesh(n, triangulateFaces(f), 4); % [n3, f3] = smoothMesh(n2, f2); % figure; drawMesh(n3, f3); % axis equal; view(3); % % merge coplanar faces, making apparent the faces of the original cube % f4 = minConvexHull(n3); % figure; drawMesh(n3, f4); % axis equal; view(3); % % % See also % meshes3d, mergeCoplanarFaces, drawMesh, convhull, convhulln % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2006-07-05 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 20/07/2006 add tolerance for coplanarity test % 21/08/2006 fix small bug due to difference of methods to test % coplanarity, sometimes resulting in 3 points of a face being not % coplanar! Also add control on precision % 18/09/2007 ensure faces are given as horizontal vectors % set up precision acc = 1e-14; if ~isempty(varargin) acc = varargin{1}; end % triangulated convex hull. It is not uniquely defined. faces = convhulln(points); % compute centroid of the nodes pointsCentroid = centroid(points); % number of base triangular faces N = size(faces, 1); % compute normals of given faces normals = planeNormal(createPlane(... points(faces(:,1),:), points(faces(:,2),:), points(faces(:,3),:))); % initialize empty faces newFaces = {}; % Processing flag for each triangle % 1 : triangle to process, 0 : already processed % in the beginning, every triangle face need to be processed flag = ones(N, 1); % iterate on each triangular face of the convex hull for iFace = 1:N % check if face was already performed if ~flag(iFace) continue; end % indices of faces with same normal ind = find(abs(vectorNorm3d(cross(repmat(normals(iFace, :), [N 1]), normals))) end end % compute order of the vertices in current face faceVertices = unique(faces(ind2, :)); [tmp, I] = angleSort3d(points(faceVertices, :)); %#ok % create the new face, ensuring it is a row vector face = faceVertices(I); face = face(:)'; % ensure face has normal pointing outwards outerNormal = meshFaceCentroids(points, face) - pointsCentroid; if dot(meshFaceNormals(points, face), outerNormal, 2) < 0 face = face([1 end:-1:2]); end % add a new face to the list newFaces = [newFaces {face}]; %#ok % mark processed faces flag(ind2) = 0; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/readMesh_ply.m0000644000000000000000000000013214055375162020211 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/readMesh_ply.m0000644000175000017500000004600614055375162021304 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = readMesh_ply(fileName) % Read mesh data stored in PLY (Stanford triangle) format. % % [V, F] = readMesh_ply(FNAME) % % Example % readMesh_ply % % References % Wrapper function for Gabriel Peyré's read_ply that is a wrapper % function of Pascal Getreuer's plyread. % % See also % meshes3d, readMesh, readMesh_off, readMesh_stl % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2018-04-26, using Matlab 9.4.0.813654 (R2018a) % Copyright 2018 INRA - Cepia Software Platform. %% open file f = fopen(fileName, 'r'); if f == -1 error('matGeom:readMesh_ply:FileNotFound', ... ['Could not find file: ' fileName]); end [vertices, faces] = read_ply(fileName); varargout = formatMeshOutput(nargout, vertices, faces); end function [vertex,face,d,c] = read_ply(filename) % read_ply - read data from PLY file. % % [vertex,face] = read_ply(filename); % % 'vertex' is a 'nb.vert x 3' array specifying the position of the vertices. % 'face' is a 'nb.face x 3' array specifying the connectivity of the mesh. % % Copyright (c) 2003 Gabriel Peyré possibleFacePropertyNames = ... {'vertex_indices','vertex_indexes','vertex_index','indices','indexes'}; [d,c] = plyread(filename); facePropertyNameIdx = find(matches(possibleFacePropertyNames, fieldnames(d.face))); assert(length(facePropertyNameIdx) == 1) vi = d.face.(possibleFacePropertyNames{facePropertyNameIdx}); lengths = cellfun('length',vi); maxLength = max(lengths); if all(maxLength == lengths) face = cell2mat(vi)+1; else face = cellfun(@(x) x+1, vi, 'uni',0); end vertex = [d.vertex.x, d.vertex.y, d.vertex.z]; end function [Elements,varargout] = plyread(Path,Str) %PLYREAD Read a PLY 3D data file. % [DATA,COMMENTS] = PLYREAD(FILENAME) reads a version 1.0 PLY file % FILENAME and returns a structure DATA. The fields in this structure % are defined by the PLY header; each element type is a field and each % element property is a subfield. If the file contains any comments, % they are returned in a cell string array COMMENTS. % % [TRI,PTS] = PLYREAD(FILENAME,'tri') or % [TRI,PTS,DATA,COMMENTS] = PLYREAD(FILENAME,'tri') converts vertex % and face data into triangular connectivity and vertex arrays. The % mesh can then be displayed using the TRISURF command. % % Note: This function is slow for large mesh files (+50K faces), % especially when reading data with list type properties. % % Example: % [Tri,Pts] = PLYREAD('cow.ply','tri'); % trisurf(Tri,Pts(:,1),Pts(:,2),Pts(:,3)); % colormap(gray); axis equal; % % See also: PLYWRITE % Pascal Getreuer 2004 [fid,Msg] = fopen(Path,'rt'); % open file in read text mode if fid == -1, error(Msg); end Buf = fscanf(fid,'%s',1); if ~strcmp(Buf,'ply') fclose(fid); error('Not a PLY file.'); end %% read header ftell(fid); Format = ''; NumComments = 0; Comments = {}; % for storing any file comments NumElements = 0; NumProperties = 0; Elements = []; % structure for holding the element data ElementCount = []; % number of each type of element in file PropertyTypes = []; % corresponding structure recording property types ElementNames = {}; % list of element names in the order they are stored in the file PropertyNames = []; % structure of lists of property names while 1 Buf = fgetl(fid); % read one line from file Token = split(Buf); % split line into tokens Count = length(Token); % count tokens if Count % parse line switch lower(Token{1}) case 'format' % read data format if Count >= 2 Format = lower(Token{2}); if Count == 3 && ~strcmp(Token{3},'1.0') fclose(fid); error('Only PLY format version 1.0 supported.'); end end case 'comment' % read file comment NumComments = NumComments + 1; Comments{NumComments} = ''; %#ok for i = 2:Count Comments{NumComments} = [Comments{NumComments},Token{i},' ']; end case 'element' % element name if Count >= 3 if isfield(Elements,Token{2}) fclose(fid); error(['Duplicate element name, ''',Token{2},'''.']); end NumElements = NumElements + 1; NumProperties = 0; Elements.(Token{2}) = []; PropertyTypes.(Token{2}) =[]; ElementNames{NumElements} = Token{2}; %#ok PropertyNames.(Token{2}) = {}; CurElement = Token{2}; ElementCount(NumElements) = str2double(Token{3}); %#ok if isnan(ElementCount(NumElements)) fclose(fid); error(['Bad element definition: ',Buf]); end else error(['Bad element definition: ',Buf]); end case 'property' % element property if ~isempty(CurElement) && Count >= 3 NumProperties = NumProperties + 1; if isfield(Elements.(CurElement),Token{Count}) fclose(fid); error(['Duplicate property name, ''',CurElement,'.',Token{2},'''.']); end % add property subfield to Elements Elements.(CurElement).(Token{Count}) = []; % add property subfield to PropertyTypes and save type PropertyTypes.(CurElement).(Token{Count}) = Token(2:Count-1); % record property name order PropertyNames.(CurElement){NumProperties} = Token{Count}; else fclose(fid); if isempty(CurElement) error(['Property definition without element definition: ',Buf]); else error(['Bad property definition: ',Buf]); end end case 'end_header' % end of header, break from while loop break; end end end %% set reading for specified data format if isempty(Format) warning('Data format unspecified, assuming ASCII.'); Format = 'ascii'; end switch Format case 'ascii' Format = 0; case 'binary_little_endian' Format = 1; case 'binary_big_endian' Format = 2; otherwise fclose(fid); error(['Data format ''',Format,''' not supported.']); end if ~Format Buf = fscanf(fid,'%f'); % read the rest of the file as ASCII data BufOff = 1; else % reopen the file in read binary mode fclose(fid); if Format == 1 fid = fopen(Path,'r','ieee-le.l64'); % little endian else fid = fopen(Path,'r','ieee-be.l64'); % big endian end % find the end of the header again (using ftell on the old handle doesn't give the correct position) BufSize = 8192; Buf = [blanks(10),char(fread(fid,BufSize,'uchar')')]; i = []; tmp = -11; while isempty(i) i = strfind(Buf,['end_header',13,10]); % look for end_header + CR/LF i = [i,strfind(Buf,['end_header',10])]; %#ok % look for end_header + LF if isempty(i) tmp = tmp + BufSize; Buf = [Buf(BufSize+1:BufSize+10),char(fread(fid,BufSize,'uchar')')]; end end % seek to just after the line feed fseek(fid,i + tmp + 11 + (Buf(i + 10) == 13),-1); end %% read element data % PLY and MATLAB data types (for fread) PlyTypeNames = {'char','uchar','short','ushort','int','uint','float','double', ... 'char8','uchar8','short16','ushort16','int32','uint32','float32','double64'}; MatlabTypeNames = {'schar','uchar','int16','uint16','int32','uint32','single','double'}; SizeOf = [1,1,2,2,4,4,4,8]; % size in bytes of each type for i = 1:NumElements % get current element property information CurPropertyNames = PropertyNames.(ElementNames{i}); CurPropertyTypes = PropertyTypes.(ElementNames{i}); NumProperties = size(CurPropertyNames,2); % fprintf('Reading %s...\n',ElementNames{i}); %% read ASCII data if ~Format Type = zeros(1,NumProperties); for j = 1:NumProperties Token = CurPropertyTypes.(CurPropertyNames{j}); if strcmpi(Token{1},'list') Type(j) = 1; end end % parse buffer if ~any(Type) % no list types Data = reshape(Buf(BufOff:BufOff+ElementCount(i)*NumProperties-1),NumProperties,ElementCount(i))'; BufOff = BufOff + ElementCount(i)*NumProperties; else ListData = cell(NumProperties,1); for k = 1:NumProperties ListData{k} = cell(ElementCount(i),1); end % list type for j = 1:ElementCount(i) for k = 1:NumProperties if ~Type(k) Data(j,k) = Buf(BufOff); BufOff = BufOff + 1; else tmp = Buf(BufOff); ListData{k}{j} = Buf(BufOff+(1:tmp))'; BufOff = BufOff + tmp + 1; end end end end else %% read binary data % translate PLY data type names to MATLAB data type names ListFlag = 0; % = 1 if there is a list type SameFlag = 1; % = 1 if all types are the same Type = cell(1,NumProperties); Type2 = Type; TypeSize = zeros(1,NumProperties); TypeSize2 = TypeSize; for j = 1:NumProperties Token = CurPropertyTypes.(CurPropertyNames{j}); if ~strcmp(Token{1},'list') % non-list type tmp = rem(find(matches(PlyTypeNames,Token{1}))-1,8)+1; if ~isempty(tmp) TypeSize(j) = SizeOf(tmp); Type{j} = MatlabTypeNames{tmp}; TypeSize2(j) = 0; Type2{j} = ''; SameFlag = SameFlag & strcmp(Type{1},Type{j}); else fclose(fid); error(['Unknown property data type, ''',Token{1},''', in ', ... ElementNames{i},'.',CurPropertyNames{j},'.']); end else % list type if length(Token) == 3 ListFlag = 1; SameFlag = 0; tmp = rem(find(matches(PlyTypeNames,Token{2}))-1,8)+1; tmp2 = rem(find(matches(PlyTypeNames,Token{3}))-1,8)+1; if ~isempty(tmp) && ~isempty(tmp2) TypeSize(j) = SizeOf(tmp); Type{j} = MatlabTypeNames{tmp}; TypeSize2(j) = SizeOf(tmp2); Type2{j} = MatlabTypeNames{tmp2}; else fclose(fid); error(['Unknown property data type, ''list ',Token{2},' ',Token{3},''', in ', ... ElementNames{i},'.',CurPropertyNames{j},'.']); end else fclose(fid); error(['Invalid list syntax in ',ElementNames{i},'.',CurPropertyNames{j},'.']); end end end % read file if ~ListFlag if SameFlag % no list types, all the same type (fast) Data = fread(fid,[NumProperties,ElementCount(i)],Type{1})'; else % no list types, mixed type Data = zeros(ElementCount(i),NumProperties); for j = 1:ElementCount(i) for k = 1:NumProperties Data(j,k) = fread(fid,1,Type{k}); end end end else ListData = cell(NumProperties,1); for k = 1:NumProperties ListData{k} = cell(ElementCount(i),1); end if NumProperties == 1 BufSize = 512; SkipNum = 4; j = 0; % list type, one property (fast if lists are usually the same length) while j < ElementCount(i) Position = ftell(fid); % read in BufSize count values, assuming all counts = SkipNum [Buf,BufSize] = fread(fid,BufSize,Type{1},SkipNum*TypeSize2(1)); Miss = find(Buf ~= SkipNum); % find first count that is not SkipNum fseek(fid,Position + TypeSize(1),-1); % seek back to after first count if isempty(Miss) % all counts are SkipNum Buf = fread(fid,[SkipNum,BufSize],[int2str(SkipNum),'*',Type2{1}],TypeSize(1))'; fseek(fid,-TypeSize(1),0); % undo last skip for k = 1:BufSize ListData{1}{j+k} = Buf(k,:); end j = j + BufSize; BufSize = floor(1.5*BufSize); else if Miss(1) > 1 % some counts are SkipNum Buf2 = fread(fid,[SkipNum,Miss(1)-1],[int2str(SkipNum),'*',Type2{1}],TypeSize(1)); Buf2 = Buf2'; for k = 1:Miss(1)-1 ListData{1}{j+k} = Buf2(k,:); end j = j + k; end % Alec: check if done and rewind one step if j >= ElementCount(i) fseek(fid,-1,0); break; end % read in the list with the missed count SkipNum = Buf(Miss(1)); j = j + 1; ListData{1}{j} = fread(fid,[1,SkipNum],Type2{1}); BufSize = ceil(0.6*BufSize); end end else % list type(s), multiple properties (slow) Data = zeros(ElementCount(i),NumProperties); for j = 1:ElementCount(i) for k = 1:NumProperties if isempty(Type2{k}) Data(j,k) = fread(fid,1,Type{k}); else tmp = fread(fid,1,Type{k}); ListData{k}{j} = fread(fid,[1,tmp],Type2{k}); end end end end end end % put data into Elements structure for k = 1:NumProperties if (~Format && ~Type(k)) || (Format && isempty(Type2{k})) Elements.(ElementNames{i}).(CurPropertyNames{k}) = Data(:,k); else Elements.(ElementNames{i}).(CurPropertyNames{k}) = ListData{k}; end end end clear Data ListData; fclose(fid); if (nargin > 1 && strcmpi(Str,'Tri')) || nargout > 2 % find vertex element field Name = {'vertex','Vertex','point','Point','pts','Pts'}; Names = []; for i = 1:length(Name) if any(strcmp(ElementNames,Name{i})) Names = PropertyNames.(Name{i}); Name = Name{i}; break; end end if any(strcmp(Names,'x')) && any(strcmp(Names,'y')) && any(strcmp(Names,'z')) varargout{1} = [Elements.(Name).x, Elements.(Name).y, Elements.(Name).z]; else varargout{1} = zeros(1,3); end varargout{2} = Elements; varargout{3} = Comments; Elements = []; % find face element field Name = {'face','Face','poly','Poly','tri','Tri'}; Names = []; for i = 1:length(Name) if any(strcmp(ElementNames,Name{i})) Names = PropertyNames.(Name{i}); Name = Name{i}; break; end end if ~isempty(Names) % find vertex indices property subfield PropertyName = {'vertex_indices','vertex_indexes','vertex_index','indices','indexes'}; for i = 1:length(PropertyName) if any(strcmp(Names,PropertyName{i})) PropertyName = PropertyName{i}; break; end end if ~iscell(PropertyName) % convert face index lists to triangular connectivity FaceIndices = varargout{2}.(Name).PropertyName; N = length(FaceIndices); Elements = zeros(N*2,3); Extra = 0; for k = 1:N Elements(k,:) = FaceIndices{k}(1:3); for j = 4:length(FaceIndices{k}) Extra = Extra + 1; Elements(N + Extra,:) = [Elements(k,[1,j-1]),FaceIndices{k}(j)]; end end Elements = Elements(1:N+Extra,:) + 1; end end else varargout{1} = Comments; end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshSilhouette.m0000644000000000000000000000013214055375162020577 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshSilhouette.m0000644000175000017500000001004414055375162021663 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function silhouette = meshSilhouette(v, f, varargin) %MESHSILHOUETTE Compute the 2D outline of a 3D mesh on an arbitrary plane. % % ATTENTION: Very slow brute force approach! Keep the number of faces as % low as possible. % % SILHOUETTE = meshSilhouette(MESH, PLANE) % Calculates the silhouette (2D outline) of the MESH projected on the % PLANE. % % SILHOUETTE = meshSilhouette(MESH) uses the x-y plane. % % SILHOUETTE = meshSilhouette(V, F, ...) % % SILHOUETTE = meshSilhouette(..., 'visu', 1) visualizes the results. % By default the results are not visualized. % % Example: % v = [5, 2, 6, 0, 3; 0, 2, 4, 2, 1; -5, -6, -6, -7, -9]'; % f = [1, 2, 4; 1, 5, 4; 1, 2, 5; 2, 3, 5; 2, 4, 3; 3, 4, 5]; % sil = meshSilhouette(v, f, rand(1,9),'visu',1); % % See also: % projPointOnPlane % % Source: % Sean de Wolski - https://www.mathworks.com/matlabcentral/answers/68004 % --------- % Authors: oqilipo % Created: 2020-07-29 % Copyright 2020 narginchk(1,5) nargoutchk(0,1) %% Parse inputs % If first argument is a struct if isstruct(v) if nargin > 1 varargin=[{f} varargin{:}]; end mesh = v; [v, f] = parseMeshData(v); else mesh.vertices = v; mesh.faces = f; end p = inputParser; logParValidFunc = @(x) (islogical(x) || isequal(x,1) || isequal(x,0)); addOptional(p,'plane',[0 0 0 1 0 0 0 1 0],@isPlane) addParameter(p,'visualization',false,logParValidFunc); parse(p, varargin{:}); plane = p.Results.plane; % Transform into the x-y plane TFM = createBasisTransform3d('g', plane); v = transformPoint3d(v,TFM); % Initialize final polygon vectors [px, py] = boundary(polyshape(v(f(1,:),1) ,v(f(1,:),2), 'Simplify',false)); for i = 2:size(f,1) A = polyshape(v(f(i,:),1), v(f(i,:),2), 'Simplify',false); B = polyshape(px, py, 'Simplify',false); [px, py] = boundary(union(A,B)); end % Transform back into the plane silhouette = transformPoint3d([px,py,zeros(size(px))], inv(TFM)); if p.Results.visualization figure('Color','w'); axH = axes(); axis(axH, 'equal', 'tight') drawPolyline3d(axH, silhouette,'Color','r','LineWidth',3) drawPlane3d(axH, plane,'FaceAlpha',0.5) drawMesh(mesh,'FaceAlpha',0.5,'FaceColor','none') axis(axH, 'equal') camTar = nanmean(silhouette); axH.CameraTarget = camTar; axH.CameraPosition = camTar + ... planeNormal(plane)*vectorNorm3d(axH.CameraPosition-axH.CameraTarget); axH.CameraUpVector = plane(4:6); xlabel(axH, 'x'); ylabel(axH, 'y'); zlabel(axH, 'z'); end end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/trimeshEdgeFaces.m0000644000000000000000000000013214055375162020777 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/trimeshEdgeFaces.m0000644000175000017500000000747014055375162022074 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edgeFaces = trimeshEdgeFaces(faces, varargin) %TRIMESHEDGEFACES Compute index of faces adjacent to each edge of a triangular mesh. % % EF = trimeshEdgeFaces(FACES) % EF = trimeshEdgeFaces(VERTICES, FACES) % EF = trimeshEdgeFaces(VERTICES, EDGES, FACES) % Compute index array of faces adjacent to each edge of a mesh. % FACES is a NF-by-3 array containing vertex indices of each face. The % result EF is a NE-by-2 array containing the indices of the two faces % incident to each edge. If an edge belongs to only one face, the other % face index is ZERO. % % The list of edges (as array of source and target vertex indices) can be % obtained from the function 'meshEdges'. % % Note: faces are listed in increasing order for each edge, and no % information is kept about relative orientation of edge and face. % % Example % % compute incidence list of each edge of an octahedron. For example, % % first edge is incident to faces 1 and 5. Second edge is incident to % % faces 4 and 8, and so on. % [v, f] = createOctahedron; % ef = trimeshEdgeFaces(v, f) % ef = % 1 5 % 4 8 % 4 1 % 5 8 % 2 6 % 1 2 % 6 5 % 3 7 % 2 3 % 7 6 % 3 4 % 7 8 % % See also % meshes3d, meshEdgeFaces, trimeshMeanBreadth, meshEdges % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2015-08-19, using Matlab 8.5.0.197613 (R2015a) % Copyright 2015 INRA - Cepia Software Platform. if nargin == 2 faces = varargin{1}; elseif nargin == 3 faces = varargin{2}; end % compute vertex indices of each edge (in increasing index order) edges = sort([faces(:,[1 2]) ; faces(:,[2 3]) ; faces(:,[3 1])], 2); % create an array to keep indices of faces "creating" each edge nFaces = size(faces, 1); edgeFaceInds = repmat( (1:nFaces)', 3, 1); % sort edges, keeping indices [edges, ia, ib] = unique(edges, 'rows'); %#ok nEdges = size(edges, 1); % allocate memory for result edgeFaces = zeros(nEdges, 2); % iterate over edges, to identify incident faces for iEdge = 1:nEdges inds = find(ib == iEdge); edgeFaces(iEdge, 1:length(inds)) = edgeFaceInds(inds); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshEdges.m0000644000000000000000000000013214055375162017501 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshEdges.m0000644000175000017500000000704314055375162020572 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges = meshEdges(faces, varargin) %MESHEDGES Computes array of edge vertex indices from face array. % % EDGES = meshEdges(FACES); % % Example % meshEdges % % See also % meshes3d, meshEdgeFaces, meshFaceEdges % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-06-28, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % HISTORY % 2013-08-22 rename from computeMeshEdges to meshEdges, add more control % on inputs %% Process input arguments if isstruct(faces) && isfield(faces, 'faces') % if input is a mesh structure, extract the 'faces' field faces = faces.faces; elseif nargin > 1 % if two arguments are given, keep the second one faces = varargin{1}; end if ~iscell(faces) %% Process faces given as numeric array % all faces have same number of vertices, stored in nVF variable % compute total number of edges nFaces = size(faces, 1); nVF = size(faces, 2); nEdges = nFaces * nVF; % create all edges (with double ones) edges = zeros(nEdges, 2); for i = 1:nFaces f = faces(i, :); edges(((i-1)*nVF+1):i*nVF, :) = [f' f([2:end 1])']; end else %% faces are given as a cell array % faces may have different number of vertices % number of faces nFaces = length(faces); % compute the number of edges nEdges = 0; for i = nFaces nEdges = nEdges + length(faces{i}); end % allocate memory edges = zeros(nEdges, 2); ind = 0; % fillup edge array for i = 1:nFaces % get vertex indices, ensuring horizontal array f = faces{i}(:)'; nVF = length(f); edges(ind+1:ind+nVF, :) = [f' f([2:end 1])']; ind = ind + nVF; end end % keep only unique edges, and return sorted result edges = sortrows(unique(sort(edges, 2), 'rows')); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createCubeOctahedron.m0000644000000000000000000000013214055375162021646 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createCubeOctahedron.m0000644000175000017500000000627214055375162022742 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createCubeOctahedron() %CREATECUBEOCTAHEDRON Create a 3D mesh representing a cube-octahedron. % % [V, E, F] = createCubeOctahedron; % Cubeoctahedron can be seen either as a truncated cube, or as a % truncated octahedron. % V is the 12-by-3 array of vertex coordinates % E is the 27-by-2 array of edge vertex indices % F is the 1-by-14 cell array of face vertex indices % % [V, F] = createCubeOctahedron; % Returns only the vertices and the face vertex indices. % % MESH = createCubeOctahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Example % [n, e, f] = createCubeOctahedron; % drawMesh(n, f); % % See also % meshes3d, drawMesh, createCube, createOctahedron % % --------- % author : David Legland % e-mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2005. % % HISTORY % 04/01/2007: remove unused variables nodes = [... 0 -1 1;1 0 1;0 1 1;-1 0 1; ... 1 -1 0;1 1 0;-1 1 0;-1 -1 0;... 0 -1 -1;1 0 -1;0 1 -1;-1 0 -1]; edges = [... 1 2; 1 4; 1 5; 1 8; ... 2 3; 2 5; 2 6; ... 3 4; 3 6; 3 7; ... 4 7; 4 8; ... 5 9; 5 10; ... 6 10; 6 11; ... 7 11; 7 12; ... 8 9; 8 12; ... 9 10; 9 12; ... 10 11; 11 12]; faces = {... [1 2 3 4], [1 5 2], [2 6 3], [3 7 4], [4 8 1], ... [5 10 6 2], [3 6 11 7], [4 7 12 8], [1 8 9 5], ... [5 9 10], [6 10 11], [7 11 12], [8 12 9], [9 12 11 10]}; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/cube.ply0000644000000000000000000000013214055375161017062 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/cube.ply0000644000175000017500000000050414055375161020146 0ustar00juanpijuanpi00000000000000ply format ascii 1.0 comment created by platoply element vertex 8 property float32 x property float32 y property float32 z element face 6 property list uint8 int32 vertex_indices end_header -1 -1 -1 1 -1 -1 1 1 -1 -1 1 -1 -1 -1 1 1 -1 1 1 1 1 -1 1 1 4 0 1 2 3 4 5 4 7 6 4 6 2 1 5 4 3 7 4 0 4 7 3 2 6 4 5 1 0 4 matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/drawFaceNormals.m0000644000000000000000000000013214055375162020645 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/drawFaceNormals.m0000644000175000017500000000532114055375162021733 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawFaceNormals(varargin) %DRAWFACENORMALS Draw normal vector of each face in a mesh. % % drawFaceNormals(V, E, F) % Compute and draw the face normals of the mesh defined by vertices V, % edges E and faces F. See meshes3d for format of each argument. % % H = drawFaceNormals(...) % Return handle array to the created objects. % % Example % % draw face normals of a cube % [v, f] = createCubeOctahedron; % figure; drawMesh(v, f) % axis([-2 2 -2 2 -2 2]); axis equal; hold on; % drawFaceNormals(v, f) % view(3); % % See also % meshes3d, drawMesh, drawVector3d, meshFaceNormals, meshFaceCentroids % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-10-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % extract vertices and faces mesh = parseMeshData(varargin{:}); % compute vector data c = meshFaceCentroids(mesh); n = meshFaceNormals(mesh); % display an arrow for each normal h = quiver3(c(:,1), c(:,2), c(:,3), n(:,1), n(:,2), n(:,3)); % format output if nargout > 0 varargout{1} = h; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/createIcosahedron.m0000644000000000000000000000013214055375162021217 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/createIcosahedron.m0000644000175000017500000000674214055375162022315 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = createIcosahedron() %CREATEICOSAHEDRON Create a 3D mesh representing an Icosahedron. % % MESH = createIcosahedron; % [V, E, F] = createIcosahedron; % Create a solid with 12 vertices, and 20 triangular faces. Faces are % oriented outwards of the mesh. % % [V, F] = createIcosahedron; % Returns only the vertices and the face vertex indices. % % MESH = createIcosahedron; % Returns the data as a mesh structure, with fields 'vertices', 'edges' % and 'faces'. % % Example % [n, e, f] = createIcosahedron; % drawMesh(n, f); % % See also % meshes3d, drawMesh % createCube, createOctahedron, createDodecahedron, createTetrahedron % % --------- % author: David Legland % mail: david.legland@inra.fr % INRA - TPV URPOI - BIA IMASTE % created the 21/03/2005. % % HISTORY % 2007-01-04 remove unused variables % 2010-12-06 format output, orient normals outwards %% Initialisations theta = 2*pi/5; l = 1/sin(theta/2)/2; z1 = sqrt(1-l*l); t1 = (0:2*pi/5:2*pi*(1-1/5))'; x1 = l*cos(t1); y1 = l*sin(t1); t2 = t1 + 2*pi/10; x2 = l*cos(t2); y2 = l*sin(t2); h = sqrt(l*l-.5*.5); z2 = sqrt(3/4 - (l-h)*(l-h)); %% Create mesh data nodes = [0 0 0;... [x1 y1 repmat(z1, [5 1])]; ... [x2 y2 repmat(z1+z2, [5 1])]; ... 0 0 2*z1+z2]; edges = [... 1 2;1 3;1 4;1 5;1 6; ... 2 3;3 4;4 5;5 6;6 2; ... 2 7;7 3;3 8;8 4;4 9;9 5;5 10;10 6;6 11;11 2; ... 7 8;8 9;9 10;10 11;11 7; ... 7 12;8 12;9 12;10 12;11 12]; % faces are ordered to have normals pointing outside of the mesh faces = [... 1 3 2 ; 1 4 3 ; 1 5 4 ; 1 6 5 ; 1 2 6;... 2 3 7 ; 3 4 8 ; 4 5 9 ; 5 6 10 ; 6 2 11;... 7 3 8 ; 8 4 9 ; 9 5 10 ; 10 6 11 ; 11 2 7;... 7 8 12 ; 8 9 12 ; 9 10 12 ; 10 11 12 ; 11 7 12]; % format output varargout = formatMeshOutput(nargout, nodes, edges, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshSurfaceArea.m0000644000000000000000000000013214055375162020633 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshSurfaceArea.m0000644000175000017500000000674014055375162021727 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function area = meshSurfaceArea(varargin) % Surface area of a polyhedral mesh. % % S = meshSurfaceArea(V, F) % S = meshSurfaceArea(V, E, F) % Computes the surface area of the mesh specified by vertex array V and % face array F. Vertex array is a NV-by-3 array of coordinates. % Face array can be a NF-by-3 or NF-by-4 numeric array, or a Nf-by-1 cell % array, containing vertex indices of each face. % % This functions iterates on faces, extract vertices of the current face, % and computes the sum of face areas. % % This function assumes faces are coplanar and convex. If faces are all % triangular, the function "trimeshSurfaceArea" should be more efficient. % % % Example % % compute the surface of a unit cube (should be equal to 6) % [v f] = createCube; % meshSurfaceArea(v, f) % ans = % 6 % % See also % meshes3d, trimeshSurfaceArea, meshVolume, meshFaceAreas, % meshFacePolygons, polygonArea3d % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2010-10-13, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % parse input arguments [vertices, faces] = parseMeshData(varargin{:}); % pre-compute normals normals = normalizeVector3d(meshFaceNormals(vertices, faces)); % init accumulator area = 0; if isnumeric(faces) % iterate on faces in a numeric array for i = 1:size(faces, 1) poly = vertices(faces(i, :), :); area = area + polyArea3d(poly, normals(i,:)); end else % iterate on faces in a cell array for i = 1:length(faces) poly = vertices(faces{i}, :); area = area + polyArea3d(poly, normals(i,:)); end end function a = polyArea3d(v, normal) nv = size(v, 1); v0 = repmat(v(1,:), nv, 1); products = sum(cross(v-v0, v([2:end 1], :)-v0, 2), 1); a = abs(dot(products, normal, 2))/2; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162017372 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/Contents.m0000644000175000017500000002542514055375162020467 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % MESHES3D 3D Surface Meshes % Version 1.22 06-Jun-2018 . % % Creation, visualization, and manipulation of 3D surface meshes or % polyhedra. % % Meshes and Polyhedra are represented by a couple of variables {V, F}: % V: Nv-by-3 array of vertices: [x1 y1 z1; ... ; xn yn zn]; % F: is either a NF-by-3 or NF-by-4 array containing reference for % vertices of each face, or a NF-by-1 cell array, where each cell is an % array containing a variable number of node indices. % For some functions, the array E of edges is needed. It consists in a % NE-by-2 array containing indices of source and target vertices. % % The library provides function to create basic polyhedric meshes (the % five platonic solids, plus few others), as well as functions to perform % basic computations (surface area, normal angles, face centroids...). % The 'MengerSponge' structure is an example of mesh that is not simply % connected (multiple tunnels in the structure). % % The drawMesh function is mainly a wrapper to the Matlab 'patch' % function, allowing passing arguments more quickly. % % Example % % create a soccer ball mesh and display it % [v, e, f] = createSoccerBall; % drawMesh(v, f, 'faceColor', 'g', 'linewidth', 2); % axis equal; view(3); % % % General processing on meshes % smoothMesh - Smooth mesh by replacing each vertex by the average of its neighbors. % subdivideMesh - Subdivides each face of the mesh. % meshVertexClustering - Simplifies a mesh using vertex clustering. % triangulateFaces - Convert face array to an array of triangular faces. % transformMesh - Applies a 3D affine transform to a mesh. % mergeCoplanarFaces - Merge coplanar faces of a polyhedral mesh. % meshFacePolygons - Returns the set of polygons that constitutes a mesh. % meshFaceCentroids - Compute centroids of faces in a mesh. % meshFaceNormals - Compute normal vector of faces in a 3D mesh. % meshVertexNormals - Compute normals to a mesh vertices. % meshComplement - Reverse the normal of each face in the mesh. % averageMesh - Compute average mesh from a list of meshes. % meshSilhouette - Compute the 2D outline of a 3D mesh on an arbitrary plane. % % Intersections and clipping % intersectLineMesh3d - Intersection points of a 3D line with a mesh. % intersectPlaneMesh - Compute the polygons resulting from plane-mesh intersection. % polyhedronSlice - Intersect a convex polyhedron with a plane. % clipMeshVertices - Clip vertices of a surfacic mesh and remove outer faces. % clipConvexPolyhedronHP - Clip a convex polyhedron by a plane. % cutMeshByPlane - Cut a mesh by a plane. % concatenateMeshes - Concatenate multiple meshes. % splitMesh - Return the connected components of a mesh. % % Geometric measures on meshes % meshSurfaceArea - Surface area of a polyhedral mesh. % trimeshSurfaceArea - Surface area of a triangular mesh. % meshFaceAreas - Surface area of each face of a mesh. % meshVolume - (Signed) volume of the space enclosed by a polygonal mesh. % meshEdgeLength - Lengths of edges of a polygonal or polyhedral mesh. % meshDihedralAngles - Dihedral at edges of a polyhedal mesh. % polyhedronCentroid - Compute the centroid of a 3D convex polyhedron. % tetrahedronVolume - Signed volume of a tetrahedron. % polyhedronNormalAngle - Compute normal angle at a vertex of a 3D polyhedron. % polyhedronMeanBreadth - Mean breadth of a convex polyhedron. % trimeshMeanBreadth - Mean breadth of a triangular mesh. % isPointInMesh - Check if a point is inside a 3D mesh. % distancePointMesh - Shortest distance between a (3D) point and a triangle mesh. % % Utility functions % meshFace - Return the vertex indices of a face in a mesh. % meshFaceEdges - Computes edge indices of each face. % meshFaceNumber - Returns the number of faces in this mesh. % meshEdges - Computes array of edge vertex indices from face array. % meshEdgeFaces - Compute index of faces adjacent to each edge of a mesh. % trimeshEdgeFaces - Compute index of faces adjacent to each edge of a triangular mesh. % meshFaceAdjacency - Compute adjacency list of face around each face. % meshAdjacencyMatrix - Compute adjacency matrix of a mesh from set of faces. % checkMeshAdjacentFaces - Check if adjacent faces of a mesh have similar orientation. % meshBoundary - Boundary of a mesh as a collection of 3D line strings. % meshBoundaryEdgeIndices - Indices of boundary edges of a mesh. % meshBoundaryVertexIndices - Indices of boundary vertices of a mesh. % % Basic edition on meshes % removeMeshVertices - Remove vertices and associated faces from a mesh. % mergeMeshVertices - Merge two vertices and removes eventual degenerated faces. % removeMeshFaces - Remove faces from a mesh by face indices. % % Mesh cleanup % trimMesh - Reduce memory footprint of a polygonal mesh. % isManifoldMesh - Check whether the input mesh may be considered as manifold. % ensureManifoldMesh - Apply several simplification to obtain a manifold mesh. % removeDuplicateFaces - Remove duplicate faces in a face array. % removeMeshEars - Remove vertices that are connected to only one face. % removeInvalidBorderFaces - Remove faces whose edges are connected to 3, 3, and 1 faces. % collapseEdgesWithManyFaces - removes mesh edges adjacent to more than two faces % % Creation and conversion % surfToMesh - Convert surface grids into face-vertex mesh. % triangulateCurvePair - Compute triangulation between a pair of 3D open curves. % triangulatePolygonPair - Compute triangulation between a pair of 3D closed curves. % cylinderMesh - Create a 3D mesh representing a cylinder. % sphereMesh - Create a 3D mesh representing a sphere. % ellipsoidMesh - Convert a 3D ellipsoid to face-vertex mesh representation. % torusMesh - Create a 3D mesh representing a torus. % curveToMesh - Create a mesh surrounding a 3D curve. % boxToMesh - Convert a box into a quad mesh with the same size. % minConvexHull - Return the unique minimal convex hull of a set of 3D points. % % Create meshes representing polyhedra % polyhedra - Index of classical polyhedral meshes. % createCube - Create a 3D mesh representing the unit cube. % createOctahedron - Create a 3D mesh representing an octahedron. % createCubeOctahedron - Create a 3D mesh representing a cube-octahedron. % createIcosahedron - Create a 3D mesh representing an Icosahedron. % createDodecahedron - Create a 3D mesh representing a dodecahedron. % createTetrahedron - Create a 3D mesh representing a tetrahedron. % createRhombododecahedron - Create a 3D mesh representing a rhombododecahedron. % createTetrakaidecahedron - Create a 3D mesh representing a tetrakaidecahedron. % createSoccerBall - Create a 3D mesh representing a soccer ball. % createStellatedMesh - Replaces each face of a mesh by a pyramid. % createDurerPolyhedron - Create a mesh representing Durer's polyhedron . % createMengerSponge - Create a cube with an inside cross removed. % steinerPolytope - Create a steiner polytope from a set of vectors. % % Drawing functions % drawMesh - Draw a 3D mesh defined by vertex and face arrays. % fillMeshFaces - Fill the faces of a mesh with the specified colors. % drawFaceNormals - Draw normal vector of each face in a mesh. % % I/O functions % readMesh - Read a 3D mesh by inferring format from file name. % writeMesh - Write 3D mesh data by inferring format from file name. % readMesh_off - Read mesh data stored in OFF format. % readMesh_ply - Read mesh data stored in PLY (Stanford triangle) format. % readMesh_stl - Read mesh data stored in STL format. % writeMesh_off - Write a mesh into a text file in OFF format. % writeMesh_ply - Write a mesh into a file in PLY format. % writeMesh_stl - Write mesh data in the STL format. % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2005-11-07 % Project homepage: http://github.com/mattools/matGeom % http://www.pfl-cepia.inra.fr/index.php?page=geom3d % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). help(mfilename); % Deprecated: % drawPolyhedron - Draw polyhedron defined by vertices and faces. % vertexNormal - Compute normals to a mesh vertices. % Others matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/dodecahedron.ply0000644000000000000000000000013214055375161020563 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/dodecahedron.ply0000644000175000017500000000152614055375161021654 0ustar00juanpijuanpi00000000000000ply format ascii 1.0 comment created by platoply element vertex 20 property float32 x property float32 y property float32 z element face 12 property list uint8 int32 vertex_indices end_header -0.57735 -0.57735 0.57735 0.934172 0.356822 0 0.934172 -0.356822 0 -0.934172 0.356822 0 -0.934172 -0.356822 0 0 0.934172 0.356822 0 0.934172 -0.356822 0.356822 0 -0.934172 -0.356822 0 -0.934172 0 -0.934172 -0.356822 0 -0.934172 0.356822 0.356822 0 0.934172 -0.356822 0 0.934172 0.57735 0.57735 -0.57735 0.57735 0.57735 0.57735 -0.57735 0.57735 -0.57735 -0.57735 0.57735 0.57735 0.57735 -0.57735 -0.57735 0.57735 -0.57735 0.57735 -0.57735 -0.57735 -0.57735 5 1 2 18 11 14 5 1 13 7 17 2 5 3 4 19 8 15 5 3 16 12 0 4 5 3 15 6 5 16 5 1 14 5 6 13 5 2 17 9 10 18 5 4 0 10 9 19 5 7 8 19 9 17 5 6 15 8 7 13 5 5 14 11 12 16 5 10 0 12 11 18 matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/removeDuplicateFaces.m0000644000000000000000000000013214055375162021667 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/removeDuplicateFaces.m0000644000175000017500000000463414055375162022763 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function faces2 = removeDuplicateFaces(faces, varargin) %REMOVEDUPLICATEFACES Remove duplicate faces in a face array. % % [V, F] = removeDuplicateFaces(V, F) % % Example % faces = [1 2 3;2 3 4;3 4 5;2 3 4]; % removeDuplicateFaces(faces) % ans = % 1 2 3 % 2 3 4 % 2 3 5 % % See also % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-08, using Matlab 8.6.0.267246 (R2015b) % Copyright 2019 INRA - Cepia Software Platform. nFaces = size(faces, 1); removeFlag = false(nFaces, 1); for iFace = 1:nFaces if removeFlag(iFace) continue; end face = faces(iFace, :); inds = find(sum(ismember(faces, face), 2) == 3); inds(inds <= iFace) = []; if ~isempty(inds) removeFlag(inds) = true; end end faces2 = faces(~removeFlag, :); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/meshFace.m0000644000000000000000000000013214055375162017310 xustar0030 mtime=1622538866.098813493 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/meshFace.m0000644000175000017500000000544614055375162020406 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function face = meshFace(faces, index) %MESHFACE Return the vertex indices of a face in a mesh. % % FACE = meshFace(FACES, INDEX) % Return the vertex indices of the i-th face in the face array. This is % mainly an utility function that manages faces stored either as int % array (when all faces have same number of sides) or cell array (when % faces may have different number of edges). % % Example % [v, f] = createCubeOctahedron; % % some faces are squares % meshFace(f, 1) % ans = % 1 2 3 4 % % other are triangles % meshFace(f, 2) % ans = % 1 5 2 % % See also % meshes3d, meshFaceCentroid, meshFaceNormals, meshFaceAreas % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-10-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % process mesh given as structure if isstruct(faces) if isfield(faces, 'faces') faces = faces.faces; else error('Mesh structure should contains a field ''faces'''); end end % switch between numeric or cell array if isnumeric(faces) face = faces(index, :); else face = faces{index}; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/trimeshMeanBreadth.m0000644000000000000000000000013214055375162021343 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.098813493 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/trimeshMeanBreadth.m0000644000175000017500000001013514055375162022430 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function mb = trimeshMeanBreadth(vertices, faces) %TRIMESHMEANBREADTH Mean breadth of a triangular mesh. % % MB = trimeshMeanBreadth(VERTICES, FACES) % Computes the mean breadth (proporitonal to the integral of mean % curvature) of a triangular mesh. % % Example % [V, F] = createCube; % F2 = triangulateFaces(F); % MB = trimeshMeanBreadth(V, F2) % MB = % 1.5000 % % See also % meshes3d, trimeshSurfaceArea, trimeshEdgeFaces, polyhedronMeanBreadth % % References % Stoyan D., Kendall W.S., Mecke J. (1995) "Stochastic Geometry and its % Applications", John Wiley and Sons, p. 26 % Ohser, J., Muescklich, F. (2000) "Statistical Analysis of % Microstructures in Materials Sciences", John Wiley and Sons, p.352 % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2015-08-19, using Matlab 8.5.0.197613 (R2015a) % Copyright 2015 INRA - Cepia Software Platform. %% Check input validity if size(faces, 2) ~= 3 error('meshes3d:trimeshMeanBreadth:NonTriangularMesh', ... 'Requires a triangular mesh as input'); end %% Compute edge and edgeFaces arrays % Uses the same code as in trimeshEdgeFaces % compute vertex indices of each edge (in increasing index order) edges = sort([faces(:,[1 2]) ; faces(:,[2 3]) ; faces(:,[3 1])], 2); % create an array to keep indices of faces "creating" each edge nFaces = size(faces, 1); edgeFaceInds = repmat( (1:nFaces)', 3, 1); % sort edges, keeping indices [edges, ia, ib] = unique(edges, 'rows'); %#ok nEdges = size(edges, 1); % allocate memory for result edgeFaces = zeros(nEdges, 2); % iterate over edges, to identify incident faces for iEdge = 1:nEdges inds = find(ib == iEdge); edgeFaces(iEdge, 1:length(inds)) = edgeFaceInds(inds); end %% Compute dihedral angle for each edge % compute normal of each face normals = meshFaceNormals(vertices, faces); % allocate memory for resulting angles alpha = zeros(nEdges, 1); % iterate over edges for iEdge = 1:nEdges % indices of adjacent faces indFace1 = edgeFaces(iEdge, 1); indFace2 = edgeFaces(iEdge, 2); % normal vector of adjacent faces normal1 = normals(indFace1, :); normal2 = normals(indFace2, :); % compute dihedral angle of two vectors alpha(iEdge) = vectorAngle3d(normal1, normal2); end %% Compute mean breadth % integrate the dihedral angles weighted by the length of each edge % compute length of each edge lengths = meshEdgeLength(vertices, edges); % compute product of length by angles mb = sum(alpha .* lengths) / (4*pi); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/trimeshSurfaceArea.m0000644000000000000000000000013214055375162021352 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/trimeshSurfaceArea.m0000644000175000017500000000567214055375162022451 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function area = trimeshSurfaceArea(v, e, f) %TRIMESHSURFACEAREA Surface area of a triangular mesh. % % S = trimeshSurfaceArea(V, F) % S = trimeshSurfaceArea(V, E, F) % Computes the surface area of the mesh specified by vertex array V and % face array F. Vertex array is a NV-by-3 array of coordinates. % Face array is a NF-by-3, containing vertex indices of each face. % % Example % % Compute area of an octahedron (equal to 2*sqrt(3)*a*a, with % % a = sqrt(2) in this case) % [v f] = createOctahedron; % trimeshSurfaceArea(v, f) % ans = % 6.9282 % % % triangulate a compute area of a unit cube % [v f] = createCube; % f2 = triangulateFaces(f); % trimeshSurfaceArea(v, f2) % ans = % 6 % % See also % meshes3d, meshSurfaceArea, trimeshMeanBreadth, triangulateFaces % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-08-26, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % check input number if nargin == 2 f = e; end % compute two direction vectors, using first vertex of each face as origin v1 = v(f(:, 2), :) - v(f(:, 1), :); v2 = v(f(:, 3), :) - v(f(:, 1), :); % area of each triangle is half the cross product norm vn = vectorNorm3d(crossProduct3d(v1, v2)); % sum up and normalize area = sum(vn) / 2; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/curveToMesh.m0000644000000000000000000000013214055375162020041 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/curveToMesh.m0000644000175000017500000001000614055375162021123 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [vertices, faces] = curveToMesh(curve, varargin) % Create a mesh surrounding a 3D curve. % % [V, F] = curveToMesh(CURVE) % Computes the vertices and the faces of the mesh surrounding the % specified 3D curve. % % [V, F] = curveToMesh(CURVE, THICKNESS) % Specifies the thickness of the mesh (distance between mesh vertices and % curve vertices). Default is 0.5. % % [V, F] = curveToMesh(CURVE, THICKNESS, NCORNERS) % Also specifies the number of mesh vertices around each curve vertex. % Default is 8. % % % Example % % Creates a tubular mesh around a trefoil knot curve % t = linspace(0, 2*pi, 200)'; % x = sin(t) + 2 * sin(2 * t); % y = cos(t) - 2 * cos(2 * t); % z = -sin(3 * t); % curve = [x, y, z]; % [v2, f2] = curveToMesh(curve, .5, 16); % figure; % drawMesh(v2, f2); % axis equal; view(3); % axis([-4 4 -4 4 -2 2]); % % See also % meshes3d, torusMesh, surfToMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2015-01-07, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. radius = .1; if nargin > 1 radius = varargin{1}; end nCorners = 8; if nargin > 2 nCorners = varargin{2}; end nNodes = size(curve, 1); nVerts = nNodes * nCorners; vertices = zeros(nVerts, 3); % create reference corners, that will be rotated and translated t = linspace(0, 2*pi, nCorners + 1)'; t(end) = []; baseCorners = radius * [cos(t) sin(t) zeros(size(t))]; for iNode = 1:nNodes % coordinate of current node node = curve(iNode, :); % compute local tangent vector iNext = mod(iNode, nNodes) + 1; tangentVector = normalizeVector3d(curve(iNext, :) - node); % convert to spherical coordinates [theta, phi, rho] = cart2sph2(tangentVector); %#ok % apply transformation to place corners around current node rotY = createRotationOy(theta); rotZ = createRotationOz(phi); trans = createTranslation3d(node); transformMatrix = trans * rotZ * rotY; corners = transformPoint3d(baseCorners, transformMatrix); % concatenate with other corners vertices( (1:nCorners) + (iNode - 1) * nCorners, :) = corners; end % indices of vertices inds = (1:nVerts)'; add1 = repmat([ones(nCorners-1, 1) ; 1-nCorners], nNodes, 1); % generate faces faces = [inds ... mod(inds + add1 - 1, nVerts) + 1 ... mod(inds + nCorners + add1 - 1, nVerts) + 1 ... mod(inds + nCorners - 1, nVerts) + 1]; matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/trimMesh.m0000644000000000000000000000013214055375162017365 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/trimMesh.m0000644000175000017500000000770114055375162020457 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = trimMesh(varargin) %TRIMMESH Reduce memory footprint of a polygonal mesh. % % [V2, F2] = trimMesh(V, F) % Unreferenced vertices are removed. % Following functions are implemented only for numeric faces: % Duplicate vertices are removed. % Duplicate faces are removed. % % Example % [V, F] = createIcosahedron; % F(13:20, :) = []; % [V2, F2] = trimMesh(V, F); % figure; drawMesh(V2, F2) % view(3); axis equal; % axis([-1 1 -1 1 0 2]) % % See also % meshes3d, clipMeshVertices % ------ % Author: David Legland, oqilipo % e-mail: david.legland@inra.fr % Created: 2014-08-01, using Matlab 8.3.0.532 (R2014a) % Copyright 2014 INRA - Cepia Software Platform. % parse input data [vertices, faces] = parseMeshData(varargin{:}); if isnumeric(faces) % Delete duplicate vertices [tempVertices, ~, tempFaceVertexIdx] = unique(vertices, 'rows'); tempFaces = tempFaceVertexIdx(faces); % Delete unindexed/unreferenced vertices usedVertexIdx = ismember(1:length(tempVertices),unique(tempFaces(:))); newVertexIdx = cumsum(usedVertexIdx); faceVertexIdx = 1:length(tempVertices); faceVertexIdx(usedVertexIdx) = newVertexIdx(usedVertexIdx); faceVertexIdx(~usedVertexIdx) = nan; tempFaces2 = faceVertexIdx(tempFaces); tempVertices2 = tempVertices(usedVertexIdx,:); % Delete duplicate faces [~, uniqueFaceIdx, ~] = unique(tempFaces2, 'rows'); duplicateFaceIdx=~ismember(1:size(tempFaces2,1),uniqueFaceIdx); [vertices2, faces2] = removeMeshFaces(tempVertices2, tempFaces2, duplicateFaceIdx); elseif iscell(faces) % identify vertices referenced by a face vertexUsed = false(size(vertices, 1), 1); for iFace = 1:length(faces) face = faces{iFace}; vertexUsed(face) = true; end vertices2 = vertices(vertexUsed, :); % compute map from old index to new index inds = find(vertexUsed); newInds = zeros(size(vertices, 1), 1); for iIndex = 1:length(inds) newInds(inds(iIndex)) = iIndex; end % change labels of vertices referenced by faces faces2 = cell(1, length(faces)); for iFace = 1:length(faces) faces2{iFace} = newInds(faces{iFace}); end else error('Unsupported format!') end % format output arguments varargout = formatMeshOutput(nargout, vertices2, faces2); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/ellipsoidMesh.m0000644000000000000000000000013214055375162020376 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/ellipsoidMesh.m0000644000175000017500000001003214055375162021457 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = ellipsoidMesh(elli, varargin) %ELLIPSOIDMESH Convert a 3D ellipsoid to face-vertex mesh representation. % % [V, F] = ellipsoidMesh(ELLI) % ELLI is given by: % [XC YC ZC A B C PHI THETA PSI], % where (XC, YC, ZC) is the ellipsoid center, A, B and C are the half % lengths of the ellipsoid main axes, and PHI THETA PSI are Euler angles % representing ellipsoid orientation, in degrees. % % % See also % meshes3d, drawEllipsoid, sphereMesh, equivalentEllipsoid % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-03-12, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. %% Default values % number of meridians nPhi = 32; % number of parallels nTheta = 16; %% Extract input arguments % Parse the input (try to extract center coordinates and radius) if nargin == 0 % no input: assumes ellipsoid with default shape elli = [0 0 0 5 4 3 0 0 0]; end % default set of options for drawing meshes options = {'FaceColor', 'g', 'linestyle', 'none'}; while length(varargin) > 1 switch lower(varargin{1}) case 'nphi' nPhi = varargin{2}; case 'ntheta' nTheta = varargin{2}; otherwise % assumes this is drawing option options = [options varargin(1:2)]; %#ok end varargin(1:2) = []; end %% Parse numerical inputs % Extract ellipsoid parameters xc = elli(:,1); yc = elli(:,2); zc = elli(:,3); a = elli(:,4); b = elli(:,5); c = elli(:,6); k = pi / 180; ellPhi = elli(:,7) * k; ellTheta = elli(:,8) * k; ellPsi = elli(:,9) * k; %% Coordinates computation % convert unit basis to ellipsoid basis sca = createScaling3d(a, b, c); rotZ = createRotationOz(ellPhi); rotY = createRotationOy(ellTheta); rotX = createRotationOx(ellPsi); tra = createTranslation3d([xc yc zc]); % concatenate transforms trans = tra * rotZ * rotY * rotX * sca; %% parametrisation of ellipsoid % spherical coordinates theta = linspace(0, pi, nTheta+1); phi = linspace(0, 2*pi, nPhi+1); % convert to cartesian coordinates sintheta = sin(theta); x = cos(phi') * sintheta; y = sin(phi') * sintheta; z = ones(length(phi),1) * cos(theta); % transform mesh vertices [x, y, z] = transformPoint3d(x, y, z, trans); % convert to FV mesh [vertices, faces] = surfToMesh(x, y, z, 'xPeriodic', false, 'yPeriodic', true); % format output varargout = formatMeshOutput(nargout, vertices, faces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/readMesh.m0000644000000000000000000000013214055375162017325 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/readMesh.m0000644000175000017500000000555414055375162020423 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = readMesh(fileName) % Read a 3D mesh by inferring format from file name. % % Usage: % [V, F] = readMesh(FILENAME) % Read the data stored in file FILENAME and return the vertex and face % arrays as NV-by-3 array and NF-by-N array respectively, where NV is the % number of vertices and NF is the number of faces. % % MESH = readMesh(FILENAME) % Read the data stored in file FILENAME and return the mesh into a struct % with fields 'vertices' and 'faces'. % % Example % mesh = readMesh('apple.ply'); % figure; drawMesh(mesh); % view([180 -70]); axis equal; % % See also % meshes3d, writeMesh, readMesh_off, readMesh_ply, readMesh_stl % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-11-20, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. [~, ~, ext] = fileparts(fileName); switch lower(ext) case '.off' mesh = readMesh_off(fileName); case '.ply' mesh = readMesh_ply(fileName); case '.stl' mesh = readMesh_stl(fileName); otherwise error('Unrecognized file format for rezading mesh: %s', ext); end % format output arguments if nargout < 2 varargout = {mesh}; else varargout = {mesh.vertices, mesh.faces}; end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/changelog.txt0000644000000000000000000000013214055375161020106 xustar0030 mtime=1622538865.998813871 30 atime=1622538865.998813871 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/changelog.txt0000644000175000017500000000057714055375161021204 0ustar00juanpijuanpi00000000000000change log for meshes3d meshes3d release 2011.06.30 =========================== Important changes: - Package has been splitted up into 'geom3d' and 'meshes3d'. See changelog of "geom3d" package for older revisions New Functions - added function clipMeshVertices - added function computeMeshEdges Bug Fixes - fixed bug in edge labeling of createCubeOctaedron matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/private0000644000000000000000000000013214055375161017013 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/private/0000755000175000017500000000000014055375161020155 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/meshes3d/private/PaxHeaders.19757/progressbar.m0000644000000000000000000000013214055375162021600 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/private/progressbar.m0000644000175000017500000000441314055375162022667 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function progressbar(n,N,w) % progressbar - display a progress bar % % progressbar(n,N,w); % % displays the progress of n out of N. % n should start at 1. % w is the width of the bar (default w=20). % % Copyright (c) Gabriel Peyré 2006 if nargin<3 w = 20; end % progress char cprog = '.'; cprog1 = '*'; % begining char cbeg = '['; % ending char cend = ']'; p = min( floor(n/N*(w+1)), w); global pprev; if isempty(pprev) pprev = -1; end if not(p==pprev) ps = repmat(cprog, [1 w]); ps(1:p) = cprog1; ps = [cbeg ps cend]; if n>1 % clear previous string fprintf( repmat('\b', [1 length(ps)]) ); end fprintf(ps); end pprev = p; if n==N fprintf('\n'); end matgeom-1.2.3/inst/meshes3d/private/PaxHeaders.19757/parseMeshData.m0000644000000000000000000000013214055375162021770 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/private/parseMeshData.m0000644000175000017500000000643614055375162023066 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = parseMeshData(varargin) %PARSEMESHDATA Conversion of data representation for meshes. % % MESH = parseMeshData(VERTICES, FACES) % MESH = parseMeshData(VERTICES, EDGES, FACES) % Returns the mesh info into a single structure with fields "vertices", % "edges" and "faces". % % [VERTICES, FACES] = parseMeshData(MESH) % Returns the mesh info into two output variables containing coordinates % of vertices (as a Nv_by_3 array) and the list of vertex indices for % each face (either as a Nf-by-3 or Nf-by-4 int array, or as a cell % array). % % [VERTICES, EDGES, FACES] = parseMeshData(MESH) % Also returns the vertex indices of each edge, as a Ne-by-2 array of % vertex indices. % % See also % meshes3d, formatMeshOutput % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2010-12-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % initialize edges to empty variable edges = []; % Process input arguments switch nargin case 1 % input is a data structure mesh = varargin{1}; vertices = mesh.vertices; faces = mesh.faces; if isfield(mesh, 'edges') edges = mesh.edges; end case 2 % input are vertices and faces vertices = varargin{1}; faces = varargin{2}; case 3 % input are vertices, edges and faces vertices = varargin{1}; edges = varargin{2}; faces = varargin{3}; otherwise error('Wrong number of arguments'); end % returns either a struct or several variables varargout = formatMeshOutput(nargout, vertices, edges, faces); matgeom-1.2.3/inst/meshes3d/private/PaxHeaders.19757/localToGlobal3d.m0000644000000000000000000000013214055375162022214 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/private/localToGlobal3d.m0000644000175000017500000001055614055375162023310 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function trans = localToGlobal3d(varargin) %LOCALTOGLOBAL3D Transformation matrix from local to global coordinate system. % % TRANS = localToGlobal3d(CENTER, THETA, PHI, PSI) % Compute the transformation matrix from a local (or modelling) % coordinate system to the global (or world) coordinate system. % This is a low-level function, used by several drawing functions. % % The transform is defined by: % - CENTER: the position of the local origin into the World coordinate % system % - THETA: colatitude, defined as the angle with the Oz axis (between 0 % and 180 degrees), positive in the direction of the of Oy axis. % - PHI: azimut, defined as the angle of the normal with the Ox axis, % between 0 and 360 degrees % - PSI: intrinsic rotation, corresponding to the rotation of the object % around the direction vector, between 0 and 360 degrees % % The resulting transform is obtained by applying (in that order): % - Rotation by PSI around he Z-axis % - Rotation by THETA around the Y-axis % - Rotation by PHI around the Z-axis % - Translation by vector CENTER % This corresponds to Euler ZYZ rotation, using angles PHI, THETA and % PSI. % % The 'createEulerAnglesRotation' function may better suit your needs as % it is more 'natural'. % % Example % localToGlobal3d % % See also % transforms3d, createEulerAnglesRotation % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2009-06-19, using Matlab 7.7.0.471 (R2008b) % Copyright 2009 INRA - Cepia Software Platform. % HISTORY % 19/08/2009 fix bug in parsing center with 4 args % 2011-06-21 use degrees % extract the components of the transform if nargin == 1 % all components are bundled in the first argument var = varargin{1}; center = var(1:3); theta = var(4); phi = var(5); psi = 0; if length(var) > 5 psi = var(6); end elseif nargin == 4 % arguments = center, then the 3 angles center = varargin{1}; theta = varargin{2}; phi = varargin{3}; psi = varargin{4}; elseif nargin > 4 % center is given in 3 arguments, then 3 angles center = [varargin{1} varargin{2} varargin{3}]; theta = varargin{4}; phi = varargin{5}; psi = 0; if nargin > 5 psi = varargin{6}; end end % conversion from degrees to radians k = pi / 180; % rotation around normal vector axis rot1 = createRotationOz(psi * k); % colatitude rot2 = createRotationOy(theta * k); % longitude rot3 = createRotationOz(phi * k); % shift center tr = createTranslation3d(center); % create final transform by concatenating transforms trans = tr * rot3 * rot2 * rot1; matgeom-1.2.3/inst/meshes3d/private/PaxHeaders.19757/formatMeshOutput.m0000644000000000000000000000013214055375162022575 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/private/formatMeshOutput.m0000644000175000017500000000661414055375162023671 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function res = formatMeshOutput(nbArgs, vertices, edges, faces) %FORMATMESHOUTPUT Format mesh output depending on nargout. % % OUTPUT = formatMeshOutput(NARGOUT, VERTICES, EDGES, FACES) % Utilitary function to convert mesh data . % If NARGOUT is 0 or 1, return a matlab structure with fields vertices, % edges and faces. % If NARGOUT is 2, return a cell array with data VERTICES and FACES. % If NARGOUT is 3, return a cell array with data VERTICES, EDGES and % FACES. % % OUTPUT = formatMeshOutput(NARGOUT, VERTICES, FACES) % Same as before, but do not intialize EDGES in output. NARGOUT can not % be equal to 3. % % Example % % Typical calling sequence (for a very basic mesh of only one face) % v = [0 0; 0 1;1 0;1 1]; % e = [1 2;1 3;2 4;3 4]; % f = [1 2 3 4]; % % varargout = formatMeshOutput(nargout, v, e, f); % % See also % meshes3d, parseMeshData % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-12-06, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. if nargin < 4 faces = edges; edges = []; end switch nbArgs case {0, 1} % output is a data structure with fields vertices, edges and faces mesh.vertices = vertices; if ~isempty(edges) mesh.edges = edges; end mesh.faces = faces; res = {mesh}; case 2 % keep only vertices and faces res = cell(nbArgs, 1); res{1} = vertices; res{2} = faces; case 3 % return vertices, edges and faces as 3 separate outputs res = cell(nbArgs, 1); res{1} = vertices; res{2} = edges; res{3} = faces; otherwise error('Can not manage more than 3 outputs'); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/isManifoldMesh.m0000644000000000000000000000013214055375162020477 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/isManifoldMesh.m0000644000175000017500000000660614055375162021574 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [b1, b2] = isManifoldMesh(varargin) %ISMANIFOLDMESH Check whether the input mesh may be considered as manifold. % % B = isManifoldMesh(V, F) % B = isManifoldMesh(V, E, F) % Checks if the specified mesh is a manifold. When mesh is a manifold, % all edges are connected to either 2 or 1 faces. % % [B, HASBORDER] = isManifoldMesh(V, E, F) % Also checks whether the mesh contains border faces. Border faces % contains at least one edge which is ajacent to only one face. % % Example % [V, F] = createOctahedron; % isManifoldMesh(V, F) % ans = % logical % 1 % % See also % meshes3d, ensureManifoldMesh, trimMesh % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2019-01-31, using Matlab 9.5.0.944444 (R2018b) % Copyright 2019 INRA - Cepia Software Platform. vertices = varargin{1}; faces = varargin{2}; % compute edge to vertex array if nargin == 3 edges = faces; faces = varargin{3}; else % compute edge to vertex array edges = meshEdges(faces); end % compute face to edge indices array % as a nFaces-by-3 array (each face connected to exactly three edges) faceEdgeInds = meshFaceEdges(vertices, edges, faces); % compute number of faces incident each edge edgeFaces = trimeshEdgeFaces(faces); edgeFaceDegrees = sum(edgeFaces > 0, 2); % for each face, concatenate the face degree of each edge faceEdgeDegrees = zeros(size(faces, 1), 3); for iFace = 1:size(faces, 1) edgeInds = faceEdgeInds{iFace}; faceEdgeDegrees(iFace, :) = edgeFaceDegrees(edgeInds); end regFaces = sum(ismember(faceEdgeDegrees, [1 2]), 2) == 3; innerFaces = sum(faceEdgeDegrees == 2, 2) == 3; borderFaces = regFaces & ~innerFaces; % check if mesh is manifold: all faces are either regular or border b1 = all(regFaces); % check if some faces are border b2 = any(borderFaces); matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/writeMesh.m0000644000000000000000000000013214055375162017544 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/writeMesh.m0000644000175000017500000000527114055375162020636 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function writeMesh(fileName, vertices, faces, varargin) % Write 3D mesh data by inferring format from file name. % % writeMesh(FNAME, V, F) % % writeMesh(FNAME, MESH) % % Example % writeMesh % % See also % meshes3d, readMesh, writeMesh_off, writeMesh_ply, writeMesh_stl % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-11-20, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. % check inputs if ~ischar(fileName) error('First argument must contain the name of the file'); end % optionnaly parses data if isstruct(vertices) if nargin > 2 varargin = [{faces} varargin{:}]; end faces = vertices.faces; vertices = vertices.vertices; end [~, ~, ext] = fileparts(fileName); switch lower(ext) case '.off' writeMesh_off(fileName, vertices, faces); case '.ply' writeMesh_ply(fileName, vertices, faces, varargin{:}); case '.stl' writeMesh_stl(fileName, vertices, faces, varargin{:}); otherwise error('Unrecognized file format for rezading mesh: %s', ext); end matgeom-1.2.3/inst/meshes3d/PaxHeaders.19757/fillMeshFaces.m0000644000000000000000000000013214055375162020302 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/meshes3d/fillMeshFaces.m0000644000175000017500000000762014055375162021374 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = fillMeshFaces(varargin) % Fill the faces of a mesh with the specified colors. % % fillMeshFaces(V, F, VERTEXCOLORS) % Colorizes a mesh by filling faces with an array of values. The colors % can be a NV-by-1 array of values, or a NV-by-3 array of values. % Face filling uses 'interp' coloring mode. % % fillMeshFaces(V, F, FACECOLORS) % Colorizes the mesh by specifying the value or the color associated to % each face. Face filling uses 'flat' coloring mode. % % fillMeshFaces(..., PNAME, PVALUE) % Specifies additional parameters that will be passed to the 'patch' % function. % % Example % % Colorize mesh based on z-coordinate of vertices. % [v, f] = createIcosahedron; % values = v(:,3); % figure; axis equal; view(3); % fillMeshFaces(v, f, values); % % % Colorize mesh using specific color for each face % [v, f] = createIcosahedron; % colors = jet(20); % figure; axis equal; view(3); % fillMeshFaces(v, f, colors); % % See also % drawMesh % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-04-16, using Matlab 9.7.0.1247435 (R2019b) Update 2 % Copyright 2020 INRAE. %% Parse input arguments % extract first argument var1 = varargin{1}; varargin(1) = []; % Check if first input argument is an axes handle if isAxisHandle(var1) ax = var1; var1 = varargin{1}; varargin(1) = []; else ax = gca; end % Check if the input is a mesh structure if isstruct(var1) % extract data to display vertices = var1.vertices; faces = var1.faces; else % assumes input is given with vertices+faces arrays vertices = var1; faces = varargin{1}; varargin(1) = []; end % next argument is face color colors = varargin{1}; varargin(1) = []; % adapt the face color key value depending on the size of the "color" input % argument faceColorMode = 'interp'; if size(colors, 1) == size(faces, 1) faceColorMode = 'flat'; end % array FACES is a NF-by-NV indices array, with NV number of vertices of % each face, and NF number of faces h = patch('Parent', ax, ... 'vertices', vertices, 'faces', faces, 'FaceVertexCData', colors, ... 'FaceColor', faceColorMode, varargin{:}); %% Process output arguments % format output parameters if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/PaxHeaders.19757/polynomialCurves2d0000644000000000000000000000013214055375161017427 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/0000755000175000017500000000000014055375161020571 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialDerivate.m0000644000000000000000000000013214055375162023532 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialDerivate.m0000644000175000017500000000446414055375162024627 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function deriv = polynomialDerivate(poly) %POLYNOMIALDERIVATE Derivate a polynomial. % % DERIV = polynomialDERIVATE(POLY) % POLY is a row vector of [n+1] coefficients, in the form: % [a0 a1 a2 ... an] % DERIV has the same format, with length n: % [a1 a2*2 ... an*n] % % % Example % T = polynomialDerivate([2 3 4]) % returns: % T = [3 8] % % See also % polynomialCurves2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % create the derivation matrices matrix = diag(0:length(poly)-1); % compute coefficients of first derivative polynomials deriv = circshift(poly*matrix, [0 -1]); matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/drawPolynomialCurve.m0000644000000000000000000000013214055375162023671 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/drawPolynomialCurve.m0000644000175000017500000000550214055375162024760 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawPolynomialCurve(tBounds, varargin) %DRAWPOLYNOMIALCURVE Draw a polynomial curve approximation. % % Usage % drawPolynomialCurve(BND, XCOEFS, YCOEFS) % drawPolynomialCurve(BND, XCOEFS, YCOEFS, NPTS) % % Example % drawPolynomialCurve % % See also % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-03-21, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. %% Extract input parameters % parametrization bounds t0 = tBounds(1); t1 = tBounds(end); % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; varargin(1) = []; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; varargin(1:2) = []; else xCoef = var(1,:); yCoef = var(2,:); varargin(1) = []; end nPts = 120; if ~isempty(varargin) nPts = varargin{1}; end %% Drawing the polyline approximation % generate vector of absissa t = linspace(t0, t1, nPts+1)'; % compute corresponding positions pts = polynomialCurvePoint(t, xCoef, yCoef); % draw the resulting curve h = drawPolyline(pts); if nargout > 0 varargout = {h}; end matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveDerivative.m0000644000000000000000000000013214055375162025076 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveDerivative.m0000644000175000017500000000611714055375162026170 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function v = polynomialCurveDerivative(t, varargin) %POLYNOMIALCURVEDERIVATIVE Compute derivative vector of a polynomial curve. % % VECT = polynomialCurveLength(T, XCOEF, YCOEF); % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % VECT is a 1x2 array containing direction of derivative of polynomial % curve, computed for position T. If T is a vector, VECT has as many rows % as the length of T. % % VECT = polynomialCurveLength(T, COEFS); % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % Example % polynomialCurveDerivative % % See also % polynomialCurves2d, polynomialCurveNormal, polynomialCurvePoint, % polynomialCurveCurvature % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Extract input parameters % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; else xCoef = var(1,:); yCoef = var(2,:); end %% compute derivative % compute derivative of the polynomial dx = polynomialDerivate(xCoef); dy = polynomialDerivate(yCoef); % convert to polyval convention dx = dx(end:-1:1); dy = dy(end:-1:1); % numerical integration of the Jacobian of parametrized curve v = [polyval(dx, t) polyval(dy, t)]; matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveFit.m0000644000000000000000000000013214055375162023516 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveFit.m0000644000175000017500000002146214055375162024610 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polynomialCurveFit(t, varargin) %POLYNOMIALCURVEFIT Fit a polynomial curve to a series of points. % % [XC YC] = polynomialCurveFit(T, XT, YT, ORDER) % T is a Nx1 vector % XT and YT are coordinate for each parameter value (column vectors) % ORDER is the degree of the polynomial used for interpolation % XC and YC are polynomial coefficients, given in ORDER+1 row vectors, % starting from degree 0 and up to degree ORDER. % % [XC YC] = polynomialCurveFit(T, POINTS, ORDER); % specifies coordinate of points in a Nx2 array. % % Example: % N = 50; % t = linspace(0, 3*pi/4, N)'; % xp = cos(t); yp = sin(t); % [xc yc] = polynomialCurveFit(t, xp, yp, 3); % curve = polynomialCurvePoint(t, xc, yc); % drawCurve(curve); % % % [XC YC] = polynomialCurveFit(..., T_I, COND_I); % Impose some specific conditions. T_I is a value of the parametrization % variable. COND_I is a cell array, with 2 columns, and as many rows as % the derivatives specified for the given T_I. Format for COND_I is: % COND_I = {X_I, Y_I; X_I', Y_I'; X_I", Y_I"; ...}; % with X_I and Y_I being the imposed coordinate at position T_I, X_I' and % Y_I' being the imposed first derivatives, X_I" and Y_I" the imposed % second derivatives, and so on... % To specify a derivative without specifying derivative with lower % degree, value of lower derivative can be let empty, using '[]' % % Example: % % defines a curve (circle arc) with small perturbations % N = 100; % t = linspace(0, 3*pi/4, N)'; % xp = cos(t)+.1*randn(size(t)); yp = sin(t)+.1*randn(size(t)); % % % plot the points % figure(1); clf; hold on; % axis([-1.2 1.2 -.2 1.2]); axis equal; % drawPoint(xp, yp); % % % fit without knowledge on bounds % [xc0 yc0] = polynomialCurveFit(t, xp, yp, 5); % curve0 = polynomialCurvePoint(t, xc0, yc0); % drawCurve(curve0); % % % fit by imposing coordinate on first point % [xc1 yc1] = polynomialCurveFit(t, xp, yp, 5, 0, {1, 0}); % curve1 = polynomialCurvePoint(t, xc1, yc1); % drawCurve(curve1, 'r'); % % % fit by imposing coordinate (1,0) and derivative (0,1) on first point % [xc2 yc2] = polynomialCurveFit(t, xp, yp, 5, 0, {1, 0;0 1}); % curve2 = polynomialCurvePoint(t, xc2, yc2); % drawCurve(curve2, 'g'); % % % fit by imposing several conditions on various points % [xc3 yc3] = polynomialCurveFit(t, xp, yp, 5, ... % 0, {1, 0;0 1}, ... % coord and first derivative of first point % 3*pi/4, {-sqrt(2)/2, sqrt(2)/2}, ... % coord of last point % pi/2, {[], [];-1, 0}); % derivative of point on the top of arc % curve3 = polynomialCurvePoint(t, xc3, yc3); % drawCurve(curve3, 'k'); % % Requires the optimization Toolbox. % % % Examples: % polynomialCurveFit % % See also % polynomialCurves2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-27 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% extract input arguments % extract curve coordinate var = varargin{1}; if min(size(var))==1 % curve given as separate arguments xt = varargin{1}; yt = varargin{2}; varargin(1:2)=[]; else % curve coordinate bundled in a matrix if size(var, 1)1 Dx = var(1); Dy = var(2); else Dx = var; Dy = var; end varargin(1)=[]; %% Initialize local conditions % For a solution vector 'x', the following relation must hold: % Aeq * x == beq, % with: % Aeq Matrix M*N % beq column vector with length M % The coefficients of the Aeq matrix are initialized as follow: % First point and last point are considered successively. For each point, % k-th condition is the value of the (k-1)th derivative. This value is % computed using relation of the form: % value = sum_i ( fact(i) * t_j^pow(i) ) % with: % i indice of the (i-1) derivative. % fact row vector containing coefficient of each power of t, initialized % with a row vector equals to [1 1 ... 1], and updated for each % derivative by multiplying by corresponding power minus 1. % pow row vector of the powers of each monome. It is represented by a % row vector containing an increasing series of power, eventually % completed with zeros for lower degrees (for the k-th derivative, % the coefficients with power lower than k are not relevant). % Example for degree 5 polynom: % iter deriv pow fact % 1 0 [0 1 2 3 4 5] [1 1 1 1 1 1] % 2 1 [0 0 1 2 3 4] [0 1 2 3 4 5] % 3 2 [0 0 0 1 2 3] [0 0 1 2 3 4] % 4 3 [0 0 0 0 1 2] [0 0 0 1 2 3] % ... % The process is repeated for coordinate x and for coordinate y. % Initialize empty matrices Aeqx = zeros(0, Dx+1); beqx = zeros(0, 1); Aeqy = zeros(0, Dy+1); beqy = zeros(0, 1); % Process local conditions while ~isempty(varargin) if length(varargin)==1 warning('MatGeom:PolynomialCurveFit:ArgumentNumber', ... 'Wrong number of arguments in polynomialCurvefit'); end % extract parameter t, and cell array of local conditions ti = varargin{1}; cond = varargin{2}; % factors for coefficients of each polynomial. At the beginning, they % all equal 1. With successive derivatives, their value increase by the % corresponding powers. factX = ones(1, Dx+1); factY = ones(1, Dy+1); % start condition initialisations for i = 1:size(cond, 1) % degrees of each polynomial powX = [zeros(1, i) 1:Dx+1-i]; powY = [zeros(1, i) 1:Dy+1-i]; % update conditions for x coordinate if ~isempty(cond{i,1}) Aeqx = [Aeqx ; factY.*power(ti, powX)]; %#ok beqx = [beqx; cond{i,1}]; %#ok end % update conditions for y coordinate if ~isempty(cond{i,2}) Aeqy = [Aeqy ; factY.*power(ti, powY)]; %#ok beqy = [beqy; cond{i,2}]; %#ok end % update polynomial degrees for next derivative factX = factX.*powX; factY = factY.*powY; end varargin(1:2)=[]; end %% Initialisations % ensure column vectors t = t(:); xt = xt(:); yt = yt(:); % number of points to fit L = length(t); %% Compute coefficients of each polynomial % avoid optimization warnings warning('off', 'optim:lsqlin:LinConstraints'); % options to turn display off options = optimset('display', 'off'); % main matrix for x coordinate, size L*(degX+1) T = ones(L, Dx+1); for i = 1:Dx T(:, i+1) = power(t, i); end % compute interpolation xc = lsqlin(T, xt, zeros(1, Dx+1), 1, Aeqx, beqx, [], [], [], options)'; % main matrix for y coordinate, size L*(degY+1) T = ones(L, Dy+1); for i = 1:Dy T(:, i+1) = power(t, i); end % compute interpolation yc = lsqlin(T, yt, zeros(1, Dy+1), 1, Aeqy, beqy, [], [], [], options)'; %% Format output arguments if nargout <= 1 varargout{1} = {xc, yc}; else varargout{1} = xc; varargout{2} = yc; end matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveProjection.m0000644000000000000000000000013214055375162025110 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveProjection.m0000644000175000017500000000614314055375162026201 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pos = polynomialCurveProjection(tBounds, varargin) %POLYNOMIALCURVEPROJECTION Projection of a point on a polynomial curve. % % T = polynomialCurveProjection([T0 T1], XCOEFS, YCOEFS, POINT); % Computes the position of POINT on the polynomial curve, such that % polynomialCurvePoint([T0 T1], XCOEFS, YCOEFS) is the same as POINT. % % See also % polynomialCurves2d, polynomialCurvePoint % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-12-21 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % parametrization bounds t0 = tBounds(1); t1 = tBounds(end); % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; varargin(1) = []; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; varargin(1:2)=[]; else xCoef = var(1,:); yCoef = var(2,:); varargin(1)=[]; end % the point to project point = varargin{1}; varargin(1)=[]; % tolerance tol = 1e-6; if ~isempty(varargin) tol = varargin{1}; end % update coefficient according to point position xCoef(1) = xCoef(1) - point(1); yCoef(1) = yCoef(1) - point(2); % convert to format of polyval c1 = xCoef(end:-1:1); c2 = yCoef(end:-1:1); % avoid warning for t=0 warning off 'MATLAB:quad:MinStepSize' % set up precision for t options = optimset('TolX', tol^2); % compute minimisation of the distance function pos = fminbnd(@(t) polyval(c1, t).^2+polyval(c2, t).^2, t0, t1, options); matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurvePosition.m0000644000000000000000000000013214055375162024600 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurvePosition.m0000644000175000017500000001120314055375162025662 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pos = polynomialCurvePosition(tBounds, varargin) %POLYNOMIALCURVEPOSITION Compute position on a curve for a given length. % % POS = polynomialCurvePosition(T, XCOEF, YCOEF, L) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % T is a 1x2 row vector, containing the bounds of the parametrization % variable: T = [T0 T1], with T taking all values between T0 and T1. % L is the geodesic length corresponding to the searched position. % POS is a scalar, verifying relation: % L = polynomialCurveLength([T(1) POS], XCOEF, YCOEF); % % POS = polynomialCurvePosition(T, COEFS, L) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % POS = polynomialCurvePosition(..., TOL) % TOL is the tolerance fo computation (absolute). % % See also % polynomialCurves2d % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-26 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % parametrization bounds t0 = tBounds(1); t1 = tBounds(end); % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; varargin(1) = []; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; varargin(1:2)=[]; else xCoef = var(1,:); yCoef = var(2,:); varargin(1)=[]; end % geodesic length corresponding to searched position L = varargin{1}; varargin(1)=[]; % tolerance tol = 1e-6; if ~isempty(varargin) tol = varargin{1}; end % compute derivative of the polynomial dx = polynomialDerivate(xCoef); dy = polynomialDerivate(yCoef); % convert to format of polyval dx = dx(end:-1:1); dy = dy(end:-1:1); % avoid warning for t=0 warning off 'MATLAB:quad:MinStepSize' % set up precision for t options = optimset('TolX', tol); % starting point, located in the middle of the paramtrization domain ts = (t0+t1)/2; % compute parameter corresponding to geodesic position by solving g(t)-tg=0 pos = fzero(@(t)funCurveLength(t0, t, dx, dy, tol)- L, ts, options); function res = funCurveLength(t0, t1, c1, c2, varargin) %FUNCURVELENGTH return the length of polynomial curve arc % output = funCurveLength(t0, t1, c1, c2) % t0 and t1 are the limits of the integral % c1 and c2 are derivative polynoms of each coordinate parametrization, % given from greater order to lower order (polyval convention). % c1 = [an a_n-1 ... a2 a1 a0]. % % Example % funCurveLength(0, 1, C2, C2); % funCurveLength(0, 1, C2, C2, RES); % RES is the resolution (ex: 1e-6). % % See also % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-14 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. if verLessThan('matlab', '7.14') res = quad(@(t)sqrt(polyval(c1, t).^2+polyval(c2, t).^2), t0, t1, varargin{:}); %#ok else res = integral(@(t)sqrt(polyval(c1, t).^2+polyval(c2, t).^2), ... t0, t1, 'AbsTol', varargin{:}); end matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveCentroid.m0000644000000000000000000000013214055375162024543 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveCentroid.m0000644000175000017500000001053314055375162025632 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function centroid = polynomialCurveCentroid(tBounds, varargin) %POLYNOMIALCURVECENTROID Compute the centroid of a polynomial curve. % % C = polynomialCurveCentroid(T, XCOEF, YCOEF) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % T is a 1x2 row vector, containing the bounds of the parametrization % variable: T = [T0 T1], with T taking all values between T0 and T1. % C contains coordinate of the polynomila curve centroid. % % C = polynomialCurveCentroid(T, COEFS) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % C = polynomialCurveCentroid(..., TOL) % TOL is the tolerance fo computation (absolute). % % Example % polynomialCurveCentroid % % See also % polynomialCurves2d, polynomialCurveLength % % % ------ % Author: David Legland % e-mail: david.legland@gignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Extract input parameters % parametrization bounds t0 = tBounds(1); t1 = tBounds(end); % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; varargin(1) = []; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; varargin(1:2)=[]; else xCoef = var(1,:); yCoef = var(2,:); varargin(1)=[]; end % tolerance tol = 1e-6; if ~isempty(varargin) tol = varargin{1}; end %% compute length by numerical integration % compute derivative of the polynomial dx = polynomialDerivate(xCoef); dy = polynomialDerivate(yCoef); % convert to polyval format dx = dx(end:-1:1); dy = dy(end:-1:1); cx = xCoef(end:-1:1); cy = yCoef(end:-1:1); if verLessThan('matlab', '7.14') % compute curve length by integrating the Jacobian L = quad(@(t)sqrt(polyval(dx, t).^2+polyval(dy, t).^2), t0, t1, tol); %#ok<*DQUAD> % compute first coordinate of centroid xc = quad(@(t)polyval(cx, t).*sqrt(polyval(dx, t).^2+polyval(dy, t).^2), t0, t1, tol); % compute first coordinate of centroid yc = quad(@(t)polyval(cy, t).*sqrt(polyval(dx, t).^2+polyval(dy, t).^2), t0, t1, tol); else % compute curve length by integrating the Jacobian L = integral(@(t)hypot(polyval(dx, t), polyval(dy, t)), ... t0, t1, 'AbsTol', tol); % compute first coordinate of centroid xc = integral(@(t)polyval(cx, t).*hypot(polyval(dx, t), polyval(dy, t)), ... t0, t1, 'AbsTol', tol); % compute first coordinate of centroid yc = integral(@(t)polyval(cy, t).*hypot(polyval(dx, t), polyval(dy, t)), ... t0, t1, 'AbsTol', tol); end % divide result of integration by total length of the curve centroid = [xc yc] / L; matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveLength.m0000644000000000000000000000013214055375162024215 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveLength.m0000644000175000017500000000677214055375162025316 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function L = polynomialCurveLength(tBounds, varargin) %POLYNOMIALCURVELENGTH Compute the length of a polynomial curve. % % LENGTH = polynomialCurveLength(T, XCOEF, YCOEF) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % T is a 1x2 row vector, containing the bounds of the parametrization % variable: T = [T0 T1], with T taking all values between T0 and T1. % % LENGTH = polynomialCurveLength(T, COEFS) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % LENGTH = polynomialCurveLength(..., TOL) % TOL is the tolerance fo computation (absolute). % % Example % polynomialCurveLength % % See also % polynomialCurves2d, polynomialCurveCentroid % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Extract input parameters % parametrization bounds t0 = tBounds(1); t1 = tBounds(end); % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; varargin(1) = []; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; varargin(1:2)=[]; else xCoef = var(1,:); yCoef = var(2,:); varargin(1)=[]; end % tolerance tol = 1e-6; if ~isempty(varargin) tol = varargin{1}; end %% compute length by numerical integration % compute derivative of the polynomial dx = polynomialDerivate(xCoef); dy = polynomialDerivate(yCoef); % convert to polyval format dx = dx(end:-1:1); dy = dy(end:-1:1); % numerical integration of the Jacobian of parametrized curve if verLessThan('matlab', '7.14') L = quad(@(t)sqrt(polyval(dx, t).^2+polyval(dy, t).^2), t0, t1, tol); %#ok else L = integral(@(t)sqrt(polyval(dx, t).^2+polyval(dy, t).^2), ... t0, t1, 'AbsTol', tol); end matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveCurvatures.m0000644000000000000000000000013214055375162025137 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveCurvatures.m0000644000175000017500000001235214055375162026227 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polynomialCurveCurvatures(t, varargin) %POLYNOMIALCURVECURVATURES Compute curvatures of a polynomial revolution surface. % % KAPPAS = polynomialCurveCurvatures(T, XCOEF, YCOEF) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % T is a column vector, containing the parametrization values for which % curvatures have to be computed. % KAPPAS is a matrix with 2 columns and as many rows as T, containing the % 2 main curvatures for each specified T. % Curvatures are computed by assuming the curve to be rotated around the % vertical axis (from point (0,0), in direction (1,0)). % % KAPPAS = polynomialCurveCurvatures(T, COEFS) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % [KAPPA1 KAPPA2] = polynomialCurveCurvatures(...) % return the 2 main curvatures in separate arrays. % % ... = polynomialCurveCurvatures(..., AXIS) % Specify the revolution axis. By default, revolution axis is the % vertical axis, going through point (0,0) and having direction vector % given by (0,1). Another axis of revolution can be specified in format: % AXIS = [x0 y0 dx dy]. % % % See also % polynomialCurves2d, polynomialCurveCurvature % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY % 28/02/2007 fix bug for the sign of the second curvature... % 12/03/2007 base on vertical revolution axis, and adapt to manage any % revolution axis %% Extract input parameters % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) % coefficients are given in a cell array xCoef = var{1}; yCoef = var{2}; varargin(1)=[]; elseif size(var, 1) == 1 % coefficients are given as two numeric vectors xCoef = varargin{1}; yCoef = varargin{2}; varargin(1:2)=[]; else % coefficients are given as a 2-by-N numeric array xCoef = var(1,:); yCoef = var(2,:); varargin(1)=[]; end % revolution axis is the 2D vertical axis by default axis = [0 0 0 1]; if ~isempty(varargin) axis = varargin{1}; end %% Coordinate of curve points % compute coordinates in original base pts = polynomialCurvePoint(t, xCoef, yCoef); % compute the matrix which transform points such that axis becomes the % vertical axis angle = lineAngle(axis); trans = createRotation(axis(1:2), pi/2 - angle); % transform points pts = transformPoint(pts, trans); %% compute first derivatives % compute first derivatives of the polynomials dx = polynomialDerivate(xCoef); dy = polynomialDerivate(yCoef); % compute local first derivatives xp = polyval(dx(end:-1:1), t); yp = polyval(dy(end:-1:1), t); % transform vectors of first derivatives vect = transformVector([xp yp], trans); xp = vect(:,1); yp = vect(:,2); %% compute second derivatives % compute second derivatives sx = polynomialDerivate(dx); sy = polynomialDerivate(dy); % compute local second derivatives xs = polyval(sx(end:-1:1), t); ys = polyval(sy(end:-1:1), t); % transform vectors of first derivatives vect = transformVector([xs ys], trans); xs = vect(:,1); ys = vect(:,2); %% computation of curvatures % compute local curvatures of polynomial curve kappa1 = sign(pts(:,1)) .* (xs.*yp - xp.*ys) ./ power(xp.*xp + yp.*yp, 3/2); kappa2 = -yp ./ abs(pts(:,1)) ./ sqrt(xp.*xp + yp.*yp); %% Format output arguments if nargout < 2 varargout{1} = [kappa1 kappa2]; else varargout{1} = kappa1; varargout{2} = kappa2; end matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveSetFit.m0000644000000000000000000000013214055375162024172 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveSetFit.m0000644000175000017500000001771714055375162025274 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = polynomialCurveSetFit(seg, varargin) %POLYNOMIALCURVESETFIT Fit a set of polynomial curves to a segmented image. % % COEFS = polynomialCurveSetFit(IMG); % COEFS = polynomialCurveSetFit(IMG, DEG); % Result is a cell array of matrices. Each matrix is DEG+1-by-2, and % contains coefficients of polynomial curve for each coordinate. % IMG is first binarised, then skeletonized. Each cure % % [COEFS LBL] = polynomialCurveSetFit(...); % also returns an image of labels for the segmented curves. The max label % is the number of curves, and the length of COEFS. % % Requires the toolboxes: % - Optimization % - Image Processing % % Example % % Fit a set of curves to a binary skeleton % img = imread('circles.png'); % % compute skeleton, and ensure one-pixel thickness % skel = bwmorph(img, 'skel', 'Inf'); % skel = bwmorph(skel, 'shrink'); % figure; imshow(skel==0) % coeffs = polynomialCurveSetFit(skel, 2); % % Display segmented image with curves % figure; imshow(~img); hold on; % for i = 1:length(coeffs) % hc = drawPolynomialCurve([0 1], coeffs{i}); % set(hc, 'linewidth', 2, 'color', 'g'); % end % % See also % polynomialCurves2d, polynomialCurveFit % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-03-21 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Initialisations % default degree for curves deg = 2; if ~isempty(varargin) deg = varargin{1}; end % ensure image is binary seg = seg > 0; %% Extract branching points and terminating points % compute image of end points imgEndPoints = imfilter(double(seg), ones([3 3])) .* seg == 2; % compute centroids of end points lblEndPoints = bwlabel(imgEndPoints, 4); regEndPoints = bwconncomp(imgEndPoints, 4); struct = regionprops(regEndPoints, 'Centroid'); endPoints = cat(1, struct.Centroid); % compute image of multiple points (intersections between curves) imgBranching = imfilter(double(seg), ones([3 3])) .* seg > 3; % compute coordinate of nodes, as centroids of the multiple points lblBranching = bwlabel(imgBranching, 4); regBranching = bwconncomp(imgBranching, 4); struct = regionprops(regBranching, 'Centroid'); branchPoints = cat(1, struct.Centroid); % list of nodes (all categories) nodes = [branchPoints; endPoints]; % image of node labels lblNodes = lblBranching; lblNodes(lblEndPoints > 0) = lblEndPoints(lblEndPoints > 0) + size(branchPoints, 1); % isolate branches imgBranches = seg & ~imgBranching & ~imgEndPoints; lblBranches = bwlabel(imgBranches, 8); % number of curves nBranches = max(lblBranches(:)); % allocate memory coefs = cell(nBranches, 1); % For each curve, find interpolated polynomial curve for i = 1:nBranches %disp(i); % extract points corresponding to current curve imgBranch = lblBranches == i; points = chainPixels(imgBranch); % if number of points is not sufficient, simply create a line segment if size(points, 1) < max(deg+1-2, 2) % find labels of nodes inds = unique(lblNodes(imdilate(imgBranch, ones(3,3)))); inds = inds(inds~=0); if length(inds)<2 disp(['Could not find extremities of branch number ' num2str(i)]); coefs{i} = [0 0;0 0]; continue; end % consider extremity nodes node0 = nodes(inds(1),:); node1 = nodes(inds(2),:); % use only a linear approximation xc = zeros(1, deg+1); yc = zeros(1, deg+1); xc(1) = node0(1); yc(1) = node0(2); xc(2) = node1(1)-node0(1); yc(2) = node1(2)-node0(2); % assigne au tableau de courbes coefs{i} = [xc;yc]; % next branch continue; end % find nodes closest to first and last points of the current curve [dist, ind0] = minDistancePoints(points(1, :), nodes); %#ok<*ASGLU> [dist, ind1] = minDistancePoints(points(end, :), nodes); % add nodes to the curve. points = [nodes(ind0,:); points; nodes(ind1,:)]; %#ok % parametrization of the polyline t = parametrize(points); t = t/max(t); % fit a polynomial curve to the set of points [xc, yc] = polynomialCurveFit(... t, points, deg, ... 0, {points(1,1), points(1,2)},... 1, {points(end,1), points(end,2)}); % stores result coefs{i} = [xc ; yc]; end %% Post-processing % manage outputs if nargout == 1 varargout = {coefs}; elseif nargout == 2 varargout = {coefs, lblBranches}; end function points = chainPixels(img, varargin) %CHAINPIXELS return the list of points which constitute a curve on image % output = chainPixels(input) % % Example % chainPixels % % See also % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-03-21 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. conn = 8; if ~isempty(varargin) conn = varargin{1}; end % matrice de voisinage if conn==4 f = [0 1 0;1 1 1;0 1 0]; elseif conn==8 f = ones([3 3]); end % find extremity points nb = imfilter(double(img), f).*img; imgEnding = nb==2 | nb==1; [yi, xi] = find(imgEnding); % extract coordinates of points [y, x] = find(img); % index of first point if isempty(xi) % take arbitrary point ind = 1; else ind = find(x==xi(1) & y==yi(1)); end % allocate memory points = zeros(length(x), 2); if conn==8 for i=1:size(points, 1) % avoid multiple neighbors (can happen in loops) ind = ind(1); % add current point to chained curve points(i,:) = [x(ind) y(ind)]; % remove processed coordinate x(ind) = []; y(ind) = []; % find next candidate ind = find(abs(x-points(i,1))<=1 & abs(y-points(i,2))<=1); end else for i=1:size(points, 1) % avoid multiple neighbors (can happen in loops) ind = ind(1); % add current point to chained curve points(i,:) = [x(ind) y(ind)]; % remove processed coordinate x(ind) = []; y(ind) = []; % find next candidate ind = find(abs(x-points(i,1)) + abs(y-points(i,2)) <=1 ); end end matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveCurvature.m0000644000000000000000000000013214055375162024754 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveCurvature.m0000644000175000017500000000647514055375162026055 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function kappa = polynomialCurveCurvature(t, varargin) %POLYNOMIALCURVECURVATURE Compute the local curvature of a polynomial curve. % % KAPPA = polynomialCurveCurvature(T, XCOEF, YCOEF) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % KAPPA is the local curvature of the polynomial curve, computed for % position T. If T is a vector, KAPPA has the same length as T. % % KAPPA = polynomialCurveCurvature(T, COEFS) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % Example % polynomialCurveCurvature % % See also % polynomialCurves2d, polynomialCurveLength, polynomialCurveDerivative % % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Extract input parameters % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; else xCoef = var(1,:); yCoef = var(2,:); end %% compute derivative % compute first derivatives of the polynomials dx = polynomialDerivate(xCoef); dy = polynomialDerivate(yCoef); % compute second derivatives sx = polynomialDerivate(dx); sy = polynomialDerivate(dy); % convert to polyval convention dx = dx(end:-1:1); dy = dy(end:-1:1); sx = sx(end:-1:1); sy = sy(end:-1:1); % compute local first and second derivatives xp = polyval(dx, t); yp = polyval(dy, t); xs = polyval(sx, t); ys = polyval(sy, t); % compute local curvature of polynomial curve kappa = (xp.*ys - xs.*yp) ./ power(xp.*xp + yp.*yp, 3/2); matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162021460 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/Contents.m0000644000175000017500000001001014055375162022535 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % POLYNOMIALCURVES2D Planar Polynomial Curves % Version 1.24 07-Jun-2018 . % % POLYNOMIALCURVES2D Manipulation of planar smooth curves % Polynomial curves are plane curves whose points are defined by a % polynomial for each x and y coordinate. % A polynomial curve is represented by 3 row vectors: % * the bounds of the parametrization % * the coefficients for the x coordinate (in increasing degree) % * the coefficients for the y coordinate (in increasing degree) % % Example: % C = {[0 1], [3 4], [0 1 -1]}; % represents the curve defined by: % x(t) = 3 + 4*t; % y(t) = t - t*t; % for t belonging to the interval [0 1]. % % As each coordinate are given by polynoms, it is possible to compute % various parameters like curvature, normal, or the exact geodesic length % of the curve. % % For most functions, parameters are given as three separate arguments. % Sometimes, only the 2 parameters corresponding to the X and Y % coefficients are required. % % % Global features % polynomialCurveCentroid - Compute the centroid of a polynomial curve % polynomialCurveProjection - Projection of a point on a polynomial curve % polynomialCurveLength - Compute the length of a polynomial curve % polynomialCurvePoint - Compute point corresponding to a position % polynomialCurvePosition - Compute position on a curve for a given length % % Local features % polynomialCurveDerivative - Compute derivative vector of a polynomial curve % polynomialCurveNormal - Compute the normal of a polynomial curve % polynomialCurveCurvature - Compute the local curvature of a polynomial curve % polynomialCurveCurvatures - Compute curvatures of a polynomial revolution surface % % Fitting % polynomialCurveFit - Fit a polynomial curve to a series of points % polynomialCurveSetFit - Fit a set of polynomial curves to a segmented image % % Drawing % drawPolynomialCurve - Draw a polynomial curve approximation % % Utilities % polynomialDerivate - Derivate a polynomial % polyfit2 - Polynomial approximation of a curve % % % ----- % Author: David Legland % e-mail: david.legland@inra.fr % created the 07/11/2005. % Project homepage: http://github.com/mattools/matGeom % http://www.pfl-cepia.inra.fr/index.php?page=geom2d % Copyright INRA - Cepia Software Platform. help(mfilename); %% Deprecated functions: %% Others... matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurveNormal.m0000644000000000000000000000013214055375162024224 xustar0030 mtime=1622538866.102813479 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurveNormal.m0000644000175000017500000000604014055375162025311 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function v = polynomialCurveNormal(t, varargin) %POLYNOMIALCURVENORMAL Compute the normal of a polynomial curve. % % N = polynomialCurveNormal(T, XCOEF, YCOEF) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % T is a 1x2 row vector, containing the bounds of the parametrization % variable: T = [T0 T1], with T taking all values between T0 and T1. % T can also be a larger vector, in this case only bounds are kept. % N is a 1x2 row vector, containing direction of curve normal in T. % If T is column vector, the result is a matrix with 2 columns containing % normal vector for each position. % % The normal is oriented such that oriented angle from derivative % vector to normal vector equals PI/2. The normal points to the 'left' % when travelling along the curve. % N = polynomialCurveNormal(T, COEFS) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % N = polynomialCurveNormal(..., TOL) % TOL is the tolerance fo computation (absolute). % % Example % polynomialCurveNormal % % See also % polynomialCurves2d, polynomialCurveDerivative % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % extract the derivative v = polynomialCurveDerivative(t, varargin{:}); % rotate by PI/2 Counter clockwise v = [-v(:,2) v(:,1)]; matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polyfit2.m0000644000000000000000000000013214055375162021433 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.102813479 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polyfit2.m0000644000175000017500000001526614055375162022532 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function coef = polyfit2(varargin) %POLYFIT2 Polynomial approximation of a curve. % % % usage : % P = POLYFIT2(X, Y, N) finds the coefficients of a polynomial P(X) of % degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense. % % P = POLYFIT2(Y, N) use default equal spacing between all values of Y % array. % % P = POLYFIT2(..., COND) specify end conditions for interpolated % polynom. COND is [M*1] array of values, M(0) is value of interpolated % polynom for X(1), M(2) is value of first derivative at first point, and % so on for each derivative degree of X. % If COND is [M*2] array, first column gives conditions for first point, % and second column gives conditions for second point. % % P = POLYFIT2(..., COND1, COND2) % where COND1 and COND2 are column arrays, specify different end % condition for each limit of the polynom domain. % % Example % % defines a basis and a function to interpolate % N = 50; % 50 points % x = linspace(0, pi, N); % basis range from 0 to PI % y = cos(x)+randn(1,N)*.2; % cosine plus gaussian noise % figure; plot(x, y, '+'); % display result % % Fit a degree 3 polynom, imposing to pass through end points [0 1] and % % [PI -1]: % p1 = polyfit2(x, y, 3, [1], [-1]); % % Fit a degree 3 polynom, imposing to pass through end points [0 1] and % % [PI -1], and imposing first derivative equals to zero at end points: % p2 = polyfit2(x, y, 3, [1;0], [-1;0]); % % display the different approximations % hold on; % plot(x, polyval(p1, x), 'g'); % plot(x, polyval(p2, x), 'r'); % % % See also : % polyfit (matlab) % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 30/04/2004. % % HISTORY % 05/01/2007 adapt to polynom bases others than [0...1] % 08/01/2007 update doc accordingly % 27/02/2007 code clean up %% Default values % boundary conditions cond1 = []; cond2 = []; %% extract input arguments if length(varargin)>2 t = varargin{1}; x = varargin{2}; N = varargin{3}; % extract end conditions if length(varargin)==4 % one input for both end conditions var = varargin{4}; if size(var, 2)==1 % only first condition is specified cond1 = var; cond2 = []; else % two end conditions in a single array cond1 = var(:,1); cond2 = var(:,2); end elseif length(varargin)==5 % both end conditions are given is separates inputs cond1 = varargin{4}; cond2 = varargin{5}; end elseif length(varargin)==2 % extract curve values and interpolation order, and compute default % parametrization. x = varargin{1}; t = 0:1/(length(x)-1):1; N = varargin{2}; else error ('POLYFIT2 : needs at least 2 input arguments'); end %% Initializations % transform to column vectors x= x(:); t = t(:); % number of points L = length(x); % start and end values of parametrisation t0 = t(1); t1 = t(end); %% Initialize matrices for end conditions % For a solution vector 'x', the following relation must hold: % Aeq * x == beq, % with: % Aeq Matrix M*N % beq column vector with length M % The coefficients of the Aeq matrix are initialized as follow: % First point and last point are considered successively. For each point, % k-th condition is the value of the (k-1)th derivative. This value is % computed using relation of the form: % value = sum_i ( fact(i) * t_j^pow(i) ) % with: % i indice of the (i-1) derivative. % fact row vector containing coefficient of each power of t, initialized % with a row vector equals to [1 1 ... 1], and updated for each % derivative by multiplying by corresponding power minus 1. % pow row vector of the powers of each monome. It is represented by a % row vector containing an increasing series of power, eventually % completed with zeros for lower degrees (for the k-th derivative, % the coefficients with power lower than k are not relevant). % Example for degree 5 polynom: % iter deriv pow fact % 1 0 [0 1 2 3 4 5] [1 1 1 1 1 1] % 2 1 [0 0 1 2 3 4] [0 1 2 3 4 5] % 3 2 [0 0 0 1 2 3] [0 0 1 2 3 4] % 4 3 [0 0 0 0 1 2] [0 0 0 1 2 3] % ... % Initialize empty matrices Aeq = zeros(0, N+1); beq = zeros(0, 1); % start condition initialisations fact = ones(1, N+1); for i = 1:length(cond1) pow = [zeros(1, i) 1:N+1-i]; Aeq = [Aeq ; fact.*power(t0, pow)]; %#ok beq = [beq; cond1(i)]; %#ok fact = fact.*pow; end % end condition initialisations fact = ones(1, N+1); for i = 1:length(cond2) pow = [zeros(1, i) 1:N+1-i]; Aeq = [Aeq ; fact.*power(t1, pow)];%#ok beq = [beq; cond2(i)];%#ok fact = fact.*pow; end %% Main algorithm % main matrix of the problem, size L*(deg+1) X = ones(L, N+1); for i = 1:N X(:, i+1) = power(t, i); end % compute interpolation coef = lsqlin(X, x, zeros(1, N+1), 1, Aeq, beq); %% format output % format output to a format similar to polyfit coef = coef(end:-1:1)'; matgeom-1.2.3/inst/polynomialCurves2d/PaxHeaders.19757/polynomialCurvePoint.m0000644000000000000000000000013214055375162024065 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/polynomialCurves2d/polynomialCurvePoint.m0000644000175000017500000000603514055375162025156 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function point = polynomialCurvePoint(t, varargin) %POLYNOMIALCURVEPOINT Compute point corresponding to a position. % % POINT = polynomialCurvePoint(T, XCOEF, YCOEF) % XCOEF and YCOEF are row vectors of coefficients, in the form: % [a0 a1 a2 ... an] % T is a either a scalar, or a column vector, containing values of the % parametrization variable. % POINT is a 1x2 array containing coordinate of point corresponding to % position given by T. If T is a vector, POINT has as many rows as T. % % POINT = polynomialCurvePoint(T, COEFS) % COEFS is either a 2xN matrix (one row for the coefficients of each % coordinate), or a cell array. % % Example % polynomialCurvePoint % % See also % polynomialCurves2d, polynomialCurveLength % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-02-23 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Extract input parameters % polynomial coefficients for each coordinate var = varargin{1}; if iscell(var) xCoef = var{1}; yCoef = var{2}; elseif size(var, 1)==1 xCoef = varargin{1}; yCoef = varargin{2}; else xCoef = var(1,:); yCoef = var(2,:); end %% compute length by numerical integration % convert polynomial coefficients to polyval convention cx = xCoef(end:-1:1); cy = yCoef(end:-1:1); % numerical integration of the Jacobian of parametrized curve point = [polyval(cx, t) polyval(cy, t)]; matgeom-1.2.3/inst/PaxHeaders.19757/graphs0000644000000000000000000000013214055375161015112 xustar0030 mtime=1622538865.998813871 30 atime=1622538866.150813297 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/0000755000175000017500000000000014055375161016254 5ustar00juanpijuanpi00000000000000matgeom-1.2.3/inst/graphs/PaxHeaders.19757/centroidalVoronoi2d.m0000644000000000000000000000013214055375162021274 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/centroidalVoronoi2d.m0000644000175000017500000001415314055375162022365 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [germs, germPaths] = centroidalVoronoi2d(germs, poly, varargin) %CENTROIDALVORONOI2D Centroidal Voronoi tesselation within a polygon. % % PTS = centroidalVoronoi2d(NPTS, POLY) % Generate points in a polygon based on centroidal voronoi tesselation. % Centroidal germs can be computed by using the Llyod's algorithm: % 1) initial germs are chosen at random within polygon % 2) voronoi polygon of the germs is computed % 3) the centroids of each domain are computed, and used as germs of the % next iteration % % [PTS, PATHLIST] = centroidalVoronoi2d(NPTS, POLY) % Also returns the path of each germs at each iteration. The result % PATHLIST is a cell array with as many cells as the number of germs, % containing in each cell the successive positions of the germ. % % PTS = centroidalVoronoi2d(.., PARAM, VALUE) % Specify one or several optional arguments. PARAM can be one of: % * 'nIter' specifies the number of iterations of the algorithm % (default is 50) % * 'verbose' display iteration number. Default is false. % % Example % poly = ellipseToPolygon([50 50 40 30 20], 200); % nGerms = 100; % germs = centroidalVoronoi2d(nGerms, poly); % figure; hold on; % drawPolygon(poly, 'k'); % drawPoint(germs, 'bo'); % axis equal; axis([0 100 10 90]); % % extract regions of the CVD % box = polygonBounds(poly); % [n, e] = boundedVoronoi2d(box, germs); % [n2, e2] = clipGraphPolygon(n, e, poly); % drawGraphEdges(n2, e2, 'b'); % % See also % graphs, boundedVoronoi2d, centroidalVoronoi2d_MC % % Rewritten from programs found in % http://people.scs.fsu.edu/~burkardt/m_src/cvt/cvt.html % % Reference: % Qiang Du, Vance Faber, and Max Gunzburger, % Centroidal Voronoi Tessellations: Applications and Algorithms, % SIAM Review, Volume 41, 1999, pages 637-676. % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-02-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. %% Parse input arguments % Number of germs if isscalar(germs) nGerms = germs; germs = []; else nGerms = size(germs, 1); end % Number of iterations nIter = 50; verbose = false; keepPaths = nargout > 1; while length(varargin) > 1 paramName = varargin{1}; switch lower(paramName) case 'verbose' verbose = varargin{2}; case 'niter' nIter = varargin{2}; otherwise error(['Unknown parameter name: ' paramName]); end varargin(1:2) = []; end %% Initialisations % bounding box of polygon bbox = polygonBounds(poly); % init germs if needed if isempty(germs) germs = generatePointsInPoly(nGerms); end germIters = cell(nIter, 1); %% Iteration of the Lloyd algorithm for i = 1:nIter if verbose disp(sprintf('Iteration: %d/%d', i, nIter)); %#ok end if keepPaths germIters{i} = germs; end % Compute Clipped Voronoi diagram of germs if verbose disp(' compute Voronoi Diagram'); end [n, e, f] = boundedVoronoi2d(bbox, germs); [n2, e2, f2] = clipMesh2dPolygon(n, e, f, poly); %#ok % update the position of each germ if verbose disp(' compute centroids'); end for iGerm = 1:nGerms polygon = n2(f2{iGerm}, :); germs(iGerm,:) = polygonCentroid(polygon); end end %% Evenutally compute germs trajectories if nargout > 1 % init germPaths = cell(nGerms, 1); path = zeros(nIter+1, 2); % Iteration on germs for i = 1:nGerms % create path corresponding to germ for j = 1:nIter pts = germIters{j}; path(j,:) = pts(i,:); end path(nIter+1, :) = germs(i,:); germPaths{i} = path; end end function pts = generatePointsInPoly(nPts) % extreme coordinates xmin = bbox(1); xmax = bbox(2); ymin = bbox(3); ymax = bbox(4); % compute size of box dx = xmax - xmin; dy = ymax - ymin; % allocate memory for result pts = zeros(nPts, 2); % iterate until all points have been sampled within the polygon ind = (1:nPts)'; while ~isempty(ind) NI = length(ind); x = rand(NI, 1) * dx + xmin; y = rand(NI, 1) * dy + ymin; pts(ind, :) = [x y]; ind = ind(~polygonContains(poly, pts(ind, :))); end end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/boundaryGraph.m0000644000000000000000000000013214055375162020153 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/boundaryGraph.m0000644000175000017500000001227714055375162021251 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = boundaryGraph(img) %BOUNDARYGRAPH Get boundary of image as a graph. % % [NODES, EDGES] = boundaryGraph(IMG) (2D) % [NODES, EDGES, FACES] = boundaryGraph(IMG) (3D) % Create a graph on the boundary of binary image IMG. Each pixel is % considered as a unit square (or cube), centered on integer coordinates. % Boundary of the shape is selected as a graph. % % Result is a set of nodes with (x,y) or (x,y,z) coordinates, a set of % edges linking two neighbour nodes, and in 3D also a set of square % faces, containing reference to each 4-tuple of nodes. % % The resulting shell is open if the binary structure touches edges of % image. % % See also : % imPatch, drawMesh % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 28/06/2004. % % HISTORY % 05/08/2004 : change name and add 2D case. dim = size(img); nd = length(dim); if nd==2 && (dim(1)==1 || dim(2)==1) nd=1; end nodes = zeros([0 nd]); % coordinates of vertices edges = zeros([0 2]); % first node and second nodes faces = zeros([0 4]); % indices of 4 corners of each square face if nd == 1 img = img(:)>0; D1 = size(img,1); nodes = find(img(1:D1-1)~=img(2:D1))+.5; if nargout==1 varargout{1} = nodes; end return elseif nd == 2 D1 = size(img, 1); D2 = size(img, 2); px = []; py = []; ind = find(img(1:D1-1, :)~=img(2:D1, :)); [x, y] = ind2sub([D1-1 D2], ind); px = [px; reshape([x+.5 x+.5]', length(x)*2,1)]; py = [py; reshape([y-.5 y+.5]', length(x)*2,1)]; ind = find(img(:, 1:D2-1)~=img(:, 2:D2)); [x, y] = ind2sub([D1 D2-1], ind); px = [px; reshape([x-.5 x+.5]', length(x)*2,1)]; py = [py; reshape([y+.5 y+.5]', length(x)*2,1)]; [nodes, i, j] = unique([py px], 'rows'); %#ok ne = floor(size(px, 1)/2); edges = repmat(1:2, [ne 1]) + repmat((0:2:2*ne-1)', [1 2]); for i=1:length(edges(:)) edges(i) = j(edges(i)); end edges = unique(sort(edges, 2), 'rows'); elseif nd==3 D1 = size(img, 1); D2 = size(img, 2); D3 = size(img, 3); px = []; py = []; pz = []; ind = find(img(1:D1-1, :, :)~=img(2:D1, :, :)); [x, y, z] = ind2sub([D1-1 D2 D3], ind); px = [px; reshape([x+.5 x+.5 x+.5 x+.5]', length(x)*4,1)]; py = [py; reshape([y-.5 y+.5 y+.5 y-.5]', length(x)*4,1)]; pz = [pz; reshape([z-.5 z-.5 z+.5 z+.5]', length(x)*4,1)]; ind = find(img(:, 1:D2-1, :)~=img(:, 2:D2, :)); [x, y, z] = ind2sub([D1 D2-1 D3], ind); px = [px; reshape([x-.5 x-.5 x+.5 x+.5]', length(x)*4,1)]; py = [py; reshape([y+.5 y+.5 y+.5 y+.5]', length(x)*4,1)]; pz = [pz; reshape([z-.5 z+.5 z+.5 z-.5]', length(x)*4,1)]; ind = find(img(:, :, 1:D3-1)~=img(:, :, 2:D3)); [x, y, z] = ind2sub([D1 D2 D3-1], ind); px = [px; reshape([x-.5 x+.5 x+.5 x-.5]', length(x)*4,1)]; py = [py; reshape([y-.5 y-.5 y+.5 y+.5]', length(x)*4,1)]; pz = [pz; reshape([z+.5 z+.5 z+.5 z+.5]', length(x)*4,1)]; [nodes, i, j] = unique([py px pz], 'rows'); %#ok nf = floor(size(px, 1)/4); faces = repmat(1:4, [nf 1]) + repmat((0:4:4*nf-1)', [1 4]); for i=1:length(faces(:)) faces(i) = j(faces(i)); end edges = [edges ; [faces(:,1) faces(:,2)]]; edges = [edges ; [faces(:,2) faces(:,3)]]; edges = [edges ; [faces(:,3) faces(:,4)]]; edges = [edges ; [faces(:,4) faces(:,1)]]; edges = unique(sort(edges, 2), 'rows'); end % format output arguments if nargout==3 varargout{1} = nodes; varargout{2} = edges; varargout{3} = faces; elseif nargout==2 varargout{1} = nodes; varargout{2} = edges; elseif nargout==1 graph.nodes = nodes; graph.edges = edges; graph.faces = faces; varargout{1} = graph; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/fillGraphFaces.m0000644000000000000000000000013214055375162020220 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/fillGraphFaces.m0000644000175000017500000001156614055375162021316 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = fillGraphFaces(varargin) %FILLGRAPHFACES Fill faces of a graph with specified color. % % fillGraphFaces(NODES, FACES) % draw the faces of a graph / mesh defined by a sef of vertices and a set % of faces. The array NODES is a NV-by-2 or NV-by-3 array containing % vertex coordinates. The array FACES is either a NF-by-3 or NF-by-4 % array of integers, or a 1-by-Nf array of cells, and contains indices of % each face vertices. % % fillGraphFaces(NODES, EDGES, FACES) % also specifies the edges ofthe graph. % % fillGraphFaces(GRAPH) % passes argument in a srtucture with at least 3 fields named 'nodes', % 'edges', and 'faces', corresponding to previously described parameters. % GRAPH can also be a cell array, whose first element is node array, % second element is edges array, and third element, if present, is faces % array. % % fillGraphFaces(..., SFACES) % specifes the draw mode for each element, as in the classical 'plot' % function. To not display some elements, uses 'none'. % % H = fillGraphFaces(...) % return handle to the set of faces. % % See also % graphs, drawGraph, drawGraphEdges % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2005-11-24 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 2017-09-04 code cleanup, rename from drawGraphFaces to fillGraphFaces %% Initialisations % drawing style for filling faces. Default is cyan. faceColor = 'c'; %% Process input arguments % if called without argument, display usage if nargin == 0 help fillGraphFaces; return; end % Extract the structure of the graph var = varargin{1}; if iscell(var) % graph is stored as a cell array : first cell is nodes, second one is % edges, and third one is faces n = var{1}; if length(var) > 2 f = var{3}; end varargin(1) = []; elseif isstruct(var) % graph is stored as a structure, with fields 'nodes', 'edges', and % eventually 'faces'. n = var.nodes; if isfield(var, 'faces') f = var.faces; end varargin(1) = []; else % graph is stored as set of variables: nodes, edges, and eventually % faces n = varargin{1}; % extract faces input argument if length(varargin) > 2 && ~ischar(varargin{3}) f = varargin{3}; varargin(1:3) = []; else f = varargin{2}; varargin(1:2) = []; end end % extract drawing style if ~isempty(varargin) faceColor = varargin{1}; end % process special case of 'none' option, that can be used in a call from % the drawGraph function if strcmp(faceColor, 'none') return; end %% Main drawing processing % setup hold to display several faces hold on; if size(n, 2) == 3 % use a zbuffer to avoid display pbms. set(gcf, 'renderer', 'zbuffer'); end if iscell(f) % each face is contained in a cell. for fi = 1:length(f) hf(fi) = patch('Faces', f{fi}, 'Vertices', n, 'FaceColor', faceColor, 'EdgeColor', 'none'); %#ok end else % process faces as a NF-by-P array. NF i the number of faces, % and all faces have the same number P of vertices (nodes). hf = patch('Faces', f, 'Vertices', n, 'FaceColor', faceColor, 'EdgeColor', 'none'); end %% format output arguments if nargout == 1 varargout{1} = hf; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/prim_mst.m0000644000000000000000000000013214055375162017200 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/prim_mst.m0000644000175000017500000000623614055375162020274 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = prim_mst(edges, vals) %PRIM_MST Minimal spanning tree by Prim's algorithm. % % EDGES2 = prim_mst(EDGES, VALUES) % Compute the minimal spanning tree (MST) of the graph with edges given % by EDGES, and whose edges are valuated by VALUES. % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-07-27, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % isolate vertices index nodes = unique(edges(:)); N = length(nodes); % initialize memory nodes2 = zeros(N, 1); edges2 = zeros(N-1, 2); vals2 = zeros(N-1, 1); % initialize with a first node nodes2(1) = nodes(1); nodes = nodes(2:end); % iterate on edges for i = 1:N-1 % find all edges from nodes2 to nodes ind = unique(find(... (ismember(edges(:,1), nodes2(1:i)) & ismember(edges(:,2), nodes)) | ... (ismember(edges(:,1), nodes) & ismember(edges(:,2), nodes2(1:i))) )); % choose edge with lowest value [tmp, ind2] = min(vals(ind)); %#ok ind = ind(ind2(1)); vals2(i) = vals(ind); % index of other vertex edge = edges(ind, :); neigh = edge(~ismember(edge, nodes2)); % add to list of nodes and list of edges nodes2(i+1) = neigh; edges2(i,:) = edge; % remove current node from list of old nodes nodes = nodes(~ismember(nodes, neigh)); end % process output arguments if nargout == 1 varargout{1} = edges2; elseif nargout==2 varargout{1} = edges2; varargout{2} = vals2; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grDilate.m0000644000000000000000000000013214055375162017101 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grDilate.m0000644000175000017500000000470614055375162020175 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grDilate(varargin) %GRDILATE Morphological dilation on graph. % % LBL2 = grDilate(EDGES, LBL1) % Each label of the graph is assigned the highest label of its % neighbours, or it keeps the same label this one is bigger. % % Example % grDilate % % See also % grErode, grOpen, grClose % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-01-20 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin) == 2 edges = varargin{1}; lbl = varargin{2}; elseif length(varargin) == 3 edges = varargin{2}; lbl = varargin{3}; else error('Wrong number of arguments in "grDilate"'); end lbl2 = zeros(size(lbl)); uni = unique(edges(:)); for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); lbl2(uni(n)) = max(lbl([uni(n); neigh])); end varargout{1} = lbl2; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/voronoi2d.m0000644000000000000000000000013214055375162017267 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/voronoi2d.m0000644000175000017500000000533114055375162020356 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges, faces] = voronoi2d(germs) %VORONOI2D Compute a voronoi diagram as a graph structure. % % [NODES, EDGES, FACES] = voronoi2d(GERMS) % GERMS an array of points with dimension 2 % NODES, EDGES, FACES: usual graph representation, FACES as cell array % % Example % [n e f] = voronoi2d(rand(100, 2)*100); % drawGraph(n, e); % % See also % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-01-12 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % compute generic Voronoi diagram [V, C] = voronoin(germs); % declaration of array for storing results nodes = V(2:end, :); edges = zeros(0, 2); faces = {}; % iterate on voronoi 'cells' for i = 1:length(C) % get node indices of current polygonal domain cell = C{i}; % do not process unbounded domains if ismember(1, cell) continue; end % fix indexing of nodes cell = cell - 1; % compute indices of edge and domain nodes edges = [edges; sort([cell' cell([2:end 1])'], 2)]; %#ok faces{length(faces)+1} = cell; %#ok end % remove duplicate edges edges = unique(edges, 'rows'); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/clipMesh2dPolygon.m0000644000000000000000000000013214055375162020710 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/clipMesh2dPolygon.m0000644000175000017500000002645414055375162022010 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2, faces2] = clipMesh2dPolygon(nodes, edges, faces, poly) %CLIPMESH2DPOLYGON Clip a planar mesh with a polygon. % % [NODES2, EDGES2, FACES2] = clipMesh2dPolygon(NODES, EDGES, FACES, POLY) % Clips the graph defined by nodes NODES and edges EDGES with the polygon % given in POLY. POLY is a N-by-2 array of vertices. % The result is a new graph containing nodes inside the polygon, as well % as nodes created by the intersection of edges with the polygon. % % Important: it is assumed that no edge crosses the polygon twice. This % is the case if the polygon is convex (or nearly convex) and if the % edges are small compared to the polygon. % % Example % elli = [50 50 40 20 30]; % figure; hold on; % drawEllipse(elli, 'k'); % poly = ellipseToPolygon(elli, 200); % box = polygonBounds(poly); % germs = randomPointInPolygon(poly, 100); % drawPoint(germs, 'b.'); % [n, e, f] = boundedVoronoi2d(box, germs); % [n2, e2, f2] = clipMesh2dPolygon(n, e, f, poly); % drawGraphEdges(n2, e2); % fillGraphFaces(n2, f2); % % See also % graphs, drawGraph, clipGraph % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % Algorithm summary: % * For each edge not outside do: % * clip edge with poly % * if no inter % * add current edge (same vertex indices) % * continue % * end % * add intersections to list, compute their indices % * create the new edge(s) %% Pre-processing % number of nodes, edges and faces nNodes = size(nodes, 1); nEdges = size(edges, 1); nFaces = meshFaceNumber(nodes, faces); % associate each face to the list of its incident edge faceEdgeInds = meshFaceEdges(nodes, edges, faces); %% Clip the nodes % find index of nodes inside clipping window nodeInside = isPointInPolygon(nodes, poly); innerNodeInds = find(nodeInside); % create correspondance between original nodes and inside nodes nodeIndsMap = zeros(nNodes, 1); for i = 1:length(innerNodeInds) nodeIndsMap(innerNodeInds(i)) = i; end % select clipped nodes nodes2 = nodes(innerNodeInds, :); %% Prepare edge clipping % Need to compute with edges will be kept. This includes (1) edges totally % inside the original polygon and (2) edges clipped by the polygon. % array of boolean flag for each end vertex of each edge insideEnds = nodeInside(edges); % find index of edges totally inside polygon % (do not test intersections with polygon edges) edgeInsideFlag = sum(insideEnds, 2) == 2; innerEdgeInds = find(edgeInsideFlag); % Create correspondance map between original edges and new edges. innerEdgeIndsMap = zeros(nEdges, 1); for i = 1:length(innerEdgeInds) innerEdgeIndsMap(innerEdgeInds(i)) = i; end % create correspondance map between old edges and new edges % Use a cell array, as each edge may be clip into several edges. % The map is initialized with inner edges indices, but may contain indices % of clipped edges in later processing edgeIndsMap = cell(nEdges, 1); for i = 1:length(innerEdgeInds) edgeIndsMap{innerEdgeInds(i)} = i; end % find edges either totally inside polygon, or with one intersection with % the polygon keepEdgeFlag = sum(insideEnds, 2) > 0; % allocate memory for edges to keep (with at least one vertex inside) nEdges2 = sum(keepEdgeFlag); edges2 = zeros(nEdges2, 2); % create correspondance map between new edges and original edge(s) % Use a cell array, as each edge may be clip into several edges. % The map is initialized with inner edges indices, but may contain indices % of clipped edges in later processing edgeIndsMap2 = cell(nEdges2, 1); %% Determine clipped edges % index of next edge % index of next edge to add to the list % iEdge2 = 1; iEdge2 = length(innerEdgeInds) + 1; % index of next vertex iNode2 = size(nodes2, 1) + 1; % iterate over all edges for iEdge = 1:nEdges % index of edge vertices v1 = edges(iEdge, 1); v2 = edges(iEdge, 2); % compute intersection(s) of current edge with polygon boundary edge0 = [nodes(v1,:) nodes(v2,:)]; intersects = intersectEdgePolygon(edge0, poly); % If current edge do not cross polygon boundary, it is either totally % inside or totally outside if isempty(intersects) % check if edge is totally inside the polygon if nodeInside(v1) && nodeInside(v2) % create new edge by converting node indices newEdge = nodeIndsMap([v1 v2])'; % add the new edge to the list of new edges ind = innerEdgeIndsMap(iEdge); edges2(ind,:) = newEdge; % keep index correspondance new->old edgeIndsMap2{ind} = iEdge; end continue; end % add intersection(s) to the vertex array nInters = size(intersects, 1); intersectInds = iNode2:iNode2+nInters-1; nodes2(intersectInds,:) = intersects; iNode2 = iNode2 + nInters; % concatenate vertex indices with indices of extremities inside poly if nodeInside(v1) intersectInds = [nodeIndsMap(v1) intersectInds]; %#ok end if nodeInside(v2) intersectInds = [intersectInds nodeIndsMap(v2)]; %#ok end % determine the number of edges corresponding to the clipped edge % (usually only one) nNewEdges = (nInters + 1) / 2; if nNewEdges ~= round(nNewEdges) warning('matGeom:graphs:AlgorithmicError', ... 'edge %d has odd number of intersects', iEdge); end % compute list of indices of the new edges newEdgeInds = (1:nNewEdges) + iEdge2 - 1; % associate new edge indices to the current edge edgeIndsMap{iEdge} = newEdgeInds; % create a new edge for each pair of contiguous intersections while length(intersectInds) > 1 edges2(iEdge2, :) = intersectInds(1:2); edgeIndsMap2{iEdge2} = iEdge; intersectInds(1:2) = []; iEdge2 = iEdge2 + 1; end if ~isempty(intersectInds) warning('matGeom:graphs:AlgorithmicError', ... 'edge %d has odd number of intersects', iEdge); end end %% Clip faces % initialize new array of faces faces2 = cell(0, 0); iFace2 = 1; for iFace = 1:nFaces % get edge indices of current face edgeInds = faceEdgeInds{iFace}; nodeInds = unique(edges(edgeInds, :)); % check which edges of current face are inside insideFlags = nodeInside(nodeInds); % do not consider faces whose all vertices are outside polygon % (for the moment) if all(~insideFlags) continue; end % check if face is totally within the polygon or if we need to clip the % face with the polygon boundary if all(insideFlags) % convert edge indices edgeInds2 = []; for iEdge = 1:length(edgeInds) edgeInds2 = [edgeInds2 edgeIndsMap{edgeInds(iEdge)}]; %#ok end % convert edge indices to list of vertices faceEdges = edges2(edgeInds2, :); newFace = faceEdges(1, :); nextInd = newFace(2); faceEdges(1,:) = []; while size(faceEdges, 1) > 1 ind = find(sum(faceEdges == nextInd, 2)); nodeInds = faceEdges(ind, :); nextInd = nodeInds(nodeInds ~= nextInd); newFace = [newFace nextInd]; %#ok faceEdges(ind, :) = []; end else % process case of clipped faces % get indices of clipped edges keepFlags = keepEdgeFlag(edgeInds); edgeInds = edgeInds(keepFlags); % convert edge indices edgeInds2 = []; for iEdge = 1:length(edgeInds) edgeInds2 = [edgeInds2 edgeIndsMap{edgeInds(iEdge)}]; %#ok end % convert edge indices to list of vertices faceEdges = edges2(edgeInds2, :); % find a vertex existing only once indices = unique(faceEdges(:)); for i = 1:length(indices) if sum(faceEdges(:) == indices(i)) == 1 ind0 = indices(i); break; end end % initialize new face from single vertex nextInd = ind0; newFace = nextInd; % iterate over edges until other single vertex while size(faceEdges, 1) > 0 ind = find(sum(faceEdges == nextInd, 2)); nodeInds = faceEdges(ind, :); nextInd = nodeInds(nodeInds ~= nextInd); newFace = [newFace nextInd]; %#ok faceEdges(ind, :) = []; end % crop the clipping polygon into two polylines node0 = nodes2(ind0, :); pos0 = projPointOnPolygon(node0, poly); pos1 = projPointOnPolygon(nodes2(nextInd, :), poly); sub1 = polygonSubcurve(poly, pos0, pos1); sub2 = polygonSubcurve(poly, pos1, pos0); % keep only the smallest polyline if polylineLength(sub1) < polylineLength(sub2) sub = sub1; else sub = sub2; end % eventually add polygon vertices contained within subcurve extremities dists = distancePoints(sub([1 end],:), node0); if dists(1) < dists(2) newNodes = sub(end-1:-1:2, :); else newNodes = sub(2:end-1, :); end newNodeInds = (1:size(newNodes, 1)) + size(nodes2, 1); nodes2 = [nodes2; newNodes]; %#ok newFace = [newFace newNodeInds]; %#ok % add new edges newEdges = [[nextInd newNodeInds]' [newNodeInds ind0]']; edges2 = [edges2 ; newEdges]; %#ok end % ensure new face is CCW-oriented if polygonArea(nodes2(newFace, :)) < 0 newFace = newFace([1 end:-1:2]); end % add the new face to the set of new faces faces2{iFace2} = newFace; iFace2 = iFace2 + 1; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grRemoveMultiplePoints.m0000644000000000000000000000013214055375162022045 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grRemoveMultiplePoints.m0000644000175000017500000000604114055375162023133 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grRemoveMultiplePoints(nodes, edges) %GRREMOVEMULTIPLEPOINTS Remove groups of close nodes in a graph. % % grRemoveMultiplePoints(nodes, edges) % Detects groups of nodes that belongs to the same global node. % This function is intended to be used as filter after a binary image % skeletonization and vectorization. % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 doc % 27/04/2005 function was not working, due to mergeNode modification. % TODO: accelerate function, by limiting action on nodes with degree>2 % TODO: algo does not work, it can forget some groups. n = 1; while n <= length(nodes) x = nodes(n, 1); y = nodes(n, 2); p1 = findPoint([x-1, y], nodes); p2 = findPoint([x+1, y], nodes); p3 = findPoint([x, y-1], nodes); p4 = findPoint([x, y+1], nodes); p = [p1 p2 p3 p4]; p = p(p ~= 0); if length(p) > 1 [nodes, edges] = grMergeNodes(nodes, edges, [n p]); end n = n+1; end % renumerate edges b = unique(edges(:)); for i = 1:length(b) edges(edges == b(i)) = i; end % remove extra nodes nodes = nodes(b, :); % process output depending on how many arguments are needed if nargout == 1 out{1} = nodes; out{2} = edges; varargout{1} = out; end if nargout == 2 varargout{1} = nodes; varargout{2} = edges; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grErode.m0000644000000000000000000000013214055375162016735 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grErode.m0000644000175000017500000000470014055375162020023 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grErode(varargin) %GRERODE Morphological erosion on graph. % % LBL2 = grErode(EDGES, LBL1) % Each label of the graph is assigned the smallest label of its % neighbours, or it keeps the same label this one is smaller. % % Example % grErode % % See also % grDilate, grOpen, grClose % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-01-20 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin) == 2 edges = varargin{1}; lbl = varargin{2}; elseif length(varargin) == 3 edges = varargin{2}; lbl = varargin{3}; else error('Wrong number of arguments in "grErode"'); end lbl2 = zeros(size(lbl)); uni = unique(edges(:)); for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); lbl2(uni(n)) = min(lbl([uni(n); neigh])); end varargout{1} = lbl2; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/boundedCentroidalVoronoi2d.m0000644000000000000000000000013214055375162022575 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/boundedCentroidalVoronoi2d.m0000644000175000017500000000750014055375162023664 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = boundedCentroidalVoronoi2d(germs, box, varargin) %BOUNDEDCENTROIDALVORONOI2D Create a 2D Centroidal Voronoi Tesselation in a box. % % [N, E, F] = boundedCentroidalVoronoi2d(GERMS, BOX) % GERMS are N-by-2 point array, BOX is given as [xmin xmax ymin ymax]. % Algorithm is an iteration of voronoi diagram computations, using at % each steps the centroids of previous diagram as germs for the new % diagram. % % [N, E, F] = boundedCentroidalVoronoi2d(GERMS, BOX, NITER) % Specifies the number of iterations. % % [N, E, F, G] = boundedCentroidalVoronoi2d(...) % also returns the positions of germs/centroids for each face. If the % number of iteration was sufficient, location of germs should correspond % to centroids of faces 'fc' computed using: % fc(i,:) = polygonCentroid(n(f{i}, :)); % % Example % [n, e, f] = boundedCentroidalVoronoi2d(rand(20, 2)*100, [0 100 0 100]); % drawGraph(n, e, f); % % See also % graphs, boundedVoronoi2d, centroidalVoronoi2d, clipGraph % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-01-12 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % HISTORY % 27/07/2007 add doc, and psb to specify number of iterations % 18/09/2007 add psb to return germs of tessellation % 23/02/2012 rename from centroidalVoronoi2d to boundedCentroidalVoronoi2d % number of iteration nIter = 10; if ~isempty(varargin) nIter = varargin{1}; end % limits and size of the box x0 = box(1); x1 = box(2); y0 = box(3); y1 = box(4); dx = x1 - x0; dy = y1 - y0; % far points to bound the voronoi diagram farPoints = [... x1 + 10 * dx, y1 + 10 * dy;... x0 - 10 * dx, y1 + 10 * dy;... x0 - 10 * dx, y0 - 10 * dy;... x1 + 10 * dx, y0 - 10 * dy]; % iterate bounded voronoi tesselation for i = 1:nIter % generate Voronoi diagram, and clip with the box [n, e, f] = voronoi2d([germs ; farPoints]); [n, e, f] = clipGraph(n, e, f, box); % centroid of each face will be used as germs for next iteration for j = 1:length(f) face = n(f{j}, :); germs(j, 1:2) = polygonCentroid(face); end end % result is given in n, e, and f, eventually germs varargout{1} = n; varargout{2} = e; varargout{3} = f; if nargout > 3 varargout{4} = germs; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/gcontour2d.m0000644000000000000000000000013214055375162017434 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/gcontour2d.m0000644000175000017500000000643014055375162020524 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges] = gcontour2d(img) %GCONTOUR2D Creates contour graph of a 2D binary image. % % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 25/06/2004. % nodes = zeros([0 2]); edges = zeros([0 2]); D1 = size(img, 1); D2 = size(img, 2); % first direction for image for i = 1:D1 % find transitions between the two phases ind = find(img(i, 1:D2-1)~=img(i, 2:D2)); % process each transition in direction 1 for i2 = 1:length(ind) n1 = [i-.5 ind(i2)+.5]; n2 = [i+.5 ind(i2)+.5]; ind1 = find(ismember(nodes, n1, 'rows')); ind2 = find(ismember(nodes, n2, 'rows')); if isempty(ind1) nodes = [nodes; n1]; %#ok ind1 = size(nodes, 1); end if isempty(ind2) nodes = [nodes; n2]; %#ok ind2 = size(nodes, 1); end edges(size(edges, 1)+1, 1:2) = [ind1(1) ind2(1)]; end end % second direction for image for i=1:D2 % find transitions between the two phases ind = find(img(1:D1-1, i)~=img(2:D1, i)); % process each transition in direction 1 for i2 = 1:length(ind) n1 = [ind(i2)+.5 i-.5]; n2 = [ind(i2)+.5 i+.5]; ind1 = find(ismember(nodes, n1, 'rows')); ind2 = find(ismember(nodes, n2, 'rows')); if isempty(ind1) nodes = [nodes; n1]; %#ok ind1 = size(nodes, 1); end if isempty(ind2) nodes = [nodes; n2]; %#ok ind2 = size(nodes, 1); end edges(size(edges, 1)+1, 1:2) = [ind1(1) ind2(1)]; end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/graphRadius.m0000644000000000000000000000013214055375162017617 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/graphRadius.m0000644000175000017500000000524114055375162020706 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function r = graphRadius(v, e, l) %GRAPHRADIUS Radius of a graph. % % R = graphRadius(V, E) % Computes the radius of the graph given by V and E. The radius of the % graph is the smallest eccentricity over all vertices in the graph. % % R = graphRadius(V, E, L) % Specifies the weight of each edge for computing the distances. Default % is to consider a weight of 1 for each edge. % % Example % nodes = [20 20;20 50;20 80;50 50;80 20;80 50;80 80]; % edges = [1 2;2 3;2 4;4 6;5 6;6 7]; % figure; drawGraph(nodes, edges); % axis([0 100 0 100]); axis equal; hold on % R = graphRadius(nodes, edges) % R = % 2 % % See Also % grPropagateDistance, grVertexEccentricity % graphCenter, graphDiameter, graphPeripheralVertices % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % ensure there is a valid length array if nargin<3 l = ones(size(e,1), 1); end g = grVertexEccentricity(v, e, l); r = min(g); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/clipGraph.m0000644000000000000000000000013214055375162017257 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/clipGraph.m0000644000175000017500000001657414055375162020361 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = clipGraph(nodes, edges, varargin) %CLIPGRAPH Clip a graph with a rectangular area. % % [N2, E2] = clipGraph(N, E, BOX); % [N2, E2, F2] = clipGraph(N, E, F, BOX); % N is an array ov vertices, E an array of edges, containing indices of % first ans second vertices, and F (optional) is either a matrice or a % cell array containing indices of vertices for each face. % BOX is either a box given as a matrix: [XMIN XMAX;YMIN YMAX], or a row % vector following matlab axis format: [XMIN XMAX YMIN YMAX]. % % Example % % create a simple graph structure % n = [0 60; 40 100; 40 60; 60 40; 100 40; 60 0]; % e = [1 3; 2 3; 3 4; 4 5; 4 6; 5 6]; % figure(1); clf; hold on; % drawGraph(n, e); % axis equal; axis([-10 110 -10 110]); % % clip with a box % box = [10 90 10 90]; % drawBox(box, 'k'); % [n2, e2] = clipGraph(n, e, box); % drawGraphEdges(n2, e2, 'color', 'b', 'linewidth', 2); % % See also % graphs, drawGraph, clipGraphPolygon % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-01-18 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Format inputs % extract input arguments faces = []; if length(varargin)==1 box = varargin{1}; elseif length(varargin)==2 faces = varargin{1}; box = varargin{2}; else error('Wrong number of arguments in clipGraph'); end % uniformization of input for box. box = box'; box = box(:); % accuracy of numeric computations ACC = 1e-14; %% Get bounding lines % get bounds of the box xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % create box corners corners = [ ... xmin ymin; ... xmin ymax; ... xmax ymin; ... xmax ymax]; ... %% Clip the nodes % find nodes inside clipping window insideNodes = ... nodes(:,1)-xmin>ACC & nodes(:,1)-xmaxACC & nodes(:,2)-ymax no clip if in1 && in2 edges2 = [edges2; hashNodes(edges(e, :))']; %#ok hashEdges(e) = size(edges2, 1); continue; end % check that edge is not totally clipped -> no edge if edge(1)-xminACC && edge(3)-xmax>ACC, continue; end if edge(2)-yminACC && edge(4)-ymax>ACC, continue; end % otherwise, we have to clip the edge ! edge = clipEdge(edge, [box(1) box(2); box(3) box(4)]); % display debug info % disp(sprintf('clip edge n°%2d, from %2d to %2d', e, edges(e,1), edges(e,2))); % Node for first vertex if ~in1 nodes2 = [nodes2; edge([1 2])]; %#ok indN1 = size(nodes2, 1); else indN1 = hashNodes(edges(e, 1)); end % Node for second vertex if ~in2 nodes2 = [nodes2; edge([3 4])]; %#ok indN2 = size(nodes2, 1); else indN2 = hashNodes(edges(e, 2)); end % add clipped edge to the list edges2 = [edges2; indN1 indN2]; %#ok hashEdges(e) = size(edges2, 1); end %% Clip the faces faces2 = {}; for f = 1:length(faces) % indices of vertices of current face face = faces{f}; % if the face is not clipped, use directly new indices of nodes face2 = hashNodes(face)'; if ~ismember(0, face2) faces2 = [faces2, {face2}]; %#ok continue; end % At least one vertex is clipped. Here is some more special processing % edges of current face faceEdges = sort([face' face([2:end 1])'], 2); % indices of face edges in edges array indEdges = ismember(edges, faceEdges, 'rows'); % convert to indices of edges in clipped edges array. indEdges with % value=0 correspond to totally clipped edges, and can be removed. indEdges = hashEdges(indEdges); indEdges = indEdges(indEdges~=0); % case of face totally clipped: break and continuue with next face if isempty(indEdges) continue; end % extract indices of vertices of the clipped face face2 = edges2(indEdges, :); face2 = unique(face2(:)); % Test whether one should add one of the corner of the box. poly = [nodes(face, 1) nodes(face, 2)]; ind = inpolygon(corners(:,1), corners(:,2), poly(:,1), poly(:,2)); if sum(ind)>0 nodes2 = [nodes2; corners(ind, :)]; %#ok face2 = [face2; size(nodes2, 1)]; %#ok end % vertices of the face, as points faceNodes = nodes2(face2, :); % sort vertices according to their angle around the centroid [faceNodes, I] = angleSort(faceNodes, centroid(faceNodes)); %#ok % add current face to list of faces faces2 = [faces2, {face2(I)'}]; %#ok end %% Format output arguments % clean up nodes to ensure coord correspond to clipping box. nodes2(:,1) = min(max(nodes2(:,1), box(1)), box(2)); nodes2(:,2) = min(max(nodes2(:,2), box(3)), box(4)); if nargout==2 varargout{1} = nodes2; varargout{2} = edges2; elseif nargout==3 varargout{1} = nodes2; varargout{2} = edges2; varargout{3} = faces2; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grRemoveNode.m0000644000000000000000000000013214055375162017742 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grRemoveNode.m0000644000175000017500000000517314055375162021035 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = grRemoveNode(nodes, edges, node) %GRREMOVENODE Remove a node in a graph. % % usage: % [NODES2 EDGES2] = grRemoveNode(NODES, EDGES, NODE2REMOVE) % remove the node with index NODE2REMOVE from array NODES, and also % remove edges containing the node NODE2REMOVE. % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004: doc % remove all edges connected to the node neighbours = grAdjacentEdges(edges, node); [nodes2, edges2] = grRemoveEdges(nodes, edges, neighbours); %#ok % change edges information, due to the node index shift for i = 1:length(edges2) if edges2(i,1) > node edges2(i,1) = edges2(i,1) - 1; end if edges2(i,2) > node edges2(i,2) = edges2(i,2) - 1; end end % allocate memory dim = size(nodes); nodes2 = zeros(dim(1)-1, 2); % copy nodes information, except the undesired node nodes2(1:node-1, :) = nodes(1:node-1, :); nodes2(node:dim(1)-1, :) = nodes(node+1:dim(1), :); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/gabrielGraph.m0000644000000000000000000000013214055375162017735 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/gabrielGraph.m0000644000175000017500000000663414055375162021033 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = gabrielGraph(pts) %GABRIELGRAPH Gabriel Graph of a set of points. % % EDGES = gabrielGraph(PTS) % Computes the Gabriel graph of the input set of points PTS. The Gabriel % graph is based on the euclidean Delaunay triangulation, and keeps only % edges whose circumcircle does not contain any other input point than % the edge extremities. % % [NODES, EDGES] = gabrielGraph(PTS) % Also returns the initial set of points; % % Example % pts = rand(100, 2); % edges = gabrielGraph(pts); % figure; drawPoint(pts); % hold on; axis([0 1 0 1]); axis equal; % drawGraph(pts, edges); % % See also % graphs, drawGraph, delaunayGraph % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2012-01-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % compute Delaunay triangulation if verLessThan('matlab', '8.1') % Code for versions before R2013a dt = DelaunayTri(pts); %#ok else % Code for versions R2013a and later dt = delaunayTriangulation(pts); end % extract edges (N-by-2 array) eds = dt.edges(); % radius of the circle circumscribed to each edge rads = edgeLength([pts(eds(:,1), :) pts(eds(:,2), :)]) / 2; % extract middle point of each edge midPts = midPoint(pts(eds(:,1), :), pts(eds(:,2), :)); % distance between midpoints and all points % closest points should be edge vertices dists = minDistancePoints(midPts, pts); % geometric tolerance (adapted to point set extent) tol = max(max(pts) - min(pts)) * eps; % keep only edges whose circumcircle does not contain any other point keep = dists >= rads - tol; edges = eds(keep, :); % format output depending on number of output arguments if nargout < 2 varargout = {edges}; else varargout = {pts, edges}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grFaceToPolygon.m0000644000000000000000000000013214055375162020410 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grFaceToPolygon.m0000644000175000017500000000707614055375162021507 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function pts2 = grFaceToPolygon(varargin) %GRFACETOPOLYGON Compute the polygon corresponding to a graph face. % % PTS2 = grFaceToPolygon(NODES, EDGES, FACES, INDF) % PTS2 = grFaceToPolygon(NODES, FACES, INDF) % Where NODES, EDGES, and FACES are internal data of graph, and INDF is % the index of the face to extract. The result is the (ordered) set of % points composing the face. % % % PTS2 = grFaceToPolygon(GRAPH, INDF) % use structure representation for graph. The structure GRAPH must % contain data for fields 'nodes' and 'faces'. % % If several indices face indices are specified, result is a cell array % of polygons. % % The number of columns of PTS2 is the same as for NODES. % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2005-11-30 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 27/07/2007: cleanup code if length(varargin)==2 % argument is a graph structure graph = varargin{1}; nodes = graph.nodes; faces = graph.faces; indf = varargin{2}; elseif length(varargin)==3 % arguments are nodes, faces and indices nodes = varargin{1}; faces = varargin{2}; indf = varargin{3}; elseif length(varargin)==4 % arguments are nodes, edges, faces and indices, we forget edges nodes = varargin{1}; faces = varargin{3}; indf = varargin{4}; end if iscell(faces) % faces is a cell array if length(indf)==1 face = faces{indf}; pts2 = nodes(face, :); else pts2 = cell(length(indf), 1); for i=1:length(indf) face = faces{indf(i)}; pts2{i} = nodes(face, :); end end else % faces is an indices array: all faces have same number of vertices if length(indf)==1 face = faces(indf, :); pts2 = nodes(face, :); else pts2 = cell(length(indf), 1); for i=1:length(indf) face = faces(indf(i), :); pts2{i} = nodes(face, :); end end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grEdgeLengths.m0000644000000000000000000000013214055375162020070 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grEdgeLengths.m0000644000175000017500000000513414055375162021160 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function lengths = grEdgeLengths(nodes, edges, varargin) %GREDGELENGTHS Compute length of edges in a geometric graph. % % LENGTHS = grEdgeLengths(NODES, EDGES) % % Example % % create a basic graph and display it % nodes = [10 10;20 10;10 20;20 20;27 15]; % edges = [1 2;1 3;2 4;2 5;3 4;4 5]; % figure; drawGraph(nodes, edges); % hold on; drawNodeLabels(nodes, 1:5) % axis equal; axis([0 40 0 30]); % % compute list of nodes adjacent to node with index 2 % grEdgeLengths(nodes, edges)' % ans = % 10.0000 10.0000 10.0000 8.6023 10.0000 8.6023 % % See also % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2014-01-13, using Matlab 7.9.0.529 (R2009b) % Copyright 2014 INRA - Cepia Software Platform. nEdges = size(edges, 1); lengths = zeros(nEdges, 1); for iEdge = 1:nEdges ed = edges(iEdge, :); node1 = nodes(ed(1),:); node2 = nodes(ed(2),:); lengths(iEdge) = sqrt(sum((node1 - node2).^2)); end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grRemoveEdge.m0000644000000000000000000000013214055375162017721 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grRemoveEdge.m0000644000175000017500000000420014055375162021002 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges2] = grRemoveEdge(nodes, edges, edge) %GRREMOVEEDGE Remove an edge in a graph. % % [NODES2 EDGES2] = grRemoveEdge(NODES, EDGES, EDGE2REMOVE) % Remove an edge in the edges list, and return the modified graph. % The NODES array is not modified. % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 doc dim = size(edges); edges2 = zeros(dim(1)-1, 2); edges2(1:edge-1, :) = edges(1:edge-1, :); edges2(edge:dim(1)-1, :) = edges(edge+1:dim(1), :); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/graphPeripheralVertices.m0000644000000000000000000000013214055375162022170 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/graphPeripheralVertices.m0000644000175000017500000000535014055375162023260 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function inds = graphPeripheralVertices(v, e, l) %GRAPHPERIPHERALVERTICES Peripheral vertices of a graph. % % INDS = graphPeripheralVertices(V, E) % Return indices of peripheral vertices, that is, vertices whose % eccentricity is maximal and equal to the diameter of the graph. % % INDS = graphPeripheralVertices(V, E, L) % Specify length of each edge. Default is 1 for each edge. % % % Example % nodes = [20 20;20 50;20 80;50 50;80 20;80 50;80 80]; % edges = [1 2;2 3;2 4;4 6;5 6;6 7]; % figure; drawGraph(nodes, edges); % axis([0 100 0 100]); axis equal; hold on % INDP = graphPeripheralVertices(nodes, edges); % INDP = % 1 % 3 % 5 % 7 % % % See Also % grPropagateDistance, grVertexEccentricity % graphCenter, graphDiameter, graphRadius % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % ensure there is a valid length array if nargin<3 l = ones(size(e,1), 1); end g = grVertexEccentricity(v, e, l); inds = find(g==max(g)); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/boundedVoronoi2d.m0000644000000000000000000000013214055375162020570 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/boundedVoronoi2d.m0000644000175000017500000000571014055375162021660 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges, faces] = boundedVoronoi2d(box, germs) %BOUNDEDVORONOI2D Return a bounded voronoi diagram as a graph structure. % % [NODES, EDGES, FACES] = boundedVoronoi2d(BOX, GERMS) % GERMS an array of points with dimension 2 % NODES, EDGES, FACES: usual graph representation, FACES as cell array % % Example % [n, e, f] = boundedVoronoi2d([0 100 0 100], rand(100, 2)*100); % drawGraph(n, e); % % See also % graphs, boundedCentroidalVoronoi2d, clipGraph, clipGraphPolygon % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2007-01-12 % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % uniformize input for box. box = box'; box = box(:); % add points far enough boxSizeX = box(2) - box(1); boxSizeY = box(4) - box(3); farPoints = [... box(2)+2*boxSizeX box(4)+3*boxSizeY;... box(1)-3*boxSizeX box(4)+2*boxSizeY;... box(1)-2*boxSizeX box(3)-3*boxSizeY;... box(2)+3*boxSizeX box(3)-2*boxSizeY;... ]; % extract voronoi vertices and face structure [V, C] = voronoin([germs ; farPoints]); % initialize graph structure, without edges and without faces nodes = V(2:end, :); edges = zeros(0, 2); faces = {}; for i = 1:size(germs, 1) cell = C{i}; cell = cell-1; edges = [edges; sort([cell' cell([2:end 1])'], 2)]; %#ok faces{length(faces)+1} = cell; %#ok end edges = unique(edges, 'rows'); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/knnGraph.m0000644000000000000000000000013214055375162017116 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/knnGraph.m0000644000175000017500000000474014055375162020210 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges = knnGraph(nodes, varargin) %KNNGRAPH Create the k-nearest neighbors graph of a set of points. % % EDGES = knnGraph(NODES) % % Example % nodes = rand(10, 2); % edges = knnGraph(nodes); % drawGraph(nodes, edges); % % See also % graphs % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2008-07-28, using Matlab 7.4.0.287 (R2007a) % Copyright 2008 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % get number of neighbors for each node k = 2; if ~isempty(varargin) k = varargin{1}; end % init size of arrays n = size(nodes, 1); edges = zeros(k*n, 2); % iterate on nodes for i = 1:n dists = distancePoints(nodes(i,:), nodes); [dists, inds] = sort(dists); %#ok for j = 1:k edges(k*(i-1)+j, :) = [i inds(j+1)]; end end % remove double edges edges = unique(sort(edges, 2), 'rows'); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/cvtIterate.m0000644000000000000000000000013214055375162017460 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/cvtIterate.m0000644000175000017500000000733214055375162020552 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cvtIterate(germs, funcPtr, funcArgs, N) %CVTITERATE Update germs of a CVT using random points with given density. % % G2 = cvtIterate(G, FPTR, FARGS, N) % G: inital germs % FPTR: pointer to a function which accept a scalar M and return M random % points with a given distribution % FARGS: arguments to be given to the FPTR function (can be empty) % N: number of random points to generate % % Example % P = randPointDiscUnif(50); % P2 = cvtIterate(P, @randPointDiscUnif, [], 1000); % P3 = cvtIterate(P2, @randPointDiscUnif, [], 1000); % % See also % % % Rewritten from programs found in % http://people.scs.fsu.edu/~burkardt/m_src/cvt/cvt.html % % Reference: % Qiang Du, Vance Faber, and Max Gunzburger, % Centroidal Voronoi Tessellations: Applications and Algorithms, % SIAM Review, Volume 41, 1999, pages 637-676. % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-10-10, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Init % format input if isempty(funcArgs) funcArgs = {}; end % number of germs Ng = size(germs, 1); % initialize centroids with values of germs centroids = germs; % number of updates of each centroid count = ones(Ng, 1); %% random points % generate N random points pts = feval(funcPtr, N, funcArgs{:}); % for each point, determines which germ is the closest ones [dist, ind] = minDistancePoints(pts, germs); %#ok h = zeros(Ng, 1); for i = 1:Ng h(i) = sum(ind==i); end %% Centroids update % add coordinate of each point to closest centroid energy = 0; for j = 1:N centroids(ind(j), :) = centroids(ind(j), :) + pts(j, :); energy = energy + sum ( ( centroids(ind(j), :) - pts(j, :) ).^2); count(ind(j)) = count(ind(j)) + 1; end % estimate coordinate by dividing by number of counts centroids = centroids ./ repmat(count, 1, size(germs, 2)); % normalizes energy by number of sample points energy = energy / N; %% format output varargout{1} = centroids; if nargout > 1 varargout{2} = energy; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/quiverToGraph.m0000644000000000000000000000013214055375162020146 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/quiverToGraph.m0000644000175000017500000000524714055375162021243 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [v, e] = quiverToGraph(x, y, dx, dy) %QUIVERTOGRAPH Converts quiver data to quad mesh. % % [V E] = quiverToGraph(x, y, dx, dy) % x, y, dx and dy are matrices the same dimension, typically ones used % for display using 'quiver'. % V and E are vertex coordinates, and edge vertex indices of the graph % joining end points of vector arrows. % % Example % quiverToGraph % % See also % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-06-16, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % compute vertex coordinates vx = x+dx; vy = y+dy; v = [vx(:) vy(:)]; % index of vertices labels = reshape(1:numel(x), size(x)); % compute indices of vertical edges N1 = numel(labels(1:end-1,:)); vedges = [reshape(labels(1:end-1, :), [N1 1]) reshape(labels(2:end, :), [N1 1])]; % compute indices of horizontal edges N2 = numel(labels(:, 1:end-1)); hedges = [reshape(labels(:, 1:end-1), [N2 1]) reshape(labels(:, 2:end), [N2 1])]; % concatenate horizontal and vertical edges e = [hedges ; vedges]; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grNodeOuterDegree.m0000644000000000000000000000013214055375162020717 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grNodeOuterDegree.m0000644000175000017500000000463714055375162022016 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function degree = grNodeOuterDegree(node, edges) %GRNODEOUTERDEGREE Outer degree of a node in a graph. % % DEG = grNodeOuterDegree(NODE, EDGES); % Returns the outer degree of a node in the given edge list, i.e. the % number of edges emanating from it. % NODE is the index of the node, and EDGES is a liste of couples of % indices (origin and destination node). % % Note: Also works when node is a vector of indices % % See Also: % grNodeDegree, grNodeInnerDegree % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-01-17 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % % HISTORY % 2008-08-07 pre-allocate memory, update doc % allocate memory N = size(node, 1); degree = zeros(N, 1); % compute outer degree of each vertex for i=1:N degree(i) = sum(edges(:,1)==node(i)); end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grVertexEccentricity.m0000644000000000000000000000013214055375162021522 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grVertexEccentricity.m0000644000175000017500000000566114055375162022617 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function g = grVertexEccentricity(v, e, l, inds) %GRVERTEXECCENTRICITY Eccentricity of vertices in the graph. % % G = grVertexEccentricity(V, E, L) % V is the array of vertices % E is the array of edges % L is a column vector containing length of each edge (assumes 1 for each % edge if not specified). % G is the maximal geodesic length of each vertex. % % G = grVertexEccentricity(V, E, L, INDV) % Compute eccentricity only for vertices whose index is given in INDV. % % Example % nodes = [20 20;20 50;20 80;50 50;80 20;80 50;80 80]; % edges = [1 2;2 3;2 4;4 6;5 6;6 7]; % figure; drawGraph(nodes, edges); % axis([0 100 0 100]); axis equal; hold on % G = grVertexEccentricity(nodes, edges); % drawNodeLabels(nodes+2, G); % % See Also % graphRadius, graphCenter, graphDiameter, graphPeripheralVertices % grPropagateDistance % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % init result Nv = size(v, 1); g = zeros(Nv, 1); % ensure there is a valid length array if nargin<3 l = ones(size(e,1), 1); end if nargin<4 inds = 1:Nv; end % compuite maximal geodesic length for each vertex for i=1:Nv g(i) = max(grPropagateDistance(v, e, inds(i), l)); end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawDirectedEdges.m0000644000000000000000000000013214055375162020717 xustar0030 mtime=1622538866.106813462 30 atime=1622538866.106813462 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawDirectedEdges.m0000644000175000017500000000631514055375162022011 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawDirectedEdges(p, e, varargin) %DRAWDIRECTEDEDGES Draw edges with arrow indicating direction. % % usage: % drawDirectedEdges(NODES, EDGES); % % drawDirectedEdges(NODES, EDGES, STYLE); % specifies style of arrrows. Can be one of: % 'left' % 'right' % 'arrow' % 'triangle' % 'fill' % % drawDirectedEdges(NODES, EDGES, STYLE, DIRECT) : also specify the base % direction of all edges. DIRECT is true by default. If DIRECT is false % all edges are inverted. % % H = drawDirectedEdges(NODES, EDGES) : return handles to each of the % lines created. % % TODO: now only style 'arrow' is implemented ... % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 12/03/2003. % % HISTORY b=1; if ~isempty(varargin) b = varargin{1}; end h = zeros(length(e),1); hold on; for l=1:length(e) p1 = e(l, 1); p2 = e(l, 2); h(l*4) = line([p(p1,1) p(p2,1)], [p(p1,2) p(p2,2)]); % position of middles of edge xm = (p(p1,1) + p(p2,1))/2; ym = (p(p1,2) + p(p2,2))/2; % orientation of edge theta = atan2(p(p2,2) - p(p1,2), p(p2,1) - p(p1,1)) + (b==0)*pi; % pin of the arrow xa0 = xm + 10*cos(theta); ya0 = ym + 10*sin(theta); % right side of the arrow xa1 = xm + 3*cos(theta-pi/2); ya1 = ym + 3*sin(theta-pi/2); % left side of the arrow xa2 = xm + 3*cos(theta+pi/2); ya2 = ym + 3*sin(theta+pi/2); h(l*4+1) = line([xa1 xa0], [ya1 ya0]); h(l*4+2) = line([xa2 xa0], [ya2 ya0]); end if nargout==1 varargout(1) = {h}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMergeNodes.m0000644000000000000000000000013214055375162017727 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMergeNodes.m0000644000175000017500000000517314055375162021022 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges] = grMergeNodes(nodes, edges, mnodes) %GRMERGENODES Merge two (or more) nodes in a graph. % % usage: % [NODES2 EDGES2] = grMergeNodes(NODES, EDGES, NODE_INDS) % NODES and EDGES are wo arrays representing a graph, and NODE_INDS is % the set of indices of the nodes to merge. % The nodes corresponding to indices in NODE_INDS are removed from the % list, and edges between two nodes are removed. % % Example: merging of lables 1 and 2 % Edges: Edges2: % [1 2] [1 3] % [1 3] [1 4] % [1 4] [3 4] % [2 3] % [3 4] % % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 30/06/2004. % refNode = mnodes(1); mnodes = mnodes(2:length(mnodes)); % replace merged nodes references by references to refNode edges(ismember(edges, mnodes))=refNode; % remove "loop edges" from and to reference node edges = edges(edges(:,1) ~= refNode | edges(:,2) ~= refNode, :); % format output edges = sortrows(unique(sort(edges, 2), 'rows')); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/graphCenter.m0000644000000000000000000000013214055375162017610 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/graphCenter.m0000644000175000017500000000536214055375162020703 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function center = graphCenter(v, e, l) %GRAPHCENTER Center of a graph. % % CENTER = graphCenter(V, E) % Computes the center of the graph given by V and E. The center of the % graph is the set of vertices whose eccentricity is minimal. The % function returns indices of center vertices. % % CENTER = graphCenter(V, E, L) % Specifies the weight of each edge for computing the distances. Default % is to consider a weight of 1 for each edge. % % Example % nodes = [20 20;20 50;20 80;50 50;80 20;80 50;80 80]; % edges = [1 2;2 3;2 4;4 6;5 6;6 7]; % figure; drawGraph(nodes, edges); % axis([0 100 0 100]); axis equal; hold on % C = graphCenter(nodes, edges) % C = % 4 % % See Also % grPropagateDistance, grVertexEccentricity % graphRadius, graphDiameter, graphPeripheralVertices % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % ensure there is a valid length array if nargin<3 l = ones(size(e,1), 1); end g = grVertexEccentricity(v, e, l); center = find(g==min(g)); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/delaunayGraph.m0000644000000000000000000000013214055375162020132 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/delaunayGraph.m0000644000175000017500000000604014055375162021217 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [points, edges] = delaunayGraph(points, varargin) %DELAUNAYGRAPH Graph associated to Delaunay triangulation of input points. % % [NODES, EDGES] = delaunayGraph(POINTS) % Compute the Delaunay triangulation of the set of input points, and % convert to a set of edges. The output NODES is the same as the input % POINTS. % % Example % % Draw a planar graph correpspionding to Delaunay triangulation % points = rand(30, 2) * 100; % [nodes, edges] = delaunayGraph(points); % figure; % drawGraph(nodes, edges); % % % Draw a 3D graph corresponding to Delaunay tetrahedrisation % points = rand(20, 3) * 100; % [nodes, edges] = delaunayGraph(points); % figure; % drawGraph(nodes, edges); % view(3); % % See Also % delaunay, delaunayn, delaunayTriangulation % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2011-05-19, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % compute triangulation tri = delaunayn(points, varargin{:}); % number of simplices (triangles), and of vertices by simplex (3 in 2D) nt = size(tri, 1); nv = size(tri, 2); % allocate memory edges = zeros(nt * nv, 2); % compute edges of each simplex for i = 1:nv-1 edges((1:nt) + (i-1)*nt, :) = sort([tri(:, i) tri(:, i+1)], 2); end edges((1:nt) + (nv-1)*nt, :) = sort([tri(:, end) tri(:, 1)], 2); % remove multiple edges edges = unique(edges, 'rows'); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawGraphEdges.m0000644000000000000000000000013214055375162020235 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawGraphEdges.m0000644000175000017500000000767414055375162021340 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawGraphEdges(varargin) % Draw edges of a graph. % % drawGraphEdges(NODES, EDGES) % Draws a graph specified by a set of nodes (array N-by-2 or N-by-3, % corresponding to coordinate of each node), and a set of edges (an array % Ne-by-2, containing to the first and the second node of each edge). % % drawGraphEdges(..., SEDGES) % Specifies the draw mode for each element, as in the classical 'plot' % function. % Default drawing is a blue line for edges. % % % H = drawGraphEdges(...) % Returns handle to the set of edges. % % See also % graphs, drawGraph, fillGraphFaces % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2005-11-24 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY %% Input argument processing % initialisations e = []; % check input arguments number if nargin == 0 help drawGraphEdges; return; end % extract handle of axis to draw on if isAxisHandle(varargin{1}) ax = varargin{1}; varargin(1) = []; else ax = gca; end % First extract the graph structure var = varargin{1}; if iscell(var) % TODO: should consider array of graph structures. % graph is stored as a cell array: first cell is nodes, second one is % edges, and third one is faces n = var{1}; if length(var) > 1 e = var{2}; end varargin(1) = []; elseif isstruct(var) % graph is stored as a structure, with fields 'nodes', 'edges' n = var.nodes; e = var.edges; varargin(1) = []; else % graph is stored as set of variables: nodes + edges n = varargin{1}; e = varargin{2}; varargin(1:2) = []; end % check if there are edges to draw if size(e, 1) == 0 return; end % setup default drawing style if not specified if isempty(varargin) varargin = {'-b'}; end %% main drawing processing if size(n, 2) == 2 % Draw 2D edges x = [n(e(:,1), 1) n(e(:,2), 1)]'; y = [n(e(:,1), 2) n(e(:,2), 2)]'; he = plot(ax, x, y, varargin{:}); elseif size(n, 2) == 3 % Draw 3D edges x = [n(e(:,1), 1) n(e(:,2), 1)]'; y = [n(e(:,1), 2) n(e(:,2), 2)]'; z = [n(e(:,1), 3) n(e(:,2), 3)]'; he = plot3(ax, x, y, z, varargin{:}); end %% format output arguments if nargout == 1 varargout = {he}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grAdjacentNodes.m0000644000000000000000000000013214055375162020401 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grAdjacentNodes.m0000644000175000017500000000563614055375162021500 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function nodes2 = grAdjacentNodes(edges, node) %GRADJACENTNODES Find list of nodes adjacent to a given node. % % NEIGHS = grAdjacentNodes(EDGES, NODE) % EDGES: the complete edges list (containing indices of neighbor nodes) % NODE: index of the node % NEIGHS: the nodes adjacent to the given node. % % NODE can also be a vector of node indices, in this case the result is % the set of neighbors of any input node, excluding the input nodes. % % Example % % create a basic graph and display it % nodes = [10 10;20 10;10 20;20 20;27 15]; % edges = [1 2;1 3;2 4;2 5;3 4;4 5]; % figure; drawGraph(nodes, edges); % hold on; drawNodeLabels(nodes, 1:5) % axis equal; axis([0 40 0 30]); % % compute list of nodes adjacent to node with index 2 % grAdjacentNodes(edges, 2) % ans = % 1 % 4 % 5 % % See Also % grAdjacentEdges % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 16/08/2004. % % HISTORY % 10/02/2004 documentation % 13/07/2004 faster algorithm % 03/10/2007 can specify several input nodes % 20/01/2013 rename from grNeighborNodes to grAdjacentNodes [i, j] = find(ismember(edges, node)); %#ok nodes2 = edges(i,1:2); nodes2 = unique(nodes2(:)); nodes2 = sort(nodes2(~ismember(nodes2, node))); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/euclideanMST.m0000644000000000000000000000013214055375162017663 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/euclideanMST.m0000644000175000017500000000727114055375162020757 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = euclideanMST(points) %EUCLIDEANMST Build euclidean minimal spanning tree of a set of points. % % EDGES = euclideanMST(POINTS) % POINTS is a [NxP] array, N being the number of points and P being the % dimension. % Result EDGES is a [Mx2] array, containing indices of each vertex for % each edges. % % [EDGES DISTS] = euclideanMST(POINTS) % Also returns the lengths of edges computed by MST algorithm. % % Algorithm first computes Delaunay triangulation of the set of points, % then computes euclidean length of each edge of triangulation, and % finally uses prim algorithm to simplify the graph. % % Example % % choose random points in the plane and display their Euclidean MST % pts = rand(50, 2)*100; % edges = euclideanMST(pts); % drawGraph(pts, edges) % % See also % prim_mst, distancePoints, delaunayn % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-07-27, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % dimension D = size(points, 2); Df = factorial(D); % compute all couples of vertices in unit triangle, tetrahedron, or n-dim % simplex subs = zeros(Df, 2); k = 1; for i = 1:D for j = i+1:D+1 subs(k, 1) = i; subs(k, 2) = j; k = k + 1; end end % compute delaunay triangulation in D dimensions tri = delaunayn(points); Nt = size(tri, 1); % compute all possible edges edges = zeros(Nt*Df, 2); for t = 1:Nt for i = 1:Df edges((t-1)*Df+i, 1) = tri(t, subs(i, 1)); edges((t-1)*Df+i, 2) = tri(t, subs(i, 2)); end end % simplify edges edges = unique(sort(edges, 2), 'rows'); % compute euclidean length of each edge val = zeros(size(edges, 1), 1); for i = 1:size(edges,1) val(i) = distancePoints(points(edges(i,1), :), points(edges(i,2), :)); end % compute MST of created graph [edges2, vals2] = prim_mst(edges, val); % process output arguments if nargout == 1 varargout{1} = edges2; elseif nargout==2 varargout{1} = edges2; varargout{2} = vals2; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawSquareMesh.m0000644000000000000000000000013214055375162020301 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawSquareMesh.m0000644000175000017500000000474414055375162021377 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawSquareMesh(nodes, edges, faces, varargin) %#ok %DRAWSQUAREMESH Draw a 3D square mesh given as a graph. % % drawSquareMesh(NODES, EDGES, FACES) % Draw the mesh defined by NODES, EDGES and FACES. FACES must be a N-by-4 % array of vertex indices. % % See Also % boundaryGraph, drawGraph % % --------- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 28/06/2004. % % input size check up if size(faces, 2) ~= 4 error('Requires a face array with 4 columns'); end % number of faces Nf = size(faces, 1); % allocate memory for vertex coordinates px = zeros(4, Nf); py = zeros(4, Nf); pz = zeros(4, Nf); % initialize vertex coordinates of each face for f = 1:Nf face = faces(f, 1:4); px(1:4, f) = nodes(face, 1); py(1:4, f) = nodes(face, 2); pz(1:4, f) = nodes(face, 3); end p = patch(px, py, pz, 'r'); if nargout > 0 varargout = {p}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/gcontour3d.m0000644000000000000000000000013214055375162017435 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/gcontour3d.m0000644000175000017500000001254714055375162020533 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges, faces] = gcontour3d(img) %GCONTOUR3D Create contour graph of a 3D binary image. % % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 28/06/2004. % nodes = zeros([0 3]); % 3 coordinates vertices edges = zeros([0 2]); % first node and second nodes faces = zeros([0 4]); % indices of 4 corners of each square face D1 = size(img, 1); D2 = size(img, 2); D3 = size(img, 3); % first direction for image for y = 1:D2 for z = 1:D3 % find transitions between the two phases ind = find(img(1:D1-1, y, z)~=img(2:D1, y, z)); % process each transition in direction 1 for i2 = 1:length(ind) % coordinates of each node n1 = [ind(i2)+.5 y-.5 z-.5]; n2 = [ind(i2)+.5 y-.5 z+.5]; n3 = [ind(i2)+.5 y+.5 z+.5]; n4 = [ind(i2)+.5 y+.5 z-.5]; % add the face (and edges) with the 4 given nodes [nodes, edges, faces] = addFace(nodes, edges, faces, [n1; n2; n3; n4]); end end end % second direction for image for x=1:D1 for z=1:D3 % find transitions between the two phases ind = find(img(x, 1:D2-1, z)~=img(x, 2:D2, z)); % process each transition in direction 1 for i2 = 1:length(ind) % coordinates of each node n1 = [x-.5 ind(i2)+.5 z-.5]; n2 = [x-.5 ind(i2)+.5 z+.5]; n3 = [x+.5 ind(i2)+.5 z+.5]; n4 = [x+.5 ind(i2)+.5 z-.5]; % add the face (and edges) with the 4 given nodes [nodes, edges, faces] = addFace(nodes, edges, faces, [n1; n2; n3; n4]); end end end % third direction for image for x=1:D1 for y=1:D2 % find transitions between the two phases ind = find(img(x, y, 1:D3-1)~=img(x, y, 2:D3)); % process each transition in direction 1 for i2 = 1:length(ind) % coordinates of each node n1 = [x-.5 y-.5 ind(i2)+.5]; n2 = [x-.5 y+.5 ind(i2)+.5]; n3 = [x+.5 y+.5 ind(i2)+.5]; n4 = [x+.5 y-.5 ind(i2)+.5]; % add the face (and edges) with the 4 given nodes [nodes, edges, faces] = addFace(nodes, edges, faces, [n1; n2; n3; n4]); end end end return; function [nodes, edges, faces] = addFace(nodes, edges, faces, faceNodes) % add given nodes and coresponding face to the graph. n1 = faceNodes(1,:); n2 = faceNodes(2,:); n3 = faceNodes(3,:); n4 = faceNodes(4,:); % search indices of each nodes ind1 = find(ismember(nodes, n1, 'rows')); ind2 = find(ismember(nodes, n2, 'rows')); ind3 = find(ismember(nodes, n3, 'rows')); ind4 = find(ismember(nodes, n4, 'rows')); % if nodes are not in the list, we add them if isempty(ind1) nodes = [nodes; n1]; ind1 = size(nodes, 1); end if isempty(ind2) nodes = [nodes; n2]; ind2 = size(nodes, 1); end if isempty(ind3) nodes = [nodes; n3]; ind3 = size(nodes, 1); end if isempty(ind4) nodes = [nodes; n4]; ind4 = size(nodes, 1); end % add current face to the list faces(size(faces, 1)+1, 1:4) = [ind1(1) ind2(1) ind3(1) ind4(1)]; % create edges of the face % (first index is the smallest one, by convention) e1 = [min(ind1, ind2) max(ind1, ind2)]; e2 = [min(ind2, ind3) max(ind2, ind3)]; e3 = [min(ind3, ind4) max(ind3, ind4)]; e4 = [min(ind4, ind1) max(ind4, ind1)]; % if nodes are not in the list, we add them if isempty(find(ismember(edges, e1, 'rows'), 1)) edges = [edges; e1]; end if isempty(find(ismember(edges, e2, 'rows'), 1)) edges = [edges; e2]; end if isempty(find(ismember(edges, e3, 'rows'), 1)) edges = [edges; e3]; end if isempty(find(ismember(edges, e4, 'rows'), 1)) edges = [edges; e4]; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/addSquareFace.m0000644000000000000000000000013214055375162020036 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/addSquareFace.m0000644000175000017500000000664214055375162021133 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges, faces] = addSquareFace(nodes, edges, faces, faceNodes) %ADDSQUAREFACE Add a (square) face defined from its vertices to a graph. % % [N2 E2 F2] = addSquareFace(N, E, F, FN) % Add a new face, defined by the nodes indices FN, to the graph defined % by node list N, edge list E, and face list F. % Edges of the face are also added, if they are not already present in % the edge list. % % See Also % patchGraph, boundaryGraph % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 28/06/2004. % n1 = faceNodes(1,:); n2 = faceNodes(2,:); n3 = faceNodes(3,:); n4 = faceNodes(4,:); % search indices of each nodes ind1 = find(ismember(nodes, n1, 'rows')); ind2 = find(ismember(nodes, n2, 'rows')); ind3 = find(ismember(nodes, n3, 'rows')); ind4 = find(ismember(nodes, n4, 'rows')); % if nodes are not in the list, we add them if isempty(ind1) nodes = [nodes; n1]; ind1 = size(nodes, 1); end if isempty(ind2) nodes = [nodes; n2]; ind2 = size(nodes, 1); end if isempty(ind3) nodes = [nodes; n3]; ind3 = size(nodes, 1); end if isempty(ind4) nodes = [nodes; n4]; ind4 = size(nodes, 1); end % add current face to the list faces(size(faces, 1)+1, 1:4) = [ind1(1) ind2(1) ind3(1) ind4(1)]; % create edges of the face % (first index is the smallest one, by convention) e1 = [min(ind1, ind2) max(ind1, ind2)]; e2 = [min(ind2, ind3) max(ind2, ind3)]; e3 = [min(ind3, ind4) max(ind3, ind4)]; e4 = [min(ind4, ind1) max(ind4, ind1)]; % search edge indices in the list % if nodes are not in the list if isempty(ismember(edges, e1, 'rows')) edges = [edges; e1]; end if isempty(ismember(edges, e2, 'rows')) edges = [edges; e2]; end if isempty(ismember(edges, e3, 'rows')) edges = [edges; e3]; end if isempty(ismember(edges, e4, 'rows')) edges = [edges; e4]; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/graph2Contours.m0000644000000000000000000000013214055375162020266 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/graph2Contours.m0000644000175000017500000000701014055375162021351 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = graph2Contours(nodes, edges) %#ok %GRAPH2CONTOURS Convert a graph to a set of contour curves. % % CONTOURS = GRAPH2CONTOURS(NODES, EDGES) % NODES, EDGES is a graph representation (type "help graphs" for details) % The algorithm assume every node has degree 2, and the set of edges % forms only closed loops. The result is a list of indices arrays, each % array containing consecutive point indices of a contour. % % To transform contours into drawable curves, please use : % CURVES{i} = NODES(CONTOURS{i}, :); % % % NOTE : contours are not oriented. To manage contour orientation, edges % also need to be oriented. So we must precise generation of edges. % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 05/08/2004. % curves = {}; c = 0; while size(edges,1)>0 % find first point of the curve n0 = edges(1,1); curve = n0; % second point of the curve n = edges(1,2); e = 1; while true % add current point to the curve curve = [curve n]; %#ok % remove current edge from the list edges = edges((1:size(edges,1))~=e,:); % find index of edge containing reference to current node e = find(edges(:,1)==n | edges(:,2)==n); e = e(1); % get index of next current node % (this is the other node of the current edge) if edges(e,1)==n n = edges(e,2); else n = edges(e,1); end % if node is same as start node, loop is closed, and we stop % node iteration. if n==n0 break; end end % remove the last edge of the curve from edge list. edges = edges((1:size(edges,1))~=e,:); % add the current curve to the list, and start a new curve c = c+1; curves{c} = curve; %#ok end if nargout == 1 varargout = {curves}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMergeNodeClusters.m0000644000000000000000000000013214055375162021271 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMergeNodeClusters.m0000644000175000017500000000676514055375162022374 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = grMergeNodeClusters(nodes, edges) %GRMERGENODECLUSTERS Merge cluster of connected nodes in a graph. % % grMergeNodeClusters(nodes, edges) % Detects groups of nodes that belongs to the same global node, and % replace them by a unique node. Coordinates of reference node is given % by the median coordinates of cluster nodes. % % This function is intended to be used as filter after a binary image % skeletonization and vectorization. % % % See Also % grMergeNodesMedian % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY %% Initialization % intialize result nodes2 = nodes; edges2 = edges; % compute degree of each node degrees = grNodeDegree(1:size(nodes, 1), edges)'; % find index of multiple nodes indMul = find(degrees > 2); % indices of edges that link several multiple nodes indEdges = sum(ismember(edges, indMul), 2) == 2; % associate a label to each cluster labels = grLabel(nodes, edges(indEdges, :)); clusterLabels = unique(labels(indMul)); %% Replace each cluster by median point % iterate on clusters for i = 1:length(clusterLabels) % indices of nodes of the current cluster inds = find(labels == clusterLabels(i)); % coordinates of new reference node clusterNodes = nodes(inds, :); medianNode = median(clusterNodes, 1); % replace coordinates of reference node refNode = min(inds); nodes2(refNode, :) = medianNode; % replace node indices in edge array edges2(ismember(edges2, inds)) = refNode; end %% Clean up % keep only relevant nodes inds = unique(edges2(:)); nodes2 = nodes2(inds, :); % relabeling of edges for i = 1:length(inds) edges2(edges2 == inds(i)) = i; end % remove double edges edges2 = unique(sort(edges2, 2), 'rows'); % remove 'loops' edges2(edges2(:,1) == edges2(:,2), :) = []; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawGraph.m0000644000000000000000000000013214055375162017265 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawGraph.m0000644000175000017500000002116014055375162020352 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawGraph(varargin) %DRAWGRAPH Draw a graph, given as a set of vertices and edges. % % drawGraph(NODES, EDGES) % Draws a graph specified by a set of nodes (array N-by-2 or N-by-3, % corresponding to coordinate of each node), and a set of edges (an array % NE-by-2, containing for each edge the first and the second node). % Default drawing is a red circle for nodes and a blue line for edges. % % drawGraph(NODES, EDGES, FACES) % Also draws faces of the graph as patches. % % drawGraph(GRAPH) % Passes argument in a srtucture with at least 2 fields named 'nodes' and % 'edges', and possibly one field 'faces', corresponding to previously % described parameters. % GRAPH can also be a cell array, whose first element is node array, % second element is edges array, and third element, if present, is faces % array. % % % drawGraph(..., SNODES) % drawGraph(..., SNODES, SEDGES) % drawGraph(..., SNODES, SEDGES, SFACES) % Specifies the draw mode for each element, as in the classical 'plot' % function. To not display some elements, uses 'none'. % % % H = drawGraph(...) % Returns handle to the set of edges. % % [HN, HE] = drawGraph(...) % Returns handle to the set of nodes and to the set of edges. % % [HN, HE, HF] = drawGraph(...) % Also returns handle to the set of faces. % % See Also % graphs, drawGraphEdges, fillGraphFaces, clipGraph, clipGraphPolygon % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/07/2003. % % HISTORY % 10/02/2004 : documentation % 06/04/2004 : change name % 09/07/2004 : add faces % 05/08/2004 : correct bug when drawing 2D graph % 06/08/2004 : small bug for drawing poins (length instead of size(.,1)) % 09/08/2004 : rewrite code (separate 2D and 3D, use of plot instead of % line, manage faces if present in 2D and 3D, ...), add style % management, various input types, and documentation % 22/09/2004 : correct bug in drawing faces % 11/11/2005 : forgot a loop index for faces stored as cells % 22/05/2009 add more drawing options %% initialisations % uses empty arrays by default for edges and faces e = []; f = []; % default styles for nodes, edges, and faces % nodes are drawn as red circles sn = {'linestyle', 'none', 'color', 'r', 'marker', 'o'}; % edges are drawn as blue lines se = {'linestyle', '-', 'color', 'b'}; % faces are cyan, their edges are not drawn sf = {'EdgeColor', 'none', 'Facecolor', 'c'}; %% Process input arguments % case of a call without arguments if nargin == 0 help drawGraph; return; end % --------------------------------------------------------------- % First extract the graph structure var = varargin{1}; if iscell(var) % graph is stored as a cell array: first cell is nodes, second one is % edges, and third is faces n = var{1}; if length(var)>1 e = var{2}; end if length(var)>2 f = var{3}; end varargin(1) = []; elseif isstruct(var) % graph is stored as a structure, with fields 'nodes', 'edges', and % eventually 'faces'. n = var.nodes; e = var.edges; if isfield(var, 'faces') f = var.faces; end varargin(1) = []; else % graph is stored as set of variables: nodes, edges, and eventually % faces n = varargin{1}; e = varargin{2}; varargin(1:2) = []; if ~isempty(varargin) var = varargin{1}; if isnumeric(var) % faces are stored in a numeric array of indices f = var; varargin(1) = []; elseif iscell(var) if ~ischar(var{1}) % faces are stored in a cell array, each cell containing a % row vector of indices f = var; varargin(1) = []; end end end end % extract drawing style if ~isempty(varargin) sn = concatArguments(sn, varargin{1}); end if length(varargin)>1 se = concatArguments(se, varargin{2}); end if length(varargin)>2 sf = concatArguments(sf, varargin{3}); end %% Main drawing processing hold on; if size(n, 2) == 2 % Draw a 2 dimensional graph ---------------------- % Draw faces of the graph ------------ if ~strcmp(sf{1}, 'none') && ~isempty(f) if iscell(f) % each face is contained in a cell. hf = zeros(size(f)); for fi = 1:length(f) hf(fi) = patch('Faces', f{fi}, 'Vertices', n, sf{:}); end else % process faces as an Nf*N array. Nf is the number of faces, % and all faces have the same number of vertices (nodes). hf = patch('Faces', f, 'Vertices', n, sf{:}); end end % Draw 2D Edges ---------------------- if ~strcmp(se{1}, 'none') && size(e, 1) > 0 he = plot([n(e(:,1),1) n(e(:,2),1)]', [n(e(:,1),2) n(e(:,2),2)]', se{:}); end % Draw 2D nodes ---------------------- if ~strcmp(sn{1}, 'none') hn = plot(n(:,1), n(:,2), sn{:}); end elseif size(n, 2)==3 % Draw a 3 dimensional graph ---------------------- % use a zbuffer to avoid display pbms. set(gcf, 'renderer', 'zbuffer'); % Draw 3D Faces ---------------------- if ~strcmp(sf{1}, 'none') if iscell(f) % each face is contained in a cell. hf = zeros(size(f)); for fi = 1:length(f) hf(fi) = patch('Faces', f{fi}, 'Vertices', n, sf{:}); end else % process faces as an Nf*N array. Nf i the number of faces, % and all faces have the same number of vertices (nodes). hf = patch('Faces', f, 'Vertices', n, sf{:}); end end % Draw 3D edges ---------------------- if ~strcmp(se{1}, 'none') && size(e, 1) > 0 he = line(... [n(e(:,1),1) n(e(:,2),1)]', ... [n(e(:,1),2) n(e(:,2),2)]', ... [n(e(:,1),3) n(e(:,2),3)]', ... se{:}); end % Draw 3D nodes ---------------------- if ~strcmp(sn{1}, 'none') hn = plot3(n(:,1), n(:,2), n(:,3), sn{:}); end end %% Format output arguments % return handle to edges if nargout==1 varargout{1} = he; end % return handle to nodes and edges if nargout==2 varargout{1} = hn; varargout{2} = he; end % return handle to nodes, edges and faces if nargout==3 varargout{1} = hn; varargout{2} = he; varargout{3} = hf; end end function res = concatArguments(in1, in2) % in1 is a cell array already initialized % in2 is an argument that can be: % - empty % - the string 'none' % - another cell array if isempty(in2) res = in1; return; end if ischar(in2) if strcmp('none', in2) res = {'none'}; return; end end if iscell(in1) res = [in1(:)' in2(:)']; else res = [{in1} in2(:)]; end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grShortestPath.m0000644000000000000000000000013214055375162020327 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grShortestPath.m0000644000175000017500000001546614055375162021430 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodePath, edgePath] = grShortestPath(nodes, edges, ind0, ind1, edgeWeights) %GRSHORTESTPATH Find a shortest path between two nodes in the graph. % % PATH = grShortestPath(NODES, EDGES, NODE1, NODE2, WEIGHTS) % NODES and EDGES defines the graph, NODE1 and NODE2 are indices of the % node extremities, and WEIGHTS is the set of weights associated to each % edge. % The function returns a set of node indices. % % PATH = grShortestPath(NODES, EDGES, NODEINDS, WEIGHTS) % Specifies two or more points that must be traversed by the path, in the % specified order. % % % Create a simple tree graph, and compute shortest path % [x y] = meshgrid([10 20 30], [10 20 30]); % nodes = [x(:) y(:)]; % edges = [1 2;2 3;2 5;3 6; 4 5;4 7;5 8; 8 9]; % drawGraph(nodes, edges) % axis equal; axis([0 40 0 40]); % drawNodeLabels(nodes, 1:9) % path = grShortestPath(nodes, edges, 1, 9); % % same as: % path = grShortestPath(nodes, edges, [1 9]); % % See also % graphs, grFindMaximalLengthPath % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % process the case where several node indices are specified in first arg. if length(ind0) > 1 % following optional argument is edge values if exist('ind1', 'var') edgeWeights = ind1; else edgeWeights = ones(size(edges, 1), 1); end % concatenate path pieces nodePath = ind0(1); edgePath = size(0, 2); for i = 2:length(ind0) [node0, edge0] = grShortestPath(nodes, edges, ind0(i-1), ind0(i), edgeWeights); nodePath = [nodePath ; node0(2:end)]; %#ok edgePath = [edgePath ; edge0]; %#ok end return; end % ensure weights are defined if ~exist('edgeWeights', 'var') edgeWeights = ones(size(edges, 1), 1); end % check indices limits nNodes = size(nodes, 1); if max(ind0) > nNodes error('Start index exceed number of nodes in the graph'); end if max(ind1) > nNodes error('End index exceed number of nodes in the graph'); end %% Initialisations % consider infinite distance for all nodes dists = inf * ones(nNodes, 1); % initial node is at distance 0 by definition dists(ind0) = 0; % create an array of indices for the predessor of each node preds = zeros(nNodes, 1); preds(ind0) = 0; % allocate memory to store the subgraph, which is a tree edges2 = zeros(nNodes-1, 2); % create an array of node flags unprocessedNodeInds = 1:nNodes; edgeCount = 0; %% Iterate until all nodes are flagged to 1 while ~isempty(unprocessedNodeInds) % choose unprocessed node with lowest distance [tmp, ind] = min(dists(unprocessedNodeInds)); %#ok ind = unprocessedNodeInds(ind); ind = ind(1); % mark current node as processed unprocessedNodeInds(unprocessedNodeInds == ind) = []; % if the current node is the target, it is not necessary to continue... if ind == ind1 break; end % find the index list of edges incident to current node adjEdgeInds = grAdjacentEdges(edges, ind); % select edges whose opposite node has not yet been processed inds2 = sum(ismember(edges(adjEdgeInds, :), unprocessedNodeInds), 2) > 0; adjEdgeInds = adjEdgeInds(inds2); % iterate over incident edges to update adjacent nodes for iNeigh = 1:length(adjEdgeInds) % extract index of current adjacent node edge = edges(adjEdgeInds(iNeigh), :); adjNodeInd = edge(~ismember(edge, ind)); newDist = dists(ind) + edgeWeights(adjEdgeInds(iNeigh)); % dists(adjNodeInd) = min(dists(adjNodeInd), newDist); if newDist < dists(adjNodeInd) dists(adjNodeInd) = newDist; preds(adjNodeInd) = ind; end end % find the list of adjacent nodes adjNodeInds = unique(edges(adjEdgeInds, :)); adjNodeInds(adjNodeInds == ind) = []; % choose the adjacent nodes with lowest distance, and add the % corresponding edges to the subgraph if ~isempty(adjNodeInds) minDist = min(dists(adjNodeInds)); closestNodeInds = adjNodeInds(dists(adjNodeInds) <= minDist); for iCloseNode = 1:length(closestNodeInds) edgeCount = edgeCount + 1; edges2(edgeCount, :) = [ind closestNodeInds(iCloseNode)]; end end end %% Path creation % create the path: start from end index, and identify successive set of % neighbor edges and nodes nodeInd = ind1; nodePath = nodeInd; edgePath = []; % find predecessors until we reach ind0 node while nodeInd ~= ind0 newNodeInd = preds(nodeInd); nodePath = [nodePath ; newNodeInd]; %#ok % search the edge (both directions) in the list of edges e_tmp = [nodeInd newNodeInd]; [~,edgeInd] = ismember ([e_tmp; e_tmp(end:-1:1)], edges, 'rows'); edgeInd(edgeInd == 0) = []; % erase the one that isn't there edgePath = [edgePath ; edgeInd]; %#ok nodeInd = newNodeInd; end % reverse the path nodePath = nodePath(end:-1:1); edgePath = edgePath(end:-1:1); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/centroidalVoronoi2d_MC.m0000644000000000000000000000013214055375162021653 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/centroidalVoronoi2d_MC.m0000644000175000017500000001770014055375162022745 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [germs, germPaths] = centroidalVoronoi2d_MC(germs, poly, varargin) %CENTROIDALVORONOI2D_MC Centroidal Voronoi tesselation by Monte-Carlo. % % PTS = centroidalVoronoi2d_MC(NPTS, POLY) % Generate points in a polygon based on centroidal voronoi tesselation. % Centroidal germs can be computed by using the Llyod's algorithm: % 1) initial germs are chosen at random within polygon % 2) voronoi polygon of the germs is computed % 3) the centroids of each domain are computed, and used as germs of the % next iteration % % This version uses a Monte-Carlo version of Llyod's algorithm. The % centroids are not computed explicitly, but approximated by sampling N % points within the bounding polygon. % % [PTS, PATHLIST] = centroidalVoronoi2d_MC(NPTS, POLY) % Also returns the path of each germs at each iteration. The result % PATHLIST is a cell array with as many cells as the number of germs, % containing in each cell the successive positions of the germ. % % PTS = centroidalVoronoi2d_MC(.., PARAM, VALUE) % Specify one or several optional arguments. PARAM can be one of: % * 'nIter' specifies the number of iterations of the algorithm % (default is 50) % * 'nPoints' number of points for updating positions of germs at each % iteration. Default is 200 times the number of germs. % * 'verbose' display iteration number. Default is false. % % Example % poly = ellipseToPolygon([50 50 40 30 20], 200); % nGerms = 100; % germs = centroidalVoronoi2d(nGerms, poly); % figure; hold on; % drawPolygon(poly, 'k'); % drawPoint(germs, 'bo'); % axis equal; axis([0 100 10 90]); % % extract regions of the CVD % box = polygonBounds(poly); % [n, e] = boundedVoronoi2d(box, germs); % [n2, e2] = clipGraphPolygon(n, e, poly); % drawGraphEdges(n2, e2, 'b'); % % See also % graphs, boundedVoronoi2d, centroidalVoronoi2d % % Rewritten from programs found in % http://people.scs.fsu.edu/~burkardt/m_src/cvt/cvt.html % % Reference: % Qiang Du, Vance Faber, and Max Gunzburger, % Centroidal Voronoi Tessellations: Applications and Algorithms, % SIAM Review, Volume 41, 1999, pages 637-676. % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-02-23, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. %% Parse input arguments % number of germs if isscalar(germs) nGerms = germs; germs = []; else nGerms = size(germs, 1); end % random point generator % Should be either empty (-> use random generator) or be an instance of % quasi-random sequence generator sucha as haltonset or sobolset. generator = []; % Number of points nPts = 200 * nGerms; % Number of iterations nIter = 50; verbose = false; keepPaths = nargout > 1; while length(varargin) > 1 paramName = varargin{1}; switch lower(paramName) case 'verbose' verbose = varargin{2}; case 'niter' nIter = varargin{2}; case 'npoints' nPts = varargin{2}; case 'generator' generator = varargin{2}; % ensure generator is a stream if isa(generator, 'qrandset') generator = qrandstream(generator); elseif isa(generator, 'qrandstream') % ok, nothing to do... else error('quasi-random generator is not properly specified'); end otherwise error(['Unknown parameter name: ' paramName]); end varargin(1:2) = []; end %% Initialisations % bounding box of polygon box = polygonBounds(poly); % init germs if needed if isempty(germs) if isempty(generator) germs = generatePointsInPoly(nGerms); else germs = generateQRandPointsInPoly(nGerms); end end germIters = cell(nIter, 1); %% Iteration of the Lloyd algorithm for i = 1:nIter if verbose disp(sprintf('Iteration: %d/%d', i, nIter)); %#ok end if keepPaths germIters{i} = germs; end % random uniform points in polygon if verbose disp(' generate points'); end if isempty(generator) points = generatePointsInPoly(nPts); else points = generateQRandPointsInPoly(nPts); end % for each point, determines index of the closest germ if verbose disp(' find closest germ'); end ind = zeros(nPts, 1); for iPoint = 1:nPts x0 = points(iPoint, 1); y0 = points(iPoint, 2); [tmp, ind(iPoint)] = min((germs(:,1)-x0).^2 + (germs(:,2)-y0).^2); %#ok end % update the position of each germ if verbose disp(' update germ position'); end for iGerm = 1:nGerms germs(iGerm,:) = centroid(points(ind == iGerm, :)); end end %% Evenutally compute germs trajectories if nargout > 1 % init germPaths = cell(nGerms, 1); path = zeros(nIter+1, 2); % Iteration on germs for i = 1:nGerms % create path corresponding to germ for j = 1:nIter pts = germIters{j}; path(j,:) = pts(i,:); end path(nIter+1, :) = germs(i,:); germPaths{i} = path; end end function pts = generatePointsInPoly(nPts) % extreme coordinates xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % compute size of box dx = xmax - xmin; dy = ymax - ymin; % allocate memory for result pts = zeros(nPts, 2); % iterate until all points have been sampled within the polygon ind = (1:nPts)'; while ~isempty(ind) NI = length(ind); x = rand(NI, 1) * dx + xmin; y = rand(NI, 1) * dy + ymin; pts(ind, :) = [x y]; ind = ind(~polygonContains(poly, pts(ind, :))); end end function pts = generateQRandPointsInPoly(nPts) % extreme coordinates xmin = box(1); xmax = box(2); ymin = box(3); ymax = box(4); % compute size of box dx = xmax - xmin; dy = ymax - ymin; % allocate memory for result pts = zeros(nPts, 2); % iterate until all points have been sampled within the polygon ind = (1:nPts)'; while ~isempty(ind) NI = length(ind); pts0 = qrand(generator, NI); x = pts0(:, 1) * dx + xmin; y = pts0(:, 2) * dy + ymin; pts(ind, :) = [x y]; ind = ind(~polygonContains(poly, pts(ind, :))); end end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grRemoveNodes.m0000644000000000000000000000013214055375162020125 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grRemoveNodes.m0000644000175000017500000000636714055375162021226 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = grRemoveNodes(nodes, edges, rmNodes) %GRREMOVENODES Remove several nodes in a graph. % % usage: % [NODES2 EDGES2] = grRemoveNodes(NODES, EDGES, NODES2REMOVE) % remove the nodes with indices NODE2REMOVE from array NODES, and also % remove edges containing the nodes NODE2REMOVE. % % Example % nodes = [... % 10 10; 20 10; 30 10; ... % 10 20; 20 20; 30 20]; % edges = [... % 1 2; 1 4; 1 5; ... % 2 3; 2 5; 2 6; ... % 3 6; 4 5; 5 6]; % toRemove = [3 4]; % [nodes2 edges2] = grRemoveNodes(nodes, edges, toRemove); % drawGraph(nodes2, edges2); % axis equal; axis([0 40 0 30]); % % See also % grRemoveEdges % % ----- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 doc % 07/03/2014 rewrite using clearer algorithm %% edges processing % remove all edges connected to one of the nodes to remove edges2 = edges(~any(ismember(edges, rmNodes), 2), :); % change edges information, due to the node index shift for i = 1:length(rmNodes) inds = edges2 > (rmNodes(i) - i + 1); edges2(inds) = edges2(inds) - 1; end %% nodes processing % number of nodes N = size(nodes, 1); NR = length(rmNodes); N2 = N-NR; % allocate memory nodes2 = zeros(N2, 2); % process the first node nodes2(1:rmNodes(1)-1,:) = nodes(1:rmNodes(1)-1,:); for i = 2:NR inds = rmNodes(i-1)+1:rmNodes(i)-1; if isempty(inds) continue; end nodes2(inds - i + 1, :) = nodes(inds, :); end % process the last node nodes2(rmNodes(NR)-NR+1:N2, :) = nodes(rmNodes(NR)+1:N, :); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/cvtUpdate.m0000644000000000000000000000013214055375162017305 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/cvtUpdate.m0000644000175000017500000000654214055375162020401 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = cvtUpdate(germs, points) %CVTUPDATE Update germs of a CVT with given points. % % G2 = cvtUpdate(G, PTS) % G: inital germs % PTS: the points % % Example % G = randPointDiscUnif(50); % P = randPointDiscUnif(10000); % G2 = cvtUpdate(G, P); % % See also % % % Rewritten from programs found in % http://people.scs.fsu.edu/~burkardt/m_src/cvt/cvt.html % % Reference: % Qiang Du, Vance Faber, and Max Gunzburger, % Centroidal Voronoi Tessellations: Applications and Algorithms, % SIAM Review, Volume 41, 1999, pages 637-676. % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-10-10, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. %% Init % number of germs and of points Ng = size(germs, 1); N = size(points, 1); % initialize centroids with values of germs centroids = germs; % number of updates of each centroid count = ones(Ng, 1); %% Generate random points % for each point, determines which germ is the closest ones [dist, ind] = minDistancePoints(points, germs); %#ok h = zeros(Ng, 1); for i = 1:Ng h(i) = sum(ind==i); end %% Centroids update % add coordinate of each point to closest centroid energy = 0; for j = 1:N centroids(ind(j), :) = centroids(ind(j), :) + points(j, :); energy = energy + sum ( ( centroids(ind(j), :) - points(j, :) ).^2); count(ind(j)) = count(ind(j)) + 1; end % estimate coordinate by dividing by number of counts centroids = centroids ./ repmat(count, 1, size(germs, 2)); % normalizes energy by number of sample points energy = energy / N; %% Format output varargout{1} = centroids; if nargout > 1 varargout{2} = energy; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMergeMultipleNodes.m0000644000000000000000000000013214055375162021443 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMergeMultipleNodes.m0000644000175000017500000000773614055375162022545 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grMergeMultipleNodes(varargin) %GRMERGEMULTIPLENODES Simplify a graph by merging multiple nodes. % % OUTPUT = grMergeMultipleNodes(INPUT); % simplify the graph INPUT, and return the result in the graph OUTPUT. % format for input can be one of % nodes, edges % % Two steps in the procedure : % * first remove multiple nodes. find all nodes with same coords, and % keep only one % * remove edges that link same nodes % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 09/08/2004. % %% process input arguments n = []; e = []; f = []; % extract data of the graph var = varargin{1}; if iscell(var) % graph is stored as a cell array : first cell is nodes, second one is % edges, and third is faces n = var{1}; if length(var)>1 e = var{2}; end if length(var)>2 f = var{3}; end elseif isstruct(var) % graph is stored as a structure, with fields 'nodes', 'edges', and % eventually 'faces'. n = var.nodes; e = var.edges; if isfield(var, 'faces') f = var.faces; end elseif length(varargin)>1 % graph is stored as set of variables : nodes, edges, and eventually % faces n = varargin{1}; e = varargin{2}; if length(varargin)==3 f = varargin{3}; end end %% Main processing % simplify graph to remove multiple nodes, and adapt edges and faces % indices % simplify nodes [n, i, j] = unique(n, 'rows'); %#ok % change edges indices and remove double edges (undirected graph) for i = 1:length(e(:)) e(i) = j(e(i)); %#ok end e = unique(sort(e, 2), 'rows'); % change faces indices if iscell(f) % faces stored as cell array (irregular mesh) for k = 1:length(f) face = f{k}; for i = 1:length(face(:)) face(i) = j(face(i)); end f{k} = face; %#ok end else % faces indices stored as regular array (square or triangle mesh). for i = 1:length(f(:)) f(i) = j(f(i)); %#ok end end %% process output depending on how many arguments are needed if nargout == 1 out{1} = n; out{2} = e; varargout{1} = out; end if nargout == 2 varargout{1} = n; varargout{2} = e; end if nargout == 3 varargout{1} = n; varargout{2} = e; varargout{3} = f; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/clipGraphPolygon.m0000644000000000000000000000013214055375162020627 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/clipGraphPolygon.m0000644000175000017500000001216414055375162021720 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = clipGraphPolygon(nodes, edges, poly) %CLIPGRAPHPOLYGON Clip a graph with a polygon. % % [NODES2, EDGES2] = clipGraphPolygon(NODES, EDGES, POLY) % Clips the graph defined by nodes NODES and edges EDGES with the polygon % given in POLY. POLY is a N-by-2 array of vertices. % The result is a new graph containing nodes inside the polygon, as well % as nodes created by the intersection of edges with the polygon. % % Example % elli = [50 50 40 20 30]; % figure; hold on; % drawEllipse(elli, 'k'); % poly = ellipseToPolygon(elli, 200); % box = polygonBounds(poly); % germs = randomPointInPolygon(poly, 100); % drawPoint(germs, 'b.'); % [n, e, f] = boundedVoronoi2d(box, germs); % [n2, e2] = clipGraphPolygon(n, e, poly); % drawGraphEdges(n2, e2); % % See also % graphs, drawGraph, clipGraph % % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2012-02-24, using Matlab 7.9.0.529 (R2009b) % Copyright 2012 INRA - Cepia Software Platform. % Algorithm summary: % * For each edge not outside do: % * clip edge with poly % * if no inter % * add current edge (same vertex indices) % * continue % * end % * add intersections to list, compute their indices % * create the new edge(s) %% Clip the nodes % find index of nodes inside clipping window nodeInside = isPointInPolygon(nodes, poly); innerNodeInds = find(nodeInside); % create correspondance between original nodes and inside nodes nodeIndsMap = zeros(size(nodes, 1), 1); for i = 1:length(innerNodeInds) nodeIndsMap(innerNodeInds(i)) = i; end % select clipped nodes nodes2 = nodes(innerNodeInds, :); %% Clip the edges insideEnds = nodeInside(edges); % allocate memory for edges with at least one vertex inside nEdges2 = sum(sum(insideEnds, 2) ~= 0); % allocate memory for at least edges inside edges2 = zeros(nEdges2, 2); nEdges = size(edges, 1); % index of next edge iEdge2 = 1; % index of next vertex iNode2 = size(nodes2, 1) + 1; % iterate over all edges for iEdge = 1:nEdges % index of edge vertices v1 = edges(iEdge, 1); v2 = edges(iEdge, 2); % compute intersection(s) of current edge with boundary edge0 = [nodes(v1,:) nodes(v2,:)]; intersects = intersectEdgePolygon(edge0, poly); % process edges that do not cross polygon boundary if isempty(intersects) if nodeInside(v1) && nodeInside(v2) % current edge is totally inside the clipping polygon edges2(iEdge2,:) = nodeIndsMap([v1 v2]); iEdge2 = iEdge2 + 1; end continue; end % add intersection(s) to the vertex array nInters = size(intersects, 1); intersectInds = iNode2:iNode2+nInters-1; nodes2(intersectInds,:) = intersects; iNode2 = iNode2 + nInters; % concatenate vertex indices with indices of extremities inside poly if nodeInside(v1) intersectInds = [nodeIndsMap(v1) intersectInds]; %#ok end if nodeInside(v2) intersectInds = [intersectInds nodeIndsMap(v2)]; %#ok end % create new edge for each couple of contiguous intersection while length(intersectInds) > 1 edges2(iEdge2, :) = intersectInds(1:2); intersectInds(1:2) = []; iEdge2 = iEdge2 + 1; end if ~isempty(intersectInds) warning('matGeom:graphs:AlgorithmicError', ... 'edge %d has odd number of intersects', iEdge); end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grFindGeodesicPath.m0000644000000000000000000000013214055375162021037 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grFindGeodesicPath.m0000644000175000017500000000677314055375162022141 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function path = grFindGeodesicPath(nodes, edges, ind0, ind1, edgeWeights) %GRFINDGEODESICPATH Find a geodesic path between two nodes in the graph. % % PATH = grFindGeodesicPath(NODES, EDGES, NODE1, NODE2, WEIGHTS) % NODES and EDGES defines the graph, NODE1 and NODE2 are indices of the % node extremities, and WEIGHTS is the set of weights associated to each % edge. % The function returns a set of edge indices. % % % See also % grFindMaximalLengthPath % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % ensure weights are defined if ~exist('edgeWeights', 'var') edgeWeights = ones(size(edges, 1), 1); end % check indices limits nNodes = size(nodes, 1); if max(ind0) > nNodes error('Start index exceed number of nodes in the graph'); end if max(ind1) > nNodes error('End index exceed number of nodes in the graph'); end % find a vertex opposite to the first extremity dists = grPropagateDistance(nodes, edges, ind0, edgeWeights); % iterate on neighbors of current node: choose next neighbor with smallest % cumulated weight, until we are back on source node path = []; while true % find neighbor with lowest cumulated distance neighs = grAdjacentNodes(edges, ind1); neighDists = dists(neighs); indN = find(neighDists == min(neighDists), 1); ind2 = neighs(indN); if isempty(ind2) warning('graphs:grFindGeodesicPath', ... 'No neighbor node found for node %d, graph may be not connected', ind1); break; end % add edge index to the path indE = find(sum(ismember(edges, [ind1 ind2]), 2) == 2, 1); path = [path indE]; %#ok % test if path is finished or not if ind2 == ind0 break; end ind1 = ind2; end % reverse path direction path = path(end:-1:1); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMedian.m0000644000000000000000000000013214055375162017074 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMedian.m0000644000175000017500000000467514055375162020175 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grMedian(varargin) % Compute median value from neighbour nodes. % % VALS2 = grMedian(EDGES, VALS) % new value for each node of the graph is computed as the median of the % values of neighbours and of old value. % % Example % grMedian % % See also % grMean, grDilate, grErode % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2006-01-20 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin) == 2 edges = varargin{1}; values = varargin{2}; elseif length(varargin) == 3 edges = varargin{2}; values = varargin{3}; else error('Wrong number of arguments in "grMedian"'); end res = zeros(size(values)); uni = unique(edges(:)); for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); res(uni(n)) = median(values([uni(n); neigh])); end varargout{1} = res; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMergeNodesMedian.m0000644000000000000000000000013214055375162021045 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMergeNodesMedian.m0000644000175000017500000000621714055375162022140 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = grMergeNodesMedian(nodes, edges, mnodes) %GRMERGENODESMEDIAN Replace several nodes by their median coordinate. % % [NODES2, EDGES2] = grMergeNodesMedian(NODES, EDGES, NODES2MERGE) % NODES ans EDGES are the graph structure, and NODES2MERGE is the list of % indices of nodes to be merged. % The median coordinate of merged nodes is computed, and all nodes are % merged to this new node. % % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 : documentation % coordinates of reference node x = median(nodes(mnodes, 1)); y = median(nodes(mnodes, 2)); % index of reference node refNode = findPoint([x y], nodes); mnodes = sort(mnodes(mnodes ~= refNode)); for n = 1:length(mnodes) node = mnodes(n); % process each neighbor of the current node neighbors = grAdjacentNodes(edges, node); for e = 1:length(neighbors) edge = neighbors(e); if edges(edge, 1) == refNode || edges(edge, 2) == refNode continue; end % find if the node is referenced as 1 or 2 in the edge, % and replace it with the reference node. if edges(edge, 1) == node edges(edge, 1) = refNode; else edges(edge, 2) = refNode; end end end % remove nodes from the list, except the reference node. for n = 1:length(mnodes) [nodes, edges] = grRemoveNode(nodes, edges, mnodes(n)-n+1); end nodes2 = nodes; edges2 = edges; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/adjacencyListToEdges.m0000644000000000000000000000013214055375162021376 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/adjacencyListToEdges.m0000644000175000017500000000520114055375162022461 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function edges = adjacencyListToEdges(adjList) % Convert an adjacency list to an edge array. % % EDGES = adjacencyListToEdges(ADJ) % Converts the adjacency list ADJ, given as a cell array of adjacent % indices, to an edge array. % % Example % % create adjacency list for a simple graph % adj = {[2 3], [1 4 5], [1 4], [2 3 5], [2 4]}; % edges = adjacencyListToEdges(adj) % edges = % 1 2 % 1 3 % 2 4 % 2 5 % 3 4 % 4 5 % % See also % graphs, polygonSkeletonGraph % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % INRAE - BIA Research Unit - BIBS Platform (Nantes) % Created: 2020-06-02, using Matlab 9.8.0.1323502 (R2020a) % Copyright 2020 INRAE. % TODO: allocate memory % create the connectivity array edges = zeros([0 2]); for iVertex = 1:length(adjList) neighs = adjList{iVertex}; for iNeigh = 1:length(neighs) edge = sort([iVertex neighs(iNeigh)]); edges = [edges ; edge]; %#ok end end edges = unique(edges, 'rows'); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawEdgeLabels.m0000644000000000000000000000013214055375162020213 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawEdgeLabels.m0000644000175000017500000000600414055375162021300 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawEdgeLabels(p, e, value) %DRAWEDGELABELS Draw values associated to graph edges. % % usage: % drawEdgeLabels(NODES, EDGES, VALUES); % NODES: array of double, containing x and y values of nodes % EDGES: array of int, containing indices of in and out nodes % VALUES is an array the same length of EDGES, containing values % associated to each edges of the graph. % % The function computes the center of each edge, and puts the text with % associated value. % % H = drawEdgeLabels(...) return array of handles to each text structure, % making possible to change font, color, size % % % ----- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2003. % % HISTORY % 10/03/2004 included into lib/graph library if length(p) > 1 && length(e) > 1 h = zeros(length(e), 1); hold on; for l=1:length(e) % indices of source and target nodes n1 = e(l, 1); n2 = e(l, 2); % node coordinates x1 = p(n1, 1); y1 = p(n1, 2); x2 = p(n2, 1); y2 = p(n2, 2); % display the edge line([x1 x2], [y1 y2]); % coordinates of edge label xm = (x1 + x2)/2; ym = (y1 + y2)/2; % display label h(l) = text(xm, ym, sprintf('%3d', floor(value(l)))); end end if nargout == 1 varargout = {h}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grNodeInnerDegree.m0000644000000000000000000000013214055375162020674 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grNodeInnerDegree.m0000644000175000017500000000464514055375162021772 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function degree = grNodeInnerDegree(node, edges) %GRNODEINNERDEGREE Inner degree of a node in a graph. % % DEG = grNodeInnerDegree(NODE, EDGES); % Returns the inner degree of a node in the given edge list, i.e. the % number of edges arriving to it. % NODE is the index of the node, and EDGES is a liste of couples of % indices (origin and destination node). % % Note: Also works when node is a vector of indices % % See Also: % grNodeDegree, grNodeOuterDegree % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-01-17 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % % HISTORY % 2008-08-07 pre-allocate memory, update doc % allocate memory N = size(node, 1); degree = zeros(N, 1); % compute inner degree of each vertex for i=1:length(node) degree(i) = sum(edges(:,2)==node(i)); end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grSimplifyBranches_old.m0000644000000000000000000000013214055375162021777 xustar0030 mtime=1622538866.110813447 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grSimplifyBranches_old.m0000644000175000017500000000564314055375162023074 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grSimplifyBranches_old(nodes, edges) %GRSIMPLIFYBRANCHES_OLD Replace branches of a graph by single edges. % % [NODES2 EDGES2] = grSimplifyBranches(NODES, EDGES) % Replaces each branch (composed of a series of edges connected only by % 2-degree nodes) by a single edge, whose extremities are nodes with % degree >= 3. % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 doc n = 1; while n < length(nodes) neigh = grAdjacentNodes(edges, n); if length(neigh) == 2 % find other node of first edge edge = edges(neigh(1), :); if edge(1) == n node1 = edge(2); else node1 = edge(1); end % replace current node in the edge by the other node % of first edge edge = edges(neigh(2), :); if edge(1) == n edges(neigh(2), 1) = node1; else edges(neigh(2), 2) = node1; end [nodes, edges] = grRemoveNode(nodes, edges, n); continue end n = n + 1; end % process output depending on how many arguments are needed if nargout == 1 out{1} = nodes; out{2} = edges; varargout = {out}; end if nargout == 2 varargout = {nodes, edges}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grSimplifyBranches.m0000644000000000000000000000013214055375162021141 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.110813447 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grSimplifyBranches.m0000644000175000017500000001364314055375162022235 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grSimplifyBranches(nodes, edges) %GRSIMPLIFYBRANCHES Replace branches of a graph by single edges. % % [NODES2 EDGES2] = grSimplifyBranches(NODES, EDGES) % renvoie une version simplifiee d'un graphe, en ne gardant que les % points multiples et les aretes reliant les points multiples. % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY : % 10/02/2004 : doc % 17/01/2006 : uses faster method to find neighbour edges % 18/01/2006 : replace call to subfunctions by inlining -> faster Mnodes = []; % size Nn*2 -> nodes coordinates Sedges = []; % size Ne*2 -> indices of nodes Mpoints = []; % size Nn*1 -> indices of Multiple points % in nodes input array branch = []; % size Nb*2 (variable) Nn = 0; Ne = 0; Nb = 0; % look for the first multiple point p = 1; while length(find(edges(:,1) == p | edges(:,2) == p)) < 3 p = p + 1; end Mpoints(1) = p; Mnodes(1, 1:2) = nodes(p, 1:2); Nn = Nn + 1; % add the branches of the first multiple point neighbours = find(edges(:,1)==p | edges(:,2)==p); for b = 1:length(neighbours) Nb = Nb+1; edge = edges(neighbours(b),:); if edge(1) == p branch(Nb, 1:2) = [p edge(2)]; %#ok else branch(Nb, 1:2) = [p edge(1)]; %#ok end end % process each branch, until there is no more branch to process. % b is index of current branch b = 0; while b < length(branch) b = b+1; % check if the branch is valid if branch(b, 1) == 0 continue; end % initialize iteration pNode = branch(b, 1); node = branch(b,2); neighbours = find(edges(:,1) == node | edges(:,2) == node); % disp(sprintf('node %3d (%03d ; %03d) -> %3d (%03d ; %03d)', ... % Mnode, nodes(Mnode, 1), nodes(Mnode, 2), ... % node, nodes(node, 1), nodes(node, 2))); while length(neighbours) < 3 % look for the next point on the current branch next = 0; for n = 1:length(neighbours) edge = edges(neighbours(n), :); if edge(1)~= node && edge(1)~= pNode next = edge(1); break; end if edge(2)~= node && edge(2)~= pNode next = edge(2); break; end end pNode = node; node = next; neighbours = find(edges(:,1) == node | edges(:,2) == node); end % node is now the next multiple point, and pNode contains the last % point of the branch. % check if the multiple point has already been processed index = find(Mpoints==node); if ~isempty(index) % find the branch starting with node, and with pNode has % second point, and set it to [0 0] to avoid it to be % processed again %disp('remove branch'); for b2 = 1:Nb if branch(b2, 1) == node && branch(b2, 2) == pNode %disp('find branch'); branch(b2, 1:2) = 0; %#ok break; end end else % add the multiple point to the list of points %disp('add point'); Nn = Nn+1; Mnodes(Nn, 1:2) = nodes(node, 1:2); %#ok index = Nn; Mpoints(Nn) = node; %#ok % add each neighbour of the new multiple point (but not % the neighbour containing pNode) to the list of branches for n = 1:length(neighbours) edge = edges(neighbours(n), :); if edge(1) ~= pNode && edge(2) ~= pNode %disp('add a branch'); Nb = Nb + 1; if edge(1) == node branch(Nb, 1:2) = [node edge(2)]; %#ok else branch(Nb, 1:2) = [node edge(1)]; %#ok end end end end %disp('add new Edge'); Ne = Ne + 1; Sedges(Ne, 1:2) = [find(Mpoints == branch(b,1)), index]; %#ok end % process output depending on how many arguments are needed if nargout == 1 out{1} = Mnodes; out{2} = Sedges; varargout{1} = out; end if nargout == 2 varargout{1} = Mnodes; varargout{2} = Sedges; end return; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawNodeLabels.m0000644000000000000000000000013214055375162020234 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawNodeLabels.m0000644000175000017500000000614314055375162021325 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawNodeLabels(nodes, value, varargin) %DRAWNODELABELS Draw values associated to graph nodes. % % Usage: % drawNodeLabels(NODES, VALUES); % NODES: array of double, containing x and y values of nodes % VALUES is an array the same length of EDGES, containing values % associated to each edges of the graph. % % H = drawNodeLabels(...) % Returns array of handles to each text structure, making it possible to % change font, color, size % % ----- % author: David Legland % INRA - TPV URPOI - BIA IMASTE % created the 10/02/2003. % % HISTORY % 10/03/2004 included into lib/graph library % extract handle of axis to draw on if isAxisHandle(nodes) ax = nodes; nodes = value; value = varargin{1}; else ax = gca; end % number and dimension of nodes Nn = size(nodes, 1); Nd = size(nodes, 2); % check input size if length(value) ~= Nn error('Value array must have same length as node number'); end % allocate memory h = zeros(Nn, 1); axes(ax); if Nd == 2 % Draw labels of 2D nodes for i = 1:Nn x = nodes(i, 1); y = nodes(i, 2); h(i) = text(x, y, sprintf('%3d', floor(value(i)))); end elseif Nd == 3 % Draw labels of 3D nodes for i = 1:Nn x = nodes(i, 1); y = nodes(i, 2); z = nodes(i, 3); h(i) = text(x, y, z, sprintf('%3d', floor(value(i)))); end else error('Node dimension must be 2 or 3'); end if nargout == 1 varargout = {h}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/readGraph.m0000644000000000000000000000013214055375162017243 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/readGraph.m0000644000175000017500000000750414055375162020336 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes, edges] = readGraph(fileName) %READGRAPH Read a graph from a text file. % % [NODES EDGES] = readGraph(FILENAME) % % Example % % create a basic graph, save it to a file, and read it again % nodes = [10 10;20 10;10 20;20 20;27 15]; % edges = [1 2;1 3;2 4;2 5;3 4;4 5]; % writeGraph(nodes, edges, 'simpleGraph.txt'); % [n2 e2] = readGraph('simpleGraph.txt'); % figure; drawGraph(n2, e2); axis equal; axis([0 40 0 30]); % % See also % writeGraph % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2014-01-21, using Matlab 7.9.0.529 (R2009b) % Copyright 2014 INRA - Cepia Software Platform. %% Open file and read header % open file for reading in text mode f = fopen(fileName, 'rt'); if f == -1 error(['could not open file for reading: ' fileName]); end % check header line = fgetl(f); if ~ischar(line) error(['can not read graph from empty file: ' fileName]); end if ~strcmpi(strtrim(line(2:end)), 'graph') error(['Wrong header line in file:' fileName]); end %% read node section % check sub-header line = fgetl(f); if ~strcmpi(strtrim(line(2:end)), 'nodes') error(['Could not interpret node section in file:' fileName]); end % read the number of nodes line = fgetl(f); [nNodesStr, line] = strtok(line); nNodes = str2double(nNodesStr); % read number of dimension, assumes 2 by default if not specified nDims = 2; if ~isempty(line) nDims = str2double(strtok(line)); end % read node coordinates [nodes, nRead] = fscanf(f, '%g', [nDims nNodes]); assert(nRead == nNodes * nDims, ... 'Could not read all node info in file %s', fileName); nodes = nodes'; % terminate the reading of current line fgetl(f); %% read edge section % check sub-header line = fgetl(f); if ~strcmpi(strtrim(line(2:end)), 'edges') error(['Could not interpret edge section in file:' fileName]); end % read the number of nodes line = fgetl(f); nEdgesStr = strtok(line); nEdges = str2double(nEdgesStr); % read node indices of each edge [edges, nRead] = fscanf(f, '%d %d\n', [2 nEdges]); assert(nRead == nEdges * 2, ... 'Could not read all edge info in file %s', fileName); edges = edges'; %% Clean up fclose(f); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/Contents.m0000644000000000000000000000013214055375162017143 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/Contents.m0000644000175000017500000002274014055375162020235 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. % GRAPHS Simple Toolbox for manipulating Geometric Graphs % Version 0.6 04-Sep-2017 . % % The aim of this package is to provide functions to easily create, % modify and display geometric graphs (geometric in a sense position % nodes are associated to geometric position in 2D or 3D). % % Graph are represented by a structure with at least two arrays: % * NODES, which contains coordinates of each vertex % * EDGES, which contains indices of start and end vertex. % Some graph functions consider adjacency list, as a cell array where % each cell contains the indices of the neighbor vertices. % % Others arrays may sometimes be used: % * FACES, which contains indices of vertices of each face (either a % double array, or a cell array) % * CELLS, which contains indices of faces of each cell. % % An alternative representation is to use a structure, with fields: % * 'nodes' % * 'edges' % corresponding to the data described above. % % Note that topological description of 2D graph is entirely contained in % EDGES array, and that NODES array is used only to display the graph. % % Caution: this type of data structure is easy to create and to manage, % but may be very inefficient for some algorithms. % % Graphs are usually considered as non-oriented in this package. % % % Graph creation % delaunayGraph - Graph associated to Delaunay triangulation of input points. % euclideanMST - Build euclidean minimal spanning tree of a set of points. % prim_mst - Minimal spanning tree by Prim's algorithm. % knnGraph - Create the k-nearest neighbors graph of a set of points. % relativeNeighborhoodGraph - Relative Neighborhood Graph of a set of points. % gabrielGraph - Gabriel Graph of a set of points. % % Create graph from images % imageGraph - Create equivalent graph of a binary image. % boundaryGraph - Get boundary of image as a graph. % gcontour2d - Creates contour graph of a 2D binary image. % gcontour3d - Create contour graph of a 3D binary image. % % Voronoi Graphs % voronoi2d - Compute a voronoi diagram as a graph structure. % boundedVoronoi2d - Return a bounded voronoi diagram as a graph structure. % centroidalVoronoi2d - Centroidal Voronoi tesselation within a polygon. % centroidalVoronoi2d_MC - Centroidal Voronoi tesselation by Monte-Carlo. % boundedCentroidalVoronoi2d - Create a 2D Centroidal Voronoi Tesselation in a box. % cvtUpdate - Update germs of a CVT with given points. % cvtIterate - Update germs of a CVT using random points with given density. % meshEnergy - Computes the energy of a tesselation, as the sum of second area moments. % % Geodesic and shortest path operations % grShortestPath - Find a shortest path between two nodes in the graph. % grPropagateDistance - Propagates distances from a vertex to other vertices. % grVertexEccentricity - Eccentricity of vertices in the graph. % graphDiameter - Diameter of a graph. % graphPeripheralVertices - Peripheral vertices of a graph. % graphCenter - Center of a graph. % graphRadius - Radius of a graph. % grFindGeodesicPath - Find a geodesic path between two nodes in the graph. % grFindMaximalLengthPath - Find a path that maximizes sum of edge weights. % % Graph processing (general applications) % adjacencyListToEdges - Convert an adjacency list to an edge array. % pruneGraph - Remove all edges with a terminal vertex. % mergeGraphs - Merge two graphs, by adding nodes, edges and faces lists. % grMergeNodes - Merge two (or more) nodes in a graph. % grMergeMultipleNodes - Simplify a graph by merging multiple nodes. % grMergeMultipleEdges - Remove all edges sharing the same extremities. % grSimplifyBranches - Replace branches of a graph by single edges. % % Filtering operations on Graph % grMean - Compute mean value from neighbour nodes. % grMedian - Compute median value from neighbour nodes. % grDilate - Morphological dilation on graph. % grErode - Morphological erosion on graph. % grClose - Morphological closing on graph. % grOpen - Morphological opening on graph. % % Operations for geometric graphs % grEdgeLengths - Compute length of edges in a geometric graph. % grMergeNodeClusters - Merge cluster of connected nodes in a graph. % grMergeNodesMedian - Replace several nodes by their median coordinate. % clipGraph - Clip a graph with a rectangular area. % clipGraphPolygon - Clip a graph with a polygon. % clipMesh2dPolygon - Clip a planar mesh with a polygon. % addSquareFace - Add a (square) face defined from its vertices to a graph. % grFaceToPolygon - Compute the polygon corresponding to a graph face. % graph2Contours - Convert a graph to a set of contour curves. % % Graph information % grNodeDegree - Degree of a node in a (undirected) graph. % grNodeInnerDegree - Inner degree of a node in a graph. % grNodeOuterDegree - Outer degree of a node in a graph. % grAdjacentNodes - Find list of nodes adjacent to a given node. % grAdjacentEdges - Find list of edges adjacent to a given node. % grOppositeNode - Return opposite node in an edge. % grLabel - Associate a label to each connected component of the graph. % % Graph management (low level operations) % grRemoveNode - Remove a node in a graph. % grRemoveNodes - Remove several nodes in a graph. % grRemoveEdge - Remove an edge in a graph. % grRemoveEdges - Remove several edges from a graph. % % Graph display % drawGraph - Draw a graph, given as a set of vertices and edges. % drawGraphEdges - Draw edges of a graph. % fillGraphFaces - Fill faces of a graph with specified color. % drawDigraph - Draw a directed graph, given as a set of vertices and edges. % drawDirectedEdges - Draw edges with arrow indicating direction. % drawEdgeLabels - Draw values associated to graph edges. % drawNodeLabels - Draw values associated to graph nodes. % drawSquareMesh - Draw a 3D square mesh given as a graph. % patchGraph - Transform 3D graph (mesh) into a patch handle. % % Input/Output % readGraph - Read a graph from a text file. % writeGraph - Write a graph to an ascii file. % % ----- % Author: David Legland % e-mail: david.legland@inra.fr % Project homepage: http://github.com/mattools/matGeom % created the 07/11/2005. % Copyright INRA - Cepia Software Platform. help(mfilename); % HISTORY % 25/07/2007 remove old functions % 27/07/2007 integrate headers of other functions % 27/07/2007 add MST by prim algo, and EuclideanMST % 24/08/2010 code cleanup % 07/09/2010 add functions for computing geodesic distances % 18/05/2011 code re-organisation, add to MatGeom library % Deprecated functions % grSimplifyBranches_old - Replace branches of a graph by single edges. % grRemoveMultiplePoints - Remove groups of close nodes in a graph. % Functions that requires further development % quiverToGraph - Converts quiver data to quad mesh. % Other functions % polygonBoundedCVT2d - BOUNDEDCENTROIDALVORONOI2D Create a 2D Centroidal Voronoi Tesselation in a box matgeom-1.2.3/inst/graphs/PaxHeaders.19757/mergeGraphs.m0000644000000000000000000000013214055375162017612 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/mergeGraphs.m0000644000175000017500000001242014055375162020676 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = mergeGraphs(varargin) %MERGEGRAPHS Merge two graphs, by adding nodes, edges and faces lists. % % % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 09/08/2004. % simplify = false; edges = {}; edges2 = {}; faces = {}; faces2 = {}; %% process input arguments % extract simplify tag var = varargin{nargin}; if ischar(var) if strcmp(var, 'simplify') simplify = true; varargin = varargin(1:length(varargin)-1); end end %% extract data of first graph var = varargin{1}; if iscell(var) % graph is stored as a cell array : first cell is nodes, second one is % edges, and third is faces nodes = var{1}; if length(var)>1 edges = var{2}; end if length(var)>2 faces = var{3}; end varargin = varargin(2:length(varargin)); elseif isstruct(var) % graph is stored as a structure, with fields 'nodes', 'edges', and % eventually 'faces'. nodes = var.nodes; edges = var.edges; if isfield(var, 'faces') faces = var.faces; end varargin = varargin(2:length(varargin)); elseif length(varargin)>2 % graph is stored as set of variables : nodes, edges, and eventually % faces nodes = varargin{1}; edges = varargin{2}; if length(varargin)==3 % last argument describe graph 2 varargin = varargin(3); else if length(varargin)~=4 || ~isnumeric(varargin{4}) % third argument is faces of graph 1 faces = varargin{3}; varargin = varargin(4:length(varargin)); else varargin = varargin(3:length(varargin)); end end else error('Error in passing arguments in mergeGraphs'); end %% extract data of second graph var = varargin{1}; if iscell(var) % graph is stored as a cell array : first cell is nodes, second one is % edges, and third is faces nodes2 = var{1}; if length(var)>1 edges2 = var{2}; end if length(var)>2 faces2 = var{3}; end elseif isstruct(var) % graph is stored as a structure, with fields 'nodes', 'edges', and % eventually 'faces'. nodes2 = var.nodes; edges2 = var.edges; if isfield(var, 'faces') faces2 = var.faces; end elseif length(varargin)>1 % graph is stored as set of variables : nodes, edges, and eventually % faces nodes2 = varargin{1}; edges2 = varargin{2}; if length(varargin)>2 % last argument describe graph 2 faces2 = varargin{3}; end else error('Error in passing arguments in mergeGraphs'); end %% Main algorithm % eventually convert faces if ~iscell(faces) f = cell(size(faces, 1), 1); for i = 1:size(faces, 1) f{i} = faces(i,:); end faces = f; end edges = [edges ; edges2 + size(nodes, 1)]; if iscell(faces2) for i = 1:length(faces2) faces{length(faces)+1} = faces2{i} + size(nodes, 1); %#ok end else % TODO end nodes = [nodes; nodes2]; if simplify if ~isempty(faces) [nodes, edges, faces] = grSimplifyBranches(nodes, edges, faces); else [nodes, edges] = grSimplifyBranches(nodes, edges); end end %% process output depending on how many arguments are needed if nargout == 1 graph.nodes = nodes; graph.edges = edges; if ~isempty(faces) graph.faces = faces; end varargout{1} = graph; end if nargout == 2 varargout{1} = nodes; varargout{2} = edges; end if nargout == 3 varargout{1} = nodes; varargout{2} = edges; varargout{3} = faces; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grNodeDegree.m0000644000000000000000000000013214055375162017700 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grNodeDegree.m0000644000175000017500000000656514055375162021001 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [degree, node] = grNodeDegree(node, edges) %GRNODEDEGREE Degree of a node in a (undirected) graph. % % DEGREE = grNodeDegree(NODE_INDEX, EDGES); % return the degree of a node in the given edge list, that is the number % of edges connected to it. % NODE_INDEX is the index of the node, and EDGES is a liste of couples of % indices (origin and destination node). % This degree is the sum of inner degree (number of edges arriving on the % node) and the outer degree (number of emanating edges). % % Note: Also works when NODE_INDEX is a vector of indices % % DEGREE = grNodeDegree(EDGES); % Return the degree of each node references by the array EDGES. DEGREE is % a column vector with as many rows as the number of nodes referenced by % edges. % % [DEG, INDS] = grNodeDegree(EDGES); % Also returns the indices of the nodes that were referenced. % % Example % edges = [1 2;1 3;2 3;2 4;3 4]; % grNodeDegree(2, edges) % ans = % 3 % grNodeDegree(edges)' % ans = % 2 3 3 2 % % See Also: grNodeInnerDegree, grNodeOuterDegree % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2003-08-13 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % 10/02/2004 documentation % 17/01/2006 change name, reimplement, and rewrite doc. % 13/01/2014 add psb to compute degree of all nodes % If only edge array is given, assume we want the degree of each node if nargin == 1 edges = node; node = unique(edges(:)); end % allocate array for result degree = zeros(size(node)); % for each node ID, count the number of edges containing it for i = 1:length(node(:)) degree(i) = sum(edges(:,1) == node(i)) + sum(edges(:,2) == node(i)); end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMergeMultipleEdges.m0000644000000000000000000000013214055375162021422 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMergeMultipleEdges.m0000644000175000017500000000512014055375162022505 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grMergeMultipleEdges(nodes, edges) %GRMERGEMULTIPLEEDGES Remove all edges sharing the same extremities. % % [NODES2, EDGES2] = grMergeMultipleEdges(NODES, EDGES) % Remove configuration with two edges sharing the same 2 nodes. % % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 doc % 2011-05-18 rename to grMergeMultipleEdges rmedge = []; for e = 1:length(edges) edge = edges(e, :); for e2 = e+1:length(edges) if (edge(1) == edges(e2, 1) && edge(2) == edges(e2, 2)) || ... (edge(1) == edges(e2, 2) && edge(2) == edges(e2, 1)) rmedge(length(rmedge)+1) = e2; %#ok end end end [nodes, edges] = grRemoveEdges(nodes, edges, rmedge); % process output depending on how many arguments are needed if nargout == 1 out{1} = nodes; out{2} = edges; varargout{1} = out; end if nargout == 2 varargout = {nodes, edges}; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/meshEnergy.m0000644000000000000000000000013214055375162017454 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/meshEnergy.m0000644000175000017500000000500614055375162020542 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function energy = meshEnergy(vertices, faces) % Computes the energy of a tesselation, as the sum of second area moments. % % This function can be used to check that the total energy of Centroidal % Voronoi Tesselation (CVT) decreases with the iterations of the Lloyd % algorithm. % % E = meshEnergy(V, F) % V is the list of mesh vertices, and F are faces, as a cell array of % vertex indices. % % Example % meshEnergy % % See also % centroidalVoronoi2d, cvtUpdate, polygonSecondAreaMoments % ------ % Author: David Legland % e-mail: david.legland@inra.fr % Created: 2017-09-01, using Matlab 9.1.0.441655 (R2016b) % Copyright 2017 INRA - Cepia Software Platform. nFaces = meshFaceNumber(vertices, faces); energyList = zeros(nFaces, 1); polygons = meshFacePolygons(vertices, faces); for i = 1:nFaces [Ix, Iy, Ixy] = polygonSecondAreaMoments(polygons{i}); %#ok energyList(i) = hypot(Ix, Iy); end energy = sum(energyList); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/relativeNeighborhoodGraph.m0000644000000000000000000000013214055375162022473 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/relativeNeighborhoodGraph.m0000644000175000017500000000744514055375162023572 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [gnodes, gedges] = relativeNeighborhoodGraph(points) %RELATIVENEIGHBORHOODGRAPH Relative Neighborhood Graph of a set of points. % % [NODES, EDGES] = relativeNeighborhoodGraph(POINTS) % EDGES = relativeNeighborhoodGraph(POINTS) % % The Relative Neighborhood Graph (RNG) is a subgraph of the Delaunay % Triangulation computed from the same set of points. The Gabriel graph % and the euclidean minimal spanning tree (EMST) are subgraphs of the % RNG. % % Example % nodes = rand(100, 2) * 100; % edges = relativeNeighborhoodGraph(nodes); % figure; drawGraph(nodes, edges); % % See also % gabrielGraph, euclideanMST % % ------ % Author: David Legland % e-mail: david.legland@nantes.inra.fr % Created: 2016-03-02, using Matlab 8.6.0.267246 (R2015b) % Copyright 2016 INRA - Cepia Software Platform. % first compute Delaunay triangulation to reduce further computations DT = delaunayTriangulation(points); E = edges(DT); % compute edge lengths nEdges = size(E, 1); edgeLengths = zeros(nEdges, 1); for i = 1:nEdges edgeLengths(i) = distancePoints(points(E(i,1),:), points(E(i,2),:)); end % identify indices of faces attached to each vertex vertexFaces = vertexAttachments(DT); % iterate over edges to check if the should be kept keepEdge = true(nEdges, 1); for iEdge = 1:nEdges iVertex1 = E(iEdge, 1); iVertex2 = E(iEdge, 2); vertex1 = points(iVertex1, :); vertex2 = points(iVertex2, :); % compute indices of faces containing one of the two vertices inds = [vertexFaces{iVertex1} vertexFaces{iVertex2}]; localFaces = DT.ConnectivityList(inds, :); % compute indices of vertices is the first neighborhood of the edge inds = unique(localFaces); inds(ismember(inds, [iVertex1 iVertex2])) = []; % compute max of distances to both original vertices dists1 = distancePoints(vertex1, points(inds, :)); dists2 = distancePoints(vertex2, points(inds, :)); distsMax = max(dists1, dists2); % keep edge if all points are outside the "lunule" defined by the edge if edgeLengths(iEdge) > min(distsMax) keepEdge(iEdge) = false; end end % filter edges gedges = E(keepEdge, :); % format output gnodes = points; if nargin == 1 gnodes = gedges; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grMean.m0000644000000000000000000000013214055375162016557 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grMean.m0000644000175000017500000000466014055375162017652 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grMean(varargin) % Compute mean value from neighbour nodes. % % LBL2 = grMean(EDGES, LBL1) % new label for each node of the graph is computed as the mean of the % values of neighbours and of old value. % % Example % grMean % % See also % grMedian, grDilate, grErode % % ------ % Author: David Legland % e-mail: david.legland@inrae.fr % Created: 2006-01-20 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin) == 2 edges = varargin{1}; values = varargin{2}; elseif length(varargin) == 3 edges = varargin{2}; values = varargin{3}; else error('Wrong number of arguments in "grMean"'); end res = zeros(size(values)); uni = unique(edges(:)); for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); res(uni(n)) = mean(values([uni(n); neigh])); end varargout{1} = res; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grFindMaximalLengthPath.m0000644000000000000000000000013214055375162022047 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grFindMaximalLengthPath.m0000644000175000017500000000715214055375162023141 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function path = grFindMaximalLengthPath(nodes, edges, edgeWeights) %GRFINDMAXIMALLENGTHPATH Find a path that maximizes sum of edge weights. % % PATH = grFindMaximalLengthPath(NODES, EDGES, EDGE_WEIGHTS); % Finds a greatest geodesic path in the graph. A path between two nodes % is a succession of adjacent edges that link the first and last nodes. % the length of the path is the sum of weights of edges that constitute % the path. % A geodesic path is a path that minimizes the length of the path among % the set of paths between the nodes. % A maximal length path maximizes the length of the geodesic path between % couples of nodes in the graph % % The result PATH is the list of edge indices that constitutes the path. % % PATH = grFindMaximalLengthPath(NODES, EDGES); % Assumes each edge has a weight equal to 1. % % See Also % grFindGeodesicPath % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2011-05-22, using Matlab 7.9.0.529 (R2009b) % Copyright 2011 INRA - Cepia Software Platform. % ensure weights are defined if ~exist('edgeWeights', 'var') edgeWeights = ones(size(edges, 1), 1); end % find an extremity vertex inds = graphPeripheralVertices(nodes, edges, edgeWeights); ind0 = inds(end); % find a vertex opposite to the first extremity dists = grPropagateDistance(nodes, edges, ind0, edgeWeights); ind1 = find(dists == max(dists), 1, 'first'); % iterate on neighbors of current node: choose next neighbor with smallest % cumulated weight, until we are back on source node path = []; while true % find neighbor with lowest cumulated distance neighs = grAdjacentNodes(edges, ind1); neighDists = dists(neighs); indN = find(neighDists == min(neighDists), 1); ind2 = neighs(indN); % add edge index to the path indE = find(sum(ismember(edges, [ind1 ind2]), 2) == 2, 1); path = [path indE]; %#ok % test if path is finished or not if ind2 == ind0 break; end ind1 = ind2; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/pruneGraph.m0000644000000000000000000000013214055375162017461 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/pruneGraph.m0000644000175000017500000000500614055375162020547 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = pruneGraph(nodes, edges) %PRUNEGRAPH Remove all edges with a terminal vertex. % % [NODES2, EDGES2] = pruneGraph(NODES, EDGES) % % Example % nodes = [... % 10 30; 30 30; 20 45; 50 30; 40 15; 70 30; 90 30; 80 15; 100 45]; % edges = [1 2;2 3;2 4;4 5;4 6;6 7;6 8;7 8;7 9]; % figure; % subplot(2, 1, 1); drawGraph(nodes, edges); % axis equal; axis([0 110 10 50]); % [nodes2, edges2] = pruneGraph(nodes, edges); % subplot(2, 1, 2); drawGraph(nodes2, edges2); % axis equal; axis([0 110 10 50]); % % See also % graphs % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2015-02-19, using Matlab 8.4.0.150421 (R2014b) % Copyright 2015 INRA - Cepia Software Platform. nNodes = size(nodes, 1); degs = grNodeDegree(1:nNodes, edges)'; termNodeInds = find(degs == 1); [nodes2, edges2] = grRemoveNodes(nodes, edges, termNodeInds); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grRemoveEdges.m0000644000000000000000000000013214055375162020104 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grRemoveEdges.m0000644000175000017500000000530714055375162021176 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function [nodes2, edges2] = grRemoveEdges(nodes, edges, rmEdges) %GRREMOVEEDGES Remove several edges from a graph. % % [NODES2 EDGES2] = grRemoveEdges(NODES, EDGES, EDGES2REMOVE) % Remove some edges in the edges list, and return the modified graph. % The NODES array is not modified. % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY : % 10/02/2004 : doc rmEdges = sort(rmEdges); % do not change the node list nodes2 = nodes; % number of edges N = size(edges, 1); NR = length(rmEdges); N2 = N - NR; % allocate memory for new edges list edges2 = zeros(N2, 2); % case of no edge to remove if NR == 0 nodes2 = nodes; edges2 = edges; return; end % process the first edge edges2(1:rmEdges(1)-1,:) = edges(1:rmEdges(1)-1,:); % process the classical edges for i = 2:NR %if rmEdges(i)-i < rmEdges(i-1)-i+2 % continue; %end edges2(rmEdges(i-1)-i+2:rmEdges(i)-i, :) = edges(rmEdges(i-1)+1:rmEdges(i)-1, :); end % process the last edge edges2(rmEdges(NR)-NR+1:N2, :) = edges(rmEdges(NR)+1:N, :); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/drawDigraph.m0000644000000000000000000000013214055375162017602 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/drawDigraph.m0000644000175000017500000000671114055375162020674 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = drawDigraph(varargin) %DRAWDIGRAPH Draw a directed graph, given as a set of vertices and edges. % % drawDigraph(NODES1, NODES2, EDGES) % NODES1 are originating vertices % NODES2 are destination vertices % EDGES is an array, with first column containing index of origin vertex % (index in NODES1), and second column containing index of destination % vertex (index in NODES2). % Edges are drawn with arrows. % % H = drawDigraph(...) % return handle to the set of edges. % % % ----- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 17/08/2004. % %% Initialisations % check number of arguments if nargin < 3 help drawDigraph; return; end % initialisations sn1 = 'bo'; % nodes are red circles sn2 = 'ro'; % nodes are red circles %% process input arguments % First extract the graph structure n1 = varargin{1}; n2 = varargin{2}; e = varargin{3}; varargin = varargin(4:length(varargin)); % extract drawing style if ~isempty(varargin) sn1 = varargin{1}; end if length(varargin)>1 sn2 = varargin{2}; end %% main drawing processing hold on; nodes = [n1 ; n2]; e(:,2) = e(:,2)+length(n1); % Draw a 2 dimensional directed graph ---------------------- % Draw 2D Edges ---------------------- %if ~strcmp(se, 'none') & size(e, 1)>0 % he = plot([n1(e(:,1),1) n2(e(:,2),1)]', [n1(e(:,1),2) n2(e(:,2),2)]', se); %end he = drawDirectedEdges(nodes, e); hn = []; % Draw 2D nodes ---------------------- if ~strcmp(sn1, 'none') hn = plot(n1(:,1), n1(:,2), sn1); end % Draw 2D nodes ---------------------- if ~strcmp(sn2, 'none') hn = plot(n2(:,1), n2(:,2), sn2); end %% format output arguments if nargout==1 varargout{1} = he; end if nargout==2 varargout{1} = hn; varargout{2} = he; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grPropagateDistance.m0000644000000000000000000000013214055375162021274 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grPropagateDistance.m0000644000175000017500000001004314055375162022357 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function d = grPropagateDistance(v, e, v0, l) %GRPROPAGATEDISTANCE Propagates distances from a vertex to other vertices. % % DISTS = grPropagateDistance(V, E, V0, L) % V0 is index of initial vertex % E is array of source and target vertices % L is the vector of length of each edge. If not specified, length 1 is % assumed for all edges. % The result DISTS is a column array with as many rows as the number of % vertices, containing the geodesic distance of each vertex to the vertex % of index V0. % % Example % nodes = [20 20;20 50;20 80;50 50;80 20;80 50;80 80]; % edges = [1 2;2 3;2 4;4 6;5 6;6 7]; % figure; drawGraph(nodes, edges); % axis([0 100 0 100]); axis equal; hold on % DISTS = grPropagateDistance(nodes, edges, 2) % DISTS = % 1 % 0 % 1 % 1 % 3 % 2 % 3 % drawNodeLabels(nodes+1, DISTS); % % See Also % graphRadius, graphCenter, graphDiameter, graphPeripheralVertices % grVertexEccentricity % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % initialize empty array for result Nv = length(v); d = ones(Nv, 1)*inf; d(v0) = 0; % ensure there is a valid length array if nargin < 4 l = ones(size(e,1), 1); end % iterate from germ vertex until there are no more vertices to process verticesToProcess = v0; while ~isempty(verticesToProcess) % init new iteration newVerticesToProcess = []; % iterate over vertices that need to be updated for i = 1:length(verticesToProcess) vertex = verticesToProcess(i); % iterate over neighbor edges of current vertex vertexEdges = grAdjacentEdges(e, vertex); for j = 1:length(vertexEdges) iEdge = vertexEdges(j); % compute distance between current vertex and its neighbor vertex2 = grOppositeNode(e(iEdge,:), vertex); newDist = d(vertex) + l(iEdge); % update geodesic distance of neighbor node if needed if newDist < d(vertex2) d(vertex2) = newDist; newVerticesToProcess = [newVerticesToProcess ; vertex2]; %#ok end end end % update set of vertices for next tieration verticesToProcess = newVerticesToProcess; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/graphDiameter.m0000644000000000000000000000013214055375162020122 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/graphDiameter.m0000644000175000017500000000527014055375162021213 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function diam = graphDiameter(v, e, l) %GRAPHDIAMETER Diameter of a graph. % % D = graphDiameter(V, E) % Computes the diameter of the graph given by V and E. The diameter of % the graph is the greatest eccentricity over all vertices in the graph. % % D = graphDiameter(V, E, L) % Specifies the weight of each edge for computing the distances. Default % is to consider a weight of 1 for each edge. % % Example % nodes = [20 20;20 50;20 80;50 50;80 20;80 50;80 80]; % edges = [1 2;2 3;2 4;4 6;5 6;6 7]; % figure; drawGraph(nodes, edges); % axis([0 100 0 100]); axis equal; hold on % D = graphDiameter(nodes, edges) % D = % 4 % % See Also % grPropagateDistance, grVertexEccentricity % graphCenter, graphRadius, graphPeripheralVertices % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07, using Matlab 7.9.0.529 (R2009b) % Copyright 2010 INRA - Cepia Software Platform. % ensure there is a valid length array if nargin<3 l = ones(size(e,1), 1); end g = grVertexEccentricity(v, e, l); diam = max(g); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grOpen.m0000644000000000000000000000013214055375162016600 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grOpen.m0000644000175000017500000000507714055375162017676 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grOpen(varargin) %GROPEN Morphological opening on graph. % % LBL2 = grOpen(EDGES, LBL1) % The labels are the result of a morphological erosion followed by a % morphological dilation. % % Example % grOpen % % See also % grClose, grErode, grDilate % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-01-20 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin) == 2 edges = varargin{1}; lbl = varargin{2}; elseif length(varargin) == 3 edges = varargin{2}; lbl = varargin{3}; else error('Wrong number of arguments in "grOpen"'); end uni = unique(edges(:)); % performs erosion lbl2 = zeros(size(lbl)); for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); lbl2(uni(n)) = min(lbl([uni(n); neigh])); end % performs dilation for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); lbl(uni(n)) = max(lbl2([uni(n); neigh])); end varargout{1} = lbl; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grLabel.m0000644000000000000000000000013214055375162016716 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grLabel.m0000644000175000017500000000600514055375162020004 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function labels = grLabel(nodes, edges) %GRLABEL Associate a label to each connected component of the graph. % % LABELS = grLabel(NODES, EDGES) % Returns an array with as many rows as the array NODES, containing index % number of each connected component of the graph. If the graph is % totally connected, returns an array of 1. % % Example % nodes = rand(6, 2); % edges = [1 2;1 3;4 6]; % labels = grLabel(nodes, edges); % labels = % 1 % 1 % 1 % 2 % 3 % 2 % % See also % getNeighborNodes % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2007-08-14, using Matlab 7.4.0.287 (R2007a) % Copyright 2007 INRA - BIA PV Nantes - MIAJ Jouy-en-Josas. % init Nn = size(nodes, 1); labels = (1:Nn)'; % iteration until stability modif = true; while modif modif = false; % compute the minimum label in the neighborhood of each node for i = 1:Nn neigh = grAdjacentNodes(edges, i); neighLabels = labels([i;neigh]); % check for a modification if length(unique(neighLabels)) > 1 modif = true; end % put new labels labels(ismember(labels, neighLabels)) = min(neighLabels); end end % renumbering to have fewer labels labels2 = unique(labels); for i = 1:length(labels2) labels(labels == labels2(i)) = i; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grOppositeNode.m0000644000000000000000000000013214055375162020307 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grOppositeNode.m0000644000175000017500000000463114055375162021400 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function node2 = grOppositeNode(edges, node) %GROPPOSITENODE Return opposite node in an edge. % % NODE2 = grOppositeNode(EDGE, NODE); % Return the index of the node opposite to NODE in EDGE. % If the edge does not contain node NODE, result is 0. % % Works also if EDGE is a N-by-2 array of source and target vertex % indices, in this case the result NODE2 has as many rows as the number % of edges. % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2010-09-07 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). % HISTORY % allocate memory for result Ne = size(edges, 1); node2 = zeros(Ne, 1); % iterate on edges for i = 1:Ne if edges(i,1) == node node2(i) = edges(i,2); elseif edges(i,2) == node node2(i) = edges(i,1); end end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grClose.m0000644000000000000000000000013214055375162016744 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grClose.m0000644000175000017500000000475114055375162020040 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = grClose(varargin) %GRCLOSE Morphological closing on graph. % % LBL2 = grClose(EDGES, LBL1) % First performs dilatation, then erosion. % % Example % grOpen % % See also % % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2006-01-20 % Copyright 2006 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). if length(varargin) == 2 edges = varargin{1}; lbl = varargin{2}; elseif length(varargin) == 3 edges = varargin{2}; lbl = varargin{3}; else error('Wrong number of arguments in "grOpen"'); end uni = unique(edges(:)); % performs dilation lbl2 = zeros(size(lbl)); for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); lbl2(uni(n)) = max(lbl([uni(n); neigh])); end % performs erosion for n = 1:length(uni) neigh = grAdjacentNodes(edges, uni(n)); lbl(uni(n)) = min(lbl2([uni(n); neigh])); end varargout{1} = lbl; matgeom-1.2.3/inst/graphs/PaxHeaders.19757/patchGraph.m0000644000000000000000000000013214055375162017427 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/patchGraph.m0000644000175000017500000000516514055375162020523 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = patchGraph(nodes, edges, faces) %#ok %PATCHGRAPH Transform 3D graph (mesh) into a patch handle. % % [PX, PY, PZ] = PATCHGRAPH(NODES, EDGES, FACES) % Transform the graph defined as a set of nodes, edges and faces in a % patch which can be drawn usind matlab function 'patch'. % The result is a set of 3 array of size [NV*NF], with NV being the % number of vertices per face, and NF being the total number of faces. % each array contains one coordinate of vertices of each patch. % % % --------- % % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 28/06/2004. % if iscell(faces) p = zeros(length(faces), 1); for i = 1:length(faces) p(i) = patch( ... 'Faces', faces{i}, ... 'Vertices', nodes, ... 'FaceColor', 'r', ... 'EdgeColor', 'none') ; end else p = patch( ... 'Faces', faces, ... 'Vertices', nodes, ... 'FaceColor', 'r', ... 'EdgeColor', 'none') ; end if nargout>0 varargout{1}=p; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/grAdjacentEdges.m0000644000000000000000000000013214055375162020360 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/grAdjacentEdges.m0000644000175000017500000000432414055375162021450 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function neigh = grAdjacentEdges(edges, node) %GRADJACENTEDGES Find list of edges adjacent to a given node. % % NEIGHS = grAdjacentEdges(EDGES, NODE) % EDGES the complete edges list (containing indices of neighbor nodes) % NODE index of the node % NEIGHS the indices of edges containing the node index % % See also % grAdjacentNodes % ----- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 13/08/2003. % % HISTORY % 10/02/2004 : documentation % 13/07/2004 : faster algorithm % 17/01/2006 : rename and change implementation neigh = find(edges(:,1) == node | edges(:,2) == node); matgeom-1.2.3/inst/graphs/PaxHeaders.19757/imageGraph.m0000644000000000000000000000013214055375162017412 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/imageGraph.m0000644000175000017500000001451414055375162020504 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function varargout = imageGraph(img, varargin) %IMAGEGRAPH Create equivalent graph of a binary image. % % [N E] = imageGraph(IMG); % or % [N E F] = imageGraph(IMG); % create graph representing adjacencies in image. N is the array of % nodes, E is the array of edges, and F is a 4-columns array containing % indices of vertices of each face. % IMG can be either 2D or 3D image. % This functions uses only 4 neighbors in 2D, and 6 neighbors in 3D. % % --------- % author : David Legland % INRA - TPV URPOI - BIA IMASTE % created the 28/06/2004. % % HISTORY %% Initialisations nodes = []; edges = zeros(0, 2); faces = zeros(0, 4); cells = []; dim = size(img); nd = ndims(img); %% Main processing if nd == 2 % Process planar image N1 = dim(1); N2 = dim(2); % first find nodes, equivalent to pixels ind = find(img); [x, y] = ind2sub([N1 N2], ind); nodes = [x y]; % find vertical edges ind = find(img(1:N1, 1:N2-1) & img(1:N1, 2:N2)); for i=1:length(ind) [x, y] = ind2sub([N1 N2-1], ind(i)); i1 = find(ismember(nodes, [x y], 'rows')); i2 = find(ismember(nodes, [x y+1], 'rows')); edges(size(edges, 1)+1, 1:2) = [i1 i2]; end % find horizontal edges ind = find(img(1:N1-1, 1:N2) & img(2:N1, 1:N2)); for i=1:length(ind) [x, y] = ind2sub([N1-1 N2], ind(i)); i1 = find(ismember(nodes, [x y], 'rows')); i2 = find(ismember(nodes, [x+1 y], 'rows')); edges(size(edges, 1)+1, 1:2) = [i1 i2]; end % find faces ind = find(img(1:N1-1, 1:N2-1) & img(2:N1, 1:N2-1) & ... img(1:N1-1, 2:N2) & img(2:N1, 2:N2) ); for i=1:length(ind) [x, y] = ind2sub([N1-1 N2-1], ind(i)); i1 = find(ismember(nodes, [x y], 'rows')); i2 = find(ismember(nodes, [x+1 y], 'rows')); i3 = find(ismember(nodes, [x+1 y+1], 'rows')); i4 = find(ismember(nodes, [x y+1], 'rows')); faces(size(faces, 1)+1, 1:4) = [i1 i2 i3 i4]; end elseif nd == 3 % Process 3D image N1 = dim(1); N2 = dim(2); N3 = dim(3); % first find nodes, equivalent to pixels ind = find(img); [x, y, z] = ind2sub([N1 N2 N3], ind); nodes = [x y z]; % find edges in direction 1 ind = find(img(1:N1-1, 1:N2, 1:N3) & img(2:N1, 1:N2, 1:N3)); [x, y, z] = ind2sub([N1-1 N2 N3], ind); i1 = find(ismember(nodes, [x y z], 'rows')); i2 = find(ismember(nodes, [x+1 y z], 'rows')); edges = [edges ; [i1 i2]]; % find edges in direction 2 ind = find(img(1:N1, 1:N2-1, 1:N3) & img(1:N1, 2:N2, 1:N3)); [x, y, z] = ind2sub([N1 N2-1 N3], ind); i1 = find(ismember(nodes, [x y z], 'rows')); i2 = find(ismember(nodes, [x y+1 z], 'rows')); edges = [edges ; [i1 i2]]; % find edges in direction 3 ind = find(img(1:N1, 1:N2, 1:N3-1) & img(1:N1, 1:N2, 2:N3)); [x, y, z] = ind2sub([N1 N2 N3-1], ind); i1 = find(ismember(nodes, [x y z], 'rows')); i2 = find(ismember(nodes, [x y z+1], 'rows')); edges = [edges ; [i1 i2]]; % find faces in direction 1 ind = find(img(1:N1, 1:N2-1, 1:N3-1) & img(1:N1, 1:N2-1, 2:N3) & ... img(1:N1, 2:N2, 1:N3-1) & img(1:N1, 2:N2, 2:N3) ); [x, y, z] = ind2sub([N1 N2-1 N3-1], ind); i1 = find(ismember(nodes, [x y z], 'rows')); i2 = find(ismember(nodes, [x y+1 z], 'rows')); i3 = find(ismember(nodes, [x y+1 z+1], 'rows')); i4 = find(ismember(nodes, [x y z+1], 'rows')); faces = [faces; [i1 i2 i3 i4]]; % find faces in direction 2 ind = find(img(1:N1-1, 1:N2, 1:N3-1) & img(1:N1-1, 1:N2, 2:N3) & ... img(2:N1, 1:N2, 1:N3-1) & img(2:N1, 1:N2, 2:N3) ); [x, y, z] = ind2sub([N1-1 N2 N3-1], ind); i1 = find(ismember(nodes, [x y z], 'rows')); i2 = find(ismember(nodes, [x+1 y z], 'rows')); i3 = find(ismember(nodes, [x+1 y z+1], 'rows')); i4 = find(ismember(nodes, [x y z+1], 'rows')); faces = [faces; [i1 i2 i3 i4]]; % find faces in direction 3 ind = find(img(1:N1-1, 1:N2-1, 1:N3) & img(1:N1-1, 2:N2, 1:N3) & ... img(2:N1, 1:N2-1, 1:N3) & img(2:N1, 2:N2, 1:N3) ); [x, y, z] = ind2sub([N1-1 N2-1 N3], ind); i1 = find(ismember(nodes, [x y z], 'rows')); i2 = find(ismember(nodes, [x+1 y z], 'rows')); i3 = find(ismember(nodes, [x+1 y+1 z], 'rows')); i4 = find(ismember(nodes, [x y+1 z], 'rows')); faces = [faces; [i1 i2 i3 i4]]; end %% Format output if nargout == 1 graph.nodes = nodes; graph.edges = edges; graph.faces = faces; if nd > 2 graph.cells = cells; end varargout{1} = graph; elseif nargout == 2 varargout{1} = nodes; varargout{2} = edges; elseif nargout == 3 varargout{1} = nodes; varargout{2} = edges; varargout{3} = faces; end matgeom-1.2.3/inst/graphs/PaxHeaders.19757/writeGraph.m0000644000000000000000000000013214055375162017462 xustar0030 mtime=1622538866.114813433 30 atime=1622538866.114813433 30 ctime=1622538866.150813297 matgeom-1.2.3/inst/graphs/writeGraph.m0000644000175000017500000000550514055375162020554 0ustar00juanpijuanpi00000000000000## Copyright (C) 2021 David Legland ## All rights reserved. ## ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions are met: ## ## 1 Redistributions of source code must retain the above copyright notice, ## this list of conditions and the following disclaimer. ## 2 Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## ## The views and conclusions contained in the software and documentation are ## those of the authors and should not be interpreted as representing official ## policies, either expressed or implied, of the copyright holders. function writeGraph(nodes, edges, fileName) %WRITEGRAPH Write a graph to an ascii file. % % writeGraph(NODES, EDGES, FILENAME) % % Example % % create a basic graph and save it to a file % nodes = [10 10;20 10;10 20;20 20;27 15]; % edges = [1 2;1 3;2 4;2 5;3 4;4 5]; % writeGraph(nodes, edges, 'simpleGraph.txt'); % % See also % readGraph % % ------ % Author: David Legland % e-mail: david.legland@grignon.inra.fr % Created: 2014-01-20, using Matlab 7.9.0.529 (R2009b) % Copyright 2014 INRA - Cepia Software Platform. %% File creation and init % extract "sizes" of the graph nNodes = size(nodes, 1); nEdges = size(edges, 1); nDims = size(nodes, 2); % file opening f = fopen(fileName, 'wt'); if f == -1 error(['could not open file for writing: ' fileName]); end % write header fprintf(f, '# graph\n'); %% write nodes info fprintf(f, '# nodes\n'); fprintf(f, '%d %d\n', nNodes, nDims); format = ['%g' repmat(' %g', 1, nDims-1) '\n']; for iNode = 1:nNodes fprintf(f, format, nodes(iNode, :)); end %% write edges info fprintf(f, '# edges\n'); fprintf(f, '%d\n', nEdges); format = '%d %d\n'; for iEdge = 1:nEdges fprintf(f, format, edges(iEdge, :)); end % close file fclose(f); matgeom-1.2.3/PaxHeaders.19757/INDEX0000644000000000000000000000013214055375162013521 xustar0030 mtime=1622538866.142813325 30 atime=1622538866.122813402 30 ctime=1622538866.150813297 matgeom-1.2.3/INDEX0000644000175000017500000002262014055375162014610 0ustar00juanpijuanpi00000000000000matgeom >> Computational Geometry geom3d anglePoints3d angles3d angleSort3d boundingBox3d box3dVolume boxes3d cart2cyl cart2sph2d cart2sph2 circle3dOrigin circle3dPoint circle3dPosition circles3d clipConvexPolygon3dHP clipEdge3d clipLine3d clipPoints3d clipPolygon3dHP clipRay3d composeTransforms3d Contents createBasisTransform3d createEdge3d createLine3d createPlane createRay3d createRotation3dLineAngle createRotationAboutPoint3d createRotationOx createRotationOy createRotationOz createRotationVector3d createRotationVectorPoint3d createScaling3d createSphere createTranslation3d crossProduct3d cyl2cart cylinderSurfaceArea dihedralAngle distanceLines3d distancePointEdge3d distancePointLine3d distancePointPlane distancePoints3d distancePointTriangle3d drawAngleBetweenVectors3d drawArrow3d drawAxis3d drawAxisCube drawBox3d drawCapsule drawCircle3d drawCircleArc3d drawCube drawCuboid drawCylinder drawDome drawEdge3d drawEllipse3d drawEllipseCylinder drawEllipsoid drawGrid3d drawLabels3d drawLine3d drawPartialPatch drawPlane3d drawPlatform drawPoint3d drawPolygon3d drawPolyline3d drawRay3d drawSphere drawSphericalEdge drawSphericalPolygon drawSphericalTriangle drawSurfPatch drawTorus drawVector3d edgeLength3d edges3d edgeToLine3d ellipsoidSurfaceArea equivalentEllipsoid eulerAnglesToRotation3d fillPolygon3d fillSphericalPolygon fillSphericalTriangle fitAffineTransform3d fitCircle3d fitEllipse3d fitLine3d fitPlane fitSphere geodesicCylinder hypot3 intersectBoxes3d intersectEdgePlane intersectEdgePolygon3d intersectLineCylinder intersectLinePlane intersectLinePolygon3d intersectLineSphere intersectLineTriangle3d intersectPlanes intersectPlaneSphere intersectRayPolygon3d intersectThreePlanes isBelowPlane isCoplanar isParallel3d isPerpendicular3d isPlane isPointInEllipsoid isPointOnEdge3d isPointOnLine3d isTransform3d linePosition3d lines3d lineToEdge3d medianPlane mergeBoxes3d midPoint3d normalizeLine3d normalizePlane normalizeVector3d oblateSurfaceArea orientedBox3d parallelLine3d parallelPlane planeNormal planePoint planePosition planes3d planesBisector points3d polygon3dNormalAngle polygonArea3d polygonCentroid3d polygons3d projLineOnPlane projPointOnCircle3d projPointOnCylinder projPointOnLine3d projPointOnPlane prolateSurfaceArea randomAngle3d randomPointInBox3d recenterTransform3d registerPoints3dAffine reverseLine3d reversePlane revolutionSurface rotation3dAxisAndAngle rotation3dToEulerAngles sph2cart2d sph2cart2 spheres sphericalAngle sphericalVoronoiDomain surfaceCurvature transformLine3d transformPlane3d transformPoint3d transforms3d transformVector3d triangleArea3d vectorAngle3d vectorCross3d vectorNorm3d vectors3d polygons2d cart2geod clipPolygonHP clipPolygon clipPolyline Contents contourMatrixToPolylines convexHull convexification curvature curveCMoment curveCSMoment curveMoment densifyPolygon distancePointPolygon distancePointPolyline distancePolygons distancePolygonsNoCross distancePolylines drawPolygon drawPolyline drawVertices expandPolygon fillPolygon findPoint geod2cart intersectEdgePolygon intersectLinePolygon intersectLinePolyline intersectPolylines intersectRayPolygon isPointInPolygon isPointOnPolyline medialAxisConvex minimumCaliperDiameter parametrize pointSetsAverage polygonArea polygonBounds polygonCentroid polygonContains polygonCurvature polygonEdges polygonEquivalentEllipse polygonInertiaEllipse polygonLength polygonLoops polygonNormalAngle polygonOuterNormal polygonPoint polygonSecondAreaMoments polygonSelfIntersections polygonSignature polygonSkeleton polygonSubcurve polygonSymmetryAxis polygonToRow polygonVertices polylineCentroid polylineLength polylinePoint polylineSelfIntersections polylineSubcurve projPointOnPolygon projPointOnPolyline randomPointInPolygon readPolygonSet removeMultipleVertices resamplePolygonByLength resamplePolygon resamplePolylineByLength resamplePolyline reversePolygon reversePolyline rowToPolygon signatureToPolygon simplifyPolygon simplifyPolyline smoothPolygon smoothPolyline splitPolygons steinerPoint steinerPolygon supportFunction triangulatePolygon writePolygonSet geom2d angle2Points angle3Points angleAbsDiff angleDiff angles2d angleSort bisector boundingBox boxes2d boxToPolygon boxToRect cartesianLine centeredEdgeToEdge centroid circleArcToPolyline circles2d circleToPolygon circumCenter circumCircle clipEdge clipLine clipPoints clipRay Contents crackPattern2 crackPattern createBasisTransform createCircle createDirectedCircle createEdge createHomothecy createLine createLineReflection createRay createRotation90 createRotation createScaling createTranslation createVector cubicBezierToPolyline distancePointEdge distancePointLine distancePoints drawArrow drawBezierCurve drawBox drawCenteredEdge drawCircleArc drawCircle drawEdge drawEllipseArc drawEllipse drawLabels drawLine drawOrientedBox drawParabola drawPoint drawRay drawRect drawShape drawVector edgeAngle edgeLength edgePosition edges2d edgeToLine edgeToPolyline ellipsePerimeter ellipses2d ellipseToPolygon enclosingCircle equivalentEllipse findClosestPoint fitAffineTransform2d fitPolynomialTransform2d hausdorffDistance hexagonalGrid inertiaEllipse intersectBoxes intersectCircles intersectEdges intersectLineCircle intersectLineEdge intersectLines isCounterClockwise isLeftOriented isParallel isPerpendicular isPointInCircle isPointInEllipse isPointInTriangle isPointOnCircle isPointOnEdge isPointOnLine isPointOnRay lineAngle lineFit linePosition lines2d lineToEdge medianLine mergeBoxes mergeClosePoints midPoint minDistancePoints nndist normalizeAngle normalize normalizeVector orientedBox orientedBoxToPolygon orthogonalLine parallelEdge parallelLine pointOnLine points2d polarPoint polynomialTransform2d principalAxes principalAxesTransform projPointOnLine radicalAxis randomPointInBox rays2d rectToBox rectToPolygon registerICP reverseEdge reverseLine rotateVector squareGrid transformEdge transformLine transformPoint transforms2d transformVector triangleArea triangleGrid vectorAngle vectorNorm vectors2d meshes3d averageMesh boxToMesh checkMeshAdjacentFaces clipConvexPolyhedronHP clipMeshVertices collapseEdgesWithManyFaces concatenateMeshes Contents createCube createCubeOctahedron createDodecahedron createDurerPolyhedron createIcosahedron createMengerSponge createOctahedron createRhombododecahedron createSoccerBall createStellatedMesh createTetrahedron createTetrakaidecahedron curveToMesh cutMeshByPlane cylinderMesh distancePointMesh drawFaceNormals drawMesh drawPolyhedron ellipsoidMesh ensureManifoldMesh fillMeshFaces intersectEdgeMesh3d intersectLineMesh3d intersectPlaneMesh isManifoldMesh isPointInMesh mergeCoplanarFaces mergeMeshVertices meshAdjacencyMatrix meshBoundaryEdgeIndices meshBoundary meshBoundaryVertexIndices meshComplement meshDihedralAngles meshEdgeFaces meshEdgeLength meshEdges meshFaceAdjacency meshFaceAreas meshFaceCentroids meshFaceEdges meshFace meshFaceNormals meshFaceNumber meshFacePolygons meshSilhouette meshSurfaceArea meshVertexClustering meshVertexNormals meshVolume minConvexHull polyhedra polyhedronCentroid polyhedronMeanBreadth polyhedronNormalAngle polyhedronSlice readMesh readMesh_off readMesh_ply readMesh_stl removeDuplicateFaces removeInvalidBorderFaces removeMeshEars removeMeshFaces removeMeshVertices smoothMesh sphereMesh splitMesh steinerPolytope subdivideMesh surfToMesh tetrahedronVolume torusMesh transformMesh triangulateCurvePair triangulateFaces triangulatePolygonPair trimeshEdgeFaces trimeshMeanBreadth trimeshSurfaceArea trimMesh vertexNormal writeMesh writeMesh_off writeMesh_ply writeMesh_stl utils isAxisHandle graphs addSquareFace adjacencyListToEdges boundaryGraph boundedCentroidalVoronoi2d boundedVoronoi2d centroidalVoronoi2d centroidalVoronoi2d_MC clipGraph clipGraphPolygon clipMesh2dPolygon Contents cvtIterate cvtUpdate delaunayGraph drawDigraph drawDirectedEdges drawEdgeLabels drawGraphEdges drawGraph drawNodeLabels drawSquareMesh euclideanMST fillGraphFaces gabrielGraph gcontour2d gcontour3d grAdjacentEdges grAdjacentNodes graph2Contours graphCenter graphDiameter graphPeripheralVertices graphRadius grClose grDilate grEdgeLengths grErode grFaceToPolygon grFindGeodesicPath grFindMaximalLengthPath grLabel grMean grMedian grMergeMultipleEdges grMergeMultipleNodes grMergeNodeClusters grMergeNodes grMergeNodesMedian grNodeDegree grNodeInnerDegree grNodeOuterDegree grOpen grOppositeNode grPropagateDistance grRemoveEdge grRemoveEdges grRemoveMultiplePoints grRemoveNode grRemoveNodes grShortestPath grSimplifyBranches grSimplifyBranches_old grVertexEccentricity imageGraph knnGraph mergeGraphs meshEnergy patchGraph prim_mst pruneGraph quiverToGraph readGraph relativeNeighborhoodGraph voronoi2d writeGraph polynomialCurves2d Contents drawPolynomialCurve polyfit2 polynomialCurveCentroid polynomialCurveCurvature polynomialCurveCurvatures polynomialCurveDerivative polynomialCurveFit polynomialCurveLength polynomialCurveNormal polynomialCurvePoint polynomialCurvePosition polynomialCurveProjection polynomialCurveSetFit polynomialDerivate matgeom-1.2.3/PaxHeaders.19757/COPYING0000644000000000000000000000013214055375162013762 xustar0030 mtime=1622538866.146813311 30 atime=1622538866.146813311 30 ctime=1622538866.150813297 matgeom-1.2.3/COPYING0000644000175000017500000000303414055375162015047 0ustar00juanpijuanpi00000000000000Copyright (c) 2011, INRA 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. matgeom-1.2.3/PaxHeaders.19757/NEWS0000644000000000000000000000013214055375162013426 xustar0030 mtime=1622538866.122813402 30 atime=1622538866.122813402 30 ctime=1622538866.150813297 matgeom-1.2.3/NEWS0000644000175000017500000000252214055375162014514 0ustar00juanpijuanpi00000000000000Summary of important user-visible changes for releases of the matgeom package =============================================================================== matgeom-1.2.3 Release Date: 2021-06-01 Release Manager: Juan Pablo Carbajal =============================================================================== * This release corresponds to upstream matgeom-1.2.2 + developments * Latest fixes and developments from upstream were added. Refer to the original matgeom website for news on that =============================================================================== matgeom-1.2.2 Release Date: 2019-02-12 Release Manager: Juan Pablo Carbajal =============================================================================== * Installation with GNU Octave 6.0.0 was fixed * The dummy function varLessThan.m in this package now installas only for GNU Octave versions lower than 6.0.0 * Latest fixes and developments from upstream were added. Refer to the original matgeom website for news on that =============================================================================== matgeom-1.2.1 Release Date: 2019-20-11 Release Manager: Juan Pablo Carbajal =============================================================================== ** First official release. =============================================================================== matgeom-1.2.3/PaxHeaders.19757/DESCRIPTION0000644000000000000000000000013214055375162014435 xustar0030 mtime=1622538866.118813416 30 atime=1622538866.126813388 30 ctime=1622538866.150813297 matgeom-1.2.3/DESCRIPTION0000644000175000017500000000052714055375162015526 0ustar00juanpijuanpi00000000000000Name: matgeom Version: 1.2.3 Date: 2021-01-06 Author: David Legland Maintainer: Juan Pablo Carbajal Title: Computational Geometry Description: Geometry toolbox for 2D/3D geometric computing Depends: octave (>= 4.2.0) Autoload: no License: FreeBSD Url: https://github.com/mattools/matGeom