To fix the position of the vertices in relation to one another, one can use the SETVERTICESDRAGGABLE function to set the property to 'false'.
To constrain the polygon to be immobile in the figure, use the MAKECONSTRAINTORECTFCN and the SETPOSITIONCONSTRAINTFCN functions to create the minimum rectangular bounding box around the polygon, and to constrain the polygon to be in that rectangle.
The following code demonstrates how to use these functions:
figure, imshow('gantrycrane.png');
position = [188,30; 189,142; 93,141; 13,41; 14,29];
h = impoly(gca,position);
setColor(h,'yellow');
setVerticesDraggable(h, logical(0))
xmin = min(position(:,1));
xmax = max(position(:,1));
ymin = min(position(:,2));
ymax = max(position(:,2));
fcn = makeConstrainToRectFcn('impoly',[xmin xmax],[ymin ymax]);
setPositionConstraintFcn(h,fcn);
Best Answer