Plot disappears when trying to interpolate
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kevin Hanekom
le 15 Sep 2021
Commenté : Kevin Hanekom
le 15 Sep 2021
Good afternoon,
In the code below for some weird reason i cant figure out how to interpolate the color so it changes as it extends away from (0,0,0), could you possibly tell me how I would be able to fix this?
clc; clear; close all;
i = 1;
PStress = zeros(134343,3);
Yieldstr = 1000; %KPa
minValue = -4*Yieldstr;
maxValue = 4*Yieldstr;
fidelity = Yieldstr/8; %We can adjust this to make cleaner graphs, might just take longer to run
for sigx = minValue:fidelity:maxValue
for sigy = minValue:fidelity:maxValue
for sigz = minValue:fidelity:maxValue
%Reduced to sig1-3
VM = (1/(sqrt(2)) * sqrt((sigx-sigy).^2 + (sigy-sigz).^2 +(sigz-sigx).^2));
if VM < Yieldstr
if (sigx==sigy) && (sigy==sigz) && (sigz==sigx)
%stops code
else
PStress(i,1) = sigx;
PStress(i,2) = sigy;
PStress(i,3) = sigz;
i = i + 1;
end
end
end
end
end
Data = sqrt(sigx.^2+sigy.^2+sigz.^2);
colormap cool
shading interp
D = alphaShape(PStress,inf);
plot(D,"FaceColor","none","EdgeColor","interp");
If you remove the edge color part you will see the plot comes back to its original shape. The goal is to have something that looks like this,
Thanks for the time as always,
Kevin
0 commentaires
Réponse acceptée
Adam Danz
le 15 Sep 2021
Modifié(e) : Adam Danz
le 15 Sep 2021
Plotting an alphaShape creates a patch object. When set to interp, the EdgeColor property requires existing CData or FaceVertexData prior to setting EdgeColor (see documentation). From your description, the interpolation should be based on distance to (0,0,0) so I've set CData to the distance of each vertex from (0,0,0).
i = 1;
PStress = zeros(134343,3);
Yieldstr = 1000; %KPa
minValue = -4*Yieldstr;
maxValue = 4*Yieldstr;
fidelity = Yieldstr/8; %We can adjust this to make cleaner graphs, might just take longer to run
for sigx = minValue:fidelity:maxValue
for sigy = minValue:fidelity:maxValue
for sigz = minValue:fidelity:maxValue
%Reduced to sig1-3
VM = (1/(sqrt(2)) * sqrt((sigx-sigy).^2 + (sigy-sigz).^2 +(sigz-sigx).^2));
if VM < Yieldstr
if (sigx==sigy) && (sigy==sigz) && (sigz==sigx)
%stops code
else
PStress(i,1) = sigx;
PStress(i,2) = sigy;
PStress(i,3) = sigz;
i = i + 1;
end
end
end
end
end
Data = sqrt(sigx.^2+sigy.^2+sigz.^2);
colormap cool
shading interp
D = alphaShape(PStress,inf);
h = plot(D, 'FaceColor', 'none');
distance = sqrt(sum(h.Vertices,2).^2);
h.CData = distance;
h.EdgeColor = 'interp';
cb = colorbar();
ylabel(cb, 'Distance');
xline(0, 'k:')
yline(0, 'k:')
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!