2014-01-10 43 views
5

我想繪製一些實驗數據,並且我正在面對三角測量的問題,如更長的解釋here。我發現解決方案可能是將網格從xy更改爲xz,並將y用作高程。Mayavi如何使用xz數據而不是xy數據來實現Delaunay三角測量

Howevever我還沒有關於這種可能性的信息。那麼有沒有辦法做到這一點,也許通過使用一些掩碼或一些過濾器來反轉三角形的y和z列?

下面是一個基本代碼:

import numpy 
from mayavi import mlab 

X2 = numpy.array([0, 0, 1, 1]) 
Y2 = numpy.array([0.5, 0.45, 1, 0.5]) 
Z2 = numpy.array([0, 1, 0.5,0]) 

fig = mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0.5, 0.5, 0.5)) 
# Define the points in 3D space 
# including color code based on Z coordinate. 
pts = mlab.points3d(X2, Y2, Z2, Y2, colormap='jet') 
# Triangulate based on X, Y with Delaunay 2D algorithm. 
# Save resulting triangulation. 
mesh = mlab.pipeline.delaunay2d(pts) 
# Remove the point representation from the plot 
pts.remove() 
# Draw a surface based on the triangulation 
surf = mlab.pipeline.surface(mesh, colormap='jet') 

# Simple plot. 
mlab.outline(extent=(0,1,0,1,0,1)) 
mlab.axes(extent=(0,1,0,1,0,1)) 
mlab.show() 

回答

1

你可以使用SciPy的的德勞算法是獨立數據的順序。 triangular_mesh()允許您指定顏色貼圖的標量:

import numpy as np 
from scipy.spatial import Delaunay 
from mayavi import mlab 

X2 = np.array([0, 0, 1, 1]) 
Y2 = np.array([0.5, 0.45, 1, 0.5]) 
Z2 = np.array([0, 1, 0.5,0]) 

# use scipy for delaunay: 
p2d = np.vstack([X2,Y2]).T 
d2d = Delaunay(p2d) 

fig = mlab.figure(1, bgcolor=(1, 0.7, 1), fgcolor=(0.5, 0.5, 0.5)) 

# Generate triangular Mesh: 
tmesh = mlab.triangular_mesh(X2, Y2, Z2, d2d.vertices, 
          scalars=Y2, colormap='jet') 

# Simple plot. 
mlab.outline(extent=(0,1,0,1,0,1)) 
mlab.axes(extent=(0,1,0,1,0,1)) 
mlab.show() 
相關問題