从一组点,我得到凸包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