Main Content

campitch

Set or query pitch angle of camera for Site Viewer

Since R2025a

    Description

    campitch(viewer,pitch) sets the pitch angle of the camera for the specified Site Viewer. Setting the pitch angle tilts the camera up or down. For more information about how camera rotations affect your view of the Site Viewer, see How Camera Orientation Affects View.

    Camera with double-headed arrow in front of lens, pointing up and down

    example

    campitch(viewer) displays the pitch angle of the camera.

    pitchOut = campitch(___) returns the pitch angle of the camera. You can return the pitch angle using any of the input argument combinations from the previous syntaxes.

    example

    Examples

    collapse all

    Create a Site Viewer. By default, Site Viewer displays a 3-D globe using satellite imagery. Position the camera near Mount Kilimanjaro by specifying a latitude, longitude, and ellipsoidal height. Set the pitch angle to 0 degrees, so that the camera points across the summit.

    viewer = siteviewer;
    campos(viewer,-3.1519,37.3561,5500)
    campitch(viewer,0)

    View of Mount Kilimanjaro

    Tilt the camera up by changing the pitch angle to 15 degrees.

    campitch(viewer,15)

    Adjusted view of Mount Kilimanjaro

    Create a Site Viewer that displays a 3-D model from an STL file. The file models a small conference room with one table and four chairs.

    viewer = siteviewer(SceneModel="conferenceroom.stl");

    3-D model of a table and four chairs

    Query the pitch angle.

    pitchOut = campitch(viewer)
    pitchOut = 
    0
    

    Tilt the camera up by adding 15 degrees to the pitch angle.

    pitch = pitchOut + 15;
    campitch(viewer,pitch)

    The same 3-D model, with the bottom of the model out-of-view of the camera

    When you display data in a Site Viewer, the Site Viewer focuses on the data by moving the camera. To preserve the camera view, before you plot the data, query the camera position and camera angles. Then, after you plot the data, reset the camera position and camera angles.

    Create a Site Viewer that displays buildings in Manhattan. For more information about the OpenStreetMap® file, see [1]. Navigate to an area of interest by interacting with the Site Viewer.

    viewer = siteviewer(Buildings="manhattan.osm",Basemap="openstreetmap");

    Site Viewer with buildings

    Query the position of the camera and the heading, pitch, and roll angles of the camera. Assign each value to a variable.

    [lat,lon,height] = campos(viewer);
    heading = camheading(viewer);
    pitch = campitch(viewer);
    roll = camroll(viewer);

    Create and display a transmitter site. Note that the camera zooms to the site.

    tx = txsite(Latitude=40.704,Longitude=-74.0155);
    show(tx)

    Close-up view of a transmitter site

    Reset the view using the stored camera position and camera angles.

    campos(viewer,lat,lon,height)
    camheading(viewer,heading)
    campitch(viewer,pitch)
    camroll(viewer,roll)

    The original camera view, including the transmitter site

    [1] The OpenStreetMap file is downloaded from https://www.openstreetmap.org, which provides access to crowd-sourced map data all over the world. The data is licensed under the Open Data Commons Open Database License (ODbL), https://opendatacommons.org/licenses/odbl/.

    Input Arguments

    collapse all

    Site Viewer, specified as a siteviewer object.1

    Pitch angle of the camera, in degrees, specified as a numeric scalar in the range [–90, 90].

    Output Arguments

    collapse all

    Pitch angle of the camera, in degrees, returned as a numeric scalar.

    More About

    collapse all

    Tips

    When the pitch angle is near –90 or 90 degrees, the camera loses one rotational degree of freedom. As a result, when you change the roll angle, the heading angle might change instead. This phenomenon is called gimbal lock. To avoid the effects of gimbal lock, call the camheading function instead of the camroll function.

    Version History

    Introduced in R2025a

    See Also

    Functions

    Objects


    1 Alignment of boundaries and region labels are a presentation of the feature provided by the data vendors and do not imply endorsement by MathWorks®.