From 9db13ba9da72e0447fb0bee73cdceed215a94bbf Mon Sep 17 00:00:00 2001 From: oqilipo <> Date: Sat, 14 Oct 2023 14:12:31 +0200 Subject: [PATCH 1/3] Fix of fillPolygon.m --- matGeom/meshes3d/meshBoundary.m | 9 +++++ matGeom/polygons2d/fillPolygon.m | 69 +++++++++----------------------- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/matGeom/meshes3d/meshBoundary.m b/matGeom/meshes3d/meshBoundary.m index 06b10a8e..17c8583a 100644 --- a/matGeom/meshes3d/meshBoundary.m +++ b/matGeom/meshes3d/meshBoundary.m @@ -4,6 +4,7 @@ % CURVES = meshBoundary(V, F) % % Example +% % Example 1 % % create centered icosahedron % [v, f] = createIcosahedron; % v(:,3) = v(:,3) - mean(v(:,3)); @@ -18,6 +19,14 @@ % curves = meshBoundary(vc, fc); % hold on; drawPolygon3d(curves{1}, 'linewidth', 2, 'color', 'b'); % +% % Example 2 +% mesh = readMesh('mushroom.off'); +% plane = createPlane([0 0 0.7], [-1 -2 3]); +% mesh = clipMeshVertices(mesh, plane, 'shape', 'plane'); +% curves = meshBoundary(mesh); +% figure; drawMesh(mesh); axis equal; view(3); +% cellfun(@(x) drawPolygon3d(x, 'linewidth', 2, 'color', 'b'), curves) +% % See also % meshes3d, meshBoundaryEdgeIndices, meshBoundaryVertexIndices % diff --git a/matGeom/polygons2d/fillPolygon.m b/matGeom/polygons2d/fillPolygon.m index 2665949c..16b8265e 100644 --- a/matGeom/polygons2d/fillPolygon.m +++ b/matGeom/polygons2d/fillPolygon.m @@ -20,71 +20,42 @@ % polygons2d, drawCurve, drawPolygon % ------ -% Author: David Legland +% Author: David Legland, oqilipo % E-mail: david.legland@inrae.fr % Created: 2005-04-07 % Copyright 2005-2023 INRA - TPV URPOI - BIA IMASTE -% check input +% Check input if isempty(varargin) - error('need to specify a polygon'); + error('Not enough input arguments.'); 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 +% Check if the polygon is given in two separate arrays. +if numel(varargin) > 1 + if isnumeric(varargin{2}) + varargin{2} = [varargin{1}, varargin{2}]; + varargin(1)=[]; 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 +% Convert into a polyShape +polyShape = parsePolygon(varargin{1}, 'polyshape'); +varargin(1)=[]; -% 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 +% Set default color format if no color is given. if isempty(varargin) - varargin = {'b'}; + varargin = {'FaceColor', 'b'}; end +if ~mod(numel(varargin), 2) == 0 + % Assume only the color was given. + varargin = ['FaceColor', varargin]; +end -% fill the polygon with desired style -h = fill(px, py, varargin{:}, 'lineStyle', 'none'); +% Fill the polygon with desired style. +h = plot(polyShape, varargin{:}, 'LineStyle', 'none'); -% output +% Output if nargout > 0 varargout{1} = h; end From 9b478f635879e5de780bd2f58cfe3b784400d31b Mon Sep 17 00:00:00 2001 From: oqilipo <> Date: Sat, 14 Oct 2023 14:29:14 +0200 Subject: [PATCH 2/3] Example added to fillPolygon.m --- matGeom/polygons2d/fillPolygon.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matGeom/polygons2d/fillPolygon.m b/matGeom/polygons2d/fillPolygon.m index 16b8265e..1f06b42c 100644 --- a/matGeom/polygons2d/fillPolygon.m +++ b/matGeom/polygons2d/fillPolygon.m @@ -11,10 +11,17 @@ % fillPolygon(PX, PY); % Specifies coordinates of the polygon in separate arrays. % -% % H = fillPolygon(...); % Also returns a handle to the created patch % +% Example +% oRectangle = [0 0;10 0;10 10;0 10]; +% iRectangle = flipud(0.5*[0 0;10 0;10 10;0 10]+1); +% pol = {oRectangle, iRectangle}; +% figure('color','w') +% fillPolygon(pol,'g') +% drawPolygon(pol,'r') +% % % See also % polygons2d, drawCurve, drawPolygon From b47164cbc423c8822951fcebaf204f8ba37a4022 Mon Sep 17 00:00:00 2001 From: oqilipo <> Date: Sat, 14 Oct 2023 14:32:51 +0200 Subject: [PATCH 3/3] Example update of fillPolygon.m --- matGeom/polygons2d/fillPolygon.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matGeom/polygons2d/fillPolygon.m b/matGeom/polygons2d/fillPolygon.m index 1f06b42c..f2c7e7ec 100644 --- a/matGeom/polygons2d/fillPolygon.m +++ b/matGeom/polygons2d/fillPolygon.m @@ -16,7 +16,7 @@ % % Example % oRectangle = [0 0;10 0;10 10;0 10]; -% iRectangle = flipud(0.5*[0 0;10 0;10 10;0 10]+1); +% iRectangle = flipud(0.5*oRectangle+1); % pol = {oRectangle, iRectangle}; % figure('color','w') % fillPolygon(pol,'g')