我基本上想在 3D 对象的网格上生成随机表面点,包括 python 中的表面法线。我在那个领域没有很多经验。那么任何人都可以向我推荐一些解决任务的包、方法和方法吗?
看了open3d和trimesh,还是有些麻烦。
谢谢!
使用 trimesh 非常简单:
In [1]: import trimesh
In [2]: m = trimesh.creation.icosphere()
In [3]: m
Out[3]: <trimesh.base.Trimesh at 0x7f99bec7d550>
In [4]: m.sample?
Signature: m.sample(count, return_index=False)
Docstring:
Return random samples distributed normally across the
surface of the mesh
Parameters
---------
count : int
Number of points to sample
return_index : bool
If True will also return the index of which face each
sample was taken from.
Returns
---------
samples : (count, 3) float
Points on surface of mesh
face_index : (count, ) int
Index of self.faces
File: /media/psf/Dropbox/robotics/trimesh/trimesh/base.py
Type: method
In [5]: points, index = m.sample(1000, return_index=True)
In [6]: points
Out[6]:
array([[ 0.79934465, 0.58103816, 0.1308479 ],
[-0.07373243, 0.08338232, 0.99055759],
[ 0.71660325, 0.21369974, 0.65889903],
...,
[-0.08330094, 0.98915598, 0.10205582],
[ 0.2558548 , -0.68523377, -0.6770221 ],
[-0.11483521, 0.97023335, 0.19696663]])
In [8]: normals = m.face_normals[index]
In [9]: normals
Out[9]:
array([[ 0.79167915, 0.58957859, 0.16012871],
[-0.04950537, 0.06905681, 0.99638365],
[ 0.73810358, 0.21732806, 0.63872656],
...,
[-0.06905681, 0.99638365, 0.04950537],
[ 0.23921922, -0.7022584 , -0.67052763],
[-0.08142553, 0.97123096, 0.22378629]])
您可以通过找到每个点的重心坐标然后插入顶点法线来获得更好的法线,但是仅使用面法线非常容易。
我会用matplotlib
. 也许“三曲面图”是您在此页面上需要的?您可以CTRL+F
Tri-Surface plots
从字面上快速找到它并查看它生成的图像,看看它是否是您正在寻找的东西。