Code covered by the BSD License  

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

» Watch video

Highlights from
2D polygon interior detection

5.0
5.0 | 4 ratings Rate this file 20 Downloads (last 30 days) File Size: 24.2 KB File ID: #27840 Version: 1.1
image thumbnail

2D polygon interior detection

by

Bruno Luong (view profile)

 

06 Jun 2010 (Updated )

Detect a whereas a point is interior or exterior to a 2D polygon

| Watch this File

File Information
Description

This function tries to improve the slow Matlab INPOLYGON function.

There are few other fast codes on FEX (e.g., by Darren Engwirda). After exploring many different ways, I come to the conclusion that Darren Engwirda's approach is close to optimal. So here you'll find a general method that share many common aspects, but implemented in C-Mex. I have makes few contributions: (1) a lean C-implementation, (2) Using Matlab SORT and HISTC for binning, (3) Derive an empirical rule when to apply the sorting, (4) a more rigorous on-boundary detection.

Acknowledgements

This file inspired Flow Cytometry Gui For Matlab.

MATLAB release MATLAB 7.10 (R2010a)
Other requirements Mex setup
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
14 Apr 2016 Alex Barnett

This code is great. 100x faster on large-scale problems than even the latest version of MATLAB I have (R2015b), amazingly! You can run my tests (within mpspack) at:
https://github.com/ahbarnett/mpspack/blob/master/test/testinpolywrapper.m

29 Oct 2014 Roger GALLOU  
04 Feb 2014 lgstarn  
22 Oct 2012 David

David (view profile)

 
07 Jun 2010 Bruno Luong

Bruno Luong (view profile)

To Matt: this is algorithm designed for for generic polygons (as with INPOLYGON)

Comment only
07 Jun 2010 Matt J

Matt J (view profile)

Does this submission apply to convex polygons or general ones? If the latter, there should be a way to make it faster if the polygon is known a priori to be convex. Perhaps an input parameter to enable this...

Comment only
Updates
07 Jun 2010 1.1

Change the criteria to trigger the presorting step

Contact us