필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Christopher Teale
Christopher Teale 2017년 4월 12일
답변: Nirav Sharda 2017년 4월 19일
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에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by