inpolygon_for_gpu
This is a point-in-polygon function that can run on a gpu using large test point array sizes. It uses a simple ray-casting algorithm without pre-processing or "on" tolerance checks. Therefore it may not give the exact same results as inpolygon. Inputs must all be gpuArray objects in order to run on the gpu. The inputs take the form of MATLAB's inpolygon function. The parallel process occurs once for every vertex of the polygon, so large numbers of vertices will run slow. I had to have around around 1e5-1e7 test points to see speedup on my simple gaming GPU on a polygon with 1e4 vertices. I am hoping that re-implementing this using mex CUDA code will result in faster run-times. For best results, the number of test points should be close to the maximum array size on your GPU.
This implementation of the ray-casting algorithm is based on C code by W. Randolf Franklin, which can be found at http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
Any advice is welcome on how to speed up this algorithm, or make it more useful. Thanks!
Example:
L = linspace(0,2.*pi,6);
xv = gpuArray(cos(L)');
yv = gpuArray(sin(L)');
pts_x=gpuArray(rand(1e5,1));
pts_y=gpuArray(rand(1e5,1));
tic
in=inpolygon_for_gpu(pts_x, pts_y, xv, ,yv);
toc
Cite As
Sulimon Sattari (2024). inpolygon_for_gpu (https://www.mathworks.com/matlabcentral/fileexchange/49157-inpolygon_for_gpu), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.