viewmtx

Returns the 4-by-4 matrix that projects 3-D points onto the 2-D screen for a given viewpoint.

Category: Graphics > Formatting and Annotation

Syntax

T = viewmtx(az, el)

Returns the orthographic transformation matrix for azimuth az and elevation el, in degrees.

Description

The matrix rotates the data so that the viewer looks along the chosen direction. Multiplying it by a point [x; y; z; 1] gives the screen coordinates in the first two entries of the result and the depth in the third. It is the same transformation that view applies to axes.

Use it to project 3-D data to 2-D by hand, for example to draw a 3-D object with plot or to compute which points are in front.

Input arguments

az, el
Azimuth and elevation of the viewpoint in degrees, with the same meaning as in view.

Output arguments

T
4-by-4 matrix acting on homogeneous column vectors [x; y; z; 1].

Example

Project a point

T = viewmtx(30, 30)
p = T * [1; 0; 0; 1]
Output
T = 4×4

    0.8660    0.5000         0         0
   -0.2500    0.4330    0.8660         0
    0.4330   -0.7500    0.5000         0
         0         0         0    1.0000
p = 4×1

    0.8660
   -0.2500
    0.4330
    1.0000

Notes

MatLivre supports only the orthographic form. The variants with a perspective angle (viewmtx(az, el, phi)) raise an error.

See also

view makehgtform pbaspect camlight