Apply affine transforms to graphic objects

Apply affine transform matrix as generated by 'makehgtform' to handle graphic objects or groups.
609 Downloads
Updated 13 Oct 2010

View License

The advantage of the function compared to hgtransform objects is that it operates directly on the XData,YData and ZData of the object which allows ButtonDownFcn callbacks to execute even when the object was moved. Moreover the applied transforms can be undone or redone stepwise as well as objects can be reseted. The transforms are stored as a structure in the 'UserData' of the graphic objects

The function supports line, surface, patch and text objects

Usage:

transform(obj, tmatrix)
[M step]=transform(obj, tmatrix)

applies the transform matrix 'tmatrix' to the graphic objects obj. Obj can be line,surface, patch, text or group objects.
Output 'M' is a cell array of transform matrices and step the index of the last transform applied.

[M step]=transform(obj,'undo',nb_steps) undoes 'nb_steps'

[M step]=transform(obj,'redo',nb_steps) redoes 'nb_steps'

transform(obj,'reset') resets obj to initial value. It deletes all transforms and associated UserData

Example:

%rotate peaks surface by pi/4 around z-axis
obj=surf(peaks);
tmatrix=makehgtform('zrotate',pi/4);
[M step]=transform(obj,tmatrix);

%undo last step
[M step]=transform(obj,'undo',1)

Cite As

Pirmin Borer (2024). Apply affine transforms to graphic objects (https://www.mathworks.com/matlabcentral/fileexchange/29017-apply-affine-transforms-to-graphic-objects), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Object Containers in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0