Add a user define property to freehand object
1 次查看(过去 30 天)
显示 更早的评论
Hi there,
I know that Freehand object does not have a rotatable property like drawrectangle.
Can anyone tell me please how can I add this property to Freehand, so I can rotate my object on the figure?
Nikan
0 个评论
回答(1 个)
Adam Danz
2021-8-3
编辑:Adam Danz
2021-8-3
You could apply your own rotation using a rotation matrix.
% anonymous function to center the obj at (0,0),
% rotate it, and move it back to its original
% center point.
ROIxy = @(h)[h.Position(:,1),h.Position(:,2)];
rotMat = @(h,th)([cosd(th), -sind(th); sind(th), cosd(th)]*(ROIxy(h)-mean(ROIxy(h)))')' + mean(ROIxy(h));
To use the functions above, create a freehand object and they apply the rotation angle in degrees.
Example:
% create freehand obj
z = drawfreehand();
% Plot the center point (red x)
hold on
xl = xlim(); yl = ylim();
cnt = mean(ROIxy(z)); % center point
plot(cnt(1),cnt(2),'rx')
xlim(xl); ylim(yl) % see [1]
% Continually rotate ROI by 12 degrees CCW
while true
z.Position = rotMat(z,12); % see [2]
drawnow
end
Footnotes
[1] I don't know why the axis limits change when adding the + marker but this resets the original axis limits.
[2] rotMat(h,th) rotates ROI object h by th degrees (negative is CW rotation)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!