File Exchange

image thumbnail

inpoly mex file

version 1.6 (68.1 KB) by

Find points inside or on the border of a polygon

6 Downloads

Updated

View License

A fast mex version of the modified inpoly function.
please run mexme_inpoly.m to compile mex file on your plateform

please run test_inpoly.m for demo

Comments and Ratings (13)

For my use case, this mex file is 1000-1500 times faster than the default inpolygon function that comes with matlab. Nicely done!

great! this was 50 times faster than inpoly.m for my application

Very good function used on my project. Thanks.

Sebastien PARIS

You are right, I'll upload a version with argument checking. Thanks

John Kua

Thanks! This has been very useful on a number of projects!

One problem - the function does not handle an empty input array of [2 x 0] and crashes MATLAB. Adding a check of the input dimensionality with a warning if the input is empty and perhaps returning an empty array would be nice.

Sebastien PARIS

Please give me an example of this bahaviour.

some points are on the edges of the polygon and the function can not detect that. what is the reason?

it sounds like inpoltgon.

Very fast!!! well done.

I thing I found an error in the demo file:
The second demo model is buggy: the polygon is self-interecant!!

Martin Podt

Very useful. On the examples I have tested, the current mex version of inpoly is about 2 times faster than the *.m file.

Sébastien Paris

sorry for my poor english level skill ...

Sébastien Paris

Yes in fact, I did this mex file a long times ago. I realized that you update the algorithm. Maybe if I had 1 hour, I'll recreate the new version of this mex-file. If not, I'll remove this submission

Darren Engwirda

Well, I guess this is what you get when you "mex" someone else's code...

This mex file is based on an old version of my "inpoly.m" function. Unfortunately for the author I've made significant improvements to the algorithm since then and a different algorithm is used in my new "inpoly.m" function.

This mex file appears to be slower than my new "inpoly.m" function by a factor of between 3 and 4 on the examples I've tested, even though I have still only coded it as a *.m file.

There is also no "help inpoly" available unless you directly open the *.c file and it also seems that the inputs are required to be transposed when compared with the original "inpoly.m" function.

As with all versions/copies of "inpoly" the point of this code is that it's faster than the MATLAB "inpolygon.m" function, especially for large inputs.

Updates

1.6

- Fix a bug (missing free)

1.5

- Add online help
- Cosmetic changes in inpoly.c and demo file

1.4

-Inputs arguments checking
-Should compile on Linux

1.3

- Inputs arguments checking
- Should compile with Linux/GCC

New algorithm imcorporated. Speed improvement between 50% up to 100%

MATLAB Release
MATLAB 7.5 (R2007b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

inpoly/

inpoly/html/