3d scipy.spatial.Delaunay的返回曲面三角形 [英] Return surface triangle of 3D scipy.spatial.Delaunay

查看:86
本文介绍了3d scipy.spatial.Delaunay的返回曲面三角形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题。我尝试通过scipy.spatial.Delaunay对点云进行三角剖分。我用过:

I have this problem. I try to triangulate points cloud by scipy.spatial.Delaunay. I used:

tri = Delaunay(points) # points: np.array() of 3d points 
indices = tri.simplices
vertices = points[indices]

但是,此代码返回四面体。仅怎么可能返回曲面三角形?

But, this code return tetrahedron. How is it possible return triangle of surface only?

谢谢

推荐答案

使其以代码形式运行,则必须将曲面参数化为2D。例如,在球(r,theta,psi)的情况下,半径是恒定的(将其丢弃),点数是由(theta,psi)给出的2D。

To get it to work as in code form, you have to parametrize the surface to 2D. For example in the case of ball (r,theta, psi), radius is constant (drop it out) and points are given by (theta,psi) which is 2D.

Scipy Delaunay是N维三角剖分,因此,如果给出3D点,它将返回3D对象。给它2D点,它返回2D对象。

下面是我用来为openSCAD创建多面体的脚本。 U和V是我的参数化(x和y),这些是我给Delaunay的坐标。请注意,现在 Delaunay三角剖分属性仅适用于u,v坐标(角度在uv -space中最大化,而不在xyz -space等中最大化)。

Below is a script that I used to create polyhedra for openSCAD. U and V are my parametrization (x and y) and these are the coordinates that I give to Delaunay. Note that now the "Delaunay triangulation properties" apply only in u,v coordinates (angles are maximized in uv -space not xyz -space, etc).

来自 http://matplotlib.org/1.3.1/mpl_toolkits/mplot3d的修改后的副本/tutorial.html 最初使用 Triangulation 函数(最终映射到Delaunay吗?)

The example is a modified copy from http://matplotlib.org/1.3.1/mpl_toolkits/mplot3d/tutorial.html which originally uses Triangulation function (maps to Delaunay eventually?)

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
from scipy.spatial import Delaunay

# u, v are parameterisation variables
u = np.array([0,0,0.5,1,1]) 
v = np.array([0,1,0.5,0,1]) 

x = u
y = v
z = np.array([0,0,1,0,0])

# Triangulate parameter space to determine the triangles
#tri = mtri.Triangulation(u, v)
tri = Delaunay(np.array([u,v]).T)

print 'polyhedron(faces = ['
#for vert in tri.triangles:
for vert in tri.simplices:
    print '[%d,%d,%d],' % (vert[0],vert[1],vert[2]),
print '], points = ['
for i in range(x.shape[0]):
    print '[%f,%f,%f],' % (x[i], y[i], z[i]),
print ']);'


fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

# The triangles in parameter space determine which x, y, z points are
# connected by an edge
#ax.plot_trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.Spectral)
ax.plot_trisurf(x, y, z, triangles=tri.simplices, cmap=plt.cm.Spectral)


plt.show()

下面是(略微结构化的)文本输出:

Below is the (slightly more structured) text output:

polyhedron(
    faces = [[2,1,0], [3,2,0], [4,2,3], [2,4,1], ], 

    points = [[0.000000,0.000000,0.000000], 
              [0.000000,1.000000,0.000000], 
              [0.500000,0.500000,1.000000], 
              [1.000000,0.000000,0.000000], 
              [1.000000,1.000000,0.000000], ]);

这篇关于3d scipy.spatial.Delaunay的返回曲面三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆