Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Can matlab determine if a point inside a polygon?

Subject: Can matlab determine if a point inside a polygon?

From: Sang-Ho Yun

Date: 3 Jun, 2010 03:57:02

Message: 1 of 8

Can we make matlab decide if a point on a plane is inside a closed polygon?
How do we know if a point is inside or outside the polygon?

Thank you,
Sang-Ho

Subject: Can matlab determine if a point inside a polygon?

From: TideMan

Date: 3 Jun, 2010 04:04:14

Message: 2 of 8

On Jun 3, 3:57 pm, Sang-Ho Yun <Sang-Ho....@jpl.nasa.gov> wrote:
> Can we make matlab decide if a point on a plane is inside a closed polygon?
> How do we know if a point is inside or outside the polygon?
>
> Thank you,
> Sang-Ho

help inpolygon

Subject: Can matlab determine if a point inside a polygon?

From: Walter Roberson

Date: 3 Jun, 2010 04:23:55

Message: 3 of 8

Sang-Ho Yun wrote:
> Can we make matlab decide if a point on a plane is inside a closed polygon?
> How do we know if a point is inside or outside the polygon?


http://www.mathworks.com/matlabcentral/fileexchange/10391-fast-points-in-polygon-test

Subject: Can matlab determine if a point inside a polygon?

From: Matt J

Date: 3 Jun, 2010 04:24:04

Message: 4 of 8

Sang-Ho Yun <Sang-Ho.Yun@jpl.nasa.gov> wrote in message <C82C761E.6F1B%Sang-Ho.Yun@jpl.nasa.gov>...
> Can we make matlab decide if a point on a plane is inside a closed polygon?
> How do we know if a point is inside or outside the polygon?
==========

For convex polygon's see the routine below. It should be faster than inpolygon because it exploits the convex structure.



function [A,b]=vert2con_special(a)
%Finds the expression of a 2D convex polygon as a set of linear inequalities from
%a set of vertices
%
% [A,b]=vert2con_special(a)
%
%in:
%
% a: Nx2 matrix whos rows are polygon vertex coordinates. The rows must
% must be ordered so that adjacent rows correspond to adjacent vertices
% (which will trivially be the case for triangles).
%
%out:
%
% [A,b]: Nx1 vector and Nx2 matrix such that A*x<=b if and only if x is a point
% inside the polygon
%
%
%Example: Detect whether a point is in a triangle
%
% %%%data
% Vertices=[0 0; 1 0; 0 1]; %vertices of a triangle
% p1=[.5;.25]; %a point inside the triangle
% p2=[.5;-.25];%a point outside the triangle
%
% [A,b]=vert2con_special(Vertices);
%
% >>all(A*p1<=b) %Test if p1 is in the triangle.
%
% ans =
%
% 1
%
% >>all(A*p2<=b) %Test if p2 in the triangle.
%
% ans =
%
% 0



centroid=mean(a).';
R=[0 1; -1 0];

A=diff([a;a(1,:)])*R;

b=sum(A.*a,2);

ii=(A*centroid>=b);

b(ii)=-b(ii);
A(ii,:)=-A(ii,:);

Subject: Can matlab determine if a point inside a polygon?

From: Evan00

Date: 7 Nov, 2012 09:39:07

Message: 5 of 8

For your code, can I know how the algorithm works? How can I find out more about it? Thank you very much!

Subject: Can matlab determine if a point inside a polygon?

From: sh

Date: 21 Jun, 2013 06:36:18

Message: 6 of 8

Is there any built in function in matlab, for checking if a point is inside an arc section of a circle?
Thanks,

Subject: Can matlab determine if a point inside a polygon?

From: Torsten

Date: 21 Jun, 2013 06:55:31

Message: 7 of 8

"sh " <lolipopkitty@yahoo.com> wrote in message <kq0s92$8n4$1@newscl01ah.mathworks.com>...
> Is there any built in function in matlab, for checking if a point is inside an arc section of a circle?
> Thanks,

If you know that the point lies on the circumference of the circle and you only
want to determine wheter it lies inside a certain arc section, you can proceed as follows:
Calculate
theta=atan2((y-y_M)/(x-x_M))
where (x_M,y_M) is the center of the circle and (x,y) is the point in question.
Then compare theta with the angular range of the arc section and decide whether the point lies inside or outside.

Best wishes
Torsten.

Subject: Can matlab determine if a point inside a polygon?

From: sh

Date: 21 Jun, 2013 07:29:14

Message: 8 of 8

Many thanks Torsten;)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us