how can I find the minimum distance from convex boundary
20 次查看(过去 30 天)
显示 更早的评论
Hi, How to find minimum distance between a point (outside convexhull) and convexhull boundary? Thanks
0 个评论
采纳的回答
更多回答(5 个)
Teja Muppirala
2013-11-27
I like Matt J's SVM-based idea. It is actually very straightforward to solve this as a maximum separation problem.
%% 1. Generate and plot random data
npts = 50;
dims = 2;
P1 = randn(npts,dims);
P2 = randn(1,2); P2 = 5*P2/norm(P2);
dt = delaunay(P1);
figure,hold all;
triplot(dt,P1(:,1),P1(:,2));
plot(P1(:,1),P1(:,2),'b.');
plot(P2(:,1),P2(:,2),'r.','markersize',16);
%% 2. Solve the quadratic programming problem
H = blkdiag(eye(dims),0);
A = [P1 ones(npts,1); -P2 -1];
b = -ones(npts+1,1);
x = quadprog(H,[],A,b,[],[],[],[]);
%% Plot the solution
D = 2/norm(x(1:2)); %distance
S = -2/norm(x(1:2))^2; % scaling for vector
quiver(P2(1),P2(2),S*x(1),S*x(2),1,'r');
title(['Distance is ' num2str(abs(D))]);
axis equal;
grid on;
0 个评论
John D'Errico
2013-11-26
There can be many faces of a convex hull. However, it is often easily possible to reduce the number of faces one need test.
Several tricks come to mind. First, one can efficiently compute a circumcircle for each facet of the hull. This is done by solving a linear system of equations for each facet. However, if you are careful, then you can put all of those linear systems into a sparse block diagonal system. Then one does the solve in ONE call to backslash, computing all of the circumcircles in one step. If you created the system as a sparse one, this will be FAST.
Next I might rank the facets, in terms of the distance to the circumcenters for those facets. Pick the closest facet using this greedy measure, and compute the true distance to that facet using a standard scheme. (I might use LDP, or something like it. Find LDP in Lawson & Hanson as I recall.) Call that distance Dmin.
You can now exclude many of the other facets from further testing based on the circumradius of the corresponding circumcircle. (Its just a little geometry.) I recall that in my tests you could exclude roughly 90% of the facets directly using this test.
2 个评论
Sean de Wolski
2013-11-26
编辑:Sean de Wolski
2013-11-26
Could you only look at facets that contain the vertex of the closest point?
John D'Errico
2013-11-26
No. That is not sufficient. One can construct a case where the closest point is NOT a vertex of the closest facet.
Admittedly, if you started looking at the facets with the nearest vertices first, this would likely find the truly closest facet soon enough. Again however, you need a scheme to decide when you can stop looking at facets. The circumcircles scheme I described above is a good one, that typically allows you to stop after examining perhaps 10% of the total facets. At that point you can know that no other facet can possibly be closer to the one you have found as best so far.
Image Analyst
2013-11-26
The bwdist() function in the Image Processing Toolbox will tell you that.
1 个评论
Image Analyst
2013-11-26
If you're interested in seeing a demo of this in 2 dimensions, see the demo file I attached below (in blue text).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176634/image.png)
Sean de Wolski
2013-11-26
编辑:Sean de Wolski
2013-11-26
No reason to reinvent the wheel, compare the distance between each face of the convex hull and the point of interest using distancePointPlane() from the above toolbox and keep the minimum.
Matt J
2013-11-26
编辑:Matt J
2013-11-26
Another possibility might be to use SVMTRAIN, if you have the Statistics Toolbox where the first training group is your single given point and the second training group consists of all the other points defining your polyhedral region.
The output will let you find a supporting hyperplane intersecting your polyhedron. The projection of your given point onto this hyperplane (an easy computation) should give you your closest point.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bounding Regions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!