Find the point on a polygon that is closest to a point near the polygon

I am currently dealing with points outside of a polygon moving on the plane of the polygon, and once the point hits the polygon (i.e. intersects a side of the polygon), I'd like to determine the location at which the point hits the polygon. A close approximation would suffice, but the resultant point must be on the polygon.

3 Comments

What information do you have about the motion of the point? show us what you have tried already
Do you need to determine if the point is initially within the polygon, or is it outside of the polygon in any case?

Sign in to comment.

Answers (3)

First I would use inpolygon() to find out when it enters the polygon. Then I would think that you could just run around all known points on the polygon (there can't be that many of them) and use the Pythagorean theorem (or the hypot or norm functions) and find out which one is closest. It should be lightning fast. I know it's kind of simple and obvious, but why not simply do it that way? Why use anything more sophisticated and complicated if you don't need to?
I'll assume it's a convex polygon, and that your sequence of moving points are 2x1 vectors each in a cell array element x{i}. Then using VERT2LCON and LCON2VERT
[A,B]=vert2lcon(V); %convert your polygon vertices to inequalities A*x<=B
for i=1:length(x)
if all(A*x{i}<B) %inside
break;
end
end
[a,b,ae,be]=vert2lcon([x{i-1:i}].');
v=lcon2vert([A;a],[B;b],ae,be).';
[~,idx]=max([norm(v(:,1)-x{i}) , norm(v(:,2)-x{i})])
finalresult=v(:,idx)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

on 1 Feb 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!