Contenu principal

roadrunner.hdmap.Polygon

R2026b

Define polygon geometry for RoadRunner HD Map using MATLAB

Since R2022b

    Description

    A roadrunner.hdmap.Polygon object defines the geometry of a polygon for RoadRunner HD Map objects. It uses one exterior boundary, and can include interior boundaries to represent holes. By adding multiple Polygon objects to a roadrunner.hdmap.MultiPolygon object, you can use them to assign geometry to map features such as junctions, represented by roadrunner.hdmap.Junction objects. For an example of how to create a complete T-junction with roads, maneuver lanes, and traffic signal phases that include bulb-level signal control, see Build Signalized Junction Using RoadRunner HD Map.

    Creation

    Description

    polygon = roadrunner.hdmap.Polygon creates an empty Polygon object.

    example

    polygon = roadrunner.hdmap.Polygon(PropertyName=Value) specifies one or more ExteriorRing and InteriorRings properties using name-value arguments.

    Properties

    expand all

    Outer boundary of the polygon, specified as an N-by-2 or N-by-3 matrix. You must specify a closed boundary by specifying identical coordinates for the first and last vertices.

    Data Types: double

    Boundaries of holes within the polygon, specified as a cell array in which each cell contains an N-by-2 or N-by-3 matrix of coordinate points representing a closed boundary. An N-by-2 matrix contains x- and y-coordinates, and an N-by-3 matrix contains x-, y-, and z-coordinates.

    RoadRunner Scene Builder does not use interior rings when building a scene. However, it preserves interior ring definitions after import, so you can access and export them later.

    If no holes exist, specify an empty cell array {}.

    Data Types: cell

    Examples

    collapse all

    Create polygon geometry with and without holes for a RoadRunner HD Map by specifying a closed exterior boundary and an optional interior boundary.

    Define a closed outer ring that traces the polygon boundary.

    outer = [-10 -10; 10 -10; 10 10; -10 10; -10 -10];

    Define a closed inner ring to create a hole inside the polygon.

    inner = [-3 -3; 3 -3; 3 3; -3 3; -3 -3];

    Create a roadrunner.hdmap.Polygon object that uses only the outer ring. Leave the InteriorRings property empty, so the polygon represents a solid region.

    polyNoHole = roadrunner.hdmap.Polygon(ExteriorRing=outer) % Polygon without a hole
    polyNoHole = 
      Polygon with properties:
    
         ExteriorRing: [5×2 double]
        InteriorRings: {}
    
    

    Create a roadrunner.hdmap.Polygon object that includes the inner ring in the InteriorRings property, defining a hole.

    polyWithHole = roadrunner.hdmap.Polygon(ExteriorRing=outer,InteriorRings={inner}) % Polygon with a hole
    polyWithHole = 
      Polygon with properties:
    
         ExteriorRing: [5×2 double]
        InteriorRings: {[5×2 double]}
    
    

    Convert the ring coordinates into polyshape objects so you can plot them in MATLAB™. Use NaN values to separate the outer and inner rings of polygons that contain holes.

    pNoHole = polyshape(outer(:,1),outer(:,2),Simplify=true);
    x = [outer(:,1); NaN; inner(:,1)];
    y = [outer(:,2); NaN; inner(:,2)];
    pWithHole = polyshape(x,y,Simplify=true);

    Plot the solid polygon and the polygon with a hole in separate subplots using consistent axes and styling.

    figure
    
    % Polygon without a hole
    subplot(1,2,1)
    plot(pNoHole,FaceColor=[0.8 0.9 1.0],FaceAlpha=0.3,EdgeColor='k',LineWidth=2)
    axis equal
    grid on
    title("Polygon without Hole")
    xlabel("X(m)")
    ylabel("Y(m)")
    
    % Polygon with a hole
    subplot(1,2,2)
    plot(pWithHole,'FaceColor',[0.8 1.0 0.8],FaceAlpha=0.3,EdgeColor='k',LineWidth=2)
    axis equal
    grid on
    title("Polygon with Hole")
    xlabel("X(m)")
    ylabel("Y(m)")

    Figure contains 2 axes objects. Axes object 1 with title Polygon without Hole, xlabel X(m), ylabel Y(m) contains an object of type polygon. Axes object 2 with title Polygon with Hole, xlabel X(m), ylabel Y(m) contains an object of type polygon.

    Version History

    Introduced in R2022b