MATLAB Function Reference |
Create an hgtransform graphics object
Syntax
Description
h = hgtransform
creates an hgtransform object and returns its handle.
h = hgtransform('
creates an hgtransform object with the property value settings specified in the argument list.PropertyName
',PropertyValue,...)
Hgtransform objects can contain other objects and thereby enable you to treat the hgtransform and its children as a single entity with respect to visibility, size, orientation, etc. You can group objects together by parenting them to a single hgtransform object (i.e., setting the object's Parent
property to the hgtransform object's handle). For example,
The primary advantage of parenting objects to an hgtransform object is that it provides the ability to perform transformations (e.g., translation, scaling, rotation, etc.) on the child objects in unison.
An hgtransform object can be the parent of any number of axes children including other hgtransform objects.
The parent of an hgtransform object is either an axes object or another hgtransform.
Although you cannot see an hgtransform object, setting its Visible
property to off
makes all its children invisible as well.
Note Many plotting functions clear the axes (i.e., remove axes children) before drawing the graph. Clearing the axes also deletes any hgtransform objects in the axes. |
More Information
Transforming a Group of Objects
This example shows how to create a 3-D star with a group of surface objects parented to a single hgtransform object. The hgtransform object is then rotated about the z-axis while its size is scaled.
Note If you are using the MATLAB help browser, you can run this example or open it in the MATLAB editor. |
[x y z] = cylinder([.2 0]); h(1) = surface(x,y,z,'FaceColor','red'); h(2) = surface(x,y,-z,'FaceColor','green'); h(3) = surface(z,x,y,'FaceColor','blue'); h(4) = surface(-z,x,y,'FaceColor','cyan'); h(5) = surface(y,z,x,'FaceColor','magenta'); h(6) = surface(y,-z,x,'FaceColor','yellow');
eye
).
for r = 1:.1:2*pi% Z-axis rotation matrix
Rz = makehgtform('zrotate',r);% Scaling matrix
Sxy = makehgtform('scale',r/4);% Concatenate the transforms and
% set the hgtransform Matrix property
set(t,'Matrix',Rz*Sxy) drawnow end pause(1)
Transforming Objects Independently
This example creates two hgtransform objects to illustrate how each can be transformed independently within the same axes. One of the hgtransform objects has been moved (by translation) away from the origin.
Note If you are using the MATLAB help browser, you can run this example or open it in the MATLAB editor. |
[x y z] = cylinder([.3 0]); h(1) = surface(x,y,z,'FaceColor','red'); h(2) = surface(x,y,-z,'FaceColor','green'); h(3) = surface(z,x,y,'FaceColor','blue'); h(4) = surface(-z,x,y,'FaceColor','cyan'); h(5) = surface(y,z,x,'FaceColor','magenta'); h(6) = surface(y,-z,x,'FaceColor','yellow');
t1
, then copy the surface objects and parent the copies to hgtransform t2
.
t2
has already been translated away from the origin, so to rotate it about its z-axis you must first translate it to its original position. You can do this with the identity matrix (eye
).
Setting Default Properties
You can set default hgtransform properties on the axes, figure, and root levels:
set(0,'DefaultHgtransformPropertyName',propertyvalue,...) set(gcf,'DefaultHgtransformPropertyName',propertyvalue,...) set(gca,'DefaultHgtransformPropertyName',propertyvalue,...)
where PropertyName
is the name of the hgtransform property and propertyvalue
is the value you are specifying. Use set
and get
to access hgtransform properties.
See Also
For more information about transforms, see Tomas Moller and Eric Haines, Real-Time Rendering, A K Peters, Ltd., 1999.
Group Objects for more information and examples.
Hgtransform Properties for property descriptions
hgsave | Hgtransform Properties |
© 1994-2005 The MathWorks, Inc.