Apply affine transforms to graphic objects

Apply affine transform matrix as generated by 'makehgtform' to handle graphic objects or groups.

You are now following this Submission

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 (2026). Apply affine transforms to graphic objects (https://www.mathworks.com/matlabcentral/fileexchange/29017-apply-affine-transforms-to-graphic-objects), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0