Plot disappears when trying to interpolate
조회 수: 3 (최근 30일)
이전 댓글 표시
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
채택된 답변
Adam Danz
2021년 9월 15일
편집: Adam Danz
2021년 9월 15일
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:')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!