フィルターのクリア

How can a ButtonDownFcn in a patch or line handle detect which polygon or segment was clicked?

7 ビュー (過去 30 日間)
Richard Kennaway
Richard Kennaway 2015 年 2 月 24 日
回答済み: matt dash 2015 年 2 月 24 日
I want to detect user clicks on a polygon mesh I've drawn using patch(), and determine which polygon was clicked in. Although Matlab must have computed that information in order to detect the mouse click, I can't find it in the arguments passed to the ButtonDownFcn that I install into the patch handle. The arguments are a handle to the patch and a Hit structure that includes the IntersectionPoint but nothing else of much use.
In principle I can calculate which polygon contains that point, but I would just be repeating work that Matlab has presumably done already. Can I get it directly?
The same question applies to clicks on line objects.

回答 (2 件)

John D'Errico
John D'Errico 2015 年 2 月 24 日
When I did this in the past (admittedly some years ago), I simply put that information into the callback I assigned to each object in the plot.
  2 件のコメント
Richard Kennaway
Richard Kennaway 2015 年 2 月 24 日
The information about which polygon was clicked does not exist until the click happens. I can't use a separate patch for each polygon, because the overhead of creating thousands of handles is enormous.
John D'Errico
John D'Errico 2015 年 2 月 24 日
Yeah, I did not say it was trivial to do. In the case I had, I was indeed forced to plot each piece separately, with a callback that was unique to that object.

サインインしてコメントする。


matt dash
matt dash 2015 年 2 月 24 日
I dont believe that Matlab has already calculated which face/edge/marker you clicked (I don't think hittest works that way). Assuming it's a 2D scene, for patches, you can use inpolygon (or http://www.mathworks.com/matlabcentral/fileexchange/27840-2d-polygon-interior-detection on the file exchange which may be faster).

カテゴリ

Help Center および File ExchangePolygons についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by