How to update position of impoly vertices using setPosition within addNewPositionCallback?

3 ビュー (過去 30 日間)
Megan
Megan 2016 年 9 月 28 日
回答済み: Flavio Palmieri 2017 年 12 月 4 日
Hi, I'm having difficulty with setPosition when used inside addNewPositionCallback with impoly. The vertices are not updating their position when a point is dragged. In this case vertex 5 remains unchanged when vertex 1 is dragged. Please see base example code below.
poly=[ -136 115; 40 115; 216 115; 216 15; 216 -185; 40 -185; -136 -185; -136 15];
figure
p = impoly(gca, poly) ;
addNewPositionCallback(p,@(pos)updatePos(pos));
function updatePos(pos)
upDate=pos;
upDate(5,:)=upDate(1,:);
setPosition(p,upDate);
end
end

回答 (1 件)

Flavio Palmieri
Flavio Palmieri 2017 年 12 月 4 日
You need to pass p parameter in the callback function like this:
addNewPositionCallback(p,@(pos)updatePos(p,pos));
and then edit the function:
function updatePos(p,pos)
upDate=pos;
upDate(5,:)=upDate(1,:);
setPosition(p,upDate);
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by