如何通过matplotlib绘制四面体网格?(How to draw a Tetrahedron mesh by matplotlib?)

编程入门 行业动态 更新时间:2024-10-28 16:22:34
如何通过matplotlib绘制四面体网格?(How to draw a Tetrahedron mesh by matplotlib?)

我想通过matplotlib绘制四面体网格,以下是一个简单的四面体网格:

xyz = np.array([ [-1,-1,-1], [ 1,-1,-1], [ 1, 1,-1], [-1, 1,-1], [-1,-1, 1], [ 1,-1, 1], [ 1, 1, 1], [-1, 1, 1]], dtype=np.float) tets = np.array([ [0,1,2,6], [0,5,1,6], [0,4,5,6], [0,7,4,6], [0,3,7,6], [0,2,3,6]], dtype=np.int)

当然,在实际应用中,网格中的四面体数量可能很大。 我在谷歌找不到任何有用的帮助信息。 那么用matplotlib绘制四面体网格的更好方法是什么?

此外,我可以得到网格的所有三角形面。

tri = np.array([ [0 2 1] [0 1 5] [0 6 1] [0 3 2] [0 2 6] [0 6 3] [0 7 3] [0 5 4] [0 6 4] [0 4 7] [0 6 5] [0 6 7] [1 2 6] [5 1 6] [2 3 6] [3 7 6] [4 5 6] [7 4 6]],dtype=np.int)

I want to plot a tetrahedron mesh by matplotlib, and the following are a simple tetrahedron mesh:

xyz = np.array([ [-1,-1,-1], [ 1,-1,-1], [ 1, 1,-1], [-1, 1,-1], [-1,-1, 1], [ 1,-1, 1], [ 1, 1, 1], [-1, 1, 1]], dtype=np.float) tets = np.array([ [0,1,2,6], [0,5,1,6], [0,4,5,6], [0,7,4,6], [0,3,7,6], [0,2,3,6]], dtype=np.int)

Of course, in practical applications, the number of tetrahedrons in a mesh can be large. I can't find any useful help information in google. So what is the better way to plot a tetrahedron mesh by matplotlib?

Furthermore, I can get all the triangle faces of the mesh.

tri = np.array([ [0 2 1] [0 1 5] [0 6 1] [0 3 2] [0 2 6] [0 6 3] [0 7 3] [0 5 4] [0 6 4] [0 4 7] [0 6 5] [0 6 7] [1 2 6] [5 1 6] [2 3 6] [3 7 6] [4 5 6] [7 4 6]],dtype=np.int)

最满意答案

matplotlib可能是该任务的错误工具。 3D绘图很难,并且有例如ParaView试用。 您可以使用meshio (我的项目)将网格编写为适当的数据类型:

import meshio meshio.write('out.vtu', xyz, {'tetra': tets})

在此处输入图像描述

One can use mpl_toolkits.mplot3d.art3d.Poly3DCollection:

import mpl_toolkits.mplot3d as a3 axes = a3.Axes3D(pl.figure()) vts = xyz[tri, :] tri = a3.art3d.Poly3DCollection(vts) tri.set_alpha(0.2) tri.set_color('grey') axes.add_collection3d(tri) axes.plot(point[:,0], point[:,1], point[:,2], 'ko') axes.set_axis_off() axes.set_aspect('equal') pl.show()

更多推荐

本文发布于:2023-08-04 17:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1420037.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   matplotlib   draw   mesh   Tetrahedron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!