How can I change the slope of a line on a GUI real time (with mouse)?

2 次查看(过去 30 天)
Hello, my name is Christopher. I am currently trying to create a GUI that uses third order polinomial interpolation, to generate a curve between two points selected by the user. This I can do. But I also am required to have the ability to change the slope of each exit or entry point (that would be the slope with which the interpolation function leaves or arrives at the point). To do this, I have to use a line which is tangential to the curve at that point. For the interpolation, I am using the basic method, which requires the following border conditions: the evaluation of the function at the points in between which I wish to do the interpolation, and the slope at these points. These conditions are given by the user. With this information, I intend to generate the apropiate lines at each point. Each line will describe the slope at that point, so I can get those values into a vector and then introduce the vector into my interpolation formula. However, after that the user must be able to change the slope of those lines by clicking on them and dragging them in different directions. The line must not change position, but only orientation. The graph must change real time, while the user is changing the slope. I can do most of it, but I have no idea how to program for the line that changes direction by dragging

回答(1 个)

Nirav Sharda
Nirav Sharda 2017-4-19
You can achieve this behavior by combining a few things. You can use the 'WindowButtonDownFcn' and 'WindowButtonUpFcn' callbacks to find mouse button clicks and releases on the figure window. More information on these callbacks can be found on Figure Properties . Here you can use the Position property to identify if the mouse click was around a line based on the xlimits and ylimits of the line. On the 'WindowButtonUpFcn' callback that is called when the mouse is released you can calculate the angle of rotation based on the original and final mouse position and then rotate the line by that angle from the center. There is a MATLAB Answers post that talks about how a line can be rotated about the center by an angle. Here is the link . Also in the 'WindowButtonDownFcn' callback on the figure window, you can change the Pointer to 'fleur' to show the dragging behaviour and this can be changed back to 'arrow' on the 'WindowButtonUpFcn'. All these are mentioned in the Figure Properties documentation page attached above.

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by