原件(2018.11.01)
我用激光扫描仪(40度/ 1步)创建了3个numpy:x,y,z。 我想用它们来构建3D模型。
我认为必须使用matplotlib.tri
但是我不知道要确定三角数据
这是我的数据:https://www.dropbox.com/s/d9p62kv9jcq9bwh/xyz.zip?dl=0
原始型号:https://i.imgur.com/XSyONff.jpg
代码:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
x_all=np.load("x.npy")
y_all=np.load("y.npy")
z_all=np.load("z.npy")
tri = #I have no idea...
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x_all,y_all,z_all,triangles=tri.triangles)
非常感谢。
更新(2018.11.02)
我尝试通过这种方式确定三角数据 Delaunay Triangulation of points from 2D surface in 3D with python?
代码:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
from stl import mesh
x_all=np.load("x.npy")
y_all=np.load("y.npy")
z_all=np.load("z.npy")
model=np.vstack((x_all,y_all,z_all))
model=np.transpose(model)
model -= model.mean(axis=0)
rad = np.linalg.norm(model, axis=1)
zen = np.arccos(model[:,-1] / rad)
azi = np.arctan2(model[:,1], model[:,0])
tris = mtri.Triangulation(zen, azi)
plt.show()
我的模型如下:
https://i.stack.imgur.com/KVPHP.png
https://i.stack.imgur.com/LLQsQ.png
https://i.stack.imgur.com/HdzFm.png
尽管表面比较好,但是我的模型上还是有一个大洞。有什么想法可以修复吗?
答案 0 :(得分:0)
假设您要降低复杂度,即在文件中找到三角形以降低复杂度。您可能会考虑使凸包适合您的点,有关更多信息,请参见here
根据您提供的文件,将生成对象的冲浪图。
from numpy import load, stack
from matplotlib.pyplot import subplots
from mpl_toolkits.mplot3d import Axes3D
from scipy import spatial
x = load("x.npy")
y = load("y.npy")
z = load("z.npy")
points = stack((x,y,z), axis = -1)
v = spatial.ConvexHull(points)
fig, ax = subplots(subplot_kw = dict(projection = '3d'))
ax.plot_trisurf(*v.points.T, triangles = v.simplices.T)
fig.show()