view - Camera line of sight - MATLAB (original) (raw)

Syntax

Description

view([az](#mw%5F216769a3-f83c-49f5-b3b0-ba50b1481f90),[el](#mw%5Fb3f07b2e-66cd-45eb-bcce-0ab51d2ea36f)) sets the azimuth and elevation angles of the camera's line of sight for the current axes.

example

view([v](#mw%5Fea953980-271f-4993-b008-b2909ad313c2)) sets the line of sight according tov, which is a two- or three-element array:

example

view([dim](#mw%5F0ab447bd-d65b-4d6d-b9f0-ccd65f3329b2)) uses the default line of sight for 2-D or 3-D plots. Specify dim as 2 for the default 2-D view or 3 for the default 3-D view.

example

view([ax](#mw%5F8374955e-902d-43fd-8755-16f640d1cf15),___) specifies the target axes when changing the line of sight.

example

[caz,cel] = view(___) returns the azimuth and elevation angles as caz and cel, respectively. Specify input arguments from any of the previous syntaxes to get the angles for the new line of sight. Or, specify no input arguments to get the angles for the current line of sight.

example

Examples

collapse all

Use the peaks function to get the _x_-, _y_-, and _z_-coordinates of a surface. Then plot the surface and label each axis.

[X,Y,Z] = peaks; surf(X,Y,Z) xlabel('X') ylabel('Y') zlabel('Z')

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type surface.

View the plot using an azimuth of 90 degrees and an elevation of 0 degrees. The new line of sight is along the _x_-axis.

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type surface.

Use the peaks function to get the _x_-, _y_-, and _z_-coordinates of a surface. Then plot the surface and label each axis.

[X,Y,Z] = peaks; surf(X,Y,Z) xlabel('X') ylabel('Y') zlabel('Z')

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type surface.

Display the plot in a 2-D view.

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type surface.

Create a set of _x_-, _y_-, and _z_-coordinates and use them to plot a surface. Then label each axis.

[X,Y] = meshgrid(-5:.5:5); Z = Y.*sin(X) - X.*cos(Y); surf(X,Y,Z) xlabel('X') ylabel('Y') zlabel('Z')

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type surface.

Get the azimuth and elevation angles for this plot.

Change the view by specifying v as the _x_- _y_- and _z_-coordinates of a vector, and return the new azimuth and elevation angles. The new angles are based on a unit vector pointing in the same direction as v.

v = [-5 -2 5]; [caz,cel] = view(v)

Figure contains an axes object. The axes object with xlabel X, ylabel Y contains an object of type surface.

Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 1-by-2 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Use them to create separate but identical line plots.

t = 0:pi/20:10*pi; xt1 = sin(t); yt1 = cos(t); tiledlayout(1,2)

% Left plot ax1 = nexttile; plot3(ax1,xt1,yt1,t) xlabel('X') ylabel('Y') zlabel('Z')

% Right plot ax2 = nexttile; plot3(ax2,xt1,yt1,t) xlabel('X') ylabel('Y') zlabel('Z')

Figure contains 2 axes objects. Axes object 1 with xlabel X, ylabel Y contains an object of type line. Axes object 2 with xlabel X, ylabel Y contains an object of type line.

Change the view of the right plot to a side view along the _x_-axis.

Figure contains 2 axes objects. Axes object 1 with xlabel X, ylabel Y contains an object of type line. Axes object 2 with xlabel X, ylabel Y contains an object of type line.

Input Arguments

collapse all

Azimuth, specified as an angle in degrees from the negative_y_-axis. Increasing this angle corresponds to counterclockwise rotation about the _z_-axis when viewing the_x_-y plane from above.

The default value depends on whether your chart is in a 2-D or 3-D view. For 2-D charts, the default value is 0. For 3-D charts, the default value is-37.5.

Example: view(45,25) sets the azimuth to 45 degrees and the elevation to 25 degrees.

Elevation, specified the minimum angle in degrees between the line of sight and the_x_-y plane. Increasing the elevation from-90 to 90 degrees corresponds to a rotation from the negative _z_-axis to the positive _z_-axis.

The default value depends on whether your chart is in a 2-D or 3-D view. For 2-D charts, the default value is 90. For 3-D charts, the default value is30.

Example: view(45,25) sets the azimuth to 45 degrees and the elevation to 25 degrees.

Line-of-sight vector, specified as one of the following:

Example: view([45 25]) sets the azimuth to 45 degrees and the elevation to 25 degrees.

Example: view([20 25 5]) sets the line of sight to a vector that points in the same direction as the vector [20 25 5].

Dimensions, specified as 2 or 3. This argument sets the azimuth and elevation to the default values that MATLAB uses for a 2-D or 3-D plot.

Value of dim Azimuth Elevation
2 0 90
3 -37.5 30

Target axes, specified as:

If you do not specify this argument, then view modifies the current axes.

More About

collapse all

The line of sight starts at the center of the plot box and points toward the camera. MATLAB defines this line using two angles, the azimuth and the_elevation_. These angles are measured within a 3-D coordinate system that has its origin at the center of the plot box.

3-D coordinate space showing the line of sight vector with the azimuth and elevation angles

Tips

Version History

Introduced before R2006a

expand all

Change the view of multiple axes objects at the same time by specifying theax argument as an array of axes objects.