正如您在标题中看到的,我想在 vtk (python) 中制作均匀分布的球体
首先,我看到了这个链接“在球体上均匀分布 n 个点”,这是一种创建均匀分布球体的方法。通过那个链接,我得到了均匀分布球体的 x,y,z 坐标。
其次,这实际上不是我必须解决的问题。问题是即使我有均匀分布球体的 x,y,z 坐标,我也无法在 vtk(python)..
import numpy as np
import mpl_toolkits.mplot3d
import matplotlib.pyplot as plt
import vtk
from scipy.spatial import Delaunay
num_pts = 1000
indices = np.arange(0, num_pts, dtype=float) + 0.5
phi = np.arccos(1 - 2*indices/num_pts)
theta = np.pi * (1 + 5**0.5) * indices
x, y, z = np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi);
# x,y,z is coordination of evenly distributed shpere
# I will try to make poly data use this x,y,z
points = vtk.vtkPoints()
for i in range(len(x)):
array_point = np.array([x[i], y[i], z[i]] )
points.InsertNextPoint(x[i],y[i],z[i])
# tri = Delaunay(points) (Do I have to use this function??)
poly = vtk.vtkPolyData()
poly.SetPoints(points)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(poly)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
ren.AddActor(actor)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
renWin.Render()
iren.Start()
代码没有抛出任何错误,但是我的 vtk 窗口中没有出现 polydata,我应该怎么做才能解决这个问题?
-泰英。