Plot disappears when trying to interpolate

2 views (last 30 days)
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);
Warning: Duplicate data points have been detected and removed.
plot(D,"FaceColor","none","EdgeColor","interp");
Warning: Error creating or updating Patch
Error in value of property FaceVertexCData
Number of colors must equal number of vertices
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

Accepted Answer

Adam Danz
Adam Danz on 15 Sep 2021
Edited: Adam Danz on 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);
Warning: Duplicate data points have been detected and removed.
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:')
  1 Comment
Kevin Hanekom
Kevin Hanekom on 15 Sep 2021
This is amazing, thank you for solving this for me! so much to learn, exciting.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!