
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!