打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
【Python】scipy.spatial.Delaunay中文教程

目前介绍Delaunay的中文教程不多,基本都是零零散散的代码实例,很少有系统的函数参数介绍。晚上用了50分钟,把英文教程翻译了一遍。


函数参数:

class scipy.spatial.Delaunay(pointsfurthest_site=Falseincremental=Falseqhull_options=None)

Delaunay tesselation in N dimensions.

参数解释:

points : ndarray of floats, shape (npoints, ndim)

把点转化为三角形。

furthest_site : bool, optional

是否计算一个最远的Delaunay三角形,默认为否。这是版本 0.12.0.中的新参数。

incremental : bool, optional

增量地添加新点,需要额外的资源. 

qhull_options : str, optional

Additional options to pass to Qhull. See Qhull manual for details. Option “Qt” is always enabled. Default:”Qbb Qc Qz Qx” for ndim > 4 and “Qbb Qc Qz” otherwise. Incremental mode omits “Qz”.。这是版本 0.12.0.中的新参数。

使用示范:

  1. # 点集的Delaunay三角划分:
  2. >>>
  3. >>> points = np.array([[0, 0], [0, 1.1], [1, 0], [1, 1]])
  4. >>> from scipy.spatial import Delaunay
  5. >>> tri = Delaunay(points)
  6. # 画出来:
  7. >>>
  8. >>> import matplotlib.pyplot as plt
  9. >>> plt.triplot(points[:,0], points[:,1], tri.simplices.copy())
  10. >>> plt.plot(points[:,0], points[:,1], 'o')
  11. >>> plt.show()

介绍一下单纯型 (simplex) 和三角剖分 (triangulation) : 

单纯形是代数拓扑中最基本的概念。单纯形是三角形和四面体的一种泛化,一个k维单纯形是指包含 k+1个节点的凸多面体。

人们希望能够把一个拓扑对象剖分成许多个小的单纯形,要求任何两个相邻的单纯形相交的公共部分仍是一个单纯形.这种剖分称为(曲)单纯剖分。在曲面情形,就是熟知的三角剖分。

  1. # 点的索引、三角划分后的两个三角形的坐标
  2. >>> tri.simplices # 三角形中顶点的索引
  3. array([[3, 2, 0],
  4. [3, 1, 0]], dtype=int32)
  5. >>> points[tri.simplices] # 三角形坐标
  6. array([[[ 1. , 1. ],
  7. [ 1. , 0. ],
  8. [ 0. , 0. ]],
  9. [[ 1. , 1. ],
  10. [ 0. , 1.1],
  11. [ 0. , 0. ]]])
  12. # 三角形0是三角形1的唯一邻居, 它和三角形1的顶点1方向相反
  13. >>> tri.neighbors[1] # 查看三角形1的邻居,不存在为-1
  14. array([-1, 0, -1], dtype=int32)
  15. >>> points[tri.simplices[1,1]] # 查看第2个三角形的第2个顶点坐标
  16. array([ 0. , 1.1])
  17. # 找出点在哪个三角形中
  18. >>> p = np.array([(0.1, 0.2), (1.5, 0.5)])
  19. >>> tri.find_simplex(p)
  20. array([ 1, -1], dtype=int32)
  21. # 计算三角形1中这些点的重心坐标 (barycentric coordinates)
  22. >>> b = tri.transform[1,:2].dot(p - tri.transform[1,2])
  23. >>> np.c_[b, 1 - b.sum(axis=1)] # 矩阵列相加, 要求行相等
  24. array([[ 0.1 , 0.2 , 0.7 ],
  25. [ 1.27272727, 0.27272727, -0.54545455]])
  26. # 注: 第一个点的坐标是正的,表示它确实在三角形内

一些属性:

transform从 x 到重心坐标 c 的仿射变换.
vertex_to_simplex查找数组, 从一个点找到它所在的单纯型
convex_hull

构成凸包的面状点集

Vertices of facets forming the convex hull of the point set.

vertex_neighbor_vertices点的邻居节点
points(ndarray of double, shape (npoints, ndim)) 点集合
simplices(ndarray of ints, shape (nsimplex, ndim+1)) 构成单纯型的点的索引. 对二维来说,点是朝着逆时针方向的.
neighbors(ndarray of ints, shape (nsimplex, ndim+1)) 每个单纯型的邻居单纯型的索引. 第k个邻居位于第k个节点的相反方向. 对于边界单纯型, -1表示无邻居.
equations

(ndarray of double, shape (nsimplex, ndim+2)) [normal, offset] 构成抛物面上的小面的超平面方程

paraboloid_scale, paraboloid_shift(float) 额外抛物面维度的范围、移动
coplanar(ndarray of int, shape (ncoplanar, 3)) 共面点的索引 and the 最近共面和最近点的索引. 共面点是输入点,由于数值精度问题不在三角划分中. If option “Qc” is not specified, this list is not computed. .. versionadded:: 0.12.0
vertices和simplices相似,不赞成使用

 方法:

add_points(points[, restart])增加新点
close()完成增量过程
find_simplex(self, xi[, bruteforce, tol])找到包含指定点的单纯型
lift_points(self, x)

Lift points to the Qhull paraboloid.

指向Qhull抛物面的升力点

plane_distance(self, xi)计算点 xi 到所有单纯型的超平面距离
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
三角剖分算法(delaunay)
OpenGL读取Obj模型文件
31
Delaunay 三角剖分 Voronoi diagram
OpenCV:图像变形(Image Morphing)
VC+OpenGL实现空间三维Delaunay三角剖分
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服