Add a user define property to freehand object

2 vues (au cours des 30 derniers jours)
Nikan Fakhari
Nikan Fakhari le 2 Août 2021
Modifié(e) : Adam Danz le 3 Août 2021
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

Réponses (1)

Adam Danz
Adam Danz le 3 Août 2021
Modifié(e) : Adam Danz le 3 Août 2021
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)

Catégories

En savoir plus sur 3-D Scene Control dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by