Main Content

camheading

Set or query heading angle of camera for Site Viewer

Since R2025a

    Description

    camheading(viewer,heading) sets the heading angle of the camera for the specified Site Viewer. Setting the heading angle rotates the camera to the left or right. 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 left and right

    example

    camheading(viewer) displays the heading angle of the camera.

    headingOut = camheading(___) returns the heading angle of the camera. You can return the heading 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

    Query the CoordinateSystem property of the Site Viewer object. The result, "geographic", indicates that increasing the heading angle rotates the camera to the right.

    viewer.CoordinateSystem
    ans = 
    "geographic"
    

    Query the heading angle. The output heading angle is 360 degrees, which is equivalent to a heading angle of 0 degrees.

    headingOut = camheading(viewer)
    headingOut = 
    360
    

    Rotate the camera to the right by changing the heading angle to 20 degrees.

    camheading(viewer,20)

    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 CoordinateSystem property of the Site Viewer object. The result, "cartesian", indicates that increasing the heading angle rotates the camera to the left.

    viewer.CoordinateSystem
    ans = 
    "cartesian"
    

    Query the heading angle.

    headingOut = camheading(viewer)
    headingOut = 
    0
    

    Rotate the camera to the left by adding 20 degrees to the heading angle.

    heading = headingOut + 20;
    camheading(viewer,heading)

    Adjusted view of the 3-D model

    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

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

    Output Arguments

    collapse all

    Heading 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®.