Main Content

terrainHeight

Returns terrain height in UAV scenarios

Since R2021a

    Description

    heights = terrainHeight(scene,x,y) returns the terrain heights of the specified xy-positions for the terrain data for a uavScenario object.

    example

    heights = terrainHeight(___,Name,Value) specifies additional options using name-value arguments. Enclose each Name in quotes.

    Examples

    collapse all

    This example shows how to add terrain and custom building mesh to a UAV scenario.

    Add Terrain Surface

    Add terrain surface based on terrain elevation data from the n39_w106_3arc_v2.dt1 DTED file.

    addCustomTerrain("CustomTerrain","n39_w106_3arc_v2.dt1");
    scenario = uavScenario("ReferenceLocation", [39.5 -105.5 0]);
    addMesh(scenario,"terrain", {"CustomTerrain", [-200 200], [-200 200]}, [0.6 0.6 0.6]);
    show3D(scenario);

    Figure contains an axes object. The axes object with xlabel East (m), ylabel North (m) contains an object of type patch.

    Add Buildings

    Add a couple custom building meshes using vertices and polygon meshes into the scenario. Use the terrainHeight function to get ground height for each build base.

    buildingCenters = [-50, -50; 100 100];
    
    buildingHeights = [30 100];
    buildingBoundary = [-25 -25; -25 50; 50 50; 50 -25];
    for idx = 1:size(buildingCenters,1)
        buildingVertices = buildingBoundary+buildingCenters(idx,:);
        buildingBase = min(terrainHeight(scenario,buildingVertices(:,1),buildingVertices(:,2)));
        addMesh(scenario,"polygon", {buildingVertices, buildingBase+[0 buildingHeights(idx)]}, [0.3922 0.8314 0.0745]);
    end
    
    show3D(scenario);
    view([0 15])

    Figure contains an axes object. The axes object with xlabel East (m), ylabel North (m) contains 3 objects of type patch.

    Remove Custom Terrain

    Remove the custom terrain that was imported.

    removeCustomTerrain("CustomTerrain")

    Input Arguments

    collapse all

    UAV scenario, specified as a uavScenario object.

    x-positions in scenario specified as a vector or matrix of scalar values in meters. If specified as a matrix, the y input and heights output are also a matrix of the same size.

    Example: [1 2 0.5 -0.97]

    Data Types: double

    y-positions in scenario specified as a vector or matrix of scalar values in meters. If specified as a matrix, the x input and heights output are also a matrix of the same size.

    Example: [1 2 0.5 -0.97]

    Data Types: double

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

    Example: h = terrainHeight(scene,x,y,"UseLatLon",true) uses latitude and longitude for the x and y inputs.

    Enable latitude and longitude coordinates, specified as true or false.

    • When specified as true, the x and y coordinates are interpreted as longitude and latitude, respectively.

    • When specified as false, the x and y coordinates are interpreted as Cartesian coordinates.

    Reference frame of coordinates, specified as an inertial frame name defined in the InertialFrames property of the uavScenario object scene. You can add new inertial frames to the scenario using the addInertialFrame object function.

    Output Arguments

    collapse all

    Terrain heights at each position, returned as a vector or matrix of scalar values in meters. If returned as a matrix, the x and y inputs are also a matrix of the same size.

    Example: [1 2 0.5 -0.97]

    Data Types: double

    Version History

    Introduced in R2021a