Fast Inpolygon in MEX

Fast inpolygon function implemented in MEX. So far one of the fastest.


Updated 22 Mar 2011

View License

This is a C implementation of the great Matlab code provided by Darren Engwirda. You can find his code in:

According to my estimates, it works more than 2x as fast. So far, this is one of the fastest implementation that I know of. Sorting is big step of this algorithm. To make it an exact replica, I use stable_sort of std library.

Here is a sample call:

tic(); [In2 On2]=inpolygon_fast(x, y, xv, yv); toc();

The call interface is similiar to inpolygon and not to inpoly. Here x and y are the points to check, where xv and yv define the polygon.

The attachment includes the cpp file, a sample function for comparison and Darren's code.

Cite As

Tolga Birdal (2023). Fast Inpolygon in MEX (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: INPOLY: A fast points-in-polygon test

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes


Small updates in description.