【发布时间】:2017-07-04 01:03:58
【问题描述】:
从一组点来看,我得到了带有scipy.spatial 的凸包,可以使用Delaunay 或ConvexHull(来自qhull 库)。
现在我想将这个凸包外的一个点投影到外壳上(即外壳上与外面的点距离最小的点)。
这是我目前的代码:
from scipy.spatial import Delaunay, ConvexHull
import numpy as np
hu = np.random.rand(10, 2) ## the set of points to get the hull from
pt = np.array([1.1, 0.5]) ## a point outside
pt2 = np.array([0.4, 0.4]) ## a point inside
hull = ConvexHull(hu) ## get only the convex hull
#hull2 = Delaunay(hu) ## or get the full Delaunay triangulation
import matplotlib.pyplot as plt
plt.plot(hu[:,0], hu[:,1], "ro") ## plot all points
#plt.triplot(hu[:,0], hu[:,1], hull2.simplices.copy()) ## plot the Delaunay triangulation
## Plot the convexhull
for simplex in hull.simplices:
plt.plot(hu[simplex,0], hu[simplex,1], "ro-")
## Plot the points inside and outside the convex hull
plt.plot(pt[0], pt[1], "bs")
plt.plot(pt2[0], pt2[1], "bs")
plt.show()
有了图片可能更容易,我想从凸包外的蓝点获取绿色的 x 和 y 坐标。这个例子是二维的,但我也需要在更高维度上应用它。 感谢您的帮助。
编辑:问题已在此处解决,但我无法实施:https://mathoverflow.net/questions/118088/projection-of-a-point-to-a-convex-hull-in-d-dimensions
【问题讨论】:
-
可以从
ConvexHull.equations得到凸包的超平面,这样就可以计算出点到每个超平面的距离。然后,您可以使用距离找到最近的超平面。但是,您应该按照自己的方式定义坐标,因为您只有法线向量。
标签: python scipy delaunay qhull