simplify
Simplify polyshape
boundaries
Description
polyout = simplify(
returns a
polyin
)polyshape
object made up of the boundaries of the polygon
polyin
with all vertex duplicates removed, and all boundary
intersections and improper nesting resolved.
Examples
Intersecting Boundary
Create and plot a polygon that contains a boundary intersection.
P = [0 0; 1 1; 1 0; 0.5 0.5; 0 1; 0 0];
polyin = polyshape(P,'Simplify',false)
polyin = polyshape with properties: Vertices: [5x2 double] NumRegions: 1 NumHoles: 0
plot(polyin)
Use the simplify
function to remove the intersection, which produces a well-defined polygon. Simplifying the polygon maintains the boundary shape, but splits the polygon into two distinct regions.
polyout = simplify(polyin)
polyout = polyshape with properties: Vertices: [7x2 double] NumRegions: 2 NumHoles: 0
Input Arguments
polyin
— Input polyshape
scalar | vector | matrix | multidimensional array
Input polyshape
, specified as a scalar, vector, matrix,
or multidimensional array.
Data Types: polyshape
TF
— Collinear vertices indicator
false
| true
Collinear vertices indicator, specified as false
or
true
:
false
— Remove collinear points so that the outputpolyshape
contains the fewest vertices necessary to define the boundaries.true
— Keep all collinear points as vertices.
When the 'KeepCollinearPoints'
parameter is not
specified, its value is automatically set to the value used when creating
the input polyshape
.
Data Types: logical
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Dynamic memory allocation must be enabled for code generation.
Name-value pair must be compile time constant.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
Version History
Introduced in R2017bR2024b: Improved performance when simplifying polyshape
objects with
many boundaries
The simplify
function shows improved performance when
operating on polyshape
objects with many boundaries. For example, this code
simplifies a polyshape
object with 11,100 vertices. The code is
about 23x faster than in the previous release.
function t = timingTest n = 300; x = (1:n)'*[sind(0:10:360),NaN]; y = (1:n)'*[cosd(0:10:360),NaN]; p = polyshape(x(:),y(:),Simplify=false); f = @() simplify(p); t = timeit(f); end
The approximate execution times are:
R2024a: 0.28 s
R2024b: 0.012 s
The code was timed on a Windows® 11, AMD EPYC™ 74F3 24-Core Processor @ 3.19 GHz test system by calling the
timingTest
function.
See Also
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)