我正在尝试在Matlab中制作3d环。以下是与我所做的类似的事情:

t = linspace(0,2*pi);
rin = 0.1;
rout = 0.25;
xin = 0.5 + rin*cos(t);% 0.5 is the center of the ring
xout = 0.5 + rout*cos(t);
yin = 0.5 + rin*sin(t);
yout = 0.5 + rout*sin(t);

% Make patch
hp = patch([xout,xin],[yout,yin],'g','linestyle','none','facealpha',0.25);

现在,我想将此扩展到3d情况。我想给这枚戒指增高。但是当我尝试添加 vector [z1,z2]时,
z1=0.5*ones(size(xin));
z2=z1;

我尝试了Z1和Z2的不同组合,但仍然找不到解决方案。

最佳答案

复制您的环并添加两个圆柱体,我得到:

%% Config
t = linspace(0,2*pi);
rin = 0.1;
rout = 0.25;
center = [1, 0.5];
xin = rin*cos(t);
xout = rout*cos(t);
yin = rin*sin(t);
yout = rout*sin(t);
z1 = 0;
z2 = 0.24;

%% Plot
clf;
hold on;
bottom = patch(center(1)+[xout,xin], ...
               center(2)+[yout,yin], ...
               z1*ones(1,2*length(xout)),'');
top = patch(center(1)+[xout,xin], ...
            center(2)+[yout,yin], ...
            z2*ones(1,2*length(xout)),'');
[X,Y,Z] = cylinder(1,length(xin));
outer = surf(rout*X+center(1), ...
             rout*Y+center(2), ...
             Z*(z2-z1)+z1);
inner = surf(rin*X+center(1), ...
             rin*Y+center(2), ...
             Z*(z2-z1)+z1);

set([bottom, top, outer, inner], ...
    'FaceColor', [0 1 0], ...
    'FaceAlpha', 0.99, ...
    'linestyle', 'none', ...
    'SpecularStrength', 0.7);
light('Position',[1 3 2]);
light('Position',[-3 -1 3]);
axis vis3d; axis equal; view(3);

关于matlab - 使用补丁在Matlab中的3d环,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27668343/

10-17 01:38