Matlab App: Get cursor position in axis continuously, keep plot interactivity

15 ビュー (過去 30 日間)
Felix
Felix 2025 年 4 月 9 日
回答済み: Kevin Holly 2025 年 4 月 10 日
Hi there,
I'm trying to create a matlab app in which users can create geometric objects and use them for some calculations later.
These are displayed in a 3D axis, rotated slightly. I am trying to create user functions to draw lines inside that axis. For this, I wan to implement continuously displayed x,y coordinates, or crosshairs or similar, as well as data snapping. Users will only draw 2D objects on the x,y plane. I still want users to be able to rotate the plot, zoom and pan normally with the mouse.
If I use a WindowButtonMotionFcn, then I lose plot interactivity with the mouse. If I use other means of getting the cursor position, like java.awt.MouseInfo.getPointerInfo().getLocation() and getpixelposition() or similar gui coordinate functions, I have to deal with a rotated camera and axis transformation. This makes "hit detection" on the data very cumbersome.
Using axes.CurrentPoint seems useless, because it only updates when the mouse is clicked, not continuously.
Any ideas on how to do this?
  1 件のコメント
Oliver Jaehrig
Oliver Jaehrig 2025 年 4 月 10 日
The CurrentPoint property gets continuosly updated when:
"Move the mouse within the figure (without pressing any buttons), as long as the WindowButtonMotionFcn property is not empty."
see:
would this help you to solve your issue? Can you explain further what you mean by:
"WindowButtonMotionFcn, then I lose plot interactivity with the mouse"?

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

回答 (1 件)

Kevin Holly
Kevin Holly 2025 年 4 月 10 日
Would something like the app attached work for the 2D drawing? The user can still zoom in, out, and pan. However, they cannot place a marker while actively zooming or panning. You could add a condition to toggle the zoom (e.g. zoom(ax,'on') or zoom(ax,'off') ).

カテゴリ

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

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by