How to update position of impoly vertices using setPosition within addNewPositionCallback?
Mostrar comentarios más antiguos
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
Respuestas (1)
Flavio Palmieri
el 4 de Dic. de 2017
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
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!