pointPolygonTest

版本 1.0.0 (105.4 KB) 作者: cui,xingxing
determine points are inside, on or outside a polygon/contour or calculate signed distance between points and the nearest contour edge.
16.0 次下载
更新时间 2022/10/23

View pointPolygonTest on File Exchange Open in MATLAB Online

Points In Polygon Test

This function inpolygon2 is an enhancement of matlab's built-in function inpolygon, which supports the calculation of the distances.Support C/C++ code generation.

👀View the example ▶️Run the example

Example

%% data, is same as https://www.mathworks.cn/help/matlab/ref/inpolygon.html fisrst Example
L = linspace(0,2*pi,6);
xv = cos(L)';
yv = sin(L)';

rng default
xq = randn(250,1);
yq = randn(250,1);

%% use inpolygon2 function determine points whether inside polygon 
points = [xq,yq];
dists = inpolygon2([xv,yv],points);

figure;hold on
plot(xv,yv) % polygon
plot(xq(dists==1),yq(dists==1),'r+') % points inside
plot(xq(dists==-1),yq(dists==-1),'bo') % points outside
axis equal;
title("points in polygon")

img

%% Distance Rating Heat Map
xy=-2:.02:2;
[x,y] = meshgrid(xy);
points = [x(:),y(:)];
dists2 = inpolygon2([xv,yv],points,true);
dists2 = reshape(dists2,size(x));

figure;hold on;
xydata = [xy(1),xy(end)];
imagesc(xydata,xydata,dists2)
plot(xv,yv,'w-','LineWidth',2)
colormap('jet');
colorbar
axis equal off
title("signed distance hot map")

img

引用格式

cui,xingxing (2024). pointPolygonTest (https://github.com/cuixing158/pointPolygonTest/releases/tag/v1.0.0), GitHub. 检索来源 .

MATLAB 版本兼容性
创建方式 R2022b
兼容任何版本
平台兼容性
Windows macOS Linux
标签 添加标签

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库