主要内容

polygonMonotonicity

Find sweep directions that enable efficient, backtrack-free coverage of a polygon

Since R2026a

    Description

    The polygonMonotonicity function analyzes a 2-D polygon and computes sweep directions that result in monotonic coverage of each region. A sweep direction is monotonic if a sweep line moving in that direction can cover the entire region without backtracking. Use this function to identify efficient sweep directions for use with the polygonSweep function.

    For more information on polygon monotonicity, see Monotonicity. To visualize monotonic intervals, use the plotMonotonicity function.

    [isMonotonic,monotonicIntervals] = polygonMonotonicity(poly) finds monotonic angle intervals for the regions in the specified polygon poly. The function returns the first monotonic angle interval it finds for each region. isMonotonic indicates whether the regions have any monotonic intervals.

    example

    [isMonotonic,monotonicIntervals] = polygonMonotonicity(poly,Intervals=intervals) specifies whether to return only the first monotonic interval, or all of the monotonic angle intervals for each region.

    Examples

    collapse all

    Define the geometry of a polygon as a polyshape object.

    poly = polyshape([0 0 1.5 3 3 1.875 1.5 1.1250 0],[0 2 1.5 2 0 0 0.5 0 0]);

    Check if any regions of the polygon are monotonic, and return the monotonic angle intervals for those regions.

    [isMono,intervals] = polygonMonotonicity(poly);

    Plot the monotonic intervals of the polygon.

    hVis = plotMonotonicity(poly);
    axis equal tight
    title(["Polygon and Corresponding","Monotonic Intervals"])
    legend("Polygon","Monotonic Intervals",Location="northeastoutside")

    Figure contains an axes object. The axes object with title Polygon and Corresponding Monotonic Intervals contains 3 objects of type patch, polygon. These objects represent Polygon, Monotonic Intervals.

    You can use these monotonic intervals to plan sweep paths. Sweeping in a monotonic interval ensures that you can fully sweep the corresponding region of a polygon in one direction, without needing to backtrack.

    Store three sweep angles from within the first monotonic angle interval.

    sweepAngles = [intervals(1,1) mean(intervals(1,:)) intervals(1,2)] - pi;

    Define the geometry of the sweep tool. In this case, assume the tool is shaped like a regular pentagon.

    tool = nsidedpoly(5,Radius=0.1);

    Set up three subplots, for showing the sweep paths along the selected sweep angles.

    t = tiledlayout(1,3,Padding="compact",TileSpacing="compact");

    Generate and plot a sweep path for each of the stored sweep angles. Plot the sweep direction arrow and sweep line direction arrow to show their relationships to the sweep angle and path.

    for i = 1:3
    opts = polysweepoptsbous(SweepAngle=sweepAngles(i),BoundaryBehavior="inset",SweepToolGeometry=tool);
    path = polygonSweep(poly,opts);
    
    nexttile
    
    hVis = plotMonotonicity(poly);
    
    hold on
    axis equal tight
    
    % Plot the swept path
    pathHandle = plot(path(:,1),path(:,2));
    
    % Plot the sweep direction arrow and sweep line direction arrows to
    % show their relationships to the sweep angle and path.
    sweepLineDirHandle = exampleHelperHighlightInterval(hVis,sweepAngles(i)+pi/2);
    sweepDirHandle = exampleHelperPlotSweepDirection(poly,sweepAngles(i));
    
    % Add a title to the current tile
    title("Sweep Angle " + num2str(rad2deg(sweepAngles(i)),"%.1f") + "°");
    
    hold off
    end
    
    handles = [hVis.MonotoneIntervals.Children(1), ...
               pathHandle, ...
               sweepDirHandle, ...
               sweepLineDirHandle];
    
    legend(handles,{"Monotonic Interval","Sweep Path","Sweep Direction","Sweep Line Direction"},Location="southoutside",Orientation="vertical");

    Figure contains 3 axes objects. Axes object 1 with title Sweep Angle -36.9° contains 6 objects of type patch, polygon, line, quiver. Axes object 2 with title Sweep Angle 0.0° contains 6 objects of type patch, polygon, line, quiver. Axes object 3 with title Sweep Angle 36.9° contains 6 objects of type patch, polygon, line, quiver. These objects represent Sweep Path, Sweep Line Direction, Sweep Direction.

    Input Arguments

    collapse all

    Polygon to check for monotonicity, specified as a polyshape object.

    Example: polyshape([0 0 1 1],[1 0 0 1]) creates a solid square defined by the four points: (0, 1), (0, 0), (1, 0), and (1, 1).

    Monotonic intervals to return, specified as “first” or “all”.

    • “first” — Returns the first continuous monotonic interval found for each region in poly, starting from 0 degrees, with counterclockwise as the positive rotation direction.

    • “all” — Returns all monotonic intervals for each region in poly.

    Output Arguments

    collapse all

    Monotonic status, returned as an N-element vector of logical values. N is the total number of regions of poly.

    A value of 1 or true indicates that the corresponding region is monotonic at one or more angular intervals. A value of 0 or false indicates that the corresponding region is not monotonic at any angular interval.

    Monotonic angle interval for each region in poly, returned in one of these formats, depending on the value of the intervals argument:

    • "first"N-by-2 matrix. Each row represents the first monotonic sweep-angle range for the corresponding region in poly.

    • "all"N-element cell array. Each cell contains an M-by-2 matrix of all monotonic sweep-angle intervals for the corresponding region in poly.

    N is the number of regions in poly, and M is the number of feasible intervals for a region in poly.

    Use these monotonic angle intervals to determine sweep directions for the polygonSweep function. Each interval defines a range of sweep angles that enables complete coverage of the polygon region without backtracking, resulting in an efficient sweep of that region.

    More About

    collapse all

    Extended Capabilities

    expand all

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2026a