简体   繁体   English

如何在Python中的3D三角曲面上绘制插值的标量场

[英]How to plot an interpolated scalar field on a 3D triangulated surface in Python

My problem is as follows: I have a triangulated surface with arrays X,Y,Z containing the coordinates of the mesh vertices and array Triangles containing the indices of the vertex points for each corner of the triangle (ie each line of the array contains a triplet defining a triangle in terms of vertices). 我的问题如下:我有一个三角表面,其中的数组X,Y,Z包含网格顶点的坐标,而数组Triangles包含三角形每个角的顶点的索引(即,数组的每一行包含一个用顶点定义三角形的三元组)。 Furthermore, I have an array Field containing scalar field values on each vertex of the mesh. 此外,我有一个数组Field其中包含网格每个顶点上的标量字段值。 I wish to plot the triangular mesh in Python, where each triangle is colored according to the field values of its vertices. 我希望在Python中绘制三角形网格,其中每个三角形根据其顶点的字段值着色。

I have found a solution for this problem, if one assigns a single color per triangle (see here ). 如果每个三角形分配一种颜色 (请参见此处 ),我已经找到了解决此问题的方法。 What if I want to interpolate the field values over the surface of each single triangle, so that there is a continuous (smooth even better) coloring of the mesh? 如果我想在每个单个三角形的表面上插值字段值,以便对网格进行连续(甚至更平滑)着色,该怎么办?

I thought to use the tri_api of Matplotlib, because it can also do interpolation over triangular grids, however I have not found a solution that suits my needs. 我以为使用Matplotlib的tri_api,因为它也可以在三角网格上进行插值,但是我没有找到适合我需要的解决方案。 This demo comes close, but it is restricted on flat surfaces and interpolates on a rectangular grid. 该演示非常接近,但仅限于平面,并插在矩形网格上。

Of course, the solution does not have to entail Matplotlib, it can be any other Python library/toolbox. 当然,该解决方案不必包含Matplotlib,它可以是任何其他Python库/工具箱。 I would be grateful for any suggestions! 如有任何建议,我将不胜感激!

Plotting in 3D is hard, and there are other software tools that you can use, notably ParaView . 在3D模式下进行绘图非常困难,您还可以使用其他软件工具,尤其是ParaView You'll first have to convert your mesh into a file that ParaView can use, though. 不过,您首先必须将网格转换为ParaView可以使用的文件。 To this end, you can for example use meshio (which I wrote): 为此,您可以例如使用meshio (我写过):

import numpy
import meshio

points = numpy.array([
    [0.0, 0.0, 0.0],
    [0.0, 1.0, 0.0],
    [0.0, 0.0, 1.0],
    ])
cells = {
    "triangle": numpy.array([
        [0, 1, 2]
        ])
    }
meshio.write_points_cells(
    "foo.vtk",
    points,
    cells,
    point_data=point_data,
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM