- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在比较 scipy (0.9.0) 和 matplotlib (1.0.1) 的 Delaunay 三角剖分例程时,我注意到一个无法解释的行为。我的点是存储在 numpy.array([[easting, northing], [easting, northing], [easting, northing]])
中的 UTM 坐标。 Scipy 的边缘缺少我的一些观点,而 matplotlib 的都在那里。有没有解决办法,还是我做错了什么?
import scipy
import numpy
from scipy.spatial import Delaunay
import matplotlib.delaunay
def delaunay_edges(points):
d = scipy.spatial.Delaunay(points)
s = d.vertices
return numpy.vstack((s[:,:2], s[:,1:], s[:,::-2]))
def delaunay_edges_matplotlib(points):
cens, edges, tri, neig = matplotlib.delaunay.delaunay(points[:,0], points[:,1])
return edges
points = numpy.array([[500000.25, 6220000.25],[500000.5, 6220000.5],[500001.0, 6220001.0],[500002.0, 6220003.0],[500003.0, 6220005.0]])
edges1 = delaunay_edges(points)
edges2 = delaunay_edges_matplotlib(points)
numpy.unique(edges1).shape # Some points missing, presumably nearby ones
numpy.unique(edges2).shape # Includes all points
最佳答案
scipy.spatial.Delaunay
的这种行为可能与浮点运算的含义有关。
如您所知,scipy.spatial.Delaunay
使用 C qhull
库来计算 Delaunay 三角剖分。 Qhull
是 Quickhull
algorithm 的实现,作者在 this 中对此进行了详细描述论文 (1)。您也可能知道计算机中使用的浮点运算是使用 IEEE 754 标准执行的(例如,您可以在 Wikipedia 中阅读相关内容)。根据标准,每个有限数最简单地由三个整数描述:s
= 符号(零或一),c
= 有效数(或“系数”) , q
= 一个指数。用于表示这些整数的位数因数据类型而异。因此,很明显, float 在数值轴上的分布密度不是恒定的——数字越大,分布越松散。即使用谷歌计算器也能看出来——你可以从 3333333333333334 和 get 0 中减去 3333333333333333。 .发生这种情况是因为 3333333333333333 和 3333333333333334 都四舍五入为相同的 float 。
现在,了解舍入误差后,我们可能想阅读论文 (1) 的第 4 章,标题为Copying with impresicion。本章介绍一种处理舍入误差的算法:
Quickhull partitions a point and determines its horizon facets by computing
whether the point is above or below a hyperplane. We have assumed that
computations return consistent results ... With floating-point arithmetic, we
cannot prevent errors from occurring, but we can repair the damage after
processing a point. We use brute force: if adjacent facets are nonconvex, one of
the facets is merged into a neighbor. Quickhull merges the facet that minimizes
the maximum distance of a vertex to the neighbor.
这就是可能发生的情况 - Quickhull
无法区分 2 个附近的点,因此它合并了两个面,从而成功地消除了其中一个。要消除这些错误,您可以尝试移动坐标原点:
co = points[0]
points = points - co
edges1 = delaunay_edges(points)
edges2 = delaunay_edges_matplotlib(points)
print numpy.unique(edges1)
>>> [0 1 2 3 4]
print numpy.unique(edges2)
>>> [0 1 2 3 4]
这会将计算转移到 float 相当密集的区域。
关于python - 在 scipy.spatial.Delaunay 附近时遗漏的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071382/
我一直在寻找这个问题的答案,但找不到任何有用的东西。 我正在使用 python 科学计算堆栈(scipy、numpy、matplotlib)并且我有一组二维点,为此我使用 scipy.spatial.
我正在试验 scipy.spatial's implementation of Qhull's Delaunay triangulation . 是否有可能以保留输入顶点定义的边的方式生成三角剖分?
我在看这个视频:Delaunay Triangulation我想用它以相同的方式生成程序内容。我很难弄清楚如何使用 LibGDX 提供的 DelaunayTriangulation 类,但我想我终于弄
我正在使用三角剖分库来计算某个大边界内的一组矩形的约束 Delaunay 三角剖分。该算法返回所有边,但也在定义约束的矩形内添加边。 我希望能够创建一个没有任何作为约束的矩形内的边的图形(当然大边界除
我想对带孔的复杂(但不是自相交)多边形进行三角剖分,以便生成的三角形都位于多边形内,完全覆盖该多边形,并遵守 Delaunay 三角形规则。 显然,我可以为所有点构建 Delaunay 三角剖分,但我
我正在使用 Delaunay 对凹多边形进行三角剖分,但它填充了凹面。如何自动删除多边形边界之外的三角形? 最佳答案 自我回答:在某些情况下,这是不可能的。我需要使用受约束的 Delaunay 算法:
如何从 Delaunay 三角剖分中删除大于我需要的距离? 示例数据: x 0 i <- abs( i[ keep ] ) j <- abs( j[ keep ] ) plot( x, y ) seg
大多数迭代算法需要一个初始的空三角形来让球滚动。似乎一个常用的技巧就是将 super 三角形与点集相比变得非常大。 但根据“数值食谱:科学计算的艺术”: “...如果距离仅仅是有限的(到边界点),则构
MATLAB 在 their website 上声明: It is more efficient to edit a delaunayTriangulation to make minor modif
我使用 Matlab 2013 版进行了 Delaunay 三角剖分。我想删除一些三角形,这意味着取消它们的连接性,例如三角形编号 760。我该如何进行此更改?当我尝试编辑连接列表时: dt.Conn
给定点集的 Delaunay 三角剖分,我应该如何索引我的三角剖分以进行快速点定位? 我目前正在遍历所有三角形。对于每个三角形,我正在检查给定点是否在三角形的边界矩形内。如果是,我会使用几何方程检查三
我已经绘制了 n 个随机点 (黑点) 并使用了 delaunay 三角剖分,现在我想插入 m 个随机评估点 (红色点) 所以我需要计算评估点在哪个三角形内。 计算每个点的三角形顶点的方法是什么? 最佳
给定有线表示中的网格的 delaunay 三角剖分,我会喜欢显示没有对角线的表面,我只是想想象一个整洁的正方形。是否有任何选项可以完成此操作,也许是过滤器? 有点像 delaunay->Boundin
在 MATLAB 中,我加载了以下点云: load tetmesh 这会将 X 和 tet 加载到工作区中。因此,我执行了一个散点图,结果如下所示: scatter3(X(:,1), X(:,2),
我有一个具有 V 个顶点和 n 个开口的多边形。如何在 MATLAB 中使用 Delaunay 三角剖分为此多边形创建网格? 我知道我可以使用 delaunay功能,但我不知道如何输入开口。 最佳答案
我想根据二维平面上一组点之间的欧式距离计算最小生成树。我当前的代码存储所有边,然后执行 Prim 算法以获得最小生成树。但是,我知道这样做会占用所有边的 O(n^2) 空间。 在做了一些研究之后,很明
接着是:How to print the faces of a Voronoi diagram? ,我现在有: #include #include #include #include #inc
我刚刚完成了 Delaunay 增量翻转算法的实现。该算法的时间复杂度为 O(N log N)。 该算法的应用是基于将每个点作为电话公司的天线。使用 Delaunay 算法,我必须用这些点对空间进行三
我有一组多边形,它们可能共享公共(public)边和节点。所有这些多边形都是严格不重叠的,尽管它们可以共享一个公共(public)顶点或边。 我想批量对所有这些多边形进行三角剖分,因此,我能想到的解决
我已经实现了 Domiter 和 Zalik 使用的扫描线方法,以在 Java 中为二维空间中的一组点生成受约束的 Delaunay 三角剖分。我想确保我开发的代码真正适用于 n 个随机生成的点和它们
我是一名优秀的程序员,十分优秀!