gpt4 book ai didi

enthought - 如何为 Mayavi 的 mlab.mesh 定义 x,y,z 坐标?

转载 作者:行者123 更新时间:2023-12-01 15:01:10 26 4
gpt4 key购买 nike

我正在尝试创建一个将出现在 Mayavi mlab.points3d 图中的 3D 框。

我认为这应该可以使用 mlab.mesh 函数来实现,如下所示:

points = mlab.points3d(xp,yp,zp,sp)
3Dbox = mlab.mesh(xbox,ybox,zbox)
mlab.show()

我查看了 mesh 的 mlab 手册条目,但是对于我的生活来说,我无法理解网格的 x、y、z 数据点是如何定义的。

有谁能给我指点一下吗?特别感谢 3D 框的 x、y、z 数据点示例。

最佳答案

您可以看到 3D 数组拆分为 x、y 和 z 轴的 3 个矩阵。每个矩阵索引将描述一个坐标,并且该坐标的每个点都将与该邻居相连。所以你可以先定义 6 个平面来制作你的盒子:

import numpy
import mayavi.mlab


# pt1_ _ _ _ _ _ _ _ _pt2
# /| /|
# / | / |
# pt3/_ | _ _ _ _ _ _pt4/ |
# | | | |
# | | | |
# | pt5_ _ _ _ _ _ _|_ _|pt6
# | / | /
# | / | /
# pt7|/_ _ _ _ _ _ _ _ _|/pt8

# Where :
x1, y1, z1 = (0, 1, 1) # | => pt1
x2, y2, z2 = (1, 1, 1) # | => pt2
x3, y3, z3 = (0, 0, 1) # | => pt3
x4, y4, z4 = (1, 0, 1) # | => pt4
x5, y5, z5 = (0, 1, 0) # | => pt5
x6, y6, z6 = (1, 1, 0) # | => pt6
x7, y7, z7 = (0, 0, 0) # | => pt7
x8, y8, z8 = (1, 0, 0) # | => pt8


box_points = numpy.array([[x1, y1, z1], [x2, y2, z2], [x3, y3, z3],
[x4, y4, z4], [x5, y5, z5], [x6, y6, z6],
[x7, y7, z7], [x8, y8, z8]])

mayavi.mlab.points3d(box_points[:, 0], box_points[:, 1], box_points[:, 2],
mode="axes", color=(1, 0, 0))


mayavi.mlab.mesh([[x1, x2],
[x3, x4]], # | => x coordinate

[[y1, y2],
[y3, y4]], # | => y coordinate

[[z1, z2],
[z3, z4]], # | => z coordinate

color=(0, 0, 0)) # black

# Where each point will be connected with this neighbors :
# (link = -)
#
# x1 - x2 y1 - y2 z1 - z2 | => pt1 - pt2
# - - and - - and - - | => - -
# x3 - x4 y3 - y4 z3 - z4 | => pt3 - pt4


mayavi.mlab.mesh([[x5, x6], [x7, x8]],
[[y5, y6], [y7, y8]],
[[z5, z6], [z7, z8]],
color=(1, 0, 0)) # red

mayavi.mlab.mesh([[x1, x3], [x5, x7]],
[[y1, y3], [y5, y7]],
[[z1, z3], [z5, z7]],
color=(0, 0, 1)) # blue

mayavi.mlab.mesh([[x1, x2], [x5, x6]],
[[y1, y2], [y5, y6]],
[[z1, z2], [z5, z6]],
color=(1, 1, 0)) # yellow

mayavi.mlab.mesh([[x2, x4], [x6, x8]],
[[y2, y4], [y6, y8]],
[[z2, z4], [z6, z8]],
color=(1, 1, 1)) # white

mayavi.mlab.mesh([[x3, x4], [x7, x8]],
[[y3, y4], [y7, y8]],
[[z3, z4], [z7, z8]],
color=(1, 0, 1)) # pink

mayavi.mlab.show()

enter image description here

否则,您还可以通过一个调用让在移动中显示更多面孔的网格。两次调用 ma​​yavi.mlab.mesh :

# Define 2 mesh objects with 3 planes connected among themselves :
#
# pt1 - pt2 - pt6 pt8 - pt6 - pt2
# - - - - - -
# pt3 - pt4 - pt8 AND pt7 pt5 - pt1
# - - - - - -
# pt7 - pt8 - pt8 pt3 - pt1 - pt1

mayavi.mlab.figure()
mayavi.mlab.mesh([[x1, x2, x6], [x3, x4, x8], [x7, x8, x8]],
[[y1, y2, y6], [y3, y4, y8], [y7, y8, y8]],
[[z1, z2, z6], [z3, z4, z8], [z7, z8, z8]],
color=(1, 0, 0)) # red

mayavi.mlab.mesh([[x8, x6, x2], [x7, x5, x1], [x3, x1, x1]],
[[y8, y6, y2], [y7, y5, y1], [y3, y1, y1]],
[[z8, z6, z2], [z7, z5, z1], [z3, z1, z1]],
color=(0, 0, 1)) # blue

mayavi.mlab.show()

enter image description here

只需调用一次 ma​​yavi.mlab.mesh:

# Merge previous mesh objects in single one:
#
# pt1 - pt2 - pt6 | => pt1 - pt2 - pt6 - pt6 - pt6
# - - - | => - - - - -
# pt3 - pt4 - pt8 | => pt3 - pt4 - pt8 - pt6 - pt2
# - - - | => - - - - -
# pt7 - pt8 - pt8 - pt6 - pt2 | => pt7 - pt8 - pt8 - pt6 - pt2
# - - - | => - - - - -
# pt7 pt5 - pt1 | => pt7 - pt7 - pt7 pt5 - pt1
# - - - | => - - - - -
# pt3 - pt1 - pt1 | => pt7 - pt3 - pt3 - pt1 - pt1


mayavi.mlab.figure()
mayavi.mlab.mesh([[x1, x2, x6, x6, x6],
[x3, x4, x8, x6, x2],
[x7, x8, x8, x6, x2],
[x7, x7, x7, x5, x1],
[x7, x3, x3, x1, x1]],

[[y1, y2, y6, y6, y6],
[y3, y4, y8, y6, y2],
[y7, y8, y8, y6, y2],
[y7, y7, y7, y5, y1],
[y7, y3, y3, y1, y1]],

[[z1, z2, z6, z6, z6],
[z3, z4, z8, z6, z2],
[z7, z8, z8, z6, z2],
[z7, z7, z7, z5, z1],
[z7, z3, z3, z1, z1]])

mayavi.mlab.show()

enter image description here

关于enthought - 如何为 Mayavi 的 mlab.mesh 定义 x,y,z 坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37849063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com