Matlab查找图形对象是否存在于给定坐标上 [英] Matlab finding if graphic object exist on figure on given coordinates
本文介绍了Matlab查找图形对象是否存在于给定坐标上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到一种方法来检查我创建的补丁对象(例如矩形)是否存在于我指定的某些X-Y坐标内.例如,我使用以下代码:
I need to find a way to check if a patch object I created (a rectangle for example) exists within certain X-Y coordinates I specify. As an example, I am using the following code:
a = figure
b = axes('Parent',a,'Xlim',[0 100],'Ylim',[0 100])
x = [0 10 10 0];
y = [0 0 10 10];
patch(x,y,'red')
现在,我想知道图中的坐标x = 6和y = 3是否存在对象.有办法检查吗?
Now I would like to know if there is an object in the figure in the point with coordinates x=6 and y=3. Is there a way to check this?
推荐答案
使用findall()和inpolygon函数.
Use the findall () and inpolygon function.
hPatches = findall(b, 'type', 'patch');
tgtX = 5; tgtY = 7;
inside = zeros (1, numel(hPatches));
for patchCtr = 1:numel(hPatches)
vert = get (hPatches(patchCtr), 'Vertices');
inside(patchCtr) = inpolygon (tgtX, tgtY, vert(:,1), vert(:,2));
end
这篇关于Matlab查找图形对象是否存在于给定坐标上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文