主要内容

plotMonotonicity

Display monotone sweep-angle intervals of polygon

Since R2026a

    Description

    The plotMonotonicity function plots a polygon specified as a polyshape object, and its monotonic intervals. The concave regions of a polyshape determine where the polygon is monotonic, so plotMonotonicity displays these intervals, offset by positive 90 degrees, so that they align with the concave regions that define them. This alignment helps clarify how the geometry of the polygon influences its monotonicity.

    Visualizing monotonicity is especially helpful when planning sweep-based coverage of regions using the polygonSweep function. In a sweep, the sweep direction refers to the direction of motion, while the sweep lines are oriented positive 90 degrees from that direction. Because plotMonotonicity displays the monotonic intervals with this same positive 90° offset, you can interpret the plotted intervals as the valid sweep-line angles. Then, you can infer the corresponding valid sweep angles and directions. The figure illustrates how these intervals relate to the sweep angles and the resulting sweep path, assuming a back-and-forth (boustrophedon) pattern.

    For more information about polygon monotonicity, see the Monotonicity section of the polygonMonotonicity function.

    plotMonotonicity(poly) plots the specified polygon and the first monotonic interval within a concave region of it.

    example

    plotMonotonicity(poly,Name=Value) specifies plot options using one or more name-value arguments. For example Intervals="all" plots all of the monotonic intervals for each region of the polygon.

    hVis = plotMonotonicity(___) returns the handles of the plotted visuals using any combination of input arguments from previous syntaxes.

    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 for which to plot 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).

    Name-Value Arguments

    collapse all

    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.

    Example:

    plotMonotonicity(poly,Parent=ax1,Intervals="all") specifies ax1 as the axes in which to plot the polygon and all of its associated monotonic intervals.

    Parent axes, specified as an Axes object. This argument specifies the axes in which to plot poly and monotonic intervals. By default, the function plots the polyshape and monotonic intervals in the active axes. For more information, see Axes Properties.

    Example:

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

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

      • Note that this also plots the complementary interval of the first monotonic interval. For example, if the monotonic interval is [0 pi/2], then plotMonotonicity plots [pi 3*pi/2], as well.

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

    Data Types: char | string

    Output Arguments

    collapse all

    Handles to the plotted visuals, returned as a monotonicityHandles object with these properties:

    • Polyshape — Represents the handles of plotted polyshape regions as an N-element array of Polyshape objects.

    • ConcaveIntervals — Represents the handles of the concave regions of the polyshape as an N-element array of Patch objects.

    • MonotoneIntervals — Represents the handles of the plotted monotone intervals as an N-element array of Group objects. See hggroup for more details.

    N is the total number of polyshape regions.

    Version History

    Introduced in R2026a