how to force Draggable points to move along a line?

1 回表示 (過去 30 日間)
Mohsen  Davarynejad
Mohsen Davarynejad 2013 年 5 月 14 日
回答済み: Roman Willi 2018 年 7 月 2 日
Hi All. I would like to use impoint to generate a draggable point. But I want to force it to move along a line. I try to do so by setPosition, but it does not work properly. Any help?
function test()
h1 = impoint(gca,[5, 5])
setString(h1,'h1');
addNewPositionCallback(h1,@(h1) CallThis(1,[1 2],[ 2 ]));
axis([0 10 0 10])
function CallThis(varargin)
pos = h1.getPosition()
h1.setPosition([pos(1,1), 2*pos(1,1)])
end
end
  2 件のコメント
Jan
Jan 2013 年 5 月 14 日
"It does not work properly" is a vague description only. Please do not let us guess, but explain the difference between your expectations and the results.
Mohsen  Davarynejad
Mohsen Davarynejad 2013 年 5 月 14 日
Sure, I mean that the point moves freely. It does not move along the line. Basically the setPosition command within the CallThis function does not update the position of the point.

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

回答 (1 件)

Roman Willi
Roman Willi 2018 年 7 月 2 日
move along a line:
obj.dragPoint = impoint();
hp = addNewPositionCallback(obj.dragPoint,@(pos) point_move(obj,pos));
function point_move(obj, pos)
pos = [.....] % Calc Y Point of line
axilim = [.....] % X axi limit
fcn = makeConstrainToRectFcn('impoint',axilim, [pos pos]);
setPositionConstraintFcn(obj.dragPoint, fcn);
end

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by