Main Content

camroll

Set or query roll angle of camera for Site Viewer

Since R2025a

    Description

    camroll(viewer,roll) sets the roll angle of the camera for the specified Site Viewer. Setting the roll angle rotates the camera around its lens. For more information about how camera rotations affect your view of the Site Viewer, see How Camera Orientation Affects View.

    This function requires the CoordinateSystem property of the Site Viewer object to be "geographic".

    Camera with double-headed arrow around lens

    example

    camroll(viewer) displays the roll angle of the camera.

    rollOut = camroll(___) returns the roll angle of the camera. You can return the roll 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. Verify that the CoordinateSystem property of the Site Viewer object is "geographic".

    viewer = siteviewer;
    viewer.CoordinateSystem
    ans = 
    "geographic"
    

    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.

    campos(viewer,-3.1519,37.3561,5500)
    campitch(viewer,0)

    View of Mount Kilimanjaro

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

    rollOut = camroll(viewer)
    rollOut = 
    360
    

    Rotate the camera in a clockwise direction by changing the roll angle to 30 degrees. When you rotate the camera in a clockwise direction, the mountain appears to move in a counterclockwise direction.

    camroll(viewer,30)

    Adjusted view of Mount Kilimanjaro

    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

    The CoordinateSystem property of the siteviewer object must be "geographic".

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

    Output Arguments

    collapse all

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