decsg fails to decompose a few ellipses out of a set of 19 for unknown reason
Hello all, I am attempting to generate a decomposed geometry matrix of various ellipses in a square region using decsg in order to then extrude the geometry into 3D and mesh for use in a static structural model in the pde toolbox.
However, some of the ellipses (#4 when included with #s 1-3 or #19 when included with the rest) cause decsg to fail when included in the decsg inputs as so:
Error using decsg
Unable to decompose objects in the geometry description matrix into minimal regions.
Error in scatteredEllipses (line 42)
[dl, ~] = decsg(gd,sf,ns);
The scatteredEllipses function is presented below in its entirety, I have also attached the force_x, force_y, and force_z variables within forces.mat which are 512×512 double matrices of force magnitudes which represent desired ellipse locations.
clearvars -except force*; close all;
%% Fit ellipses to each traction island
tractionMask = abs(force_x) + abs(force_y) + abs(force_z); %combine x,y,z tractions to create mask of all nonzero elements
tractionMask(tractionMask ~= 0) = 1; %convert nonzero elements to 1
cc = bwconncomp(tractionMask); %get all connected ellipse regions
s = regionprops(cc,{‘Centroid’,’Orientation’,’MajorAxisLength’,’MinorAxisLength’}); %fit ellipse parameters to each detected region
figure, imshow(tractionMask,[]), hold on
theta = linspace(0,2*pi);
orientationList = zeros(size(s,1),2);
for i = 1:length(s)
col = (s(i).MajorAxisLength/2)*cos(theta);
row = (s(i).MinorAxisLength/2)*sin(theta);
M = makehgtform(‘translate’,[s(i).Centroid, 0],’zrotate’,deg2rad(-1*s(i).Orientation));
[orientationList(i,1),orientationList(i,2)] = pol2cart(deg2rad(-1*s(i).Orientation),1);
D = M*[col;row;zeros(1,numel(row));ones(1,numel(row))];
plot(D(1,:),D(2,:),’r’,’LineWidth’,2); hold on
s(i).Orientation = -1 * s(i).Orientation; %convert orientation to xy coordinate frame
end
%axis xy
hold off
%% Generate geometry
meshPtsFwdSol = 512;
halfSide = meshPtsFwdSol/2;
bound = [3; 4; -halfSide; halfSide; halfSide; -halfSide; halfSide; halfSide; -halfSide; -halfSide];
ns = char(‘bound’);
sf = ‘bound’;
full = 1:length(s);
workingSubset = 4:length(s)-1;
g = 1;
for i = workingSubset %switch with full to cause error
sf = [sf,’+elli’,num2str(g)];
ns = char(ns,[‘elli’,num2str(g)]);
elli(:,g) = [4; s(i).Centroid(1)-halfSide; s(i).Centroid(2)-halfSide; s(i).MajorAxisLength/2; s(i).MinorAxisLength/2; deg2rad(s(i).Orientation); 0; 0; 0; 0];
g = g + 1;
end
gd = [bound,elli];
ns = ns’;
[dl, ~] = decsg(gd,sf,ns);
%figure,pdegplot(dl,’EdgeLabels’,’on’,’FaceLabels’,’on’)
pdem = createpde;
g = geometryFromEdges(pdem,dl);
%figure,pdegplot(pdem,’EdgeLabels’,’on’,’FaceLabels’,’on’)
facets = facetAnalyticGeometry(pdem,g,0);
gm = analyticToDiscrete(facets);
pdem.Geometry = gm;
figure,pdegplot(pdem,’EdgeLabels’,’on’,’FaceLabels’,’on’)Hello all, I am attempting to generate a decomposed geometry matrix of various ellipses in a square region using decsg in order to then extrude the geometry into 3D and mesh for use in a static structural model in the pde toolbox.
However, some of the ellipses (#4 when included with #s 1-3 or #19 when included with the rest) cause decsg to fail when included in the decsg inputs as so:
Error using decsg
Unable to decompose objects in the geometry description matrix into minimal regions.
Error in scatteredEllipses (line 42)
[dl, ~] = decsg(gd,sf,ns);
The scatteredEllipses function is presented below in its entirety, I have also attached the force_x, force_y, and force_z variables within forces.mat which are 512×512 double matrices of force magnitudes which represent desired ellipse locations.
clearvars -except force*; close all;
%% Fit ellipses to each traction island
tractionMask = abs(force_x) + abs(force_y) + abs(force_z); %combine x,y,z tractions to create mask of all nonzero elements
tractionMask(tractionMask ~= 0) = 1; %convert nonzero elements to 1
cc = bwconncomp(tractionMask); %get all connected ellipse regions
s = regionprops(cc,{‘Centroid’,’Orientation’,’MajorAxisLength’,’MinorAxisLength’}); %fit ellipse parameters to each detected region
figure, imshow(tractionMask,[]), hold on
theta = linspace(0,2*pi);
orientationList = zeros(size(s,1),2);
for i = 1:length(s)
col = (s(i).MajorAxisLength/2)*cos(theta);
row = (s(i).MinorAxisLength/2)*sin(theta);
M = makehgtform(‘translate’,[s(i).Centroid, 0],’zrotate’,deg2rad(-1*s(i).Orientation));
[orientationList(i,1),orientationList(i,2)] = pol2cart(deg2rad(-1*s(i).Orientation),1);
D = M*[col;row;zeros(1,numel(row));ones(1,numel(row))];
plot(D(1,:),D(2,:),’r’,’LineWidth’,2); hold on
s(i).Orientation = -1 * s(i).Orientation; %convert orientation to xy coordinate frame
end
%axis xy
hold off
%% Generate geometry
meshPtsFwdSol = 512;
halfSide = meshPtsFwdSol/2;
bound = [3; 4; -halfSide; halfSide; halfSide; -halfSide; halfSide; halfSide; -halfSide; -halfSide];
ns = char(‘bound’);
sf = ‘bound’;
full = 1:length(s);
workingSubset = 4:length(s)-1;
g = 1;
for i = workingSubset %switch with full to cause error
sf = [sf,’+elli’,num2str(g)];
ns = char(ns,[‘elli’,num2str(g)]);
elli(:,g) = [4; s(i).Centroid(1)-halfSide; s(i).Centroid(2)-halfSide; s(i).MajorAxisLength/2; s(i).MinorAxisLength/2; deg2rad(s(i).Orientation); 0; 0; 0; 0];
g = g + 1;
end
gd = [bound,elli];
ns = ns’;
[dl, ~] = decsg(gd,sf,ns);
%figure,pdegplot(dl,’EdgeLabels’,’on’,’FaceLabels’,’on’)
pdem = createpde;
g = geometryFromEdges(pdem,dl);
%figure,pdegplot(pdem,’EdgeLabels’,’on’,’FaceLabels’,’on’)
facets = facetAnalyticGeometry(pdem,g,0);
gm = analyticToDiscrete(facets);
pdem.Geometry = gm;
figure,pdegplot(pdem,’EdgeLabels’,’on’,’FaceLabels’,’on’) Hello all, I am attempting to generate a decomposed geometry matrix of various ellipses in a square region using decsg in order to then extrude the geometry into 3D and mesh for use in a static structural model in the pde toolbox.
However, some of the ellipses (#4 when included with #s 1-3 or #19 when included with the rest) cause decsg to fail when included in the decsg inputs as so:
Error using decsg
Unable to decompose objects in the geometry description matrix into minimal regions.
Error in scatteredEllipses (line 42)
[dl, ~] = decsg(gd,sf,ns);
The scatteredEllipses function is presented below in its entirety, I have also attached the force_x, force_y, and force_z variables within forces.mat which are 512×512 double matrices of force magnitudes which represent desired ellipse locations.
clearvars -except force*; close all;
%% Fit ellipses to each traction island
tractionMask = abs(force_x) + abs(force_y) + abs(force_z); %combine x,y,z tractions to create mask of all nonzero elements
tractionMask(tractionMask ~= 0) = 1; %convert nonzero elements to 1
cc = bwconncomp(tractionMask); %get all connected ellipse regions
s = regionprops(cc,{‘Centroid’,’Orientation’,’MajorAxisLength’,’MinorAxisLength’}); %fit ellipse parameters to each detected region
figure, imshow(tractionMask,[]), hold on
theta = linspace(0,2*pi);
orientationList = zeros(size(s,1),2);
for i = 1:length(s)
col = (s(i).MajorAxisLength/2)*cos(theta);
row = (s(i).MinorAxisLength/2)*sin(theta);
M = makehgtform(‘translate’,[s(i).Centroid, 0],’zrotate’,deg2rad(-1*s(i).Orientation));
[orientationList(i,1),orientationList(i,2)] = pol2cart(deg2rad(-1*s(i).Orientation),1);
D = M*[col;row;zeros(1,numel(row));ones(1,numel(row))];
plot(D(1,:),D(2,:),’r’,’LineWidth’,2); hold on
s(i).Orientation = -1 * s(i).Orientation; %convert orientation to xy coordinate frame
end
%axis xy
hold off
%% Generate geometry
meshPtsFwdSol = 512;
halfSide = meshPtsFwdSol/2;
bound = [3; 4; -halfSide; halfSide; halfSide; -halfSide; halfSide; halfSide; -halfSide; -halfSide];
ns = char(‘bound’);
sf = ‘bound’;
full = 1:length(s);
workingSubset = 4:length(s)-1;
g = 1;
for i = workingSubset %switch with full to cause error
sf = [sf,’+elli’,num2str(g)];
ns = char(ns,[‘elli’,num2str(g)]);
elli(:,g) = [4; s(i).Centroid(1)-halfSide; s(i).Centroid(2)-halfSide; s(i).MajorAxisLength/2; s(i).MinorAxisLength/2; deg2rad(s(i).Orientation); 0; 0; 0; 0];
g = g + 1;
end
gd = [bound,elli];
ns = ns’;
[dl, ~] = decsg(gd,sf,ns);
%figure,pdegplot(dl,’EdgeLabels’,’on’,’FaceLabels’,’on’)
pdem = createpde;
g = geometryFromEdges(pdem,dl);
%figure,pdegplot(pdem,’EdgeLabels’,’on’,’FaceLabels’,’on’)
facets = facetAnalyticGeometry(pdem,g,0);
gm = analyticToDiscrete(facets);
pdem.Geometry = gm;
figure,pdegplot(pdem,’EdgeLabels’,’on’,’FaceLabels’,’on’) pde, pdetoolbox, decsg MATLAB Answers — New Questions