makehgtform

Creates a 4-by-4 transformation matrix for translation, scaling and rotation in 3-D.

Category: Graphics > Formatting and Annotation

Syntax

M = makehgtform('translate', [tx ty tz])

Translation by the given amounts.

M = makehgtform('scale', s)

Uniform scaling, or [sx sy sz] for different factors.

M = makehgtform('xrotate', t)

Rotation by t radians about the x-axis. 'yrotate' and 'zrotate' act on the other axes.

M = makehgtform('axisrotate', [ax ay az], t)

Rotation by t radians about an arbitrary axis.

Description

The matrix acts on column vectors [x; y; z; 1]. Translation values sit in the last column, scale factors on the diagonal, and a rotation fills the upper-left 3-by-3 block.

Several transformations can be given in one call. They are combined, and the matrices are multiplied so that the last one listed is applied first. The result can also be built by multiplying the single matrices yourself.

Input arguments

t
Angle in radians.
[tx ty tz]
Translation vector.

Output arguments

M
4-by-4 homogeneous transformation matrix, to be used as the Matrix property of an hgtransform object.

Example

Translate and scale

T = makehgtform('translate', [1 2 3])
S = makehgtform('scale', 2);
M = T * S;
M * [1; 1; 1; 1]
Output
T = 4×4

     1     0     0     1
     0     1     0     2
     0     0     1     3
     0     0     0     1
ans = 4×1

     3
     4
     5
     1

See also

viewmtx rotate view pbaspect