开发者

Interactively manipulating a rectangle on a matlab figure

I would like to draw and manipulate a rectangle on a matlab figure. By manipulating, I mean I want to drag, rotate, resize (change side lengths) the rectange with "intuitive" mouse clicks.

I have not found any built in mechanism for doing this. (Property editor? Or matlab function? Or matlab file exchange?) Maybe I can't google well.

So, in order to write my own, it looks to me like the buttonDownFcn on the rectangle function is a start for this. That is, I can use this to listen to mouse clicks on the rectangle itself, but what about mouseclicks on the inside of the rectangle? I can't figure out how to receive them. What about a "buttonUpFcn" don't see one of those. What about w开发者_StackOverflow社区hen I move the cursor around, I see no way to capture those (unless I start querying the figure instead of the rectangle, but that gets to be a huge hassle, and very complicated I would think.)

Thanks for your consideration.

John


If you don't absolutely need rotation, IMRECT will do what you want. Also, if you need to be able to draw oblique lines, IMPOLY, could be helpful, though you may need to write a POSITIONCONSTRAINFCN to guarantee that you're drawing right angles.


One way to do it is to store the location of the top-left and bottom-right rectangle corners and use those to determine whether clicks are inside or outside the rectangle. Those corners will give you the [xmin ymin] and [xmax ymax] values of the rectangle, and you can simply compare the location of the click to those values to determine whether the click is inside or outside the borders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜