Matlab:从轮廓线创建3D图形时的工件

时间:2019-05-01 20:55:05

标签: matlab matlab-figure

我需要绘制3个级别的幅度并将其映射到另一个距离,以获得类似圆锥形的3D图形。这是原始图片,其最高水平为90%,80%和70%: enter image description here

以下是轮廓线的数据:https://pastebin.com/NUaJJbpt

我选择使用shapeAlpha()绘制3D多边形:

clear;
c11 = load('cntr1.txt', '-ascii');
c21 = load('cntr2.txt', '-ascii');
c31 = load('cntr3.txt', '-ascii');
c11(:, 1:2) = c11(:, 1:2)-100.;
c21(:, 1:2) = c21(:, 1:2)-100.;
c31(:, 1:2) = c31(:, 1:2)-100.;
c12(:, 1:2) = c11(:, 1:2).*804./540.;
c22(:, 1:2) = c21(:, 1:2).*804./540.;
c32(:, 1:2) = c31(:, 1:2).*804./540.;
c11(:, 3) = 540.;
c21(:, 3) = 540.;
c31(:, 3) = 540.;
c11 = [c11; c21];
c21 = [c21; c31];
c12(:, 3) = 804.;
c22(:, 3) = 804.;
c32(:, 3) = 804.;
c12 = [c12; c22];
c22 = [c22; c32];
P1 = [c11(:,1), c11(:,2), c11(:,3); c12(:,1), c12(:,2), c12(:,3)];
P2 = [c21(:,1), c21(:,2), c21(:,3); c22(:,1), c22(:,2), c22(:,3)];
P3 = [c31(:,1), c31(:,2), c31(:,3); c32(:,1), c32(:,2), c32(:,3)];
P1 = unique(P1, 'rows');
P2 = unique(P2, 'rows');
P3 = unique(P3, 'rows');
figure;
hold on;
axis equal;
shp1 = alphaShape(P1(:,1), P1(:,2), P1(:,3), Inf);
shp2 = alphaShape(P2(:,1), P2(:,2), P2(:,3), Inf);
shp3 = alphaShape(P3(:,1), P3(:,2), P3(:,3), Inf);
h3 = shp3.plot;
h2 = shp2.plot;
h1 = shp1.plot;
set(h1,'edgecolor', 'none', 'facealpha', 0.2, 'facecolor', 'green');
set(h2,'edgecolor', 'none', 'facealpha', 0.2, 'facecolor', 'blue');
set(h3,'edgecolor', 'none', 'facealpha', 0.4, 'facecolor', 'red');
view(3);
hold off;

这就是我得到的:

enter image description here

据我了解,之所以会发生颜色干涉,是因为每个图形都是实心的,没有孔,并且我需要内圈为实心,而两个外层为“环”。我尝试了HoleThresholdRegionThreshold的各种值,但是渲染错误或渲染不完整。

我的问题:如何创建具有不同颜色和透明度的三个振幅级别的图,以使它们不会互相干扰?

1 个答案:

答案 0 :(得分:5)

一个简单的解决方法是避免顶部和底部呈现丑陋的颜色,这是使P1P2P3的z值彼此略有偏移:

offset = 0.1;
P2(:,3) = P2(:,3) + offset;
P3(:,3) = P3(:,3) + offset*2;

但是,通过这种方式,体积仍然是实体,因此透明体积仍会重叠。