3.0

3.0 | 1 rating Rate this file 236 downloads (last 30 days) File Size: 11.05 KB File ID: #22287

In Polygon test for convex polygon

by Luigi Giaccari

 

01 Dec 2008 (Updated 11 Dec 2008)

Detects points inside a convex polygon in 2D space. Should be faster than general inpolygon.

Download Now | Watch this File

File Information
Description

This is Brand new so please advise-me if problems occurs.  
 
Here you can find an m-file with trhee different algorithms for inpolygon test.  
Depending on the input data, the one who is estimate to be the best will be chosen.  
 
This version do not support the onpolygon output so tollerance is not necessary. Maybe in my next revision this feature will be added.  
 
I'll be very glad receiving suggestion (even on preferred sintax), questions bug reports.  
 
    SYNTAX:  
   
      in=InPolyConvex(qx,qy,x,y)  
   
      qx : The points to be tested, vector [Nx1] of x coordinate.  
      qy : The points to be tested, vector [Nx1] of y coordinate.  
   
      x : The x coordinate of vertices of the convex polygon [Nx1]  
            The syntax assumes that the vertices are specified in  
            consecutive order.  
      y : The y coordinate of vertices of the convex polygon [Nx1]  
            The syntax assumes that the vertices are specified in  
            consecutive order.  
   
   
      in : An Nx1 logical array with IN(i) = TRUE if P(i,:) lies within the  
            region.  
   
    Notes:  
            -InPolyConvex do not support on polygon options so tollerance is not necessary.  
            -InPolyConvex do not support edges input format of the polygon.  
            Maybe in the next revision these two feature will be added.  
   
    EXAMPLE:  
   
           %query points  
           Nq=100;  
           qx=rand(Nq,1);  
           qy=rand(Nq,1);  
   
           %the convex polygon: a square  
           x=.2+[0,.5,.5,0]';  
           y=.3+[0,0,.5,.5]';  
   
           in=InPolyConvex(qx,qy,x,y);  
   
           figure;  
           hold on  
           axis equal  
           plot(x,y)  
           plot(qx(in),qy(in),'.r');  
           plot(qx(~in),qy(~in),'.k');  
           legend('Polygon','Inside','Outside')  
   

MATLAB release MATLAB 7.5 (R2007b)
Other requirements Should work on all platforms
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
02 Dec 2008 Jveer how abt one for 3d?
20 Dec 2008 Maula Maula Nice one, 
 
I'm looking for possibilities x and y are not the same size, i've been googling for an example for such operation, but no luck. 
 
Please login to add a comment or rating.
Updates
11 Dec 2008 Changed the presentation

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com