MATLAB-基于不平等的3D体积填充

发布于 2025-02-13 06:09:09 字数 755 浏览 3 评论 0原文

我有三个变量xyz。我的形式不平等

x> = a,y> = b,z> = c,x+y> = d,y+z> = e,= e,x+z> = f,x> = f,x+y+ z> = g

其中a to g是正数。在带有轴x的3D图上,yz,这是一个打开的卷。我想用颜色填充开放的侧面(即远离0)形状,并在图中显示。在MATLAB上执行此操作的方法是什么?

我尝试使用fill3和网格,但是使用plot3也不是很好,结果

[x,y,z] = meshgrid(0:0.01:2,0:0.01:2,0:0.01:2);
ineq = (x>=1)& (y>0.5)&(z>=0.25)&(x+y>1.25)&(y+z>0.6)&(x+z>1.1)&(x+y+z>1.6);
fill3(x(:),y(:),z(:), 'r')
box on
grid on

也不是很好。还有其他方法可以在MATLAB上生成漂亮的3D数字吗?

Mathematica使用regionPlot3D来做到这一点。我希望有类似的结果图像。

I have three variables x, y and z. I have inequalities of the form

x >= a, y>= b, z>=c, x+y>=d, y+z>=e, x+z>=f, x+y+z>=g

where a to g are positive numbers. On a 3D plot with axes x, y and z, this is an open volume. I would like to fill the open side (i.e. away from 0) shape with color and show it in a plot. What is the way to do this on MATLAB?

I attempted to use fill3 and a mesh but the result was not very good

[x,y,z] = meshgrid(0:0.01:2,0:0.01:2,0:0.01:2);
ineq = (x>=1)& (y>0.5)&(z>=0.25)&(x+y>1.25)&(y+z>0.6)&(x+z>1.1)&(x+y+z>1.6);
fill3(x(:),y(:),z(:), 'r')
box on
grid on

Using plot3 also was not very good. Is there any other way to generate a nice 3D figure on MATLAB?

Mathematica does this using RegionPlot3D. I was hoping for a similar resultant image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2025-02-20 06:09:09

首先,使用3D网格时要小心,您定义的一个包含8m+点。

假设您的形状为凸,您可以使用 href =“ https://www.mathworks.com/help/matlab/ref/ref/trisurf.html” rel =“ nofollow noreferrer”> trisurf

不是选项设置为真实,以减少凸船体中所述的元素数量。

[x,y,z] = meshgrid(0:0.1:2,0:0.1:2,0:0.1:2);
ineq = (x>=1)& (y>0.5)&(z>=0.25)&(x+y>1.25)&(y+z>0.6)&(x+z>1.1)&(x+y+z>1.6);

figure;

x_ineq = x(ineq);
y_ineq = y(ineq);
z_ineq = z(ineq);

id_cvhl = convhull(x_ineq,y_ineq,z_ineq,'Simplify',true);

trisurf(id_cvhl,x_ineq,y_ineq,z_ineq,'FaceColor','cyan','edgecolor','none')

xlim([0 2])
ylim([0 2])
zlim([0 2])

如果您希望结果看起来比regionplot3d多一点,请不要使用简化,然后绘制边缘(请小心不要与太多点的网格!)。

id_cvhl = convhull(x_ineq,y_ineq,z_ineq);

trisurf(id_cvhl,x_ineq,y_ineq,z_ineq,'Facecolor','yellow')

First of all, be careful when using 3D meshes, the one you defined contains 8M+ points.

Assuming your shape is convex, you can use convhull and trisurf:

Not that the option 'Simplify' is set as true to reduce the number of elements accounted for in the convex hull.

[x,y,z] = meshgrid(0:0.1:2,0:0.1:2,0:0.1:2);
ineq = (x>=1)& (y>0.5)&(z>=0.25)&(x+y>1.25)&(y+z>0.6)&(x+z>1.1)&(x+y+z>1.6);

figure;

x_ineq = x(ineq);
y_ineq = y(ineq);
z_ineq = z(ineq);

id_cvhl = convhull(x_ineq,y_ineq,z_ineq,'Simplify',true);

trisurf(id_cvhl,x_ineq,y_ineq,z_ineq,'FaceColor','cyan','edgecolor','none')

xlim([0 2])
ylim([0 2])
zlim([0 2])

enter image description here

In case you want the result to look a bit more than RegionPlot3D, don't use Simplify, and plot the edges (Be careful not too have a mesh with too many points!).

id_cvhl = convhull(x_ineq,y_ineq,z_ineq);

trisurf(id_cvhl,x_ineq,y_ineq,z_ineq,'Facecolor','yellow')

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文